We are working on an application where coreMQTT Agent uses Cellular Library to communicate. While Agent tasks is running we would also like to run some AT commands to get Signal Strength etc. periodically. I don’t think Cellular Library enforces any locks for thread safety.
What would be the recommended way to use the Cellular library in an application at the same time as coreMQTT Agent?
Should we have a wrapper around Cellular that utilizes a Mutex?
Should we switch to polled coreMQTT to ensure access to Cellular library is on a single thread.
Are there any other alternatives?
Cellular library ensures thread safety between internal pktio thread and the thread calling cellular interface API. Application has to ensure that only one thread calling the cellular interface API at the same time.
Both of the methods you mentioned should work. The decision depends on your application requirements. Polled coreMQTT should not have problem since cellular library is used in single thread.
Please feedback in this thread if you are using coreMQTT-Agent with a Mutex and having problem. We would like to discuss with you here.
I came back to this ticket at work and I would like to discuss a bit more.
I feel like wrapping cellular interface with mutexes is just a hack to access modem from two threads and goes against software principle of using Agents in the first place.
Switching from Agent to basic implementation also feels bad since we lose thread safety and now we will need to work on another Agent like implementation which will work like MQTT Agent but will also have our modem related messages in there like querying the signal strength etc.
It feels like the problem is Cellular Interface not allowing multiple users since it doesn’t have an Agent like design. Additionally MQTT Agent does not allow anyone to use the modem when it takes ownership of it and we can’t extend the Agent thread to allow our messages.
I also noticed that Cellular Interface is essentially a singleton because of config header usage and even though the modem we are using allows 2 UART connections at the same time to communicate we are not able to have 2 instances of the Cellular Interface
My questions are:
Are there any plans to have an Agent like design for the cellular interface?
Is there a way to use 2 cellular interfaces in the same application?
Do you know any other examples/applications with MQTT Agent that also query the modem for additional information?
We are interested in periodically getting and logging the Signal Strength info from the modem and there is no URC that gives us that metric for 4G on this modem so polling is our only option.
Are there any plans to have an Agent like design for the cellular interface?
Currently, we don’t have plan to provide agent like design for the cellular interface.
Is there a way to use 2 cellular interfaces in the same application?
The design of cellular interface considers one communication interface for a modem. From your description, it looks like your modem has two UART interfaces. You can send command to the modem through both UARTs at the same time without corrupting the modem stack. Since both UARTs can control the same modem, we still need to consider the synchronization problem if the command changes modem state.
Do you know any other examples/applications with MQTT Agent that also query the modem for additional information?
The reference integration BG96 and SARA-R4 support proprietary command for signal indication callback through Cellular_RegisterUrcSignalStrengthChangedCallback. I am not sure if Telit Cinterion PLS63 also supports signal strength URC.
URC can only solve signal strength problem. I can image that there will be requirements for other commands in the future. Using an agent may help developers implement the multi-threaded application. Thank you for feedback this feature. I will also bring it back to the team for discussion. We will still discuss with you in this thread for any further questions.
Our modem is definitely less traditional with multiple UARTs.
If we stay with the agent design one thing we might do is only do read commands from second UART so state never changes but I understand since the cellular library has state in it we couldn’t use two instances anyways since they would both try to open the modem.
The modem has a URC for signal strength but it only returns a basic RSSI value which is not good for 4G and also as you mentioned if we have any other requirement that does not have a URC we are stuck again.
I think we will go with our own Agent like wrapper around coreMQTT and Cellular Interface in the mean time.
Also another reason why I asked for multiple Cellular Interface instances was that we also have a Bluetooth chip on the board that uses AT commands as well. So we will need to write a more basic parser for that as well. It would be nice to use the cellular library with both chips.
Thanks again for the reply, I appreciate the discussion.