I want to get the serialport data using edge workflow,do you have any sample workflow for getting serial port data?

Hi,

The below one is my serialport information.

1.I have installed losant edge agent in my laptop.


2.My gateway information


3.My losant edge agent log.

{
  "topic": "losant/5cfb4dfbafabc800087c61d1/toAgent/flows",
  "payload": {
    "time": 1560075667344,
    "mode": "complete",
    "flows": {
      "5cfbef7c50371c00095ba876": {
        "name": "energymtr work flow",
        "globals": {},
        "triggers": [
          {
            "type": "serial",
            "meta": {
              "x": 40,
              "y": 60,
              "id": "cwbYEnvljv",
              "category": "trigger",
              "name": "serial",
              "label": "Serial",
              "uiId": "cwbYEnvljv",
              "description": "",
              "parseBy": "byteLength"
            },
            "config": {
              "path": "/dev/ttyUSB0",
              "baudRate": 9600,
              "encoding": "hex",
              "writeOnOpen": "hi em",
              "byteLength": "8"
            },
            "key": "5cfbef7c50371c00095ba876-lohrEzH3aYJ4QlsWrieVE",
            "outputIds": [["hJdOs_FpLR"]]
          }
        ],
        "nodes": [
          {
            "type": "DebugNode",
            "config": {"message": "", "property": ""},
            "id": "hJdOs_FpLR",
            "outputIds": []
          }
        ],
        "version": "2019-06-08T18-01-58",
        "versionId": "5cfbf81b66b3b30008490a67",
        "minimumAgentVersion": "1.8.0"
      }
    },
    "application": {"name": "smartphone", "id": "5ca5f7f18b62290008d0e84d", "globals": {}},
    "device": {"name": "comportgateway", "id": "5cfb4dfbafabc800087c61d1", "tags": {}}
  }
}

4.after my edge workflow deployment,I got the following error.

2019-06-09T10:23:51.326Z [#[33mwarn#[39m] Serial path will retry to open in 30 seconds.
2019-06-09T10:24:21.340Z [#[33mwarn#[39m] Serial path /dev/ttyUSB0 is attempting to reopen…
2019-06-09T10:24:21.340Z [#[33mwarn#[39m] Error in serial manager while listening at /dev/ttyUSB0: Error:Error: No such file or directory,

5.I want to get the serialport data using edge workflow,do you have any sample workflow for
getting serial port data?

Hi

Have you mapped the serial port with the device option so the container has access to the serial port ?
this is used as an argument with the docker run command

--device=/dev/ttyUSB0
1 Like

Hi @sivasankari_s,

A similar question can be found here with the same error, I recommend checking it out. I will look further into this as well to see if anything obvious is amiss.

Thanks!
Julia

Getting serial devices across the Docker boundary can be a challenge. If you’re using a Debian-based Linux distribution, here are the steps we’ve taken to successfully and reliably gain access to serial devices from inside Docker.

1. Set udev rule

By default, serial devices are mounted so that only root users can access the device. We need to add a udev rule to make them readable by non-root users. For security reasons, Losant’s Edge Agent does not run under a root user.

Create a file named /etc/udev/rules.d/99-serial.rules. Add the following line to that file:

KERNEL=="ttyUSB[0-9]*",MODE="0666"

MODE="0666" will give all users read/write (but not execute) permissions to your ttyUSB devices. This is the most permissive option, and you may want to restrict this further depending on your security requirements. You can read up on udev to learn more about controlling what happens when a device is plugged into a Linux gateway.

2. Mount in /dev folder from host to container

Serial devices are often ephemeral (can be plugged and unplugged at any time). Because of this, we can’t mount in the direct device or even the /dev/serial folder, because those can disappear when things are unplugged. Even if you plug them back in and the device shows up again, it’s technically a different file than what was mounted in, so Docker won’t see it. For this reason, we mount the entire /dev folder from the host to the container. You can do this by adding the following volume command to your Docker run command:

-v /dev:/dev

If your device is permanently attached, then using the --device option or a more specific volume mount is likely a better option from a security perspective. Since we are the authors of the Edge Agent, we obviously trust the code running in there and aren’t worried about exposing additional devices.

3. Run container in privileged mode

If you did not use the --device option and mounted in the entire /dev folder, you will be required to run the container is privileged mode. You can do this by adding the following to your Docker run command:

--privileged

4. Access device from the /dev/serial/by-id folder

If your device can be plugged and unplugged, Linux does not guarantee it will always be mounted at the same ttyUSBxxx location (especially if you have multiple devices). Fortunately, Linux will make a symlink automatically to the device in the /dev/serial/by-id folder. The file in this folder will always be named the same.

1 Like

Thank you very much Brandon_Cannaday.
Your reply was super helpful .once i set up the permission for my serial port,my serial
write node working fine.

Now I want to read my serial port data using edge work flow.do we have any
specific node for read serial port data?

Thanks
Sivasankari S

@sivasankari_s,

We don’t have a “Serial Read” Node. Instead, that’s the purpose of the Serial Trigger. With it, you are listening on that Serial port and triggering a workflow whenever your device(s) write Serial.

Thank you anaptfox.
I am trying serial trigger at the same time if you have any samples
for serial write and serial trigger kindly share me.

Thanks
Sivasankari S