|
4 years ago | |
---|---|---|
.github | 4 years ago | |
examples | 4 years ago | |
extras | 5 years ago | |
src | 4 years ago | |
tools | 4 years ago | |
.clang-format | 5 years ago | |
.gitattributes | 5 years ago | |
.gitignore | 4 years ago | |
.travis.yml | 5 years ago | |
LICENSE | 8 years ago | |
Makefile | 8 years ago | |
README.md | 4 years ago | |
cpplint.cfg | 5 years ago | |
keywords.txt | 6 years ago | |
library.json | 4 years ago | |
library.properties | 4 years ago |
A small Arduino library for GSM modules, that just works.
If you like TinyGSM - give it a star, or fork it and contribute!
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.
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.
More modems may be supported later:
Watch this repo for new updates! And of course, contributions are welcome ;)
Data connections
USSD
SMS
Voice Calls
Location
Credits
AT
command using this sketchThe general flow of your code should be:
#define TINY_GSM_MODEM_SIM800
#include <TinyGsmClient.h>
TinyGsm modem(SerialAT);
TinyGsmClient client(modem);
or
TinyGsmClientSecure client(modem);
(on supported modules)TinyGsmClient clientX(modem, 0);
, TinyGsmClient clientY(modem, 1);
, etc
orTinyGsmClientSecure clientX(modem, 0);
, TinyGsmClientSecure clientY(modem, 1);
, etcmodem.init()
or modem.restart()
modem.simUnlock(GSM_PIN)
modem.networkConnect(wifiSSID, wifiPass)
modem.waitForNetwork(600000L)
modem.gprsConnect(apn, gprsUser, gprsPass)
(or simply modem.gprsConnect(apn)
)client.connect(server, port)
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.
For GPRS data streams, this library provides the standard Arduino Client interface. For additional functions, please refer to this example sketch
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!
Sometimes (especially if you played with AT commands), your module configuration may become invalid. This may result in problems such as:
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.)
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
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:
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)client.print(String("GET ") + resource + " HTTP/1.1\r\n");
instead of
client.print("GET ");
client.print(resource);
client.println(" HTTP/1.1")
client.print("....\r\n\r\n")
or put in an extra client.println()
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.
When using ESP32 HardwareSerial
, you may need to specify additional parameters to the .begin()
call.
Please refer to this comment.
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.
When using SAMD21-based boards, you may need to use a sercom uart port instead of Serial1
.
Please refer to this comment.
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.
This project is released under The GNU Lesser General Public License (LGPL-3.0)