GSM Modem library advice ...

1 post / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,

I thought I'd ask the AVRfreaks hive mind about the "best" way to implement a GSM library.

I want to talk to a GSM modem. All GSM modems use standard AT commands to send text messages, transfer GPRS data, make calls, etc. There must be a billion devices out there all running code to talk AT to a GSM modem, but I can't find a decent library ...

Nearly all libraries I've seen, seem to fire and forget. They just send the commands and either wait for an OK or just assume the command succeeded.

My project requires regular sending (a messages every 10-15 minutes) and the device will be moving, so I need to cope with it dropping in and out of service.

I can't find a library that monitors the state of the modem in real-time and knows at any instance if the device is ready or not to send ? That would involve a reasonably complex state machine interpreting the huge number of errors and messages asynchronously output by the modem and deciding if this means it's online or offline.

If I understand it correctly, there are three options :
* Reset the modem every time you send a message, so in effect it boots every time. Then I just need to wait for it to come online, be ready to send and send the message, then shut down. No real-time monitoring required. No state machine. However see note 1 below.
* Don't continuously monitor the status, but if you try and send, check the return status and if it fails, keep retrying until it succeeds. No complex state machine or parsing of every error message required, but not very clean. However see note 2 below.
* Build a complex state machine that interprets all the asynchronous status and error messages, and keep a flag or whether the modem is "ready" or not. I had assumed a library of this type would already exist, as a billion of devices must do this and the state machine and interpretation of the errors and status messages is large and complex. But I haven't found anything. I also can't seem to find a definitely list of what defines "ready to send".

Is there anyone in the hive mind, who has worked with commercial mobile devices and understand how a phone does this for example ? Does it have a huge state machine constantly monitoring the state of the modem ? or does it just try and retry if it fails ? Or is there a single "is the modem ready" command I haven't seen ?

Note 1 :
There doesn't seem to be a standard order of status messages. When the modem boots I sometimes get :
+SIND: 11 // Registered to network
+SIND: 3 // AT module is partially ready
+SIND: 4 // AT module is totally ready

Or, sometimes :
+SIND: 3 // AT module is partially ready
+SIND: 4 // AT module is totally ready
+SIND: 11 // Registered to network

I'm sure in other situations I will get others, especially if at that time it doesn't have a signal.

So a +SIND 4 doesn't necessarily mean the modem can send. I get an error if I send after the +SIND 4, but before the +SIND 11. I need a +SIND 4 & +SIND 11, and they come in different orders ? So, I'm back to needing a state machine again. Not being able to send after a +SIND 4 seems odd, as its described as "AT module is totally ready" I have a different understanding of the word "totally ready" obviously ... :-)

Note 2 :
I don't get a single error message if the send fails, I get lots of different ones. E.g. :
+CME ERROR: 3 operation not allowed
Or sometimes
+CME ERROR: 4 operation not supported

There will be more. In truth, an error is an error, and I just need to wait, then retry. But it's difficult to predict all the different things that could happen, as the modem is asynchronous. I could try and send and at the same time, the modem could bleat something, which I have to parse and understand. To decide if the operation failed or not.

Thanks.

Regards,

Jon.

Jon Russell