Automatic data connection



I am trying to create an application that publishes data to a MQTT broker, and after publishing going into ULPM. I am using MQTT client from My issue is that the application will crash if there is no data connection and my question is: is there a way to verify board has data connection before trying to publish data?



Hi basti,

I think a better approach would be to try to make it so that attempting to publish when there’s not data connection is a detectable error, but doesn’t cause anything to crash.



and thanks for the answer! I will try that approach. Would you use le_data API to achieve this, or is there another API that would be more suitable?

And is there a demo/example of an application that would use this?


I found an example I could follow (dcsTestComp), but I cannot publish to broker using it for some reason. If I manually input cm data connect before running application, there are no issues. And using the dcsTestComp example I can see there is a connection established. le_data_TryConnectService returns LE_OK and cm data gives:
Index: 1
PDP Type: IPV4
Connected: yes
Interface: rmnet0
Family: inet

But /etc/resolv.conf is empty. If you use cm data connect it will have “” in it.

Any ideas what could be going on?


You might also want to look through this code example which uses the data connection service and ULPM. It uses le_avdata rather than MQTT though.


Hi @dfrey,

Thanks for the answer, I had pretty much the same solution but could not get it to work. I noticed that wifiService was also crashing because i had no SSID. After removing that app I was able to find a “workaround”, but maybe you could clarify or give a solution.
When I am launching my MQTT app I need to put in a delay (sleep) for dcsDaemon to run:
dcsDaemon[791]/le_pa_dcs T=main | pa_dcs_general.c AddNameserversToResolvConf() 305 | Set DNS ‘’ '’
When this happens, the application has connection and works fine.

So right now my workaround is havin a small delay before checking “LE_FATAL_IF(mqtt_Connect(mqttSession) != LE_OK, “Connection failed”);”. Thank you!