Follow up to "Multiple MQTT Clients using nrf9160"

I have been developing and debugging this situation for a while.  I discovered that the original advice didn't work.  First; to get more than 2 client connections going, I had to increase the number of file descriptors;

CONFIG_POSIX_MAX_FDS=20

Then I discovered that I wasn't able to add more than 4 client connections.  This took some real digging and I got down to the nrf_socket interface but things disappear into the modem at that point.  Then I noticed this little tidbit in the nrf_socket documentation;

The library has the following set of sockets:

* 8 generic sockets that can be used freely between UDP, TCP, TLS, DTLS, and AT commands
* 1 GNSS/AGPS socket
* 1 modem DFU socket
* 10 PDN sockets

Which I assume means I'm limited to 8 sockets.  I'm guessing this means I can't have more than 8 sockets active at one time.  I'm also figuring that some combination of the 4 sockets I'm using for my client connection and other uses are leading me to the errors I'm getting;

[00:24:01.650,085] <err> net_mqtt_sock_tls: Connection Error -1
[00:24:01.651,794] <err> net_mqtt: Error creating transport connection -22
[00:24:01.651,824] <err> gcloud: mqtt_connect failed: -22 Invalid argument

Unfortunately, I can see no way to increase this limit to test the hypothesis further.  I was hoping that you could add some insite.

Parents
  • Hi, I'm using the 1.6.1 SDK and the 1.3.0 Modem version.

    It's a simple IoT unit measuring things like Battery Charge, temperature and a host of other sensors activities on it and other meshed devices that report to it and reports them to a Google Cloud infrastructure through Google IoT Core.

    I don't use GNSS but I do use AT commands

    The multiple clients was a request from the cloud team.  We have a device that is a gateway that is running with the nrf9160.  It reports data itself plus there are a bunch of devices in a meshed network that report through the gateway.  The 2 options for this with Google IoT core is to simulate the meshed device connections with a dedicated MQTT client connection.  Or have all of the meshed devices communicate through a bridged connection (which is the normal way to do a gateway).  The bridged connection requires an extra layer of management software that the cloud team didn't want to have to do.  Of course that was when I thought multiple clients on the gateway side was going to be simple.  And that is what I was told when I submitted the original ticket ( please see Case ID: 269731 ).

    I also ran into this looking at the release notes of modem firmware version 1.3.0;

    - Maximum number of raw sockets is 4.

    I don't know if that has anything to do with it.  I'm curious, is there any way to use the Zephyr network stack and just use the modem for IP communications?

    Randall

  • Randall said:
    The multiple clients was a request from the cloud team.  We have a device that is a gateway that is running with the nrf9160.  It reports data itself plus there are a bunch of devices in a meshed network that report through the gateway.

    Thanks. That makes sense.

    Randall said:
    I'm using the 1.6.1 SDK

    You can free up a socket by upgrading to NCS v1.7.0 or 1.8.0, and use the new AT interface instead (nrf_modem_at.h).

    However, you will still be limited to a total of 8 sockets. But a bigger limitation is that the modem only supports 3 TLS connections at the same time.

    You can work around this by running the TLS stack on the application core, but the cost in flash and RAM can be quite high. To see how you can run the TLS stack on the application core, you can look at the https_client sample, or the serial_lte_modem application.

    Randall said:

    I also ran into this looking at the release notes of modem firmware version 1.3.0;

    - Maximum number of raw sockets is 4.

    I don't know if that has anything to do with it.  I'm curious, is there any way to use the Zephyr network stack and just use the modem for IP communications?

    Yes, that is what the raw sockets can be used for. Note that I don't belive we have tested this configuration properly. You also probably have to implement the glue layer that ties Zephyr's IP stack to the raw sockets.

    At that point, it might be easier to implement the logic in the cloud instead.

Reply
  • Randall said:
    The multiple clients was a request from the cloud team.  We have a device that is a gateway that is running with the nrf9160.  It reports data itself plus there are a bunch of devices in a meshed network that report through the gateway.

    Thanks. That makes sense.

    Randall said:
    I'm using the 1.6.1 SDK

    You can free up a socket by upgrading to NCS v1.7.0 or 1.8.0, and use the new AT interface instead (nrf_modem_at.h).

    However, you will still be limited to a total of 8 sockets. But a bigger limitation is that the modem only supports 3 TLS connections at the same time.

    You can work around this by running the TLS stack on the application core, but the cost in flash and RAM can be quite high. To see how you can run the TLS stack on the application core, you can look at the https_client sample, or the serial_lte_modem application.

    Randall said:

    I also ran into this looking at the release notes of modem firmware version 1.3.0;

    - Maximum number of raw sockets is 4.

    I don't know if that has anything to do with it.  I'm curious, is there any way to use the Zephyr network stack and just use the modem for IP communications?

    Yes, that is what the raw sockets can be used for. Note that I don't belive we have tested this configuration properly. You also probably have to implement the glue layer that ties Zephyr's IP stack to the raw sockets.

    At that point, it might be easier to implement the logic in the cloud instead.

Children
No Data
Related