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 https://github.com/mangOH/MqttClient/tree/use_paho_linux_version. 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?
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.
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
APN: internet.sierrawireless.com
PDP Type: IPV4
Connected: yes
Interface: rmnet0
Family: inet
IP: 100.71.213.157
Gateway: 100.71.213.158
Dns1: 8.8.8.8
Dns2: 4.2.2.2
But /etc/resolv.conf is empty. If you use cm data connect it will have “8.8.8.8 4.2.2.2” in it.
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 ‘8.8.8.8’ '4.2.2.2’
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!