vshymanskyy / TinyGSM

A small Arduino library for GSM modules, that just works
GNU Lesser General Public License v3.0
1.94k stars 719 forks source link

Missing example on long term connections #415

Closed Zambiorix closed 4 years ago

Zambiorix commented 4 years ago

[x] I have read the Troubleshooting section of the ReadMe

What type of issues is this?

[ ] Request to support a new module

[ ] Bug or problem compiling the library [ ] Bug or issue with library functionality (ie, sending data over TCP/IP) [x] Question or request for help

What are you working with?

Modem: Sara R410m-02b Main processor board: ESP32 TinyGSM version: 0.10.6 Code:

Scenario, steps to reproduce

Expected result

Actual result

Hi,

Unless I'm mistaken I'm missing an example of how to use the library in a long term connected situation.

Most examples are: initialise, wait for network, connect gprs, connect client, send, receive, disconnect client, disconnect gprs and then loop indefinitely.

I'm totaly new to using gsm communication, so I'm struggling with the correct approach to use the library in case of an always-on situation. I understand this a place where issues should be reported. But I have no clue where to turn to, I cannot find a forum for TinyGSM users.

I am working on an application with Sara R410 LTE cat m1 and I need to send a small packet every 60 sec.

How do I keep going?

Now I do this (in a separate task):

  1. Initialize (restart etc)
  2. wait for network
  3. connect gprs
  4. connect client
  5. loop (waiting for packets to send, checking on connection states of network, gprs & client)

In my loop, I tear down the client and/or gprs connection and reconnect if needed (or wait for the network again if it's gone)

Is this the correct approach?

Or is it better to connect/disconnect my client for each packet to send? Same for grps connection, do I keep it alive or do I need to connect and disconnect for each packet to send?

And what if I need to send every 10 sec? or every 2 hours? Is the approach different in this situation?

If there is a longer time between sending packets, is there a way to put the device in sleep while still maintaining a connection? Or do I need to cleanup client and gprs connections?

Thank you for your help, much appreciated!

Cheers Gerd

SRGDamia1 commented 4 years ago

There is a gitter discussion chat, but it's very lightly used: https://gitter.im/tinygsm/Lobby

I haven't well tested options for keeping the connection open long term. In my applications everything has been battery powered and data is only ever going out so I set the module down to lowest power disconnected state (AT+CPWROFF) or cut its power entirely between connections (usually once every 5-15 minutes). That's easy and saves power, but it also means you miss all incoming data while your not powered and you have to go through the whole network registration with each power up.

With the SARA R410 if you're savvy you can save significant power while staying connected or at least semi-connected by using

Neither of those implemented in this library, though. If you want to implement it, most of the documentation on how to use both eDRX and PSM is in the system integration manual for the R4 series (get it on the u-blox website). Look in section 1.4 on operating modes. You use the commands AT+CPSMS and AT+CEDRXS to configure your timers. You need access to the PWR_ON pin to use PSM (just like you would for power-off mode).

Beyond power saving, there's no need to disconnect between outgoing packets. If you want an instant response to incoming and outgoing data you should be able to stay fully connected all the time.

Zambiorix commented 4 years ago

Thank you for the detailed feedback! I have already started writing my own custom driver for Sara R410 based on TinyGSM ..

eDRX looks exactely what I need!

Cheers

Mr-HaleYa commented 4 years ago

@Zambiorix Close this now that you solved it