Giter VIP home page Giter VIP logo

tinygsm's Introduction

SWUbanner

TinyGSM logo

A small Arduino library for GSM modules, that just works.

GitHub version Build status GitHub issues GitHub wiki GitHub stars License

If you like TinyGSM - give it a star, or fork it and contribute! GitHub stars GitHub forks

You can also join our chat: Gitter

Arduino Client interface support

This library is easy to integrate with lots of sketches which use Ethernet or WiFi. PubSubClient (MQTT), Blynk, HTTP Client and File Download examples are provided.

examples

TinyGSM is tiny

The complete WebClient example for Arduino Uno (via Software Serial) takes little resources:

Sketch uses 15022 bytes (46%) of program storage space. Maximum is 32256 bytes.
Global variables use 574 bytes (28%) of dynamic memory, leaving 1474 bytes for local variables. Maximum is 2048 bytes.

Arduino GSM library uses 15868 bytes (49%) of Flash and 1113 bytes (54%) of RAM in a similar scenario. TinyGSM also pulls data gently from the modem (whenever possible), so it can operate on very little RAM. Now, you have more space for your experiments.

Supported modems

  • SIMCom SIM800 series (SIM800A, SIM800C, SIM800L, SIM800H, SIM808, SIM868)
  • SIMCom SIM900 series (SIM900A, SIM900D, SIM908, SIM968)
  • SIMCom WCDMA/HSPA/HSPA+ Modules (SIM5360, SIM5320, SIM5300E, SIM5300E/A)
  • SIMCom LTE Modules (SIM7100E, SIM7500E, SIM7500A, SIM7600C, SIM7600E)
  • SIMCom SIM7000E/A/G CAT-M1/NB-IoT Module
  • SIMCom SIM7070/SIM7080/SIM7090 CAT-M1/NB-IoT Module
  • AI-Thinker A6, A6C, A7, A20
  • ESP8266/ESP32 (AT commands interface, similar to GSM modems)
  • Digi XBee WiFi and Cellular (using XBee command mode)
  • Neoway M590
  • u-blox 2G, 3G, 4G, and LTE Cat1 Cellular Modems (many modules including LEON-G100, LISA-U2xx, SARA-G3xx, SARA-U2xx, TOBY-L2xx, LARA-R2xx, MPCI-L2xx)
  • u-blox LTE-M/NB-IoT Modems (SARA-R4xx, SARA-N4xx, but NOT SARA-N2xx)
  • Sequans Monarch LTE Cat M1/NB1 (VZM20Q)
  • Quectel BG96
  • Quectel M95
  • Quectel MC60 (alpha)

Supported boards/modules

  • Arduino MKR GSM 1400
  • GPRSbee
  • Microduino GSM
  • Adafruit FONA (Mini Cellular GSM Breakout)
  • Adafruit FONA 800/808 Shield
  • Industruino GSM
  • RAK WisLTE (alpha)
  • ... other modules, based on supported modems. Some boards require special configuration.

More modems may be supported later:

  • Quectel M10, UG95
  • SIMCom SIM7020
  • Telit GL865
  • ZTE MG2639
  • Hi-Link HLK-RM04

Watch this repo for new updates! And of course, contributions are welcome ;)

Features

Data connections

  • TCP (HTTP, MQTT, Blynk, ...)
    • ALL modules support TCP connections
    • Most modules support multiple simultaneous connections:
      • A6/A7 - 8
      • ESP8266 - 5
      • Neoway M590 - 2
      • Quectel BG96 - 12
      • Quectel M95 - 6
      • Quectel MC60/MC60E - 6
      • Sequans Monarch - 6
      • SIM 800/900 - 5
      • SIM 5360/5320/5300/7100 - 10
      • SIM7000 - 8 possible without SSL, only 2 with
      • SIM 7070/7080/7090 - 12
      • SIM 7500/7600/7800 - 10
      • u-blox 2G/3G - 7
      • u-blox SARA R4/N4 - 7
      • Digi XBee - only 1 connection supported!
  • UDP
    • Not yet supported on any module, though it may be some day
  • SSL/TLS (HTTPS)
    • Supported on:
      • SIM800, SIM7000, u-Blox, XBee cellular, ESP8266, and Sequans Monarch
      • Note: only some device models or firmware revisions have this feature (SIM8xx R14.18, A7, etc.)
    • Not yet supported on:
      • Quectel modems, SIM 5360/5320/7100, SIM 7500/7600/7800
    • Not possible on:
      • SIM900, A6/A7, Neoway M590, XBee WiFi
    • Like TCP, most modules support simultaneous connections
    • TCP and SSL connections can usually be mixed up to the total number of possible connections

USSD

  • Sending USSD requests and decoding 7,8,16-bit responses
    • Supported on:
      • All SIMCom modems, Quectel modems, most u-blox
    • Not possible on:
      • XBee, u-blox SARA R4/N4, ESP8266 (obviously)

SMS

  • Only sending SMS is supported, not receiving
    • Supported on all cellular modules

Voice Calls

  • Supported on:
    • SIM800/SIM900, SIM7600, A6/A7, Quectel modems, u-blox
  • Not yet supported on:
    • SIM7000, SIM5360/5320/7100, SIM7500/7800, VZM20Q (Monarch)
  • Not possible on:
    • XBee (any type), u-blox SARA R4/N4, Neoway M590, ESP8266 (obviously)
  • Functions:
    • Dial, hangup
    • DTMF sending

Location

  • GPS/GNSS
    • SIM808, SIM7000, SIM7500/7600/7800, BG96, u-blox
    • NOTE: u-blox chips do NOT have embedded GPS - this functionality only works if a secondary GPS is connected to primary cellular chip over I2C
  • GSM location service
    • SIM800, SIM7000, Quectel, u-blox

Credits

Getting Started

First Steps

  1. Using your phone: - Disable PIN code on the SIM card - Check your balance - Check that APN, User, Pass are correct and you have internet
  2. Ensure the SIM card is correctly inserted into the module
  3. Ensure that GSM antenna is firmly attached
  4. Ensure that you have a stable power supply to the module of at least 2A.
  5. Check if serial connection is working (Hardware Serial is recommended) Send an AT command using this sketch
  6. Try out the WebClient example

Writing your own code

The general flow of your code should be:

  • Define the module that you are using (choose one and only one)
    • ie, #define TINY_GSM_MODEM_SIM800
  • Included TinyGSM
    • #include <TinyGsmClient.h>
  • Create a TinyGSM modem instance
    • TinyGsm modem(SerialAT);
  • Create one or more TinyGSM client instances
    • For a single connection, use
      • TinyGsmClient client(modem); or TinyGsmClientSecure client(modem); (on supported modules)
    • For multiple connections (on supported modules) use:
      • TinyGsmClient clientX(modem, 0);, TinyGsmClient clientY(modem, 1);, etc or
      • TinyGsmClientSecure clientX(modem, 0);, TinyGsmClientSecure clientY(modem, 1);, etc
    • Secure and insecure clients can usually be mixed when using multiple connections.
    • The total number of connections possible varies by module
  • Begin your serial communication and set all your pins as required to power your module and bring it to full functionality.
    • The examples attempt to guess the module's baud rate. In working code, you should use a set baud.
  • Wait for the module to be ready (could be as much as 6s, depending on the module)
  • Initialize the modem
    • modem.init() or modem.restart()
    • restart generally takes longer than init but ensures the module doesn't have lingering connections
  • Unlock your SIM, if necessary:
    • modem.simUnlock(GSM_PIN)
  • If using WiFi, specify your SSID information:
    • modem.networkConnect(wifiSSID, wifiPass)
    • Network registration should be automatic on cellular modules
  • Wait for network registration to be successful
    • modem.waitForNetwork(600000L)
  • If using cellular, establish the GPRS or EPS data connection after your are successfully registered on the network
    • modem.gprsConnect(apn, gprsUser, gprsPass) (or simply modem.gprsConnect(apn))
    • The same command is used for both GPRS or EPS connection
    • If using a Digi brand cellular XBee, you must specify your GPRS/EPS connection information before waiting for the network. This is true ONLY for Digi cellular XBees! For all other cellular modules, use the GPRS connect function after network registration.
  • Connect the TCP or SSL client client.connect(server, port)
  • Send out your data.

If you have any issues

  1. Read the whole README (you're looking at it!), particularly the troubleshooting section below.
  2. Some boards require special configuration.
  3. Try running the Diagnostics sketch
  4. Check for highlighted topics here
  5. If you have a question, please post it in our Gitter chat

How does it work?

Many GSM modems, WiFi and radio modules can be controlled by sending AT commands over Serial. TinyGSM knows which commands to send, and how to handle AT responses, and wraps that into standard Arduino Client interface.

This library is "blocking" in all of its communication. Depending on the function, your code may be blocked for a long time waiting for the module responses. Apart from the obvious (ie, waitForNetwork()) several other functions may block your code for up to several minutes. The gprsConnect() and client.connect() functions commonly block the longest, especially in poorer service regions. The module shutdown and restart may also be quite slow.

This libary does not support any sort of "hardware" or pin level controls for the modules. If you need to turn your module on or reset it using some sort of High/Low/High pin sequence, you must write those functions yourself.

API Reference

For GPRS data streams, this library provides the standard Arduino Client interface. For additional functions, please refer to this example sketch

Troubleshooting

Ensure stable data & power connection

Most modules require as much as 2A to properly connect to the network. This is 4x what a "standard" USB will supply! Improving the power supply actually solves stability problems in many cases!

  • Read about powering your module.
  • Keep your wires as short as possible
  • Consider soldering them for a stable connection
  • Do not put your wires next to noisy signal sources (buck converters, antennas, oscillators etc.)
  • If everything else seems to be working but you are unable to connect to the network, check your power supply!

Baud rates

Most modules support some sort of "auto-bauding" feature where the module will attempt to adjust it's baud rate to match what it is receiving. TinyGSM also implements its own auto bauding function (TinyGsmAutoBaud(SerialAT, GSM_AUTOBAUD_MIN, GSM_AUTOBAUD_MAX);). While very useful when initially connecting to a module and doing tests, these should NOT be used in any sort of production code. Once you've established communication with the module, set the baud rate using the setBaud(#) function and stick with that rate.

Broken initial configuration

Sometimes (especially if you played with AT commands), your module configuration may become invalid. This may result in problems such as:

  • Can't connect to the GPRS network
  • Can't connect to the server
  • Sent/received data contains invalid bytes
  • etc.

To return module to Factory Defaults, use this sketch: File -> Examples -> TinyGSM -> tools -> FactoryReset

In some cases, you may need to set an initial APN to connect to the cellular network. Try using the gprsConnect(APN) function to set an initial APN if you are unable to register on the network. You may need set the APN again after registering. (In most cases, you should set the APN after registration.)

Failed connection or no data received

The first connection with a new SIM card, a new module, or at a new location/tower may take a LONG time - up to 15 minutes or even more, especially if the signal quality isn't excellent. If it is your first connection, you may need to adjust your wait times and possibly go to lunch while you're waiting.

If you are able to open a TCP connection but have the connection close before receiving data, try adding a keep-alive header to your request. Some modules (ie, the SIM7000 in SSL mode) will immediately throw away any un-read data when the remote server closes the connection - sometimes without even giving a notification that data arrived in the first place. When using MQTT, to keep a continuous connection you may need to reduce your keep-alive interval (PINGREQ/PINGRESP).

Diagnostics sketch

Use this sketch to help diagnose SIM card and GPRS connection issues: File -> Examples -> TinyGSM -> tools -> Diagnostics

If the diagnostics fail, uncomment this line to output some debugging comments from the library:

#define TINY_GSM_DEBUG SerialMon

In any custom code, TINY_GSM_DEBUG must be defined before including the TinyGSM library.

If you are unable to see any obvious errors in the library debugging, use StreamDebugger to copy the entire AT command sequence to the main serial port. In the diagnostics example, simply uncomment the line:

#define DUMP_AT_COMMANDS

In custom code, you can add this snippit:

#ifdef DUMP_AT_COMMANDS
  #include <StreamDebugger.h>
  StreamDebugger debugger(SerialAT, SerialMon);
  TinyGsm modem(debugger);
#else
  TinyGsm modem(SerialAT);
#endif

Web request formatting problems - "but it works with PostMan"

This library opens a TCP (or SSL) connection to a server. In the OSI model, that's layer 4 (or 5 for SSL). HTTP (GET/POST), MQTT, and most of the other functions you probably want to use live up at layer 7. This means that you need to either manually code the top layer or use another library (like HTTPClient or PubSubClient) to do it for you. Tools like PostMan also show layer 7, not layer 4/5 like TinyGSM. If you are successfully connecting to a server, but getting responses of "bad request" (or no response), the issue is probably your formatting. Here are some tips for writing layer 7 (particularly HTTP request) manually:

  • Look at the "WebClient" example
  • Make sure you are including all required headers.
    • If you are testing with PostMan, make sure you un-hide and look at the "auto-generated" headers; you'll probably be surprised by how many of them there are.
  • Use client.print("..."), or client.write(buf, #), or even client.write(String("...")), not client.write("...") to help prevent text being sent out one character at a time (typewriter style)
  • Enclose the entirety of each header or line within a single string or print statement
    • use
    client.print(String("GET ") + resource + " HTTP/1.1\r\n");
    instead of
    client.print("GET ");
    client.print(resource);
    client.println(" HTTP/1.1")
  • Make sure there is one entirely blank line between the last header and the content of any POST request.
    • Add two lines to the last header client.print("....\r\n\r\n") or put in an extra client.println()
    • This is an HTTP requirement and is really easy to miss.

SoftwareSerial problems

When using SoftwareSerial (on Uno, Nano, etc), the speed 115200 may not work. Try selecting 57600, 38400, or even lower - the one that works best for you. In some cases 9600 is unstable, but using 38400 helps, etc. Be sure to set correct TX/RX pins in the sketch. Please note that not every Arduino pin can serve as TX or RX pin. Read more about SoftSerial options and configuration here and here.

ESP32 Notes

HardwareSerial

When using ESP32 HardwareSerial, you may need to specify additional parameters to the .begin() call. Please refer to this comment.

HttpClient

You will not be able to compile the HttpClient or HttpsClient examples with ESP32 core 1.0.2. Upgrade to 1.0.3, downgrade to version 1.0.1 or use the WebClient example.

SAMD21

When using SAMD21-based boards, you may need to use a sercom uart port instead of Serial1. Please refer to this comment.

Goouuu Tech IOT-GA6 vs AI-Thinker A6 confusion

It turns out that Goouuu Tech IOT-GA6 is not the same as AI-Thinker A6. Unfortunately IOT-GA6 is not supported out of the box yet. There are some hints that IOT-GA6 firmware may be updated to match A6... See this topic.

SIM800 and SSL

Some, but not all, versions of the SIM800 support SSL. Having SSL support depends on the firmware version and the individual module. Users have had varying levels of success in using SSL on the SIM800 even with apparently identical firmware. If you need SSL and it does not appear to be working on your SIM800, try a different module or try using a secondary SSL library.

Which version of the SIM7000 code to use

There are two versions of the SIM7000 code, one using TINY_GSM_MODEM_SIM7000 and another with TINY_GSM_MODEM_SIM7000SSL. The TINY_GSM_MODEM_SIM7000 version does not support SSL but supports up to 8 simultaneous connections. The TINY_GSM_MODEM_SIM7000SSL version supports both SSL and unsecured connections with up to 2 simultaneous connections. So why are there two versions? The "SSL" version uses the SIM7000's "application" commands while the other uses the "TCP-IP toolkit". Depending on your region/firmware, one or the other may not work for you. Try both and use whichever is more stable. If you do not need SSL, I recommend starting with TINY_GSM_MODEM_SIM7000.


License

This project is released under The GNU Lesser General Public License (LGPL-3.0)

tinygsm's People

Contributors

adrianca88 avatar alexiii avatar anoxysoftware avatar bhagman avatar brvdg avatar captfuture avatar dependabot[bot] avatar ffontaine avatar fishingbit avatar hubaksis avatar iotthinks avatar ivankravets avatar j3tm0t0 avatar jpmeijers avatar ldab avatar lukasskywalker avatar marabesi avatar mikhailgalitskiy avatar nootropicdesign avatar qcabrol avatar replicadeltd avatar shajek avatar slavino avatar srgdamia1 avatar ucis avatar v1pr avatar vincekezel avatar vshymanskyy avatar wifixcort avatar xslim avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tinygsm's Issues

Shield connection

Issue similar to the previous one (#18).
I have a sim900 arduino shield, similar to attached image.
sim900-gprsgsm-shield-for-arduino

When it is mounted on arduino uno, using this wonderful library, all works fine. But when I make connections with jumper wires it doesn't work. I use softwareserial on pins 7 and 8 at 9600 bauds and 9 for powering on/off the shield.

Manual AT commands works, but the AT_debug sketch doesn't find any baudrate, and cannot connect even with forced 9600 set.

Should I connect other pins in addition to 7, 8 and 9 to make the library work?

Lots of thanks, also for the great job made with this library!
L.

[A6/A7] Encrypted MQTT Connection

Hi,

Great work on TinyGSM, just tested with an AI Thinker A7. I started testing against my MQTT broker on port 8883 and it times out, tested with 1883 and that works fine.

Cant find any information on the A7 or A6 about TLS/SSL support, do you know if its supported ?

Loss of connectivity doesn't force modem restart

Hello!
Thanks for the great lib and forgive me if it isn´t the proper place to post this. The issue I'm having is related to a lost of connection with the GPRS network. I.e. the modem is still connected but I can't access any host.

System setup:
Arduino Nano
Neoway M590e GPRS modem

Heres the log:

Initializing modem...
[35153] 
    ___  __          __
   / _ )/ /_ _____  / /__
  / _  / / // / _ \/  '_/
 /____/_/\_, /_//_/_/\_\
        /___/ v0.4.7 on Arduino Nano

[35161] Free RAM: 925
[35163] Modem init...
[35491] Connecting to network...
[54733] Network: TIM BRASIL
[54733] Connecting to timbrasil.br ...
[65097] Connected to GPRS
[69203] Connecting to blynk-cloud.com:8442
[293616] Connecting to blynk-cloud.com:8442
[320898] <[02|00|01|00] ****
[328081] Connecting to blynk-cloud.com:8442
[328978] <[02|00|01|00] ****
[330229] >[00|00|01|00|C8]
[330230] Ready (ping: 1122ms).
[330241] <[11|00|01|00]fver[00]0.4.7[00]h-beat[00]60[00]buff-in[00]256[00]dev[00]Arduino Nano[00]cpu[00]ATmega328P[00]con[00]SIM800[00]build[00]Jun  4 2017 13:17:30[00]
[332735] <[14|00|02|00|0B]vw[00]1[00]23.000
[332839] <[14|00|03|00|0B]vw[00]2[00]68.000
[333014] >[00|00|01|00|C8]
[392953] <[06|00|04|00|00]
[393335] <[14|00|05|00|0B]vw[00]1[00]23.000
[393445] <[14|00|06|00|0B]vw[00]2[00]68.000
[399041] <[06|00|07|00|00]
[431951] >[00|00|07|00|C8]
[453758] <[14|00|08|00|0B]vw[00]1[00]24.000
[454777] Cmd error
[456830] Cmd skipped:20
[459939] Connecting to blynk-cloud.com:8442
[691460] Cmd skipped:20
[691461] Cmd skipped:20
[694569] Connecting to blynk-cloud.com:8442
[926090] Cmd skipped:20
[926091] Cmd skipped:20
[929199] Connecting to blynk-cloud.com:8442

As you may see the modem initializes, the connection is established but then it loses the heartbeat and keeps trying to reconnect forever. A modem restart seems to solve the problem, but the code it self could´ve been able to handle this situation.
Looking on the library code I saw a private function "dnsIpQuery" which could be a good way to check if the connectivity is lost and force a modem restart but I haven't been able to understand how to use it. Dunno if it might help, but here's my sketch code:

#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#define BLYNK_DEBUG
// Default heartbeat interval for GSM is 60
// If you want override this value, uncomment and set this option:
//#define BLYNK_HEARTBEAT 30

#define TINY_GSM_MODEM_M590

#include <TinyGsmClient.h>
#include <BlynkSimpleSIM800.h>

#include <SimpleTimer.h>
#include <DHT.h>
#define DHTPIN 4 // O pino que estive conectado...
#define DHTTYPE DHT11 // DHT 11

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
const char auth[] = "********";

// Your GPRS credentials
// Leave empty, if missing user or pass
const char apn[]  = "timbrasil.br";
const char user[] = "tim";
const char pass[] = "tim";

// Hardware Serial on Mega, Leonardo, Micro
//#define SerialAT Serial1

// or Software Serial on Uno, Nano
#include <SoftwareSerial.h>
SoftwareSerial SerialAT(2, 3); // RX, TX

TinyGsm modem(SerialAT);
DHT dht(DHTPIN, DHTTYPE); //Da um nome para o Sensor
SimpleTimer timer; // define o objeto timer

void setup()
{
  // Set console baud rate
  Serial.begin(115200);
  delay(10);

  // Set GSM module baud rate
  SerialAT.begin(9600);
  delay(3000);

  // Restart takes quite some time
  // To skip it, call init() instead of restart()
  Serial.println("Initializing modem...");
  modem.restart();

  // Unlock your SIM card with a PIN
  //modem.simUnlock("1234");

  Blynk.begin(auth, modem, apn, user, pass);
  dht.begin();
  delay(2000);
  sendUpdtTempHum();
  timer.setInterval(60000, sendUpdtTempHum);
}

void loop()
{
  while(modem.dnsIpQuery("blynk-cloud.com")) {
    Blynk.run();
    timer.run();
  }
  modem.restart();
 }

void sendUpdtTempHum()
{
  float humid = dht.readHumidity();
  float temp = dht.readTemperature();
//  Serial.print("Temp: ");
//  Serial.println(temp);
//  Serial.print("Humid: ");
//  Serial.println(humid);
  Blynk.virtualWrite(1, temp);
  Blynk.virtualWrite(2, humid);
}

Faster processors fail inside of Blynk.begin() -- trying to authorize--Simcom 800

I have found that an Arduino Pro (even 8mHz version) gets through the blynk connection phase, whereas the Intel Curie, for example, does not. I turned on traces (DBG) in TinyGsmClientSIM800.h and observed the following on my Arduino 101. It appears waitResponse is giving up prior to receiving the entire string "+CIPRXGET: 1,1:" following the write of the 37 bytes of authorization cmd.:

### AT: +CIPSEND= 1 , 37

The response shows up instead as two arrivals that are unhandled:

### Unhandled: +CIPRX
### Unhandled: GET: 1,1:

Here's more of a trace:

[10140] Connecting to network...
### AT: +CREG?
### AT: +COPS?
[10360] Network: T-Mobile USA
[10386] Connecting to  ...
### AT: +CIPSHUT
### AT: +SAPBR=3,1,"Contype","GPRS"
### AT: +SAPBR=3,1,"APN","  "
### AT: +SAPBR=3,1,"USER","  "
### AT: +SAPBR=3,1,"PWD","  "
### AT: +CGDCONT=1,"IP","  "
### AT: +CGACT=1,1
### AT: +SAPBR=1,1
### AT: +SAPBR=2,1
### AT: +CGATT=1
### AT: +CIPMUX=1
### AT: +CIPQSEND=1
### AT: +CIPRXGET=1
### AT: +CSTT="  ","  ","  "
### AT: +CIICR
### AT: +CIFSR;E0
### AT: +CDNSCFG="8.8.8.8","8.8.4.4"
[11723] Connected to GPRS
### AT: +CIPCLOSE= 1
### AT: +CIPCLOSE= 1
[11884] Connecting to blynk-cloud.com:8442
### AT: +CIPSTART= 1 , "TCP "," blynk-cloud.com ", 8442
[12756] <[02|00|01|00] axx627d16c4vv640aee7d6tte731zzz0  // string disguised
### AT: +CIPSEND= 1 , 37
### Unhandled: +CIPRX
### Unhandled: GET: 1,1
[19011] Login timeout
### AT: +CIPCLOSE= 1
### AT: +CIPCLOSE= 1
[19189] Connecting to blynk-cloud.com:8442
### AT: +CIPSTART= 1 , "TCP "," blynk-cloud.com ", 8442
[19869] <[02|00|01|00] axx627d16c4vv640aee7d6tte731zzz0  // string disguised
### AT: +CIPSEND= 1 , 37
### Unhandled: +CIPRX
### Unhandled: GET: 1,1

[A6] Diagnostics from tools "### Unhandled:" or 0 byte on read()

Hi,

two issues with the same result.

using the A6 modem on a A20 with ESP8285 and SoftwareSerial on 9600 baud I receive
"### Unhandled: OK" or "no content at all"

I use the
https://github.com/arduino-libraries/ArduinoHttpClient/
and receive a timeout.

This scatch will lead lead to the "###Unhandled:" debug statements while the request is seen on the server side. "###Unhandled:" will appear on the server response upon +CIPRCV.
If "###Unhandled:" does not appear, you can see from the debug log that CIPRCV receives the data but the gsmclient.read() API does not receive a single byte.

  
  if (!gsmclient.connect(SERVER, HTTP_PORT)) {
    delay(10000);
    return ret;
  }

  // Make a HTTP GET request:
  gsmclient.print(String("GET ") + url + " HTTP/1.1\r\n");
  gsmclient.print(String("Host: ") + SERVER + "\r\n");
  gsmclient.print("Connection: close\r\n\r\n");

  unsigned long timeout = millis();
  while (gsmclient.connected() && millis() - timeout < 10000L) {
    // Print available data
    while (gsmclient.available()) {
      char c = gsmclient.read();
      Serial.print(c);
      timeout = millis();
    }
  }

  gsmclient.stop();
chksum Initializing modem...ATE0
ATE0
ATE0
ATE0
ATE0
ATE0
ATE0

OK
AT+RST=1
ATE0
ATE0
ATE0
ATE0
ATE0
ATE0
ATE0
ATE0
ATE0
ATE0
ATE0
ATE0
ATE0
ATE0
ATE0
ATE0
ATE0

OK
AT&FZE0

OK
AT+CMEE=0

OK
AT+CPIN?

ERROR
AT+CPIN?

+CPIN:SIM PIN

OK
AT+CPIN="6450"

OK
AT+CPIN?

^STN: 37

^CINIT: 4, 8192AT+CPIN?
CINIT: 32, 0, 0

+CREG: 0
AT+CPIN?

+CPIN:READY

+CPIN:READY

OK
Waiting for network...AT+CREG?

+CREG: 1,10

OK
AT+CREG?

+CREG: 1,10

OK
AT+CREG?

+CREG: 1,10

OK
AT+CREG?

+CREG: 1,10

OK
AT+CREG?

+CREG: 1,10

OK
AT+CREG?

+CREG: 1,10

OK
AT+CREG?

+CREG: 1,10

OK
AT+CREG?

+CREG: 1,10

OK
AT+CREG?

+CREG: 1,10

OK
AT+CREG?

+CREG: 1,10

OK
AT+CREG?

+CREG: 1,10

OK
AT+CREG?

+CREG: 1,10

OK
AT+CREG?

+CREG: 1,10

OK
AT+CREG?

+CREG: 1,10

OK
AT+CREG?

+CREG: 1,10

OK
AT+CREG?

+CREG: 1,10

OK
AT+CREG?

+CREG: 1,10

OK
AT+CREG?

+CREG: 1,10

OK
AT+CREG?

+CREG: 1,10

OK
AT+CREG?

+CREG: 1,10

OK
AT+CREG?

+CREG: 1,10

OK
AT+CREG?

+CREG: 1,10

OK
AT+CREG?

+CREG: 1,1

OK
 OK
Connecting to internetAT+CIPSHUT

ERROR
AT+CGDCONT=1,"IP","internet"

OK
AT+CSTT="internet","",""

OK
AT+CGACT=1,1

+CTZV:17/07/17,22:22:35,+02

OK
AT+CGATT=1

OK
AT+CIPMUX=1

OK
 OK
Connecting to cdn.rawgit.comAT+CIPSTART="TCP","cdn.rawgit.com",80

+CIPNUM:0

CONNECT OK

OK
 OK
AT+CIPSEND=0,65

>GET /vshymanskyy/tinygsm/master/extras/test_simple.txt HTTP/1.1

OK
AT+CIPSEND=0,22

>Host: cdn.rawgit.com

OK
AT+CIPSEND=0,21

>Connection: close


OK

+CIPRCV:0,402,HTTP/1.1 200 OK
Date: Mon, 17 Jul 2017 22:22:43 GMT
Content-Type: text/plain;charset=utf-8
Transfer-Encoding: chunked
Connection: close
X-Content-Type-Options: nosniff
X-Robots-Tag: none
Access-Control-Allow-Origin: *
ETag: "675136a9bcc9b879e0ebcfbee3eb7bc7745c2e27"
Cache-Control: max-age=86400
Vary: Accept-Encoding
RawGit-Cache-Status: HIT
Server: NetDNA-cache/2.2
X-Cache: HIT

3e8


�+CIPRCV:0,402,01 #$%@`"'~^&-*+=!?.,:;_\|/<>()[]{} 0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
02 #$%@`"'~^&-*+=!?.,:;_\|/<>()[]{} 0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
03 #$%@`"'~^&-*+=!?.,:;_\|/<>()[]{} 0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
04 #$%@`"'~^&-*+=!?.,:;_\|/<>()[]{} 0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
05

�+CIPRCV:0,402, #$%@`"'~^&-*+=!?.,:;_\|/<>()[]{} 0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
06 #$%@`"'~^&-*+=!?.,:;_\|/<>()[]{} 0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
07 #$%@`"'~^&-*+=!?.,:;_\|/<>()[]{} 0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
08 #$%@`"'~^&-*+=!?.,:;_\|/<>()[]{} 0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
09 #

�+CIPRCV:0,203,$%@`"'~^&-*+=!?.,:;_\|/<>()[]{} 0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
10 #$%@`"'~^&-*+=!?.,:;_\|/<>()[]{} 0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz

0



�
+TCPCLOSED:0

OK
AT+CIPCLOSE=0

ERROR
Server disconnected
AT+CIPSHUT

ERROR
GPRS disconnected

************************
 Received: 0 bytes
 Test:     FAIL
************************

[A7] ESP8266 will not connect to network.

Hi, I cant get the lib to connect to my local network.
APN, UuserName, Password are correct.
It just will not pass:
if (!modem.gprsConnect(apn, user, pass)) {
Serial.println(" fail");
delay(10000);
return;
}
any ideas?

Library that just fail

Hi!
I have Mega2560, SIM800L and standard wiring:
SIM800L has separate strong power.
Mega TX -> SIM RX0
Mega RX -> SIM TX0

After sketch started, I open Serial Monitor and see rubbish (mostly empty squares). Maybe speed? At bottom of Monitor speed is 9600, obviously not a problem. Library which just fails...
I didn't run 'Diagnostics', because it requires downloading other lib, what is boring. Just stopped.

[SIM800] modem.getBattVoltage() cause lockup

Hi there

Thanks for a nice and compact GSM library. I've recently tried adding the getBattVoltage to my sketch (operating on a SIM800H) and noticed that calling this function cause my code to hang roughly every 5-20th time it's being called (a 5x8 sec watchdog interrupt alert me that I'm hanging).

I'm sure that it is the function which cause these crashes, but it might be the product of factors I don't consider. When the code freezeI never reach the "vBat OK" print - and if I comment out the modem.getBattVoltage() the code runs without problems for hours.

Any ideas on how to fix this or what it might be caused by?

  payload += ",\"SG\":" ; //Sleep Gateway
  payload += sleepTime; // append sleep time of node
  Serial.print(F("Sleep OK: "));
  delay(10);
  //Use: float vBatt = modem.getBattVoltage() / 1000.0;
  float vBatt = modem.getBattVoltage() / 1000.0 ;
  payload += ",\"BG\":" ;//
  payload += vBatt; // append battery of gateway
  Serial.print(F("vBat OK: "));
  payload += "}}";
  Serial.print(F("Sending payload: "));
  Serial.println(payload);
  delay(50);

Kind regards
Jesper

[SIM900/SIM800] Freeze after about 15 Minutes

After about 10-15 minutes, with a few reconnectings in between my code stops working. The ardino dose not receive anything and dose not transmit anything anymore. I have to manualy reset it to get it working again.
Dose anybody managed to get anything stable with this library?
I'm using sim800H with arduino running on 8Mhz. The GSM modem works just fine and i don't think is anything related to my code.
The brocker i use is : broker.hivemq.com
Can it be something related to the brocker?
Thanks.

ESP-12E and A6

Greetings,

I'm attempting to integrate this library into my project where I am publishing MQTT packets to the server via Wi-Fi and when it's not available, then the publishing is done via A6 module. While implementing the Wi-Fi part is quite easy with the PubSubClient, I found a lot of difficulties implementing this library. ESP-12E has a thing called watchdog that makes sure the loop() doesn't take too long, otherwise the module restarts itself to prevent possible infinite loops or some other errors. TinyGSM takes a while waiting for response from the A6 module and ESP-12E just restarts itself as the loop() takes too long. So I'm looking for any kind of useful tip to work my way around this instead of writing a new library from scratch.

Thank you for your time.

[SIM908][DFROBOT Shield][Arduino Mega][GSM] problem Initializing modem

Hello,

I'd like to use the TinyGSM library but until now for me is something impossible.

First of all, I've been able to connect using the "AT Command Tester" app and the module works fine but when I try to use the TinyGSM with the Diagnostic I get this output:

Initializing modem...
fail


Is your modem connected properly?
Is your serial speed (baud rate) correct?
Is your modem powered on?
Do you use a good, stable power source?
Try useing File -> Examples -> TinyGSM -> tools -> AT_Debug to find correct configuration


Following the instructions from dfrobot wiki for use the AT Command Tester app:

  1. Shield switchs S1: Prog and S2: Arduino
  2. Loaded sketch
void setup() {
  //Init the driver pins for GSM function
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  //Output GSM Timing
  digitalWrite(5, HIGH);
  delay(1500);
  digitalWrite(5, LOW);
}

void loop() {
  digitalWrite(3, HIGH); //disable GSM TX、RX
  digitalWrite(4, HIGH); //disable GPS TX、RX
}
  1. Power off and put Shield switchs S1: Comm and S2: Arduino
  2. Power on and connect the AT Command Tester with 9600 bauds
  3. Send AT commands as normal and working fine.

Now If I try to load the Diagnostics sketch of the TinyGSM library it doesn't work, and I'm totally lost.

Before upload the code I modified a little bit:

  1. Select the modem: #define TINY_GSM_MODEM_SIM900
  2. Adapt the baud setup:
void setup() {
  // Set console baud rate
  SerialMon.begin(9600);
  delay(10);

  // Set GSM module baud rate
  SerialAT.begin(9600);
  delay(3000);
}

The arduino mega is connected to an external power supply of 12v and 2.5A. And I follow this instructions for change the Auto baud setup of the module to 9600.

Any ideas?

I know that place is for issues about the library and my question is support question, but I don't know where I have to go. A lot of thanks!!

A6 work unstable.

Hi!
I use a A7mini +mega2560 with sample mqtt code.Seems work good,but after hours,it can't connect to my
mqtt sever. The module 's blue led blinks once a second. I can't solve .Could u help me?

Adafruit Fona 808 (SIM808) on Arduino mega (help wanted)

I have an Arduino Mega 2560 and a Adafruit Fona 808 shield.
When I use the Adafruit test sketch the serial monitor says "FONA is OK" and "Found FONA 808 (v2)" and I can run the test cases like read the sim ID, etc.
So I assume the wiring, available power etc all is OK.
Even though I am using the Mega I am using SoftwareSerial since Adafruit Fona currently does not support hardware serial. Next to the pins that work for the Adafruit test sketch, I have tried all Mega serial pins without any luck.
While using AT_debug all baud rates fail.
Do you have a suggestion what to do/check next?

GPRS Status

Hi! First of all, congratulations for your library! It just works! I am integrating it with the thinger.io platform, and got nice results! :)

Just one question. My device must be connected indefinitely to a socket, and the device have some mechanisms to detecting connection loss, autoreconnect, and so on. I have managed to check the current network status by calling the getRegistrationStatus(), that let me avoid registering again to the network if the modem is already connected to it. I need a similar check for the GPRS Apn connection. The socket may be closed by the remote endpoint, but my modem can still be connected to the APN. Do you know if there is any way to check if the modem is connected to the APN to avoid reconnecting again? I am trying to optimize and minimize the network operations...

Thanks!

Example for a stable MQTT client

Hi,
it seems, that the example MQTT client is not stable. Sometimes it works some hour, sometimes only few minutes.

Did somebody wrote a really stable MQTT client and can get me the code?

Here is my testcode, very close to the example code:

/**************************************************************
*


  • Use Mosquitto client tools to work with MQTT
  • Ubuntu/Linux: sudo apt-get install mosquitto-clients
  • Windows: https://mosquitto.org/download/
  • Subscribe for messages:
  • mosquitto_sub -h test.mosquitto.org -t GsmClientTest/init -t GsmClientTest/ledStatus -q 1
  • Toggle led:
  • mosquitto_pub -h test.mosquitto.org -t GsmClientTest/led -q 1 -m "toggle"
  • You can use Node-RED for wiring together MQTT-enabled devices
  • https://nodered.org/
  • Also, take a look at these additional Node-RED modules:
  • node-red-contrib-blynk-websockets
  • node-red-dashboard

**************************************************************/

// Select your modem:
#define TINY_GSM_MODEM_SIM800
//#define TINY_GSM_MODEM_SIM900
//#define TINY_GSM_MODEM_A6
//#define TINY_GSM_MODEM_M590

#define TINY_GSM_RX_BUFFER 512

#include <TinyGsmClient.h>
#include <PubSubClient.h>

// Your GPRS credentials
// Leave empty, if missing user or pass
const char apn[] = "web.vodafone.de";
const char user[] = "";
const char pass[] = "";

// Use Hardware Serial on Mega, Leonardo, Micro
#define SerialAT Serial

// or Software Serial on Uno, Nano
//#include <SoftwareSerial.h>
//SoftwareSerial SerialAT(5, 4); // RX, TX

TinyGsm modem(SerialAT);
TinyGsmClient client(modem);
PubSubClient mqtt(client);

long lastReconnectAttempt = 0;

unsigned long lastSend = 0;

void setup() {
// Set GSM module baud rate
SerialAT.begin(115200);
delay(3000);

// Restart takes quite some time
// To skip it, call init() instead of restart()
//Serial.println("Initializing modem...");
modem.restart();

//Serial.print("Waiting for network...");
if (!modem.waitForNetwork()) {
//Serial.println(" fail");
while (true);
}
//Serial.println(" OK");

//Serial.print("Connecting to ");
//Serial.print(apn);
if (!modem.gprsConnect(apn, user, pass)) {
//Serial.println(" fail");
while (true);
}
//Serial.println(" OK");

// MQTT Broker setup
mqtt.setServer("servername", 1883);
}

boolean mqttConnect() {
if (!mqtt.connect("GsmClientTest", "username", "password")) {
//Serial.println(" fail");
//Serial.println(mqtt.state());
return false;
}
//Serial.println(" OK");
delay(10000);
mqtt.publish("owntracks/wohnmobil/elnagh", "GsmClientTest started");
return mqtt.connected();
}

void loop() {
unsigned long time;

char msgBuffer[20];

if (mqtt.connected()) {
mqtt.loop();
} else {
// Reconnect every 10 seconds
unsigned long t = millis();
if (t - lastReconnectAttempt > 10000L) {
lastReconnectAttempt = t;
if (mqttConnect()) {
lastReconnectAttempt = 0;
}
}
}
if (millis()-lastSend>10000) {
time = millis();
mqtt.publish("owntracks/wohnmobil/elnagh", dtostrf(time, 6, 0, msgBuffer));
lastSend=millis();
}
}

best regards

Holger

Start to implement getLocation()

Hi,
I need to access to A6 module location, however as I can see since february in Issue #14 , getLocation() is not working.
I've got the following questions:

  1. What is missing to implement getLocation() ? , or What issues have you found by trying to implement that?
  2. Which of the following commands are you using?
    2.1 GSM 07.07
    2.2 GSM 07.05
    2.3 Ai Thinker extended commands

I'll start to work on getLocation, please help me with any information you have.
Thank you 👍

SIM5320

Thank you for your work on this so far. Can't wait to get my projects working over cellular networks!

If you had time to implement the SIM5320 I know a lot of people would appreciate it - Adafruit haven't yet completed a library for this module in their FONA 3G break-out.

knowing Local IP Address

is there any function in TinyGsm class so that i can get the Local IP address assigned by GSM operator after calling gprsConnect() function ?????
Thank you!

A6 don't connect APN

I test found A6 don't connect APN,always fail, I used MQTT example, but AT_DBUG is OK

Http Post

Hi,

I am trying to send some args to a web server. The example is showing fine with HTTP get below:

client.print(String("GET ") + resource + " HTTP/1.0\r\n");
client.print(String("Host: ") + server + "\r\n");
client.print("Connection: close\r\n\r\n");`

But how do I achieve for POST method?
Thanks.

[SIM900/SIM800] ERROR LOOP after a short time

I have a SIM900 connected to an arduino uno (Software Serial) running the MQTT example.
I publish a message every 10 seconds.
After about 3-5 Minutes the sketch will end up in a loop.
This also happens if i use Hardware Serial for the SIM900.
Can it be a bad serial connection (i´m using 9600 baud)? (Noise because of the GSM Module).
Or is there something wrong with the software.

Attached is a Debug log of the communication and the sktech

testgsm2sktech.txt

debug.txt

[A6/A7] call status

Hi,
i have a question about a6/a7 future implementation,
You are planning to add call status information?
Something like in this lib:
https://github.com/skorokithakis/A6lib/blob/master/A6lib.h#L30

I try to build car location logger with some alarm functions
and Your lib looks promising, at this moment I can upload
data to remote server (I hope that getLocation will be added soon)

But very desirable fuction is a callstatus, when A7 module call number
then I need feedback inside code if recipient picked up or reject or not answer etc...

What about receive sms? It would be also a good option for sending commands to module.

regards!

Bug when sending an SMS

#include <TinyGsmClient.h>
#include <StreamDebugger.h>

// Set serial for debug console (to the Serial Monitor, speed 115200)
#define SerialMon Serial

// Set serial for AT commands (to the module)
// Use Hardware Serial on Mega, Leonardo, Micro
//#define SerialAT Serial1

// or Software Serial on Uno, Nano
#include <SoftwareSerial.h>
SoftwareSerial SerialAT(10, 11); // TX, RX

StreamDebugger debugger(SerialAT, SerialMon);
TinyGsm modem(debugger);
//TinyGsm modem(Serial);
TinyGsmClient client(modem);

void setup()
{
// Set console baud rate
SerialMon.begin(38400);
delay(10);
SerialMon.println("1");

// Set GSM module baud rate
SerialAT.begin(57600);
SerialMon.println("2");
delay(3000);
SerialMon.println("3");

if (!modem.init())
{
SerialMon.println("4");
return;
}
SerialMon.println("5");
modem.sendSMS("0xxxxxxxxx", "Text here");
SerialMon.println("6");
}

Does not send an SMS, but prints a weird character instead after the text supposedly to be sent.

OK
AT+CMGS="0xxxxxxxxx"

">Text here�"

[SIM900] using AT_Debug I can get a connection. Diagnostic on the other hand...

I get this:
(I added some Serial output: ______ signifies we got a response. -------- signifies timeout in waitResponse)

Initializing modem...AT
### AT: 

OK
______
AT+CFUN=0
### AT: +CFUN=0

OK
______
AT+CFUN=1,1
### AT: +CFUN=1,1

+CPIN: NOT READY
�����------
______
### Unhandled: +CPIN: NOT READY
�����
 fail
************************
 Is your modem connected properly?
 Is your serial speed (baud rate) correct?
 Is your modem powered on?
 Do you use a good, stable power source?
 Try useing File -> Examples -> TinyGSM -> tools -> AT_Debug to find correct configuration
************************
Waiting for network...AT+CREG?
### AT: +CREG?

+CREG:______
 0,1

OK
______
 OK
Connecting to net.hotmAT+CIPSHUT
### AT: +CIPSHUT

SHUT OK
______
AT+SAPBR=3,1,"Contype","GPRS"
### AT: +SAPBR=3,1,"Contype","GPRS"

OK
______
AT+SAPBR=3,1,"APN","net.hotm"
### AT: +SAPBR=3,1,"APN"," net.hotm "

OK
______
AT+CGDCONT=1,"IP","net.hotm"
### AT: +CGDCONT=1,"IP"," net.hotm "

OK
______
AT+CGACT=1,1
### AT: +CGACT=1,1

OK
______
AT+SAPBR=1,1
### AT: +SAPBR=1,1

ERROR
______
AT+SAPBR=2,1
### AT: +SAPBR=2,1

+SAPBR: 1,3,"0.0.0.0"

OK
______
AT+CGATT=1
### AT: +CGATT=1

OK
______
AT+CIPMUX=1
### AT: +CIPMUX=1

OK
______
AT+CIPQSEND=1
### AT: +CIPQSEND=1

OK
______
AT+CIPRXGET=1
### AT: +CIPRXGET=1

OK
______
AT+CSTT="net.hotm","",""
### AT: +CSTT=" net.hotm ","  ","  "

OK
______
AT+CIICR
### AT: +CIICR

+PDP: DEACT

ERROR
______

Any recommendations? your library does seem the most user friendly one, and I'd like to use it in my project.

Thanks in advance!

problem when sending email..

I want to create a project that can send email directly from arduino via at command. I've tried adding a function called sendEmail. Email successfully sent but the body/content of the message is empty.

Here is my testcode..

/********************************************************************************************************/
 bool sendEmail(const String& smtp_server, const String& smtp_port, const String& smtp_username, const String& smtp_password, const String& sender_address, const String& sender_name, const String& to_address, const String& to_name, const String& subject, const String& body, const String& apn, const String& username, const String& pass)
{
	sendAT(GF("+SMTPSRV=\""), smtp_server, GF("\",\""), smtp_port, '"');
	waitResponse();
	
	sendAT(GF("+SMTPAUTH=1,\""), smtp_username, GF("\",\""), smtp_password, GF("\""));
	waitResponse();
	
	sendAT(GF("+SMTPFROM=\""), sender_address, GF("\",\""), sender_name, GF("\""));
	waitResponse();
	
	sendAT(GF("+SMTPRCPT=1,0,\""), to_address, GF("\",\""), to_name, GF("\""));
	waitResponse();
	
	sendAT(GF("+SMTPSUB=\""), subject, GF("\""));
	waitResponse();
	
	sendAT(GF("+SMTPBODY=\""), body, GF("\""));
        waitResponse();
  
	sendAT(GF("+CGSOCKCONT=1,\"IP\",\""), apn, '"');
	waitResponse();
	
	sendAT(GF("+CSOCKAUTH=1,1,\""), username, GF("\",\""), pass, GF("\""));
	waitResponse();
	
	sendAT(GF("+SMTPSEND"));
	if (waitResponse(GF(GSM_NL "+SMTP: SUCCESS"))!= 1)
	{
		//return false;
		return waitResponse() == 0;
	}
	else
	{
		//return true
		return waitResponse() == 1;
	}
  }
/********************************************************************************************************/

for diagnostic test, there have missing streamdebugger.h notice

I connected my sim800c with arduino Duemilanove board, and upload diagnostic to the board, will get error at the compile stage, the error message as below

Arduino:1.6.8 (Windows 7), TD: 1.28, 板子:"Arduino Duemilanove or Diecimila, ATmega328"

C:\Users\CHERRY~1\AppData\Local\Temp\arduino_modified_sketch_37504\Diagnostics.ino:22:28: fatal error: StreamDebugger.h: No such file or directory

#include <StreamDebugger.h>

                        ^

compilation terminated.

exit status 1
Error compiling for board Arduino Duemilanove or Diecimila.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

[A6] BlynkClient example crashes after ~20hrs

Hi!
Blynk client works, but crashes after about 20hrs every time. After arduino reset works again for ~20 hrs, but never more.
Tried with Arduino ProMini, Arduino Mega. Last test with enabled debugg Serial

[83811073] Connecting to blynk-cloud.com:8442
[83811144] <[02|00|01|00] AUTH_KEY
[83811202] Sent 65535/37
[83811316] Connecting to blynk-cloud.com:8442

Serial port dump between Arduino and A6:

AT+CIPSTART="TCP","blynk-cloud.com",8442
AT+CIPSEND=255,37
AT+CIPCLOSE=255
AT+CIPCLOSE=255
AT+CIPSTART="TCP","blynk-cloud.com",8442
AT+CIPSEND=255,37
AT+CIPCLOSE=255
AT+CIPCLOSE=255

A6 replies:

ERROR
ERROR
ERROR
ERROR

After Arduino reset (A6 stays powered), after modem.restart() command A6 "wakes up" and functions again.

[SIM800] WaitforNetwork doesn't actually wait for a network connection

When I run waitForNetwork(), I expect that it will and keep trying until a connection is made. But it seems to be making one attempt to get the network status and then just returning false. In the code, I think the for loop of waitForNetwork() should actually be a while loop instead. Am I doing something wrong?

Serial.println(F("Waiting for network..."));  // For debugging
if (!_modem->waitForNetwork()){
  Serial.println("... Connection failed");  // For debugging
} else {
   _modem->gprsConnect(_APN, "", "");
}

[A6] - ### Buffer overflow

Hi,

so at some point internally it seems the response causes to exceed TINY_GSM_RX_BUFFER

+CIPRCV:1,349,### Buffer overflow: 349 -> 255

if I increase the buffer by
#define TINY_GSM_RX_BUFFER 512

its ok.
+CIPRCV:1,349,### Got: 349 -> 511

on a A20 by default the buffer of 256 is easily exceeded and the connection will stall. Is there a way to limit the CIPRECV on the A20 or to increase the buffer only?

Hardware Serial Issue in Arduino Uno

Dear vshymanskyy,
I am using your TinyGSM library with Arduino UNO R3. I am using GSM800L for the communication purpose.
As per Library Example if i use software serial with baud rate 9600 its working correct. but i want to use hardware serial instead of software serial than communication to broker gives fail at baud rate 9600 or lower baudrate and for baudrate >9600 its connecting with broker but after 2 to 3 minute it reconnect to broker and same thing continue at same interval.

So could you please help me to solve this issue with hardware serial.

Thanks in Advance.
Darshit

[A6] - AT+CIPCLOSE=ID ERROR upon AT+CIPSEND failure

Hardware: SoftwareSerial on A20/A6 (13, 15) baud 38400.

apparently the lib does not handle the close properly when a sending failure occurred or any other error occurs (dont know what exactly happends).

Closing the socket aka httpclient->stop(); will trigger the AT+CIPCLOSE=mux, which results in an ERR, especially if the CIPSTART was not successful. Thus the successive CIPSTART can only be closed via "CIPCLOSE" without the "=1".

My assumption:
AT+IPMUX=1 was set at some point. However, there is only one connection opened
and closing that connection will cause an ERROR when calling AT+CIPCLOSE=1.
Every other further connection is then blocked. only a "AT+CIPCLOSE", without the =1, does the trick.

A6

Very cool! I hope that support for the A6 too? Thank you for the work done!

Sending Http header through Sim808

Hi,

Can you please guide me how to send HTTP Header. Using Sim808 with Arduino Uno. Trying to connecting to Dweetpro.io. Need to pass X-DWEET-AUTH value in the header.

Successfully connected to Dweet.io, as that doesn't require to pass any data in the header.

Below is the code I tried unsuccessfully.

if (client.connect(https://dweetpro.io, 443)) {
Serial.println(" fail");
delay(10000);
return;
}
client.println("POST /v2/dweets HTTP/1.1");
Serial.println(1);// For debugging
client.println("Host: dweetpro.io");
Serial.println(2);// For debugging
client.println("X-DWEET-AUTH: XYZ");
Serial.println(3);// For debugging
client.println("Accept: application/json");
Serial.println(4);// For debugging
client.println("Content-Type: application/json");
Serial.println(5);// For debugging
client.print("Content-Length: ");
Serial.println(6); // For debugging
client.println(144);
client.println();
Serial.println(7); // For debugging
client.print(PostData);
Serial.println(PostData);

[A6] connect to mqtt server is failed. and the state is -4.according to pubsubclient.it means the server didn't respond within the keepalive time

@xslim @vshymanskyy I use A6 + Nano and try to send data to mqtt server by GPRS. so I use the mqttclient example in this library.the mqtt server is OK because I have test it.but I get this result:

Initializing modem...
Waiting for network... OK
Connecting to uninet OK

Connecting to MQTTServer fail
Connecting to MQTTServer fail
Connecting to MQTTServer fail
Connecting to MQTTServer fail
...

anyone can have any tips for me?

function GET TIME

Please do get the time function on sim800l
AT+CCLK?
convert toInt();

performance / timeout issue with 9600 baud rate

Hello,
i tried really hard and read all issues. But i can't found a solution for my problem. So maybe you can give me a hint.

I try your example code for a mqtt client. If i set the connection speed for the modem to a higher value than 9600, it's working. If a set it to 9600, i get the error:

Initializing modem...
Waiting for network... OK
Connecting to web.vodafone.de OK
Connecting to alpha.holgerkoch.de fail
-4
Connecting to alpha.holgerkoch.de fail
-4

and the Logfile of the mosquitto server:

1491121475: New connection from 109.43.1.92 on port 1883.
1491121475: New client connected from 109.43.1.92 as elnagh (c1, k15, u'wohnmobil').
1491121475: Sending CONNACK to elnagh (0, 0)
1491121491: Socket error on client elnagh, disconnecting.

I use the latest version of pubsub and TinyGSM library. The MQTT Server is

[root@alpha mosquitto]# rpm -qa|grep mosquitto
libmosquitto1-1.4.10-3.1.x86_64
libmosquitto-devel-1.4.10-3.1.x86_64
mosquitto-1.4.10-3.1.x86_64
mosquitto-clients-1.4.10-3.1.x86_64

I tried to raise the timeouts for

#define MQTT_KEEPALIVE 60
#define MQTT_SOCKET_TIMEOUT 60

but it doesn't help.
From time to time, maybe once the hour, i got a connection and then it works like a dream.

Can you give me a hint?

Best regards

Holger

/**************************************************************
 *
 * For this example, you need to install PubSubClient library:
 *   https://github.com/knolleary/pubsubclient/releases/latest
 *   or from http://librarymanager/all#PubSubClient
 *
 * TinyGSM Getting Started guide:
 *   http://tiny.cc/tiny-gsm-readme
 *
 **************************************************************
 * Use Mosquitto client tools to work with MQTT
 *   Ubuntu/Linux: sudo apt-get install mosquitto-clients
 *   Windows:      https://mosquitto.org/download/
 *
 * Subscribe for messages:
 *   mosquitto_sub -h test.mosquitto.org -t GsmClientTest/init -t GsmClientTest/ledStatus -q 1
 * Toggle led:
 *   mosquitto_pub -h test.mosquitto.org -t GsmClientTest/led -q 1 -m "toggle"
 *
 * You can use Node-RED for wiring together MQTT-enabled devices
 *   https://nodered.org/
 * Also, take a look at these additional Node-RED modules:
 *   node-red-contrib-blynk-websockets
 *   node-red-dashboard
 *
 **************************************************************/

// Select your modem:
#define TINY_GSM_MODEM_SIM800
//#define TINY_GSM_MODEM_SIM900
//#define TINY_GSM_MODEM_A6
//#define TINY_GSM_MODEM_M590

#include <TinyGsmClient.h>
#include <PubSubClient.h>

// Your GPRS credentials
// Leave empty, if missing user or pass
const char apn[]  = "web.vodafone.de";
const char user[] = "";
const char pass[] = "";

// Use Hardware Serial on Mega, Leonardo, Micro
//#define SerialAT Serial1

// or Software Serial on Uno, Nano
#include <SoftwareSerial.h>
SoftwareSerial SerialAT(5, 4); // RX, TX

TinyGsm modem(SerialAT);
TinyGsmClient client(modem);
PubSubClient mqtt(client);


long lastReconnectAttempt = 0;


void setup() {
  // Set console baud rate
  Serial.begin(9600);
  delay(10);

  // Set GSM module baud rate
  SerialAT.begin(9600);
  delay(3000);

  // Restart takes quite some time
  // To skip it, call init() instead of restart()
  Serial.println("Initializing modem...");
  modem.restart();

  Serial.print("Waiting for network...");
  if (!modem.waitForNetwork()) {
    Serial.println(" fail");
    while (true);
  }
  Serial.println(" OK");

  Serial.print("Connecting to ");
  Serial.print(apn);
  if (!modem.gprsConnect(apn, user, pass)) {
    Serial.println(" fail");
    while (true);
  }
  Serial.println(" OK");

  // MQTT Broker setup
  mqtt.setServer("alpha.holgerkoch.de", 1883);
}

boolean mqttConnect() {
  Serial.print("Connecting to ");
  Serial.print("alpha.holgerkoch.de");
  if (!mqtt.connect("elnagh", "<usernam>", "<password>")) {
    Serial.println(" fail");
    Serial.println(mqtt.state());
    return false;
  }
  Serial.println(" OK");
  mqtt.publish("owntracks/wohnmobil/elnagh", "GsmClientTest started");
  return mqtt.connected();
}

void loop() {

  if (mqtt.connected()) {
    mqtt.loop();
  } else {
    // Reconnect every 10 seconds
    unsigned long t = millis();
    if (t - lastReconnectAttempt > 10000L) {
      lastReconnectAttempt = t;
      if (mqttConnect()) {
        lastReconnectAttempt = 0;
      }
    }
  }
  delay(5000);
  mqtt.publish("owntracks/wohnmobil/elnagh", "Bin drin");


}

Automatic reconnection

Is it possible to automatically restore GPRS connection of the modem in case of network or power loss?
If so, how to implement it?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.