Ubuntu server on EC2 - Edge compute device

Hi there,
I have set up an EC2 instance with Ubuntu and I have installed the Gateway Edge Agent, and it’s connected to an Edge Compute device.
The server needs to listen for inbound messages on a UDP port. I assumed I’d only have to use the UDP node in an edge workflow to get the messages but it doesn’t appear to be the case.
I saw here that @Brandon_Cannaday had play with a similar setup, would anyone happen to have some guidelines?

@Jules_Huguenin,

Would you be able to share the Docker command you used to start up the Edge Agent? We have some guidance in our documentation regarding passing UDP ports and data to the Edge Agent.

Thank you,
Heath

Hi @Heath
Below is the UDP config in the device config file:


I assume I don’t need to change anything?

Outbound messages from the IoT devices are going to the server port 20500. Here is the docker command I have used:


I’m a bit lost between the port in the container and the port in the host, I guess my mistake is here?

For the GEA workflow I have used a UDP node to log incoming messages:

Thanks for sending along all that info @Jules_Huguenin.

You will need to uncomment the lines in your configuration file. So, your updated UDP config section will look like this:

[udp]
# Address for UDP server - CLI: --udp-address, EnvVar: UDP_ADDRESS
address = '0.0.0.0'

EDIT: The UDP address for the Edge Agent defaults to 0.0.0.0, so uncommenting the address in the config is only necessary if you plan on changing the UDP address.

Then, in your Docker Run command, it looks like you may have mixed up the ports. The -p flag is hostPort:containerPort. If your server is expecting UDP messages on port 20500, then you’ll need to change that publish line to -p 20500:20500/udp.

I will make some updates to our documentation to better reflect what needs to be done to make this work.

Let me know if this works for you.

Thank you,
Heath

Thanks @Heath, it works now!
I didn’t realise the potential of the GEA, it’s going to help me lots.

For my own understanding, what is the UDP address in the config file?
Cheers
Jules

We love hearing that! As always, as you work with and have any questions, don’t hesitate to reach out!

For my own understanding, what is the UDP address in the config file?

The UDP address allows you to identify the IP address of the machine that is running this UDP server. In most cases, the IP address of the device (0.0.0.0 for example) works, but there are some cases where you may have multiple network interfaces on your machine and you want to listen for UDP messages on one a specific interface.

Let me know if that makes sense or if there is anything I can expand on.

Thank you,
Heath

1 Like

Hey @Heath

Same topic, I’m a bit stuck with a problem that might be getting too specific but let’s try anyway:

The GEA is running and I can see incoming UDP messages from the edge workflow. I receive a message, a source port, and an source ip address:
image

The format of the message is strange but I can decode it anyways so it’s fine up to this point:
image

For each message received I need to send back an acknowledgement message response, and this is where I’m having troubles.
I’m fairly confident I have the correct outbound port and I use the source ip address for the host address:


I tried to change the port to the source port but it doesn’t work either.

Regarding the acknowledgement message itself, the host wants to see a message that looks like this:
image

Considering the format of the incoming message I also tried with this:
image

My device doesn’t receive the acknowledgement message and I’m running out of ideas.
Would you have any pointers?
Cheers
Jules

@Jules_Huguenin what happens if you put 161 - the default UDP port - in as the Port Template in the UDP Send Node? The port from which your message originated is not necessarily the port that is listening for UDP messages. I tested this just now in a GEA workflow (attached) and I could only get the trigger to fire when listening on port 161, not when I use the sourcePort.

If that doesn’t work, are you able to receive the UDP message when sending as a broadcast?

udp-test-develop.flow (2.3 KB)

Hi @Dylan_Schuster,
My devices’ documentation states that all devices are listening to port 20510 and I did try to send a UDP message to this port without success. The server is listening to port 20500 and I do receive the messages on this port in Losant.
Is port 161 special?

I don’t think I understand the concept of the broadcast send and the host network mode, are you able to clarify this and give me an example of a command to start the docker with those setting?

FYI, inbound messages are coming from many devices and I need to respond to each device with a specific acknowledgement message.

Hey @Jules_Huguenin,

Just so we’re on the same page: you’re trying to get acknowledgement messages back out from the Edge Agent to your devices over port 20510, while the server is listening for UDP messages on 20500. Is that right?

To get the Edge Agent to be able to “hear” those UDP messages we had to make sure that you were passing in the correct port with the publish flag on the docker run command. Have you restarted the Edge Agent with the new port being published?

I don’t think I understand the concept of the broadcast send and the host network mode, are you able to clarify this and give me an example of a command to start the docker with those setting?

Docker containers are typically isolated from the host machines network, which is why we have to use the publish flag (-p) to map the host machine’s ports to the ports of the container. When you start the container in the host network mode, the container takes on the same network as the host machine, so there’s no need to be selective for each port and list them all out. Here’s a post that goes into some more detail.

You can add --net=host do your docker run command to start a container in host mode. So, something like:

docker run -d --restart always --net=host \
  -v /var/lib/losant-edge-agent/data:/data
  ...
  ...

Let me know if this helps or if you need more clarification.

Thanks,
Heath

Hi @Heath,

Just so we’re on the same page: you’re trying to get acknowledgement messages back out from the Edge Agent to your devices over port 20510, while the server is listening for UDP messages on 20500. Is that right?

Correct

To get the Edge Agent to be able to “hear” those UDP messages we had to make sure that you were passing in the correct port with the publish flag on the docker run command. Have you restarted the Edge Agent with the new port being published?

Yes, and it works as I am receiving the messages on the GEA.

Docker containers are typically isolated from the host machines network, which is why we have to use the publish flag ( -p ) to map the host machine’s ports to the ports of the container. When you start the container in the host network mode, the container takes on the same network as the host machine, so there’s no need to be selective for each port and list them all out. Here’s a post that goes into some more detail.

Right, but since I’m listening on port 20500 only and I have used the publish flag (-p) to pass this port, is the host network relevant for me? The problem is with messages sent to port 20510 from the GEA to the devices, is it necessary to use the host machine network to do this?

@Jules_Huguenin,

Right, but since I’m listening on port 20500 only and I have used the publish flag (-p) to pass this port, is the host network relevant for me?

I may have explained this incorrectly. So, you’ve got incoming messages (i.e. messages coming to this machine) on port 20500 (which you’ve published in your docker run command with -p 20500:20500). Now, you’re trying to send outbound messages, or messages from the server to the device, on port 20510. So, to do this you will need to publish the 20510 port in your docker run command also. Something like this:

docker run -d --restart always \
  ...
  -p 20500:20500 \
  -p 20510:20510 \ 
  ...
  ... 

The problem is with messages sent to port 20510 from the GEA to the devices, is it necessary to use the host machine network to do this?

It is not necessary to use the host machine network to do this. The host network option is an option that allows the programs inside the Docker container to look like they are running on the host itself. Dylan mentioned using this as an option so that you could test the default port that the Losant GEA uses for UDP messages.

Thank you,
Heath

Hey @Heath,
Ok, it makes sense now. I have published the outbound port (20510) but the message is still not reaching the device.

I can see 2 potential areas where the problem could be:

1 - as mentioned above, the device is supposed to send HEX messages but I’m receiving what looks like to be a message in Unicode format:
image
I can decode this to get my HEX message, and the ACK message is prepared in the HEX format as well.
Would the GEA decode HEX message when sending the ACK back to the device?
Note that I have tried every format the UDP send node offers.

2 - the sourceAddress is always different than the public IP address of the device, should they be the same?