MQTT with FX30

Hello,

I’am currently trying to publish some MQTT data with an FX30 CAT M modem but encounter some issue…

I’am using the SDK for FX30-CATM (Release 15.1.0.004 + Legato 21.05.0) and built a very small system:

#include "$LEGATO_ROOT/default.sdef"

apps:
{
    mqttClient
}

appSearch:
{
    $CURDIR/apps/mqttClient/
}

interfaceSearch:
{

}

The mqttClient API application is a copy from the SDK source : legato-af/apps/platformServices/mqttClient at master · legatoproject/legato-af · GitHub

But any other application using this API seems to not start (no message printed), I guess there is a problem with the API.

If I restart the API manually, i get this:

$ app start mqttClient
root@192.168.2.2's password: 
There was an error.  Application 'mqttClient' could not be started.
Check the system log for error messages.

And the log:

Feb 25 09:14:14 fx30 user.info Legato:  INFO | supervisor[9560]/supervisor T=main | app.c app_Start() 3589 | Starting app 'mqttClient'
Feb 25 09:14:14 fx30 user.info Legato:  INFO | supervisor[9560]/supervisor T=main | app.c CreateFileLink() 2202 | Skipping file link '/dev/log' to '/legato/systems/current/appsWriteable/mqttClient/dev/log': Already exists
Feb 25 09:14:14 fx30 user.info Legato:  INFO | supervisor[9560]/supervisor T=main | app.c CreateFileLink() 2202 | Skipping file link '/dev/null' to '/legato/systems/current/appsWriteable/mqttClient/dev/null': Already exists
Feb 25 09:14:14 fx30 user.info Legato:  INFO | supervisor[9560]/supervisor T=main | app.c CreateFileLink() 2202 | Skipping file link '/dev/zero' to '/legato/systems/current/appsWriteable/mqttClient/dev/zero': Already exists
Feb 25 09:14:14 fx30 user.info Legato:  INFO | supervisor[9560]/supervisor T=main | app.c CreateFileLink() 2202 | Skipping file link '/dev/urandom' to '/legato/systems/current/appsWriteable/mqttClient/dev/urandom': Already exists
Feb 25 09:14:14 fx30 user.info Legato:  INFO | supervisor[9560]/supervisor T=main | app.c CreateFileLink() 2202 | Skipping file link '/legato/systems/current/lib/liblegato.so' to '/legato/systems/current/appsWriteable/mqttClient/lib/liblegato.so': Already exists
Feb 25 09:14:14 fx30 user.info Legato:  INFO | supervisor[9560]/supervisor T=main | app.c CreateFileLink() 2202 | Skipping file link '/lib/ld-linux.so.3' to '/legato/systems/current/appsWriteable/mqttClient/lib/ld-linux.so.3': Already exists
Feb 25 09:14:14 fx30 user.info Legato:  INFO | supervisor[9560]/supervisor T=main | app.c CreateFileLink() 2202 | Skipping file link '/lib/libc.so.6' to '/legato/systems/current/appsWriteable/mqttClient/lib/libc.so.6': Already exists
Feb 25 09:14:14 fx30 user.info Legato:  INFO | supervisor[9560]/supervisor T=main | app.c CreateFileLink() 2202 | Skipping file link '/lib/libpthread.so.0' to '/legato/systems/current/appsWriteable/mqttClient/lib/libpthread.so.0': Already exists
Feb 25 09:14:14 fx30 user.info Legato:  INFO | supervisor[9560]/supervisor T=main | app.c CreateFileLink() 2202 | Skipping file link '/lib/librt.so.1' to '/legato/systems/current/appsWriteable/mqttClient/lib/librt.so.1': Already exists
Feb 25 09:14:14 fx30 user.info Legato:  INFO | supervisor[9560]/supervisor T=main | app.c CreateFileLink() 2202 | Skipping file link '/lib/libdl.so.2' to '/legato/systems/current/appsWriteable/mqttClient/lib/libdl.so.2': Already exists
Feb 25 09:14:14 fx30 user.info Legato:  INFO | supervisor[9560]/supervisor T=main | app.c CreateFileLink() 2202 | Skipping file link '/lib/libgcc_s.so.1' to '/legato/systems/current/appsWriteable/mqttClient/lib/libgcc_s.so.1': Already exists
Feb 25 09:14:14 fx30 user.info Legato:  INFO | supervisor[9560]/supervisor T=main | app.c CreateFileLink() 2202 | Skipping file link '/lib/libm.so.6' to '/legato/systems/current/appsWriteable/mqttClient/lib/libm.so.6': Already exists
Feb 25 09:14:14 fx30 user.info Legato:  INFO | supervisor[9560]/supervisor T=main | app.c CreateFileLink() 2202 | Skipping file link '/usr/lib/libstdc++.so.6' to '/legato/systems/current/appsWriteable/mqttClient/lib/libstdc++.so.6': Already exists
Feb 25 09:14:14 fx30 user.info Legato:  INFO | supervisor[9560]/supervisor T=main | app.c CreateFileLink() 2202 | Skipping file link '/lib/libresolv.so.2' to '/legato/systems/current/appsWriteable/mqttClient/lib/libresolv.so.2': Already exists
Feb 25 09:14:14 fx30 user.info Legato:  INFO | supervisor[9560]/supervisor T=main | app.c CreateFileLink() 2202 | Skipping file link '/legato/systems/current/apps/mqttClient/read-only/lib/libpaho-mqtt3cs.so.1.0' to '/legato/systems/current/appsWriteable/mqttClient/l
Feb 25 09:14:14 fx30 user.info Legato:  INFO | supervisor[9560]/supervisor T=main | app.c CreateFileLink() 2202 | Skipping file link '/legato/systems/current/apps/mqttClient/read-only/lib/libcrypto.so.1.1' to '/legato/systems/current/appsWriteable/mqttClient/lib/lib
Feb 25 09:14:14 fx30 user.info Legato:  INFO | supervisor[9560]/supervisor T=main | app.c CreateFileLink() 2202 | Skipping file link '/legato/systems/current/apps/mqttClient/read-only/lib/libssl.so.1.1' to '/legato/systems/current/appsWriteable/mqttClient/lib/libssl
Feb 25 09:14:14 fx30 user.info Legato:  INFO | supervisor[9560]/supervisor T=main | app.c CreateFileLink() 2202 | Skipping file link '/legato/systems/current/apps/mqttClient/read-only/lib/libComponent_mqttClientService.so' to '/legato/systems/current/appsWriteable/m
Feb 25 09:14:14 fx30 user.info Legato:  INFO | supervisor[9560]/supervisor T=main | app.c CreateFileLink() 2202 | Skipping file link '/legato/systems/current/apps/mqttClient/read-only/lib/libpaho-mqtt3cs.so.1' to '/legato/systems/current/appsWriteable/mqttClient/lib
Feb 25 09:14:14 fx30 user.info Legato:  INFO | supervisor[9560]/supervisor T=main | app.c CreateFileLink() 2202 | Skipping file link '/legato/systems/current/apps/mqttClient/read-only/lib/libpaho-mqtt3cs.so' to '/legato/systems/current/appsWriteable/mqttClient/lib/l
Feb 25 09:14:14 fx30 user.info Legato:  INFO | supervisor[9560]/supervisor T=main | app.c CreateFileLink() 2202 | Skipping file link '/legato/systems/current/apps/mqttClient/read-only/bin/mqttClientService' to '/legato/systems/current/appsWriteable/mqttClient/bin/mq
Feb 25 09:14:14 fx30 user.info Legato:  INFO | supervisor[9560]/supervisor T=main | app.c CreateFileLink() 2202 | Skipping file link '/legato/systems/current/apps/mqttClient/read-only/lib/libcrypto.so.1.1' to '/legato/systems/current/appsWriteable/mqttClient/lib/lib
Feb 25 09:14:14 fx30 user.info Legato:  INFO | supervisor[9560]/supervisor T=main | app.c CreateFileLink() 2202 | Skipping file link '/legato/systems/current/apps/mqttClient/read-only/lib/libssl.so.1.1' to '/legato/systems/current/appsWriteable/mqttClient/lib/libssl
Feb 25 09:14:14 fx30 user.info Legato:  INFO | supervisor[9560]/supervisor T=main | app.c CreateFileLink() 2202 | Skipping file link '/legato/systems/current/apps/mqttClient/read-only/lib/libpaho-mqtt3cs.so' to '/legato/systems/current/appsWriteable/mqttClient/lib/l
Feb 25 09:14:14 fx30 user.info Legato:  INFO | supervisor[9560]/supervisor T=main | app.c CreateFileLink() 2202 | Skipping file link '/legato/systems/current/apps/mqttClient/read-only/lib/libpaho-mqtt3cs.so.1' to '/legato/systems/current/appsWriteable/mqttClient/lib
Feb 25 09:14:14 fx30 user.info Legato:  INFO | supervisor[9560]/supervisor T=main | app.c CreateFileLink() 2202 | Skipping file link '/legato/systems/current/apps/mqttClient/read-only/lib/libpaho-mqtt3cs.so.1.0' to '/legato/systems/current/appsWriteable/mqttClient/l
Feb 25 09:14:14 fx30 user.info Legato:  INFO | supervisor[9560]/supervisor T=main | app.c CreateDirLink() 2094 | Skipping directory link '/etc/ssl' to '/legato/systems/current/appsWriteable/mqttClient/etc/ssl': Already exists
Feb 25 09:14:14 fx30 user.err Legato: =ERR= | supervisor[9560]/supervisor T=main | app.c CreateFileLink() 2160 | Could not stat file at '/usr/lib/libcrypto.so.1.0.2'. No such file or directory
Feb 25 09:14:14 fx30 user.err Legato: =ERR= | supervisor[9560]/supervisor T=main | app.c CreateFileLink() 2277 | Failed to create link at '/usr/lib/libcrypto.so.1.0.2' in app 'mqttClient'.
Feb 25 09:14:14 fx30 user.err Legato: =ERR= | supervisor[9560]/supervisor T=main | app.c app_Start() 3621 | Failed to set Smack rules or set up app area.
Feb 25 09:14:14 fx30 user.info Legato:  INFO | supervisor[9560]/supervisor T=main | supervisor.c SigChildHandler() 885 | Reaping unconfigured child process 9905.
Feb 25 09:14:28 fx30 user.info Legato:  INFO | supervisor[9560]/supervisor T=main | supervisor.c HandleRebootExpiry() 633 | Expired reboot timer

Any idea on how to fix theses errors ?

How about using this app?
.

On the Component.cdef file of this example application, there is dependency:
requires:{ api: { mqtt.api } }.
Binded to the mqttClient API in the mqttPublisher.adef file:
bindings: testPublisher.testPublisher.mqtt -> mqttClient.mqtt.

Since the mqttClient API application failed to start, this example application can’t start too.

I have tryed to add a debug print LE_INFO("== testPublisher START =="); in the first line of COMPONENT_INIT function, but this print never appears in the log.

I saw these lines in your log:

Feb 25 09:14:14 fx30 user.err Legato: =ERR= | supervisor[9560]/supervisor T=main | app.c CreateFileLink() 2277 | Failed to create link at '/usr/lib/libcrypto.so.1.0.2' in app 'mqttClient'.
Feb 25 09:14:14 fx30 user.err Legato: =ERR= | supervisor[9560]/supervisor T=main | app.c app_Start() 3621 | Failed to set Smack rules or set up app area.
Feb 25 09:14:14 fx30 user.info Legato:  INFO | supervisor[9560]/supervisor T=main | supervisor.c SigChildHandler() 885 | Reaping unconfigured child process 9905.

you might need to check \components\3rdParty\paho.mqtt.c\Component.c
As i saw these libraries are hardcoded with version, it might not be matched to your current module

Effectively, in Component file, we can found an hardcoded version :

        /usr/lib/ssl/openssl.cnf    /usr/lib/ssl/
        /usr/lib/libssl.so.1.0.2    /usr/lib/
        /usr/lib/libcrypto.so.1.0.2 /usr/lib/

The openssl.cnf file is also in the wrong folder, it should be in /etc instead of /lib.

I edited the file with this new lines:

        #if file_exists(${LEGATO_SYSROOT}/usr/lib/ssl/openssl.cnf)
            /usr/lib/ssl/openssl.cnf     /usr/lib/
        #endif
        #if file_exists(${LEGATO_SYSROOT}/etc/ssl/openssl.cnf)
            /etc/ssl/openssl.cnf         /etc/ssl/
        #endif

        #if file_exists(${LEGATO_SYSROOT}/usr/lib/libssl.so.1.1)
            /usr/lib/libssl.so.1.1       /usr/lib/
            /usr/lib/libcrypto.so.1.1    /usr/lib/
        #elif file_exists(${LEGATO_SYSROOT}/usr/lib/libssl.so.1.0.2)
            /usr/lib/libssl.so.1.0.2     /usr/lib/
            /usr/lib/libcrypto.so.1.0.2  /usr/lib/
        #elif file_exists(${LEGATO_SYSROOT}/usr/lib/libssl.so.1.0.0)
            /usr/lib/libssl.so.1.0.0     /usr/lib/
            /usr/lib/libcrypto.so.1.0.0  /usr/lib/
        #else
            /openssl/not/found /lib/
        #endif

The mqttClient API application is now started normally, GOOD!

But still impossible to connect…
After many tests, I noticied that curl and wget commands failed to connect on HTTP service (port 80), only HTTPS was working, maybe some firewall…

And here it is:

root@fx30:~# iptables -L
Chain INPUT (policy DROP)
target     prot opt source               destination         
ACCEPT     udp  --  anywhere             anywhere             udp spt:ntp ctstate ESTABLISHED
ACCEPT     udp  --  anywhere             anywhere             udp spt:443 state ESTABLISHED
ACCEPT     tcp  --  anywhere             anywhere             tcp spt:https state ESTABLISHED
ACCEPT     udp  --  anywhere             anywhere             udp spt:5686 state ESTABLISHED
ACCEPT     udp  --  anywhere             anywhere             udp spt:5684 state ESTABLISHED
ACCEPT     icmp --  anywhere             anywhere             icmp echo-reply state ESTABLISHED
ACCEPT     tcp  --  anywhere             anywhere             tcp spt:domain state ESTABLISHED
ACCEPT     udp  --  anywhere             anywhere             udp spt:domain state ESTABLISHED
ACCEPT     icmp --  anywhere             anywhere            
ACCEPT     tcp  --  anywhere             anywhere             tcp spt:domain state ESTABLISHED
ACCEPT     udp  --  anywhere             anywhere             udp spt:domain state ESTABLISHED
ACCEPT     tcp  --  anywhere             anywhere             tcp dpt:ssh
ACCEPT     icmp --  anywhere             anywhere             icmp echo-request
ACCEPT     udp  --  anywhere             anywhere             udp spts:bootps:bootpc dpts:bootps:bootpc

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination         

The INPUT policy set to DROP and some exeption on ESTABLISHED, including the https port.
This explains why i failed to connect on port 80 with curl/wget and also failed to connect on port 1883 or 8883 for MQTT.

Now, i have some questions:

  • Why use a such aggressive IPTABLE configuration in the default image ?

  • Is there a way to change this configuration in the generated system update file by mksys ?

see if this helps to configure the firewall: