lloydroc / ebyte-sx1276

EByte E32 for the Raspberry Pi on Linux
Apache License 2.0
20 stars 5 forks source link

feat: add Dockerfile #17

Closed renanqts closed 2 years ago

renanqts commented 2 years ago

@lloydroc would be great if we have Dockerfile in this repo. Most of my automation at home runs in k3s, meaning that a container like this one helps a lot.

lloydroc commented 2 years ago

Thanks we can add a Docker file. Don't we need to mount the UART from the raspberry PI into the pod? Seems like we'd also need to expose UDP or TCP sockets instead of the Unix Domain sockets.

renanqts commented 2 years ago

Don't we need to mount the UART from the raspberry PI into the pod?

Yes, we need it. It can be achieved in the Kubernetes manifest. You can mount it there.

Seems like we'd also need to expose UDP or TCP sockets instead of the Unix Domain sockets.

It would be great if we have, but we can also achieve it by sharing volumes between containers in the same POD

lloydroc commented 2 years ago

OK I'd be happy to add UDP sockets instead of the Unix Domain sockets, any preference UDP over TCP?

renanqts commented 2 years ago

TCP is easy to configure in the readiness probe I guess

renanqts commented 2 years ago

@lloydroc

I was testing it in ubuntu, and I faced with

ERROR [EBADF Bad file descriptor] error reading from stdin

my best guess is it is some wrong output in reading UART. Do you have some clue?

lloydroc commented 2 years ago

Looks like processes in containers don't have stdin open when started. My guess would be since we are running in the foreground and not as a daemon it is failing because only the daemon closes stdin. Let me see if we can do without a new option or perhaps we don't need to have a fatal error if stdin is open.

lloydroc commented 2 years ago

If you can make modifications change this outside the daemon option an rerun.

https://github.com/lloydroc/ebyte-sx1276/blob/ebffb7f69edc60c370dee756af1a56833c26a950/src/options.c#L336

On Sun, Nov 28, 2021, 11:08 AM Renan Rodrigues @.***> wrote:

I was testing it in ubuntu, and I faced with

ERROR [EBADF Bad file descriptor] error reading from stdin

My best guess is it is some wrong output in reading UART. Do you have some clue?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/lloydroc/ebyte-sx1276/pull/17#issuecomment-981127646, or unsubscribe https://github.com/notifications/unsubscribe-auth/AASHO6TQBOTFW2MLYZ7NYYLUOJV2HANCNFSM5IZG6JJQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

lloydroc commented 2 years ago

Better yet just change this to zero.

https://github.com/lloydroc/ebyte-sx1276/blob/ebffb7f69edc60c370dee756af1a56833c26a950/src/options.c#L66

On Sun, Nov 28, 2021, 11:34 AM Lloyd Rochester @.***> wrote:

If you can make modifications change this outside the daemon option an rerun.

https://github.com/lloydroc/ebyte-sx1276/blob/ebffb7f69edc60c370dee756af1a56833c26a950/src/options.c#L336

On Sun, Nov 28, 2021, 11:08 AM Renan Rodrigues @.***> wrote:

I was testing it in ubuntu, and I faced with

ERROR [EBADF Bad file descriptor] error reading from stdin

My best guess is it is some wrong output in reading UART. Do you have some clue?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/lloydroc/ebyte-sx1276/pull/17#issuecomment-981127646, or unsubscribe https://github.com/notifications/unsubscribe-auth/AASHO6TQBOTFW2MLYZ7NYYLUOJV2HANCNFSM5IZG6JJQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

renanqts commented 2 years ago

I was running directly in the OS (I'm also using Ubuntu as node :D), but I will try this. Thanks.

renanqts commented 2 years ago

It worked. One more time, thanks. Should we make it optional? Actually, I didn't get it. If it is required to be 0 in non daemon and daemon, why it is 1 by default?

lloydroc commented 2 years ago

Yes, will look for a fix on the stdin option. I cannot seem to get past this error to test it on my Raspberry Pi 4. I plan to make a docker-compose file to test it as I don't have a k8s setup in place.

Step 3/5 : RUN apt-get update && apt-key add gpg && apt-get install -y         ca-certificates         build-essential         wget
 ---> Running in 5a3f87eadf22
Get:1 http://ports.ubuntu.com/ubuntu-ports focal InRelease [265 kB]
Get:2 http://ports.ubuntu.com/ubuntu-ports focal-updates InRelease [114 kB]
Get:3 http://ports.ubuntu.com/ubuntu-ports focal-backports InRelease [101 kB]
Get:4 http://ports.ubuntu.com/ubuntu-ports focal-security InRelease [114 kB]
Err:1 http://ports.ubuntu.com/ubuntu-ports focal InRelease
  At least one invalid signature was encountered.
Err:2 http://ports.ubuntu.com/ubuntu-ports focal-updates InRelease
  At least one invalid signature was encountered.
Err:3 http://ports.ubuntu.com/ubuntu-ports focal-backports InRelease
  At least one invalid signature was encountered.
Err:4 http://ports.ubuntu.com/ubuntu-ports focal-security InRelease
  At least one invalid signature was encountered.
Reading package lists...
W: GPG error: http://ports.ubuntu.com/ubuntu-ports focal InRelease: At least one invalid signature was encountered.
E: The repository 'http://ports.ubuntu.com/ubuntu-ports focal InRelease' is not signed.
W: GPG error: http://ports.ubuntu.com/ubuntu-ports focal-updates InRelease: At least one invalid signature was encountered.
E: The repository 'http://ports.ubuntu.com/ubuntu-ports focal-updates InRelease' is not signed.
W: GPG error: http://ports.ubuntu.com/ubuntu-ports focal-backports InRelease: At least one invalid signature was encountered.
E: The repository 'http://ports.ubuntu.com/ubuntu-ports focal-backports InRelease' is not signed.
W: GPG error: http://ports.ubuntu.com/ubuntu-ports focal-security InRelease: At least one invalid signature was encountered.
E: The repository 'http://ports.ubuntu.com/ubuntu-ports focal-security InRelease' is not signed.
The command '/bin/sh -c apt-get update && apt-key add gpg && apt-get install -y         ca-certificates         build-essential         wget' returned a non-zero code: 100
lloydroc commented 2 years ago

Ok got past that error by running this:

curl http://ftp.us.debian.org/debian/pool/main/libs/libseccomp/libseccomp2_2.5.1-1_armhf.deb --output libseccomp2_2.5.1-1_armhf.deb
sudo dpkg -i libseccomp2_2.5.1-1_armhf.deb
lloydroc commented 2 years ago

Would you mind sending the output of a docker inspect <container> so I can compare? I can now run it with some modifications and the docker-compose.yaml below but when running in the foreground it does receive data but always gets 0 bytes. If I run in the background I see no output.

The docker-compose.yaml I'm using to test with.

---
version: '3'
services:
  e32:
    image: e32
    devices:
#     - /dev/ttyAMA0:/dev/ttyAMA0:rw
     - /dev/serial0:/dev/serial0:rw
    volumes:
      - /sys/devices:/sys/devices:rw
      - /sys/class/gpio:/sys/class/gpio:rw
      - /var/run:/var/run:rw
lloydroc commented 2 years ago

@renanqts it is working for me now. I don't have your exact Dockerfile but similar. I don't get the EBADF you're seeing but perhaps the following will fix it. I'm assuming you don't see waiting for input from the terminal in the logs. Regardless, can you change your ENTRYPOINT to include the -v option so we can see some more output?

Would you mind reverting the changes in the options.c and add this logic to e32.c?

$ git diff
diff --git a/src/e32.c b/src/e32.c
index d156e28..f64f15e 100644
--- a/src/e32.c
+++ b/src/e32.c
@@ -808,7 +808,12 @@ e32_poll_init(struct E32 *dev, struct options *opts, struct pollfd pfd[])
     dev->isatty = 1;
     info_output("waiting for input from the terminal\n");
   }
-    // used for stdin or a pipe
+  else
+  {
+    opts->input_standard = 0;
+  }
+
+  // used for stdin or a pipe
   pfd[PFD_STDIN].fd = -1;
   pfd[PFD_STDIN].events = 0;
renanqts commented 2 years ago

@lloydroc sorry for the delay. I will take a look today.

renanqts commented 2 years ago

actually, with the previous tip that you give to me, it worked in ubuntu. When I run in Kubernetes, I'm facing with

getting out of loop

option reset is 0
option help is 0
option verbose is 1
option status is 0
option mode is -1
option GPIO M0 Pin is 23
option GPIO M1 Pin is 24
option GPIO AUX Pin is 18
option daemon 0
option TTY Name is /dev/serial0
option socket unix data file desciptor 3
option socket unix control file desciptor 4
opened /dev/serial0
read mode 0
mode 0 unchanged
e32_poll_input_enable
e32_poll_stdin: got 0 bytes as input writing to uart
e32_transmit: transmitted 0 bytes
getting out of loop
e32_poll_input_disable

I don't have anything special I would say

apiVersion: apps/v1
kind: Deployment
metadata:
  name: e32
  namespace: lora
  labels:
    k8s-app: e32
spec:
  selector:
    matchLabels:
      name: e32
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        name: e32
    spec:
      containers:
      - name: e32
        image: renanqts/ebyte-sx1276
        securityContext:
          privileged: true
        command: ["e32"]
        #command: ["tail","-f","/dev/null"]
        args:
          - --verbose
          - --sock-unix-data
          - /var/run/e32.data
          - --sock-unix-ctrl
          - /var/run/e32.control
        volumeMounts:
        - mountPath: /var/run
          name: e32-sockets
        - mountPath: /dev
          name: dev
        - mountPath: /sys
          name: sys
        # - mountPath: /run
        #   name: run
        # resources:
        #   requests:
        #     hugepages-2Mi: 1Gi
        #     memory: 1000Mi
        #   limits:
        #     hugepages-2Mi: 1Gi
        #     memory: 1000Mi
      nodeSelector:
        k3s.io/hostname: k3s-de-node
      volumes:
      - name: dev
        hostPath:
          path: /dev
      - name: sys
        hostPath:
          path: /sys
      # - name: run
      #   hostPath:
      #     path: /run
      - name: e32-sockets
        emptyDir: {}
lloydroc commented 2 years ago

Thanks! I'm going through the logic here and this is strange because that change should never have it try to read from stdin at all. So I'm not sure how it is doing so.

  dev->isatty = isatty(fileno(stdin));
  if(dev->isatty)
  {
    dev->isatty = 1;
    info_output("waiting for input from the terminal\n"); // we don't see this output so we know that dev->isatty = 0;
  }
  else
  {
    opts->input_standard = 0; // thus, we know that opts->input_standard = 0
  }

So we'll never listen on stdin:

  if(opts->input_standard) // because opts->input_standard = 0 we won't ever poll it
  {
    pfd[PFD_STDIN].fd = fileno(stdin);
    pfd[PFD_STDIN].events = POLLIN;
  }

So I'm not sure how we see got the output in the logs e32_poll_stdin as it was never enabled. Could it be the change wasn't put in right or the container wasn't built properly?

Also, did this change work on Ubuntu? By that I assume you're running Ubuntu on your Raspberry Pi not in a container.

renanqts commented 2 years ago

@lloydroc sorry for delay here

Also, did this change work on Ubuntu? By that I assume you're running Ubuntu on your Raspberry Pi not in a container.

My first test that worked was directed in the Ubuntu OS in the PI, the second one mentioned below, is in k3s that runs inside this ubuntu.

actually, I miss this change here

Would you mind reverting the changes in the options.c and add this logic to e32.c?

After doing that, it worked

e32-96f54fb47-lh5k8   1/1     Running   0          44s

thanks for supporting again

lloydroc commented 2 years ago

@renanqts thanks for the followup. Do you want me to open a PR and get this change in and then you update your branch with it or did you want to add it into this PR? Just let me know so we can go ahead and close this one!

renanqts commented 2 years ago

@lloydroc we can bring it here