You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

345 lines
16 KiB

8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
7 years ago
8 years ago
6 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
7 years ago
8 years ago
6 years ago
8 years ago
7 years ago
7 years ago
5 years ago
8 years ago
7 years ago
6 years ago
7 years ago
7 years ago
6 years ago
6 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
8 years ago
6 years ago
6 years ago
8 years ago
6 years ago
8 years ago
6 years ago
6 years ago
6 years ago
6 years ago
7 years ago
6 years ago
7 years ago
8 years ago
7 years ago
7 years ago
8 years ago
6 years ago
7 years ago
8 years ago
8 years ago
7 years ago
7 years ago
7 years ago
  1. ![TinyGSM logo](https://cdn.rawgit.com/vshymanskyy/TinyGSM/d18e93dc51fe988a0b175aac647185457ef640b5/extras/logo.svg)
  2. A small Arduino library for GSM modules, that just works.
  3. <!---
  4. [![GitHub download](https://img.shields.io/github/downloads/vshymanskyy/TinyGSM/total.svg)](https://github.com/vshymanskyy/TinyGSM/releases/latest)--->
  5. [![GitHub version](https://img.shields.io/github/release/vshymanskyy/TinyGSM.svg)](https://github.com/vshymanskyy/TinyGSM/releases/latest)
  6. [![Build status](https://img.shields.io/travis/vshymanskyy/TinyGSM.svg)](https://travis-ci.org/vshymanskyy/TinyGSM)
  7. [![GitHub issues](https://img.shields.io/github/issues/vshymanskyy/TinyGSM.svg)](https://github.com/vshymanskyy/TinyGSM/issues)
  8. [![GitHub wiki](https://img.shields.io/badge/Wiki-available-brightgreen.svg)](https://github.com/vshymanskyy/TinyGSM/wiki)
  9. [![GitHub stars](https://img.shields.io/github/stars/vshymanskyy/TinyGSM.svg)](https://github.com/vshymanskyy/TinyGSM/stargazers)
  10. [![License](https://img.shields.io/badge/license-LGPL3-blue.svg)](https://github.com/vshymanskyy/TinyGSM/blob/master/LICENSE)
  11. If you like **TinyGSM** - give it a star, or fork it and contribute!
  12. [![GitHub stars](https://img.shields.io/github/stars/vshymanskyy/TinyGSM.svg?style=social&label=Star)](https://github.com/vshymanskyy/TinyGSM/stargazers)
  13. [![GitHub forks](https://img.shields.io/github/forks/vshymanskyy/TinyGSM.svg?style=social&label=Fork)](https://github.com/vshymanskyy/TinyGSM/network)
  14. You can also join our chat:
  15. [![Gitter](https://img.shields.io/gitter/room/vshymanskyy/TinyGSM.svg)](https://gitter.im/tinygsm)
  16. ### Arduino Client interface support
  17. This library is easy to integrate with lots of sketches which use Ethernet or WiFi.
  18. **PubSubClient ([MQTT](http://mqtt.org/))**, **[Blynk](http://blynk.cc)**, **HTTP Client** and **File Download** examples are provided.
  19. ![examples](/extras/examples.png)
  20. ### TinyGSM is tiny
  21. The complete WebClient example for Arduino Uno (via Software Serial) takes little resources:
  22. ```
  23. Sketch uses 15022 bytes (46%) of program storage space. Maximum is 32256 bytes.
  24. Global variables use 574 bytes (28%) of dynamic memory, leaving 1474 bytes for local variables. Maximum is 2048 bytes.
  25. ```
  26. Arduino GSM library uses 15868 bytes (49%) of Flash and 1113 bytes (54%) of RAM in a similar scenario.
  27. TinyGSM also pulls data gently from the modem (whenever possible), so it can operate on very little RAM.
  28. **Now, you have more space for your experiments.**
  29. ## Supported modems
  30. - SIMCom SIM800 series (SIM800A, SIM800C, SIM800L, SIM800H, SIM808, SIM868)
  31. - SIMCom SIM900 series (SIM900A, SIM900D, SIM908, SIM968)
  32. - SIMCom WCDMA/HSPA/HSPA+ Modules (SIM5360, SIM5320, SIM5300E, SIM5300E/A)
  33. - SIMCom LTE Modules (SIM7100E, SIM7500E, SIM7500A, SIM7600C, SIM7600E)
  34. - SIMCom SIM7000E/A/G CAT-M1/NB-IoT Module
  35. - AI-Thinker A6, A6C, A7, A20
  36. - ESP8266 (AT commands interface, similar to GSM modems)
  37. - Digi XBee WiFi and Cellular (using XBee command mode)
  38. - Neoway M590
  39. - 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)
  40. - u-blox LTE-M/NB-IoT Modems (SARA-R4xx, SARA-N4xx, _but NOT SARA-N2xx_)
  41. - Sequans Monarch LTE Cat M1/NB1 (VZM20Q)
  42. - Quectel BG96
  43. - Quectel M95
  44. - Quectel MC60 ***(alpha)***
  45. ### Supported boards/modules
  46. - Arduino MKR GSM 1400
  47. - GPRSbee
  48. - Microduino GSM
  49. - Adafruit FONA (Mini Cellular GSM Breakout)
  50. - Adafruit FONA 800/808 Shield
  51. - Industruino GSM
  52. - RAK WisLTE ***(alpha)***
  53. - ... other modules, based on supported modems. Some boards require [**special configuration**](https://github.com/vshymanskyy/TinyGSM/wiki/Board-configuration).
  54. More modems may be supported later:
  55. - [ ] Quectel M10, UG95
  56. - [ ] SIMCom SIM7020
  57. - [ ] Telit GL865
  58. - [ ] ZTE MG2639
  59. - [ ] Hi-Link HLK-RM04
  60. Watch this repo for new updates! And of course, contributions are welcome ;)
  61. ## Features
  62. **Data connections**
  63. - TCP (HTTP, MQTT, Blynk, ...)
  64. - ALL modules support TCP connections
  65. - Most modules support multiple simultaneous connections:
  66. - A6/A7 - 8
  67. - ESP8266 - 5
  68. - Neoway M590 - 2
  69. - Quectel BG96 - 12
  70. - Quectel M95 - 6
  71. - Quectel MC60/MC60E - 6
  72. - Sequans Monarch - 6
  73. - SIM 800/900 - 5
  74. - SIM 5360/5320/5300/7100 - 10
  75. - SIM7000 - 2 (8 possible without SSL, only 2 with)
  76. - SIM 7500/7600/7800 - 10
  77. - u-blox 2G/3G - 7
  78. - u-blox SARA R4/N4 - 7
  79. - Digi XBee - _only 1 connection supported!_
  80. - UDP
  81. - Not yet supported on any module, though it may be some day
  82. - SSL/TLS (HTTPS)
  83. - Supported on:
  84. - SIM800, SIM7000, u-Blox, XBee _cellular_, ESP8266, and Sequans Monarch
  85. - Note: only some device models or firmware revisions have this feature (SIM8xx R14.18, A7, etc.)
  86. - Not yet supported on:
  87. - Quectel modems, SIM 5360/5320/7100, SIM 7500/7600/7800
  88. - Not possible on:
  89. - SIM900, A6/A7, Neoway M590, XBee _WiFi_
  90. - Like TCP, most modules support simultaneous connections
  91. - TCP and SSL connections can usually be mixed up to the total number of possible connections
  92. **USSD**
  93. - Sending USSD requests and decoding 7,8,16-bit responses
  94. - Supported on:
  95. - All SIMCom modems, Quectel modems, most u-blox
  96. - Not possible on:
  97. - XBee, u-blox SARA R4/N4, ESP8266 (obviously)
  98. **SMS**
  99. - Only _sending_ SMS is supported, not receiving
  100. - Supported on all cellular modules
  101. **Voice Calls**
  102. - Supported on:
  103. - SIM800/SIM900, A6/A7, Quectel modems, u-blox
  104. - Not yet supported on:
  105. - SIM7000, SIM5360/5320/7100, SIM7500/7600/7800, VZM20Q (Monarch)
  106. - Not possible on:
  107. - XBee (any type), u-blox SARA R4/N4, Neoway M590, ESP8266 (obviously)
  108. - Functions:
  109. - Dial, hangup
  110. - DTMF sending
  111. **Location**
  112. - GPS/GNSS
  113. - SIM808, SIM7000, SIM7500/7600/7800, BG96, u-blox
  114. - 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
  115. - GSM location service
  116. - SIM800, SIM7000, Quectel, u-blox
  117. **Credits**
  118. - Primary Authors/Contributors:
  119. - [vshymanskyy](https://github.com/vshymanskyy)
  120. - [SRGDamia1](https://github.com/SRGDamia1/)
  121. - SIM7000:
  122. - [captFuture](https://github.com/captFuture/)
  123. - [FStefanni](https://github.com/FStefanni/)
  124. - Sequans Monarch:
  125. - [nootropicdesign](https://github.com/nootropicdesign/)
  126. - Quectel M9C60
  127. - [V1pr](https://github.com/V1pr)
  128. - Quectel M95
  129. - [replicadeltd](https://github.com/replicadeltd)
  130. - Other Contributors:
  131. - https://github.com/vshymanskyy/TinyGSM/graphs/contributors
  132. ## Getting Started
  133. #### First Steps
  134. 1. Using your phone:
  135. - Disable PIN code on the SIM card
  136. - Check your balance
  137. - Check that APN, User, Pass are correct and you have internet
  138. 2. Ensure the SIM card is correctly inserted into the module
  139. 3. Ensure that GSM antenna is firmly attached
  140. 4. Ensure that you have a stable power supply to the module of at least **2A**.
  141. 5. Check if serial connection is working (Hardware Serial is recommended)
  142. Send an ```AT``` command using [this sketch](tools/AT_Debug/AT_Debug.ino)
  143. 6. Try out the [WebClient](https://github.com/vshymanskyy/TinyGSM/blob/master/examples/WebClient/WebClient.ino) example
  144. #### Writing your own code
  145. The general flow of your code should be:
  146. - Define the module that you are using (choose one and only one)
  147. - ie, ```#define TINY_GSM_MODEM_SIM800```
  148. - Included TinyGSM
  149. - ```#include <TinyGsmClient.h>```
  150. - Create a TinyGSM modem instance
  151. - ```TinyGsm modem(SerialAT);```
  152. - Create one or more TinyGSM client instances
  153. - For a single connection, use
  154. - ```TinyGsmClient client(modem);```
  155. or
  156. ```TinyGsmClientSecure client(modem);``` (on supported modules)
  157. - For multiple connections (on supported modules) use:
  158. - ```TinyGsmClient clientX(modem, 0);```, ```TinyGsmClient clientY(modem, 1);```, etc
  159. or
  160. - ```TinyGsmClientSecure clientX(modem, 0);```, ```TinyGsmClientSecure clientY(modem, 1);```, etc
  161. - Secure and insecure clients can usually be mixed when using multiple connections.
  162. - The total number of connections possible varies by module
  163. - Begin your serial communication and set all your pins as required to power your module and bring it to full functionality.
  164. - The examples attempt to guess the module's baud rate. In working code, you should use a set baud.
  165. - Wait for the module to be ready (could be as much as 6s, depending on the module)
  166. - Initialize the modem
  167. - ```modem.init()``` or ```modem.restart()```
  168. - restart generally takes longer than init but ensures the module doesn't have lingering connections
  169. - Unlock your SIM, if necessary:
  170. - ```modem.simUnlock(GSM_PIN)```
  171. - If using **WiFi**, specify your SSID information:
  172. - ```modem.networkConnect(wifiSSID, wifiPass)```
  173. - Network registration should be automatic on cellular modules
  174. - Wait for network registration to be successful
  175. - ```modem.waitForNetwork(600000L)```
  176. - If using cellular, establish the GPRS or EPS data connection _after_ your are successfully registered on the network
  177. - ```modem.gprsConnect(apn, gprsUser, gprsPass)``` (or simply ```modem.gprsConnect(apn)```)
  178. - The same command is used for both GPRS or EPS connection
  179. - 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._
  180. - Connect the TCP or SSL client
  181. ```client.connect(server, port)```
  182. - Send out your data.
  183. #### If you have any issues:
  184. 1. Read the whole README (you're looking at it!), particularly the troubleshooting section below.
  185. 2. Some boards require [**special configuration**](https://github.com/vshymanskyy/TinyGSM/wiki/Board-configuration).
  186. 3. Try running the Diagnostics sketch
  187. 4. Check for [**highlighted topics here**](https://github.com/vshymanskyy/TinyGSM/issues?utf8=%E2%9C%93&q=is%3Aissue+label%3A%22for+reference%22+)
  188. 5. If you have a question, please post it in our [Gitter chat](https://gitter.im/tinygsm)
  189. ## How does it work?
  190. Many GSM modems, WiFi and radio modules can be controlled by sending AT commands over Serial.
  191. TinyGSM knows which commands to send, and how to handle AT responses, and wraps that into standard Arduino Client interface.
  192. ## API Reference
  193. For GPRS data streams, this library provides the standard [Arduino Client](https://www.arduino.cc/en/Reference/ClientConstructor) interface.
  194. For additional functions, please refer to [this example sketch](examples/AllFunctions/AllFunctions.ino)
  195. ## Troubleshooting
  196. ### Ensure stable data & power connection
  197. Most modules require _**as much as 2A**_ to properly connect to the network.
  198. This is 4x what a "standard" USB will supply!
  199. Improving the power supply actually solves stability problems in **many** cases!
  200. - Read about [**powering your module**](https://github.com/vshymanskyy/TinyGSM/wiki/Powering-GSM-module).
  201. - Keep your wires as short as possible
  202. - Consider soldering them for a stable connection
  203. - Do not put your wires next to noisy signal sources (buck converters, antennas, oscillators etc.)
  204. - If everything else seems to be working but you are unable to connect to the network, check your power supply!
  205. ### Broken initial configuration
  206. Sometimes (especially if you played with AT commands), your module configuration may become invalid.
  207. This may result in problems such as:
  208. * Can't connect to the GPRS network
  209. * Can't connect to the server
  210. * Sent/received data contains invalid bytes
  211. * etc.
  212. To return module to **Factory Defaults**, use this sketch:
  213. File -> Examples -> TinyGSM -> tools -> [FactoryReset](https://github.com/vshymanskyy/TinyGSM/blob/master/tools/FactoryReset/FactoryReset.ino)
  214. In some cases, you may need to set an initial APN to connect to the cellular network.
  215. Try using the ```gprsConnect(APN)``` function to set an initial APN if you are unable to register on the network.
  216. You may need set the APN again after registering.
  217. (In most cases, you should set the APN after registration.)
  218. ### Diagnostics sketch
  219. Use this sketch to help diagnose SIM card and GPRS connection issues:
  220. File -> Examples -> TinyGSM -> tools -> [Diagnostics](https://github.com/vshymanskyy/TinyGSM/blob/master/tools/Diagnostics/Diagnostics.ino)
  221. If the diagnostics fail, uncomment this line to output some debugging comments from the library:
  222. ```cpp
  223. #define TINY_GSM_DEBUG SerialMon
  224. ```
  225. In any custom code, ```TINY_GSM_DEBUG``` must be defined before including the TinyGSM library.
  226. If you are unable to see any obvious errors in the library debugging, use [StreamDebugger](https://github.com/vshymanskyy/StreamDebugger) to copy the entire AT command sequence to the main serial port.
  227. In the diagnostics example, simply uncomment the line:
  228. ```cpp
  229. #define DUMP_AT_COMMANDS
  230. ```
  231. In custom code, you can add this snippit:
  232. ```cpp
  233. #ifdef DUMP_AT_COMMANDS
  234. #include <StreamDebugger.h>
  235. StreamDebugger debugger(SerialAT, SerialMon);
  236. TinyGsm modem(debugger);
  237. #else
  238. TinyGsm modem(SerialAT);
  239. #endif
  240. ```
  241. ### Web request formatting problems - "but it works with PostMan"
  242. This library opens a TCP (or SSL) connection to a server.
  243. In the [OSI model](https://en.wikipedia.org/wiki/OSI_model), that's [layer 4](http://www.tcpipguide.com/free/t_TransportLayerLayer4.htm) (or 5 for SSL).
  244. HTTP (GET/POST), MQTT, and most of the other functions you probably want to use live up at [layer 7](http://www.tcpipguide.com/free/t_ApplicationLayerLayer7.htm).
  245. This means that you need to either manually code the top layer or use another library (like [HTTPClient](https://github.com/arduino-libraries/ArduinoHttpClient) or [PubSubClient](https://pubsubclient.knolleary.net/)) to do it for you.
  246. Tools like [PostMan](https://www.postman.com/) also show layer 7, not layer 4/5 like TinyGSM.
  247. If you are successfully connecting to a server, but getting responses of "bad request" (or no response), the issue is probably your formatting.
  248. Here are some tips for writing layer 7 (particularly HTTP request) manually:
  249. - Look at the "WebClient" example
  250. - Make sure you are including all required headers.
  251. - 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.
  252. - 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)
  253. - Enclose the entirety of each header or line within a single string or print statement
  254. - use
  255. ```cpp
  256. client.print(String("GET ") + resource + " HTTP/1.1\r\n");
  257. ```
  258. instead of
  259. ```cpp
  260. client.print("GET ");
  261. client.print(resource);
  262. client.println(" HTTP/1.1")
  263. ```
  264. - Make sure there is one entirely blank line between the last header and the content of any POST request.
  265. - Add two lines to the last header ```client.print("....\r\n\r\n")``` or put in an extra ```client.println()```
  266. - This is an HTTP requirement and is really easy to miss.
  267. ### SoftwareSerial problems
  268. When using ```SoftwareSerial``` (on Uno, Nano, etc), the speed **115200** may not work.
  269. Try selecting **57600**, **38400**, or even lower - the one that works best for you.
  270. In some cases **9600** is unstable, but using **38400** helps, etc.
  271. 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.
  272. **Read more about SoftSerial options and configuration [here](https://www.pjrc.com/teensy/td_libs_AltSoftSerial.html) and [here](https://www.arduino.cc/en/Reference/SoftwareSerial).**
  273. ### ESP32 Notes
  274. #### HardwareSerial
  275. When using ESP32 `HardwareSerial`, you may need to specify additional parameters to the `.begin()` call.
  276. Please [refer to this comment](https://github.com/vshymanskyy/TinyGSM/issues/91#issuecomment-356024747).
  277. #### HttpClient
  278. 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.
  279. ### SAMD21
  280. When using SAMD21-based boards, you may need to use a sercom uart port instead of `Serial1`.
  281. Please [refer to this comment](https://github.com/vshymanskyy/TinyGSM/issues/102#issuecomment-345548941).
  282. ### Goouuu Tech IOT-GA6 vs AI-Thinker A6 confusion
  283. 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](https://github.com/vshymanskyy/TinyGSM/issues/164).
  284. __________
  285. ### License
  286. This project is released under
  287. The GNU Lesser General Public License (LGPL-3.0)