Data Connection API - connection state handler setup


I am a bit confused how that handler thing works in Legato. I read Legato concept part as well but that did not help me to understand it. Can anyone explain how to set up properly data connection API le_data_AddConnectionStateHandler

Documentation says: Add handler function for EVENT ‘le_data_ConnectionState’ - Ok, I guess that means I have to great my own function and pass it to the le_data_AddConnectionStateHandler() as a first parameter([in] handlerPtr). Is it so?

How should that function look like?
What is this [in]contextPtr? Why we need this and what is the proper way to get/great the reference?


There’s an example of using the data connection service in the RedSensorToCloud app.

Here is where the handler is registered:

And here is the handler:

Please ignore the TODO comment. It’s no longer true. I forgot to remove it when I removed the other comment that it refers to.


I understand that part, put what is contextPtr and why NULL?


Sorry for the slow reply. The le_avdata_AddSessionStateHandler function takes a contextPtr parameter. When the session state changes, the supplied function will be called and the contextPtr will be passed back to that function. When you don’t have a need for the contextPtr, you can just pass NULL instead. I’m having a hard time coming up with an example of when the contextPtr would be useful for the session state handler, but it’s a fairly common idiom that you will encounter in other Legato services.


Hello David,

I’ve been playing with “RedSensorToCloud” code to enable the sending of GPS data to Airvantage (would love to see my mangOH red position on the Airvantage website!).

The code seems to be GPS ready under the flag “GPS_ENABLE”.

The project compiles fine once I enable the flag (“define GPS_ENABLE”) but starting the app returns the following message:
" redSensorToCloud[8524]/avPublisherComponent T=main | avPublisher.c SampleTimerHandler() 386 | Failed to read gps".
This doesn’t seem to be an issue with making a GPS fix but an issue with the Airvantage handler (other data such as temperature etc. is successfully sent to Airvantage).

Have you seen this error message / problem before?
Do you have any code (avPublisher.c etc.) working fine? If so could you send it to me?

Thanks a lot in advance,