SIM800 GSM module understanding the commands help

Thread Starter

zazas321

Joined Nov 29, 2015
936
Hey. I am using TinyGSM library to perform OTA firmware update for my ESP32 device using GSM. I have got it to work but I still have some questions that I want to understand.

I am using debugging mode which allows me to check all executed AT commands and the responses I get. I have gone through each AT command one by one and I feel like most of the commands are not necessary. I am hoping that someone who knows more about GSM modules ( SIM800L in particular because thats the one I am using) will be able to comment a little bit and help me figure out why does this library use so many commands.


1618300362046.png
1618300382379.png
1618300405040.png

1618300426060.png


And then the download starts from the server.

I am also including a word document which contains all the AT commands used in this program. I really cant grasp my does it require so many AT commands to perform this simple task.
 

Attachments

Last edited:

Thread Starter

zazas321

Joined Nov 29, 2015
936
I am not able to add my arduino code for some reason. The forum does not allow pasting code within code tags and also it does not allow to attach .ino file.
 

Ya’akov

Joined Jan 27, 2019
9,154
The initialization of the modem is to ensure it is in a known state before using it. The library is being conservative and not assuming the modem is in the expected configuration.
 

Thread Starter

zazas321

Joined Nov 29, 2015
936
Since I cannot understand the reason why most functions are being used in that library. I am developing my own GSM setup function:
Code:
void custom_modem_startup(){
  uint8_t res=0;
  Serial.println("Sending AT command to test the module");
  modem.sendAT(GF(""));
  modem.waitResponse();
  Serial.println("Setting up module in normal working mode");
  modem.sendAT(GF("+CFUN=1,1"));
  modem.waitResponse(20000L);
  delay(3000);
 
  Serial.println("test AT command after restart");
  // this will keep sending AT commands until it receives a good response. It may not response at first attempt because CFUN command restart the modem
  modem.sendAT(GF(""));
  res = modem.waitResponse(10000L);
  while(!res){
    modem.sendAT(GF(""));
    res = modem.waitResponse(10000L);
    delay(1000);
  }

  Serial.println("setting up time stamp");
  modem.sendAT(GF("+CLTS=1"));
  modem.waitResponse(10000L);

  Serial.println("testing AT command one last time to make sure all OK");
  modem.sendAT(GF(""));
  modem.waitResponse();
}
My custom GSM setup will execute following commands:
1. AT
2.AT+CFUN=1,1
3.AT+CLTS=1

I dont see why I would need anything else

whereas the library executes:
  • AT
  • AT&W (not sure what this command does)
  • AT+CFUN=0 why use this funciton if the following command sets the mode
  • AT+CFUN=1,1 (set phone functionality to full)
  • AT (at test)
  • ATE0 (turn of at command echo)
  • AT+CMEE=0 dont understand what this command does
  • AT+CLTS=1 (turn on local timestamp)
  • AT+CBATCHK=1 (this command not found on sim800 datasheet)
  • AT+CPIN? dont need this command for my application because I dont use password



Perhaps someone has an idea whether there will be any difference between my setup and tinygsm library setup
 

Ya’akov

Joined Jan 27, 2019
9,154
You seem to be doing things backwards. While it is possible that some of the setup is not needed, since you say, explicitly, you don’t understand why what appear to be redundant commands are being set, shouldn’t you leave them until such time as you know?

Many of these things are empirical. Through use people add things to deal with idiosyncratic behavior. It may well be, for example, setting CFUN to 0 is a way of clearing the setting to ensure the following setting to 1,1 is successful. If these things were done as bug fixes, how will you properly test that removing them doesn’t cause some boundary condition failure.

Something works, you don’t know why it’s done that way, so you want to change it because you can’t understand it? This just goes against all my experience. I’d certainly advise against fixing something that isn’t broken.
 

Thread Starter

zazas321

Joined Nov 29, 2015
936
From my experience, using a code that you cannot fully understand can bring a lot of problems in the future. I would not worry too much if that was my little hobby project but that is not the case for this project. For example if you encounter a problem, you may not even know where to look for an error because you simply dont understand whet the code does. I need to know exactly what each command does and how it affects the modem before I am confident enough to put this code for production.

While the setup function may be fine, the part where it is setting up gprs for the tcp connection confuses my even more.

I am reading SIM800L module datasheet where it explains how to make a tcp connection ( starting at page 6 )
https://cdn-shop.adafruit.com/product-files/2637/SIM800+Series_TCPIP_Application+Note_V1.01.pdf

And the explained procedure in the datasheet is quite a bit different compared to what the library is doing. That concerns me the most.
 

Ya’akov

Joined Jan 27, 2019
9,154
But you are using code you can't understand. Modifying it to code you also don't understand doesn't make it better.

Contact the library author, find a product specific forum, research the issue further—but cut out what you don't understand because you don't know why it is there? This is odd.

You might be right, it could be cruft or the result of previous cargo cult programming. It could be remnants of workarounds that are no longer needed, or, it could be stuff that was added as boundary condition failures occurred.

Your principle is correct, but can you find any indication the library is not reliable? If you don't understand it why would you think you are qualified to refactor it?
 

Thread Starter

zazas321

Joined Nov 29, 2015
936
I will keep learning more about the GSM module and use the library code for now since it seems to be working fine. The issue with the library is that the community has been very silent for the last couple of months. No new issues being solved on github as well as no one is chatting on gitter from what I have seen.
 

Ya’akov

Joined Jan 27, 2019
9,154
I will keep learning more about the GSM module and use the library code for now since it seems to be working fine. The issue with the library is that the community has been very silent for the last couple of months. No new issues being solved on github as well as no one is chatting on gitter from what I have seen.
I'd just be careful about ripping things out you don't understand. Unless you can find some evidence the library is flaky or poorly written, I would work from the assumption it was put there for a reason.
 

Ya’akov

Joined Jan 27, 2019
9,154
I don't know if you've seen this, but this article claims to provide a barebones initialization for GPRS use:

https://exploreembedded.com/wiki/Setting_up_GPRS_with_SIM800L

It makes sense, but it is exactly because the widely used library does so many additional and apparently contradictory things that I am concerned they were added empirically for some reason.

On the other hand, it could be a poorly written library, but it is so widely used it seems it would have been fixed by now.
 
Top