I have a modified version of RedSensorToCloud which retries a data connection every 5 minutes if LE_AVDATA_SESSION_STOPPED occurs. This seems to be generating a lot of connection device registrations on Air Vantage when the cellular connection is poor (IE 1 bar).
What is the best way to avoid this additional cost? I’m thinking it would be better to check the cell signal level and only attempt a session if the signal level is above a threshold after some number of attempts but I’m not sure if this makes sense.
Would you recommend these checks are performed before a call to le_avdata_RequestSession? We have had some problems with the data session not reconnecting unless we reboot the modem is this normal or should we be able to restart the app and acquire a data connection again?
Also does the modem automatically try and connect to the cellular network once it boots? Are they docs that talk about this behaviour?
Hi Darren, You don’t have to reboot the modem to reestablish the cellular connection. You should be able to reconnect if you release the session and request session again. A quick way to check cellular connection is also by using the ‘cm tool’. Use commands ‘cm radio’, ‘cm data’. Typically after a boot the device will connect to the cellular network but you have to request a data connect explicitly.
Right after boot
root@swi-mdm9x28-wp:~# cm data
Index: 1
APN: ltemobile.apn
PDP Type: IPV4
Connected: no
root@swi-mdm9x28-wp:~# cm radio
Power: ON
Current Network Operator: Rogers Wireless
Current RAT: GSM network (LE_MRC_RAT_GSM)
Status: Registered, home network (LE_MRC_REG_HOME)
Signal: Very strong signal strength (5)
PS: Packet Switched Registered, home network (LE_MRC_REG_HOME)
Explicit data connection
root@swi-mdm9x28-wp:~# cm data connect
Setting up profile 1
Connecting … ok
Checking if device ‘rmnet_data0’ is up … ok
Routing inet … ok
mv: can’t remove ‘/etc/resolv.conf’: Device or resource busy
Updating /etc/resolv.conf … ok
Updating /etc/resolv.conf … ok
Testing connection … ok
root@swi-mdm9x28-wp:~# cm data
Index: 1
APN: ltemobile.apn
PDP Type: IPV4
Connected: yes
Interface: rmnet_data0
Family[IPv4]: inet
IP[IPv4]: 25.167.7.155
Gateway[IPv4]: 25.167.7.156
Dns1[IPv4]: 64.71.255.254
Dns2[IPv4]: 64.71.255.253
root@swi-mdm9x28-wp:~#
Thanks for the help and the pointers about the cm tool. I noticed while I was debugging today that le_avdata_RequestSession seems to return a non-null reference even when cm radio indicated no network connection. Is this normal?
Sounds like le_avdata_ReleaseSession() should be called if le_avdata_RequestSession returned a non-null reference, correct.
Most cases you will get a non-null reference unless the service ran out of resources. Getting a non-null reference doesn’t imply you have a connection to the server. You still have to wait for events from avc service.
Look at the sample in:
avcStatusHandler() will notify your app when the connection goes up/down.
When your app doesn’t need avdata connection you can call le_avdata_ReleaseSession(). When all clients release their sessions avms connection will be torn down.
The dependency for avc app is “avc -> data connection service -> modem service”.
The cm tool is a debug tool which interacts directly with modem. You cannot compare events from modem service to events from avc.
For example, when avc indicates a connection is up, you can check the and rmnet interface and ip by running ‘cm data’. But when avc indicates that the avms connection is down, you might still see rmnet interface and ip depedning on if other app is using that channel.
Thanks for the sample code reference but I’m not sure how similar this app is to our sensorToCloud app. The AssetData app purposely stops sending data after 10 minutes.
Our app opens a data connection and then keeps trying that data connection (every 5 minutes) if the response handler isn’t called. After 10 minutes it gives up and reboots.
I’m trying illuminate the reboots and at the same time optimize LWM2M session data costs. So I better understand.
Is it best practice to setup and tear down a data session or should a data sessions be setup for as long as possible?
Should le_avdata_ReleaseSession be called before attempting to call le_avdata_RequestSession if the first call to le_avdata_RequestSession returned a non-null reference?
Answer to 2: Looking at avcData.c in avcDaemon le_avdata_RequestSession will return the existing reference if it’s a duplicate request. So no need to release the session before trying again.
Here is my opinion: #1) It is best if you can tear down session if you know for sure you don’t need it for a long time. To save power. But if you transfer every 5 minutes it may be better to keep data session up all the time to save bandwidth. #2) Yes, le_avdata_ReleaseSession() should be called