mirror of
https://github.com/vshymanskyy/TinyGSM.git
synced 2026-05-15 04:06:10 +00:00
Refactor for handle URCs, add to tests
Signed-off-by: Sara Damiano <sdamiano@stroudcenter.org>
This commit is contained in:
@@ -27,7 +27,7 @@ jobs:
|
||||
[
|
||||
TINY_GSM_MODEM_A6,
|
||||
TINY_GSM_MODEM_BG96,
|
||||
TINY_GSM_MODEM_BG95SSL,
|
||||
TINY_GSM_MODEM_A7672X,
|
||||
TINY_GSM_MODEM_ESP8266,
|
||||
TINY_GSM_MODEM_M95,
|
||||
TINY_GSM_MODEM_M590,
|
||||
@@ -44,13 +44,6 @@ jobs:
|
||||
TINY_GSM_MODEM_XBEE,
|
||||
TINY_GSM_MODEM_SEQUANS_MONARCH,
|
||||
]
|
||||
exclude:
|
||||
- modem: TINY_GSM_MODEM_BG95SSL
|
||||
example: examples/BlynkClient
|
||||
- modem: TINY_GSM_MODEM_BG95SSL
|
||||
example: examples/FileDownload
|
||||
- modem: TINY_GSM_MODEM_BG95SSL
|
||||
example: examples/MqttClient
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
15
README.md
15
README.md
@@ -29,7 +29,7 @@ You can also join our chat:
|
||||
- [How does it work?](#how-does-it-work)
|
||||
- [API Reference](#api-reference)
|
||||
- [Troubleshooting](#troubleshooting)
|
||||
- [Ensure stable data & power connection](#ensure-stable-data--power-connection)
|
||||
- [Ensure stable data \& power connection](#ensure-stable-data--power-connection)
|
||||
- [Baud rates](#baud-rates)
|
||||
- [Broken initial configuration](#broken-initial-configuration)
|
||||
- [Failed connection or no data received](#failed-connection-or-no-data-received)
|
||||
@@ -70,6 +70,7 @@ TinyGSM also pulls data gently from the modem (whenever possible), so it can ope
|
||||
- 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
|
||||
- SIMCom A7672X CAT-M1 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)
|
||||
@@ -92,13 +93,6 @@ TinyGSM also pulls data gently from the modem (whenever possible), so it can ope
|
||||
- RAK WisLTE ***(alpha)***
|
||||
- ... other modules, based on supported modems. Some boards require [**special configuration**](https://github.com/vshymanskyy/TinyGSM/wiki/Board-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
|
||||
@@ -120,6 +114,7 @@ Watch this repo for new updates! And of course, contributions are welcome ;)
|
||||
- SIM7000 - 8 possible without SSL, only 2 with
|
||||
- SIM 7070/7080/7090 - 12
|
||||
- SIM 7500/7600/7800 - 10
|
||||
- SIM A7672X - 10
|
||||
- u-blox 2G/3G - 7
|
||||
- u-blox SARA R4/N4 - 7
|
||||
- Digi XBee - _only 1 connection supported!_
|
||||
@@ -127,10 +122,10 @@ Watch this repo for new updates! And of course, contributions are welcome ;)
|
||||
- Not yet supported on any module, though it may be some day
|
||||
- SSL/TLS (HTTPS)
|
||||
- Supported on:
|
||||
- SIM800, SIM7000, u-Blox, XBee _cellular_, ESP8266, Sequans Monarch and Quectel BG95
|
||||
- SIM800, SIM7000, A7672X, u-Blox, XBee _cellular_, ESP8266, Sequans Monarch and Quectel BG95 and BG96
|
||||
- Note: **only some device models or firmware revisions have this feature** (SIM8xx R14.18, A7, etc.)
|
||||
- Not yet supported on:
|
||||
- Quectel BG96, SIM 5360/5320/7100, SIM 7500/7600/7800
|
||||
- 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
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
// #define TINY_GSM_MODEM_SIM7080
|
||||
// #define TINY_GSM_MODEM_SIM5360
|
||||
// #define TINY_GSM_MODEM_SIM7600
|
||||
// #define TINY_GSM_MODEM_A7672X
|
||||
// #define TINY_GSM_MODEM_UBLOX
|
||||
// #define TINY_GSM_MODEM_SARAR4
|
||||
// #define TINY_GSM_MODEM_SARAR5
|
||||
|
||||
@@ -22,11 +22,11 @@
|
||||
* Change GPRS apm, user, pass, and Blynk auth token to run :)
|
||||
**************************************************************/
|
||||
|
||||
#define BLYNK_TEMPLATE_ID "TMPxxxxxx"
|
||||
#define BLYNK_TEMPLATE_NAME "Device"
|
||||
#define BLYNK_AUTH_TOKEN "YourAuthToken"
|
||||
#define BLYNK_TEMPLATE_ID "TMPxxxxxx"
|
||||
#define BLYNK_TEMPLATE_NAME "Device"
|
||||
#define BLYNK_AUTH_TOKEN "YourAuthToken"
|
||||
|
||||
#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
|
||||
#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
|
||||
|
||||
// Default heartbeat interval for GSM is 60
|
||||
// If you want override this value, uncomment and set this option:
|
||||
@@ -42,10 +42,12 @@
|
||||
// #define TINY_GSM_MODEM_SIM7080
|
||||
// #define TINY_GSM_MODEM_SIM5360
|
||||
// #define TINY_GSM_MODEM_SIM7600
|
||||
// #define TINY_GSM_MODEM_A7672X
|
||||
// #define TINY_GSM_MODEM_UBLOX
|
||||
// #define TINY_GSM_MODEM_SARAR4
|
||||
// #define TINY_GSM_MODEM_SARAR5
|
||||
// #define TINY_GSM_MODEM_M95
|
||||
// #define TINY_GSM_MODEM_BG95
|
||||
// #define TINY_GSM_MODEM_BG96
|
||||
// #define TINY_GSM_MODEM_A6
|
||||
// #define TINY_GSM_MODEM_A7
|
||||
@@ -84,8 +86,7 @@ const char auth[] = "YourAuthToken";
|
||||
|
||||
TinyGsm modem(SerialAT);
|
||||
|
||||
void setup()
|
||||
{
|
||||
void setup() {
|
||||
// Set console baud rate
|
||||
SerialMon.begin(115200);
|
||||
delay(10);
|
||||
@@ -104,12 +105,11 @@ void setup()
|
||||
SerialMon.println(modemInfo);
|
||||
|
||||
// Unlock your SIM card with a PIN
|
||||
//modem.simUnlock("1234");
|
||||
// modem.simUnlock("1234");
|
||||
|
||||
Blynk.begin(auth, modem, apn, user, pass);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
void loop() {
|
||||
Blynk.run();
|
||||
}
|
||||
|
||||
@@ -23,10 +23,12 @@
|
||||
// #define TINY_GSM_MODEM_SIM7080
|
||||
// #define TINY_GSM_MODEM_SIM5360
|
||||
// #define TINY_GSM_MODEM_SIM7600
|
||||
// #define TINY_GSM_MODEM_A7672X
|
||||
// #define TINY_GSM_MODEM_UBLOX
|
||||
// #define TINY_GSM_MODEM_SARAR4
|
||||
// #define TINY_GSM_MODEM_SARAR5
|
||||
// #define TINY_GSM_MODEM_M95
|
||||
// #define TINY_GSM_MODEM_BG95
|
||||
// #define TINY_GSM_MODEM_BG96
|
||||
// #define TINY_GSM_MODEM_A6
|
||||
// #define TINY_GSM_MODEM_A7
|
||||
|
||||
@@ -28,10 +28,12 @@
|
||||
// #define TINY_GSM_MODEM_SIM7080
|
||||
// #define TINY_GSM_MODEM_SIM5360
|
||||
// #define TINY_GSM_MODEM_SIM7600
|
||||
// #define TINY_GSM_MODEM_A7672X
|
||||
// #define TINY_GSM_MODEM_UBLOX
|
||||
// #define TINY_GSM_MODEM_SARAR4
|
||||
// #define TINY_GSM_MODEM_SARAR5
|
||||
// #define TINY_GSM_MODEM_M95
|
||||
// #define TINY_GSM_MODEM_BG95
|
||||
// #define TINY_GSM_MODEM_BG96
|
||||
// #define TINY_GSM_MODEM_A6
|
||||
// #define TINY_GSM_MODEM_A7
|
||||
|
||||
@@ -32,10 +32,12 @@
|
||||
// #define TINY_GSM_MODEM_SIM7080
|
||||
// #define TINY_GSM_MODEM_SIM5360
|
||||
// #define TINY_GSM_MODEM_SIM7600
|
||||
// #define TINY_GSM_MODEM_A7672X
|
||||
// #define TINY_GSM_MODEM_UBLOX
|
||||
// #define TINY_GSM_MODEM_SARAR4
|
||||
// #define TINY_GSM_MODEM_SARAR5
|
||||
// #define TINY_GSM_MODEM_M95
|
||||
// #define TINY_GSM_MODEM_BG95
|
||||
// #define TINY_GSM_MODEM_BG96
|
||||
// #define TINY_GSM_MODEM_A6
|
||||
// #define TINY_GSM_MODEM_A7
|
||||
|
||||
@@ -18,10 +18,12 @@
|
||||
// #define TINY_GSM_MODEM_SIM7080
|
||||
// #define TINY_GSM_MODEM_SIM5360
|
||||
// #define TINY_GSM_MODEM_SIM7600
|
||||
// #define TINY_GSM_MODEM_A7672X
|
||||
// #define TINY_GSM_MODEM_UBLOX
|
||||
// #define TINY_GSM_MODEM_SARAR4
|
||||
// #define TINY_GSM_MODEM_SARAR5
|
||||
// #define TINY_GSM_MODEM_M95
|
||||
// #define TINY_GSM_MODEM_BG95
|
||||
// #define TINY_GSM_MODEM_BG96
|
||||
// #define TINY_GSM_MODEM_A6
|
||||
// #define TINY_GSM_MODEM_A7
|
||||
|
||||
@@ -79,7 +79,8 @@ typedef TinyGsmSaraR5::GsmClientSecureR5 TinyGsmClientSecure;
|
||||
typedef TinyGsmM95 TinyGsm;
|
||||
typedef TinyGsmM95::GsmClientM95 TinyGsmClient;
|
||||
|
||||
#elif defined(TINY_GSM_MODEM_BG96) || defined(TINY_GSM_MODEM_BG95SSL)
|
||||
#elif defined(TINY_GSM_MODEM_BG96) || defined(TINY_GSM_MODEM_BG95) || \
|
||||
defined(TINY_GSM_MODEM_BG95SSL)
|
||||
#include "TinyGsmClientBG96.h"
|
||||
typedef TinyGsmBG96 TinyGsm;
|
||||
typedef TinyGsmBG96::GsmClientBG96 TinyGsmClient;
|
||||
|
||||
@@ -13,6 +13,10 @@
|
||||
|
||||
#define TINY_GSM_MUX_COUNT 10
|
||||
#define TINY_GSM_BUFFER_READ_AND_CHECK_SIZE
|
||||
#ifdef AT_NL
|
||||
#undef AT_NL
|
||||
#endif
|
||||
#define AT_NL "\r\n" // NOTE: define before including TinyGsmModem!
|
||||
|
||||
#include "TinyGsmBattery.tpp"
|
||||
#include "TinyGsmCalling.tpp"
|
||||
@@ -26,15 +30,7 @@
|
||||
#include "TinyGsmNTP.tpp"
|
||||
#include "TinyGsmTemperature.tpp"
|
||||
|
||||
#define GSM_NL "\r\n"
|
||||
static const char GSM_OK[] TINY_GSM_PROGMEM = "OK" GSM_NL;
|
||||
static const char GSM_ERROR[] TINY_GSM_PROGMEM = "ERROR" GSM_NL;
|
||||
#if defined TINY_GSM_DEBUG
|
||||
static const char GSM_CME_ERROR[] TINY_GSM_PROGMEM = GSM_NL "+CME ERROR:";
|
||||
static const char GSM_CMS_ERROR[] TINY_GSM_PROGMEM = GSM_NL "+CMS ERROR:";
|
||||
#endif
|
||||
|
||||
enum RegStatus {
|
||||
enum A7672xRegStatus {
|
||||
REG_NO_RESULT = -1,
|
||||
REG_UNREGISTERED = 0,
|
||||
REG_SEARCHING = 2,
|
||||
@@ -181,7 +177,7 @@ class TinyGsmA7672X : public TinyGsmModem<TinyGsmA7672X>,
|
||||
* Basic functions
|
||||
*/
|
||||
protected:
|
||||
bool initImpl(const char* pin = NULL) {
|
||||
bool initImpl(const char* pin = nullptr) {
|
||||
DBG(GF("### TinyGSM Version:"), TINYGSM_VERSION);
|
||||
DBG(GF("### TinyGSM Compiled Module: A7672X"));
|
||||
|
||||
@@ -203,9 +199,8 @@ class TinyGsmA7672X : public TinyGsmModem<TinyGsmA7672X>,
|
||||
DBG(GF("### Modem:"), getModemName());
|
||||
|
||||
SimStatus ret = getSimStatus();
|
||||
// if the sim isn't ready and a pin has been provided, try to unlock the
|
||||
// sim
|
||||
if (ret != SIM_READY && pin != NULL && strlen(pin) > 0) {
|
||||
// if the sim isn't ready and a pin has been provided, try to unlock the sim
|
||||
if (ret != SIM_READY && pin != nullptr && strlen(pin) > 0) {
|
||||
simUnlock(pin);
|
||||
return (getSimStatus() == SIM_READY);
|
||||
} else {
|
||||
@@ -221,7 +216,7 @@ class TinyGsmA7672X : public TinyGsmModem<TinyGsmA7672X>,
|
||||
sendAT(GF("+CGMM"));
|
||||
String res2;
|
||||
if (waitResponse(1000L, res2) != 1) { return name; }
|
||||
res2.replace(GSM_NL "OK" GSM_NL, "");
|
||||
res2.replace(AT_NL "OK" AT_NL, "");
|
||||
res2.replace("_", " ");
|
||||
res2.trim();
|
||||
|
||||
@@ -230,18 +225,8 @@ class TinyGsmA7672X : public TinyGsmModem<TinyGsmA7672X>,
|
||||
return name;
|
||||
}
|
||||
|
||||
float getTemperatureImpl() {
|
||||
String res = "";
|
||||
sendAT(GF("+CPMUTEMP"));
|
||||
if (waitResponse(1000L, res)) { return 0; }
|
||||
res = res.substring(res.indexOf(':'), res.indexOf('\r'));
|
||||
float temp = res.toFloat();
|
||||
waitResponse();
|
||||
return temp;
|
||||
}
|
||||
|
||||
bool factoryDefaultImpl() {
|
||||
sendAT(GF("&F")); // Factory + Reset
|
||||
sendAT(GF("&F")); // Factory + Reset
|
||||
waitResponse();
|
||||
sendAT(GF("+IFC=0,0")); // No Flow Control
|
||||
waitResponse();
|
||||
@@ -249,7 +234,7 @@ class TinyGsmA7672X : public TinyGsmModem<TinyGsmA7672X>,
|
||||
waitResponse();
|
||||
sendAT(GF("+CSCLK=0")); // Control UART Sleep always work
|
||||
waitResponse();
|
||||
sendAT(GF("&W")); // Write configuration
|
||||
sendAT(GF("&W")); // Write configuration
|
||||
return waitResponse() == 1;
|
||||
}
|
||||
|
||||
@@ -281,7 +266,7 @@ class TinyGsmA7672X : public TinyGsmModem<TinyGsmA7672X>,
|
||||
* Power functions
|
||||
*/
|
||||
protected:
|
||||
bool restartImpl(const char* pin = NULL) {
|
||||
bool restartImpl(const char* pin = nullptr) {
|
||||
if (!testAT()) { return false; }
|
||||
sendAT(GF("+CRESET"));
|
||||
waitResponse();
|
||||
@@ -325,8 +310,8 @@ class TinyGsmA7672X : public TinyGsmModem<TinyGsmA7672X>,
|
||||
* Generic network functions
|
||||
*/
|
||||
public:
|
||||
RegStatus getRegistrationStatus() {
|
||||
return (RegStatus)getRegistrationStatusXREG("CREG");
|
||||
A7672xRegStatus getRegistrationStatus() {
|
||||
return (A7672xRegStatus)getRegistrationStatusXREG("CREG");
|
||||
}
|
||||
|
||||
String getLocalIPImpl() {
|
||||
@@ -345,7 +330,7 @@ class TinyGsmA7672X : public TinyGsmModem<TinyGsmA7672X>,
|
||||
|
||||
protected:
|
||||
bool isNetworkConnectedImpl() {
|
||||
RegStatus s = getRegistrationStatus();
|
||||
A7672xRegStatus s = getRegistrationStatus();
|
||||
return (s == REG_OK_HOME || s == REG_OK_ROAMING);
|
||||
}
|
||||
|
||||
@@ -381,8 +366,8 @@ class TinyGsmA7672X : public TinyGsmModem<TinyGsmA7672X>,
|
||||
* GPRS functions
|
||||
*/
|
||||
protected:
|
||||
bool gprsConnectImpl(const char* apn, const char* user = NULL,
|
||||
const char* pwd = NULL) {
|
||||
bool gprsConnectImpl(const char* apn, const char* user = nullptr,
|
||||
const char* pwd = nullptr) {
|
||||
gprsDisconnect();
|
||||
|
||||
// Define the PDP context
|
||||
@@ -429,7 +414,7 @@ class TinyGsmA7672X : public TinyGsmModem<TinyGsmA7672X>,
|
||||
protected:
|
||||
String getSimCCIDImpl() {
|
||||
sendAT(GF("+CICCID"));
|
||||
if (waitResponse(GF(GSM_NL "+ICCID:")) != 1) { return ""; }
|
||||
if (waitResponse(GF(AT_NL "+ICCID:")) != 1) { return ""; }
|
||||
String res = stream.readStringUntil('\n');
|
||||
waitResponse();
|
||||
res.trim();
|
||||
@@ -473,6 +458,19 @@ class TinyGsmA7672X : public TinyGsmModem<TinyGsmA7672X>,
|
||||
* Battery functions //todo:
|
||||
*/
|
||||
protected:
|
||||
/*
|
||||
* Temperature functions
|
||||
*/
|
||||
protected:
|
||||
float getTemperatureImpl() {
|
||||
String res = "";
|
||||
sendAT(GF("+CPMUTEMP"));
|
||||
if (waitResponse(1000L, res)) { return 0; }
|
||||
res = res.substring(res.indexOf(':'), res.indexOf('\r'));
|
||||
float temp = res.toFloat();
|
||||
waitResponse();
|
||||
return temp;
|
||||
}
|
||||
/*
|
||||
* Client related functions
|
||||
*/
|
||||
@@ -537,9 +535,9 @@ class TinyGsmA7672X : public TinyGsmModem<TinyGsmA7672X>,
|
||||
if (waitResponse(2000L) != 1) { return false; }
|
||||
|
||||
sendAT(GF("+CCHOPEN="), 0, GF(",\""), host, GF("\","), port, GF(",2"));
|
||||
rsp = waitResponse(timeout_ms, GF("+CCHOPEN: 0,0" GSM_NL),
|
||||
GF("+CCHOPEN: 0,1" GSM_NL), GF("+CCHOPEN: 0,4" GSM_NL),
|
||||
GF("ERROR" GSM_NL), GF("CLOSE OK" GSM_NL));
|
||||
rsp = waitResponse(timeout_ms, GF("+CCHOPEN: 0,0" AT_NL),
|
||||
GF("+CCHOPEN: 0,1" AT_NL), GF("+CCHOPEN: 0,4" AT_NL),
|
||||
GF("ERROR" AT_NL), GF("CLOSE OK" AT_NL));
|
||||
} else {
|
||||
sendAT(GF("+NETOPEN"));
|
||||
if (waitResponse(2000L) != 1) { return false; }
|
||||
@@ -551,9 +549,9 @@ class TinyGsmA7672X : public TinyGsmModem<TinyGsmA7672X>,
|
||||
port);
|
||||
|
||||
rsp = waitResponse(
|
||||
timeout_ms, GF("+CIPOPEN: 0,0" GSM_NL), GF("+CIPOPEN: 0,1" GSM_NL),
|
||||
GF("+CIPOPEN: 0,4" GSM_NL), GF("ERROR" GSM_NL),
|
||||
GF("CLOSE OK" GSM_NL)); // Happens when HTTPS handshake fails
|
||||
timeout_ms, GF("+CIPOPEN: 0,0" AT_NL), GF("+CIPOPEN: 0,1" AT_NL),
|
||||
GF("+CIPOPEN: 0,4" AT_NL), GF("ERROR" AT_NL),
|
||||
GF("CLOSE OK" AT_NL)); // Happens when HTTPS handshake fails
|
||||
}
|
||||
|
||||
return (1 == rsp);
|
||||
@@ -569,9 +567,9 @@ class TinyGsmA7672X : public TinyGsmModem<TinyGsmA7672X>,
|
||||
stream.flush();
|
||||
|
||||
if (waitResponse() != 1) { return 0; }
|
||||
if (waitResponse(10000L, GF("+CCHSEND: 0,0" GSM_NL),
|
||||
GF("+CCHSEND: 0,4" GSM_NL), GF("+CCHSEND: 0,9" GSM_NL),
|
||||
GF("ERROR" GSM_NL), GF("CLOSE OK" GSM_NL)) != 1) {
|
||||
if (waitResponse(10000L, GF("+CCHSEND: 0,0" AT_NL),
|
||||
GF("+CCHSEND: 0,4" AT_NL), GF("+CCHSEND: 0,9" AT_NL),
|
||||
GF("ERROR" AT_NL), GF("CLOSE OK" AT_NL)) != 1) {
|
||||
return 0;
|
||||
}
|
||||
return len;
|
||||
@@ -593,7 +591,7 @@ class TinyGsmA7672X : public TinyGsmModem<TinyGsmA7672X>,
|
||||
streamSkipUntil(','); // Skip DATA
|
||||
streamSkipUntil(','); // Skip mux
|
||||
len_requested = streamGetIntBefore('\n');
|
||||
len_confirmed = len; // streamGetIntBefore(',');
|
||||
len_confirmed = len; // streamGetIntBefore(',');
|
||||
} else {
|
||||
sendAT(GF("+CIPRXGET=2,"), mux, ',', (uint16_t)size);
|
||||
if (waitResponse(GF("+CIPRXGET:")) != 1) { return 0; }
|
||||
@@ -669,162 +667,91 @@ class TinyGsmA7672X : public TinyGsmModem<TinyGsmA7672X>,
|
||||
* Utilities
|
||||
*/
|
||||
public:
|
||||
// TODO(vshymanskyy): Optimize this!
|
||||
int8_t waitResponse(uint32_t timeout_ms, String& data,
|
||||
GsmConstStr r1 = GFP(GSM_OK),
|
||||
GsmConstStr r2 = GFP(GSM_ERROR),
|
||||
#if defined TINY_GSM_DEBUG
|
||||
GsmConstStr r3 = GFP(GSM_CME_ERROR),
|
||||
GsmConstStr r4 = GFP(GSM_CMS_ERROR),
|
||||
#else
|
||||
GsmConstStr r3 = NULL, GsmConstStr r4 = NULL,
|
||||
#endif
|
||||
GsmConstStr r5 = NULL) {
|
||||
/*String r1s(r1); r1s.trim();
|
||||
String r2s(r2); r2s.trim();
|
||||
String r3s(r3); r3s.trim();
|
||||
String r4s(r4); r4s.trim();
|
||||
String r5s(r5); r5s.trim();
|
||||
DBG("### ..:", r1s, ",", r2s, ",", r3s, ",", r4s, ",", r5s);*/
|
||||
data.reserve(64);
|
||||
uint8_t index = 0;
|
||||
uint32_t startMillis = millis();
|
||||
do {
|
||||
TINY_GSM_YIELD();
|
||||
while (stream.available() > 0) {
|
||||
TINY_GSM_YIELD();
|
||||
int8_t a = stream.read();
|
||||
if (a <= 0) continue; // Skip 0x00 bytes, just in case
|
||||
data += static_cast<char>(a);
|
||||
if (r1 && data.endsWith(r1)) {
|
||||
index = 1;
|
||||
goto finish;
|
||||
} else if (r2 && data.endsWith(r2)) {
|
||||
index = 2;
|
||||
goto finish;
|
||||
} else if (r3 && data.endsWith(r3)) {
|
||||
#if defined TINY_GSM_DEBUG
|
||||
if (r3 == GFP(GSM_CME_ERROR)) {
|
||||
streamSkipUntil('\n'); // Read out the error
|
||||
}
|
||||
#endif
|
||||
index = 3;
|
||||
goto finish;
|
||||
} else if (r4 && data.endsWith(r4)) {
|
||||
index = 4;
|
||||
goto finish;
|
||||
} else if (r5 && data.endsWith(r5)) {
|
||||
index = 5;
|
||||
goto finish;
|
||||
} else if (data.endsWith(GF(GSM_NL "+CIPRXGET:"))) {
|
||||
int8_t mode = streamGetIntBefore(',');
|
||||
if (mode == 1) {
|
||||
int8_t mux = streamGetIntBefore('\n');
|
||||
if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) {
|
||||
sockets[mux]->got_data = true;
|
||||
}
|
||||
data = "";
|
||||
DBG("### Got Data:", mux);
|
||||
} else {
|
||||
data += mode;
|
||||
}
|
||||
} else if (data.endsWith(GF("RECV EVENT" GSM_NL))) {
|
||||
sendAT(GF("+CCHRECV?"));
|
||||
String res = "";
|
||||
waitResponse(2000L, res);
|
||||
int8_t mux = res.substring(res.lastIndexOf(',') + 1).toInt();
|
||||
int16_t len =
|
||||
res.substring(res.indexOf(',') + 1, res.lastIndexOf(',')).toInt();
|
||||
if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) {
|
||||
sockets[mux]->got_data = true;
|
||||
if (len >= 0 && len <= 1024) { sockets[mux]->sock_available = len; }
|
||||
}
|
||||
data = "";
|
||||
DBG("### Got Data:", len, "on", mux);
|
||||
} else if (data.endsWith(GF("+CCHRECV: 0,0" GSM_NL))) {
|
||||
int8_t mux = data.substring(data.lastIndexOf(',') + 1).toInt();
|
||||
if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) {
|
||||
sockets[mux]->sock_connected = true;
|
||||
}
|
||||
data = "";
|
||||
DBG("### ACK:", mux);
|
||||
} else if (data.endsWith(GF("+IPCLOSE:"))) {
|
||||
int8_t mux = streamGetIntBefore(',');
|
||||
if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) {
|
||||
sockets[mux]->sock_connected = false;
|
||||
}
|
||||
data = "";
|
||||
streamSkipUntil('\n');
|
||||
DBG("### TCP Closed: ", mux);
|
||||
} else if (data.endsWith(GF("+CCHCLOSE:"))) {
|
||||
int8_t mux = streamGetIntBefore(',');
|
||||
if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) {
|
||||
sockets[mux]->sock_connected = false;
|
||||
}
|
||||
data = "";
|
||||
streamSkipUntil('\n');
|
||||
DBG("### SSL Closed: ", mux);
|
||||
} else if (data.endsWith(GF("+CCH_PEER_CLOSED:"))) {
|
||||
int8_t mux = streamGetIntBefore('\n');
|
||||
if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) {
|
||||
sockets[mux]->sock_connected = false;
|
||||
}
|
||||
data = "";
|
||||
DBG("### SSL Closed: ", mux);
|
||||
} else if (data.endsWith(GF("*PSNWID:"))) {
|
||||
streamSkipUntil('\n'); // Refresh network name by network
|
||||
data = "";
|
||||
DBG("### Network name updated.");
|
||||
} else if (data.endsWith(GF("*PSUTTZ:"))) {
|
||||
streamSkipUntil('\n'); // Refresh time and time zone by network
|
||||
data = "";
|
||||
DBG("### Network time and time zone updated.");
|
||||
} else if (data.endsWith(GF("+CTZV:"))) {
|
||||
streamSkipUntil('\n'); // Refresh network time zone by network
|
||||
data = "";
|
||||
DBG("### Network time zone updated.");
|
||||
} else if (data.endsWith(GF("DST:"))) {
|
||||
streamSkipUntil(
|
||||
'\n'); // Refresh Network Daylight Saving Time by network
|
||||
data = "";
|
||||
DBG("### Daylight savings time state updated.");
|
||||
bool handleURCs(String& data) {
|
||||
if (data.endsWith(GF(AT_NL "+CIPRXGET:"))) {
|
||||
int8_t mode = streamGetIntBefore(',');
|
||||
if (mode == 1) {
|
||||
int8_t mux = streamGetIntBefore('\n');
|
||||
if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) {
|
||||
sockets[mux]->got_data = true;
|
||||
}
|
||||
data = "";
|
||||
DBG("### Got Data:", mux);
|
||||
return true;
|
||||
} else {
|
||||
data += mode;
|
||||
return false;
|
||||
}
|
||||
} else if (data.endsWith(GF("RECV EVENT" AT_NL))) {
|
||||
sendAT(GF("+CCHRECV?"));
|
||||
String res = "";
|
||||
waitResponse(2000L, res);
|
||||
int8_t mux = res.substring(res.lastIndexOf(',') + 1).toInt();
|
||||
int16_t len =
|
||||
res.substring(res.indexOf(',') + 1, res.lastIndexOf(',')).toInt();
|
||||
if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) {
|
||||
sockets[mux]->got_data = true;
|
||||
if (len >= 0 && len <= 1024) { sockets[mux]->sock_available = len; }
|
||||
}
|
||||
} while (millis() - startMillis < timeout_ms);
|
||||
finish:
|
||||
if (!index) {
|
||||
data.trim();
|
||||
if (data.length()) { DBG("### Unhandled:", data); }
|
||||
data = "";
|
||||
DBG("### Got Data:", len, "on", mux);
|
||||
return true;
|
||||
} else if (data.endsWith(GF("+CCHRECV: 0,0" AT_NL))) {
|
||||
int8_t mux = data.substring(data.lastIndexOf(',') + 1).toInt();
|
||||
if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) {
|
||||
sockets[mux]->sock_connected = true;
|
||||
}
|
||||
data = "";
|
||||
DBG("### ACK:", mux);
|
||||
return true;
|
||||
} else if (data.endsWith(GF("+IPCLOSE:"))) {
|
||||
int8_t mux = streamGetIntBefore(',');
|
||||
if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) {
|
||||
sockets[mux]->sock_connected = false;
|
||||
}
|
||||
data = "";
|
||||
streamSkipUntil('\n');
|
||||
DBG("### TCP Closed: ", mux);
|
||||
return true;
|
||||
} else if (data.endsWith(GF("+CCHCLOSE:"))) {
|
||||
int8_t mux = streamGetIntBefore(',');
|
||||
if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) {
|
||||
sockets[mux]->sock_connected = false;
|
||||
}
|
||||
data = "";
|
||||
streamSkipUntil('\n');
|
||||
DBG("### SSL Closed: ", mux);
|
||||
return true;
|
||||
} else if (data.endsWith(GF("+CCH_PEER_CLOSED:"))) {
|
||||
int8_t mux = streamGetIntBefore('\n');
|
||||
if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) {
|
||||
sockets[mux]->sock_connected = false;
|
||||
}
|
||||
data = "";
|
||||
DBG("### SSL Closed: ", mux);
|
||||
return true;
|
||||
} else if (data.endsWith(GF("*PSNWID:"))) {
|
||||
streamSkipUntil('\n'); // Refresh network name by network
|
||||
data = "";
|
||||
DBG("### Network name updated.");
|
||||
return true;
|
||||
} else if (data.endsWith(GF("*PSUTTZ:"))) {
|
||||
streamSkipUntil('\n'); // Refresh time and time zone by network
|
||||
data = "";
|
||||
DBG("### Network time and time zone updated.");
|
||||
return true;
|
||||
} else if (data.endsWith(GF("+CTZV:"))) {
|
||||
streamSkipUntil('\n'); // Refresh network time zone by network
|
||||
data = "";
|
||||
DBG("### Network time zone updated.");
|
||||
return true;
|
||||
} else if (data.endsWith(GF("DST:"))) {
|
||||
streamSkipUntil('\n'); // Refresh Network Daylight Saving Time by network
|
||||
data = "";
|
||||
DBG("### Daylight savings time state updated.");
|
||||
return true;
|
||||
}
|
||||
// data.replace(GSM_NL, "/");
|
||||
// DBG('<', index, '>', data);
|
||||
return index;
|
||||
}
|
||||
|
||||
int8_t waitResponse(uint32_t timeout_ms, GsmConstStr r1 = GFP(GSM_OK),
|
||||
GsmConstStr r2 = GFP(GSM_ERROR),
|
||||
#if defined TINY_GSM_DEBUG
|
||||
GsmConstStr r3 = GFP(GSM_CME_ERROR),
|
||||
GsmConstStr r4 = GFP(GSM_CMS_ERROR),
|
||||
#else
|
||||
GsmConstStr r3 = NULL, GsmConstStr r4 = NULL,
|
||||
#endif
|
||||
GsmConstStr r5 = NULL) {
|
||||
String data;
|
||||
return waitResponse(timeout_ms, data, r1, r2, r3, r4, r5);
|
||||
}
|
||||
|
||||
int8_t waitResponse(GsmConstStr r1 = GFP(GSM_OK),
|
||||
GsmConstStr r2 = GFP(GSM_ERROR),
|
||||
#if defined TINY_GSM_DEBUG
|
||||
GsmConstStr r3 = GFP(GSM_CME_ERROR),
|
||||
GsmConstStr r4 = GFP(GSM_CMS_ERROR),
|
||||
#else
|
||||
GsmConstStr r3 = NULL, GsmConstStr r4 = NULL,
|
||||
#endif
|
||||
GsmConstStr r5 = NULL) {
|
||||
return waitResponse(1000, r1, r2, r3, r4, r5);
|
||||
return false;
|
||||
}
|
||||
|
||||
public:
|
||||
@@ -832,7 +759,6 @@ class TinyGsmA7672X : public TinyGsmModem<TinyGsmA7672X>,
|
||||
|
||||
protected:
|
||||
GsmClientA7672X* sockets[TINY_GSM_MUX_COUNT];
|
||||
const char* gsmNL = GSM_NL;
|
||||
bool hasSSL = false;
|
||||
String certificates[TINY_GSM_MUX_COUNT];
|
||||
};
|
||||
|
||||
@@ -10,11 +10,20 @@
|
||||
|
||||
// Select your modem:
|
||||
#define TINY_GSM_MODEM_SIM800
|
||||
// #define TINY_GSM_MODEM_SIM900
|
||||
// #define TINY_GSM_MODEM_SIM808
|
||||
// #define TINY_GSM_MODEM_SIM868
|
||||
// #define TINY_GSM_MODEM_SIM900
|
||||
// #define TINY_GSM_MODEM_SIM7000
|
||||
// #define TINY_GSM_MODEM_SIM7000SSL
|
||||
// #define TINY_GSM_MODEM_SIM7080
|
||||
// #define TINY_GSM_MODEM_SIM5360
|
||||
// #define TINY_GSM_MODEM_SIM7600
|
||||
// #define TINY_GSM_MODEM_A7672X
|
||||
// #define TINY_GSM_MODEM_UBLOX
|
||||
// #define TINY_GSM_MODEM_SARAR4
|
||||
// #define TINY_GSM_MODEM_SARAR5
|
||||
// #define TINY_GSM_MODEM_M95
|
||||
// #define TINY_GSM_MODEM_BG95
|
||||
// #define TINY_GSM_MODEM_BG96
|
||||
// #define TINY_GSM_MODEM_A6
|
||||
// #define TINY_GSM_MODEM_A7
|
||||
@@ -23,6 +32,7 @@
|
||||
// #define TINY_GSM_MODEM_MC60E
|
||||
// #define TINY_GSM_MODEM_ESP8266
|
||||
// #define TINY_GSM_MODEM_XBEE
|
||||
// #define TINY_GSM_MODEM_SEQUANS_MONARCH
|
||||
|
||||
// Set serial for debug console (to the Serial Monitor, speed 115200)
|
||||
#define SerialMon Serial
|
||||
@@ -43,7 +53,7 @@ SoftwareSerial SerialAT(2, 3); // RX, TX
|
||||
#include <TinyGsmClient.h>
|
||||
|
||||
// Module baud rate
|
||||
uint32_t rate = 0; // Set to 0 for Auto-Detect
|
||||
uint32_t rate = 0; // Set to 0 for Auto-Detect
|
||||
|
||||
void setup() {
|
||||
// Set console baud rate
|
||||
@@ -52,17 +62,17 @@ void setup() {
|
||||
}
|
||||
|
||||
void loop() {
|
||||
if (!rate) { rate = TinyGsmAutoBaud(SerialAT); }
|
||||
|
||||
if (!rate) {
|
||||
rate = TinyGsmAutoBaud(SerialAT);
|
||||
}
|
||||
|
||||
if (!rate) {
|
||||
SerialMon.println(F("***********************************************************"));
|
||||
SerialMon.println(
|
||||
F("***********************************************************"));
|
||||
SerialMon.println(F(" Module does not respond!"));
|
||||
SerialMon.println(F(" Check your Serial wiring"));
|
||||
SerialMon.println(F(" Check the module is correctly powered and turned on"));
|
||||
SerialMon.println(F("***********************************************************"));
|
||||
SerialMon.println(
|
||||
F(" Check the module is correctly powered and turned on"));
|
||||
SerialMon.println(
|
||||
F("***********************************************************"));
|
||||
delay(30000L);
|
||||
return;
|
||||
}
|
||||
@@ -70,19 +80,19 @@ void loop() {
|
||||
SerialAT.begin(rate);
|
||||
|
||||
// Access AT commands from Serial Monitor
|
||||
SerialMon.println(F("***********************************************************"));
|
||||
SerialMon.println(
|
||||
F("***********************************************************"));
|
||||
SerialMon.println(F(" You can now send AT commands"));
|
||||
SerialMon.println(F(" Enter \"AT\" (without quotes), and you should see \"OK\""));
|
||||
SerialMon.println(F(" If it doesn't work, select \"Both NL & CR\" in Serial Monitor"));
|
||||
SerialMon.println(F("***********************************************************"));
|
||||
SerialMon.println(
|
||||
F(" Enter \"AT\" (without quotes), and you should see \"OK\""));
|
||||
SerialMon.println(
|
||||
F(" If it doesn't work, select \"Both NL & CR\" in Serial Monitor"));
|
||||
SerialMon.println(
|
||||
F("***********************************************************"));
|
||||
|
||||
while(true) {
|
||||
if (SerialAT.available()) {
|
||||
SerialMon.write(SerialAT.read());
|
||||
}
|
||||
if (SerialMon.available()) {
|
||||
SerialAT.write(SerialMon.read());
|
||||
}
|
||||
while (true) {
|
||||
if (SerialAT.available()) { SerialMon.write(SerialAT.read()); }
|
||||
if (SerialMon.available()) { SerialAT.write(SerialMon.read()); }
|
||||
delay(0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
// #define TINY_GSM_MODEM_SIM7080
|
||||
// #define TINY_GSM_MODEM_SIM5360
|
||||
// #define TINY_GSM_MODEM_SIM7600
|
||||
// #define TINY_GSM_MODEM_A7672X
|
||||
// #define TINY_GSM_MODEM_UBLOX
|
||||
// #define TINY_GSM_MODEM_SARAR4
|
||||
// #define TINY_GSM_MODEM_M95
|
||||
|
||||
@@ -11,11 +11,19 @@
|
||||
|
||||
// Select your modem:
|
||||
#define TINY_GSM_MODEM_SIM800
|
||||
// #define TINY_GSM_MODEM_SIM900
|
||||
// #define TINY_GSM_MODEM_SIM808
|
||||
// #define TINY_GSM_MODEM_SIM868
|
||||
// #define TINY_GSM_MODEM_SIM900
|
||||
// #define TINY_GSM_MODEM_SIM7000
|
||||
// #define TINY_GSM_MODEM_SIM7000SSL
|
||||
// #define TINY_GSM_MODEM_SIM7080
|
||||
// #define TINY_GSM_MODEM_SIM5360
|
||||
// #define TINY_GSM_MODEM_SIM7600
|
||||
// #define TINY_GSM_MODEM_A7672X
|
||||
// #define TINY_GSM_MODEM_UBLOX
|
||||
// #define TINY_GSM_MODEM_SARAR4
|
||||
// #define TINY_GSM_MODEM_M95
|
||||
// #define TINY_GSM_MODEM_BG95
|
||||
// #define TINY_GSM_MODEM_BG96
|
||||
// #define TINY_GSM_MODEM_A6
|
||||
// #define TINY_GSM_MODEM_A7
|
||||
@@ -24,6 +32,7 @@
|
||||
// #define TINY_GSM_MODEM_MC60E
|
||||
// #define TINY_GSM_MODEM_ESP8266
|
||||
// #define TINY_GSM_MODEM_XBEE
|
||||
// #define TINY_GSM_MODEM_SEQUANS_MONARCH
|
||||
|
||||
#include <TinyGsmClient.h>
|
||||
|
||||
@@ -43,7 +52,7 @@ SoftwareSerial SerialAT(2, 3); // RX, TX
|
||||
|
||||
#include <StreamDebugger.h>
|
||||
StreamDebugger debugger(SerialAT, SerialMon);
|
||||
TinyGsm modem(debugger);
|
||||
TinyGsm modem(debugger);
|
||||
|
||||
void setup() {
|
||||
// Set console baud rate
|
||||
@@ -55,22 +64,25 @@ void setup() {
|
||||
delay(6000);
|
||||
|
||||
if (!modem.init()) {
|
||||
SerialMon.println(F("***********************************************************"));
|
||||
SerialMon.println(
|
||||
F("***********************************************************"));
|
||||
SerialMon.println(F(" Cannot initialize modem!"));
|
||||
SerialMon.println(F(" Use File -> Examples -> TinyGSM -> tools -> AT_Debug"));
|
||||
SerialMon.println(
|
||||
F(" Use File -> Examples -> TinyGSM -> tools -> AT_Debug"));
|
||||
SerialMon.println(F(" to find correct configuration"));
|
||||
SerialMon.println(F("***********************************************************"));
|
||||
SerialMon.println(
|
||||
F("***********************************************************"));
|
||||
return;
|
||||
}
|
||||
|
||||
bool ret = modem.factoryDefault();
|
||||
|
||||
SerialMon.println(F("***********************************************************"));
|
||||
SerialMon.print (F(" Return settings to Factory Defaults: "));
|
||||
SerialMon.println(
|
||||
F("***********************************************************"));
|
||||
SerialMon.print(F(" Return settings to Factory Defaults: "));
|
||||
SerialMon.println((ret) ? "OK" : "FAIL");
|
||||
SerialMon.println(F("***********************************************************"));
|
||||
SerialMon.println(
|
||||
F("***********************************************************"));
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
}
|
||||
void loop() {}
|
||||
|
||||
Reference in New Issue
Block a user