Merge pull request #287 from EnviroDIY/master
Fix the damage I did to SIM800
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -16,6 +16,7 @@
|
|||||||
.settings
|
.settings
|
||||||
.pioenvs
|
.pioenvs
|
||||||
.piolibdeps
|
.piolibdeps
|
||||||
|
.pio/*
|
||||||
.clang_complete
|
.clang_complete
|
||||||
.gcc-flags.json
|
.gcc-flags.json
|
||||||
platformio.ini
|
platformio.ini
|
||||||
|
@@ -28,6 +28,16 @@
|
|||||||
// #define TINY_GSM_MODEM_XBEE
|
// #define TINY_GSM_MODEM_XBEE
|
||||||
// #define TINY_GSM_MODEM_SEQUANS_MONARCH
|
// #define TINY_GSM_MODEM_SEQUANS_MONARCH
|
||||||
|
|
||||||
|
// See all AT commands, if wanted
|
||||||
|
// #define DUMP_AT_COMMANDS
|
||||||
|
|
||||||
|
// Define the serial console for debug prints, if needed
|
||||||
|
#define TINY_GSM_DEBUG SerialMon
|
||||||
|
|
||||||
|
// Range to attempt to autobaud
|
||||||
|
#define GSM_AUTOBAUD_MIN 9600
|
||||||
|
#define GSM_AUTOBAUD_MAX 38400
|
||||||
|
|
||||||
// Set serial for debug console (to the Serial Monitor, default speed 115200)
|
// Set serial for debug console (to the Serial Monitor, default speed 115200)
|
||||||
#define SerialMon Serial
|
#define SerialMon Serial
|
||||||
|
|
||||||
@@ -39,24 +49,15 @@
|
|||||||
//#include <SoftwareSerial.h>
|
//#include <SoftwareSerial.h>
|
||||||
//SoftwareSerial SerialAT(2, 3); // RX, TX
|
//SoftwareSerial SerialAT(2, 3); // RX, TX
|
||||||
|
|
||||||
// See all AT commands, if wanted
|
|
||||||
//#define DUMP_AT_COMMANDS
|
|
||||||
|
|
||||||
// See the debugging, if wanted
|
|
||||||
#define TINY_GSM_DEBUG SerialMon
|
|
||||||
|
|
||||||
// Range to attempt to autobaud
|
|
||||||
#define GSM_AUTOBAUD_MIN 9600
|
|
||||||
#define GSM_AUTOBAUD_MAX 38400
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Test enabled
|
* Test enabled
|
||||||
*/
|
*/
|
||||||
#define TINY_GSM_USE_GPRS true
|
#define TINY_GSM_TEST_GPRS true
|
||||||
#define TINY_GSM_USE_WIFI false
|
#define TINY_GSM_TEST_WIFI false
|
||||||
#define TINY_GSM_USE_CALL true
|
#define TINY_GSM_TEST_CALL true
|
||||||
#define TINY_GSM_USE_SMS true
|
#define TINY_GSM_TEST_SMS true
|
||||||
#define TINY_GSM_USE_USSD true
|
#define TINY_GSM_TEST_USSD true
|
||||||
|
#define TINY_GSM_TEST_BATTERY true
|
||||||
// powerdown modem after tests
|
// powerdown modem after tests
|
||||||
#define TINY_GSM_POWERDOWN false
|
#define TINY_GSM_POWERDOWN false
|
||||||
|
|
||||||
@@ -70,10 +71,10 @@
|
|||||||
// Your GPRS credentials
|
// Your GPRS credentials
|
||||||
// Leave empty, if missing user or pass
|
// Leave empty, if missing user or pass
|
||||||
const char apn[] = "YourAPN";
|
const char apn[] = "YourAPN";
|
||||||
const char user[] = "";
|
const char gprsUser[] = "";
|
||||||
const char pass[] = "";
|
const char gprsPass[] = "";
|
||||||
const char wifiSSID[] = "YourSSID";
|
const char wifiSSID[] = "YourSSID";
|
||||||
const char wifiPass[] = "SSIDpw";
|
const char wifiPass[] = "YourWiFiPass";
|
||||||
|
|
||||||
#include <TinyGsmClient.h>
|
#include <TinyGsmClient.h>
|
||||||
|
|
||||||
@@ -98,11 +99,11 @@ void setup() {
|
|||||||
digitalWrite(23, HIGH);
|
digitalWrite(23, HIGH);
|
||||||
|
|
||||||
DBG("Wait...");
|
DBG("Wait...");
|
||||||
delay(3000);
|
|
||||||
|
|
||||||
// Set GSM module baud rate
|
// Set GSM module baud rate
|
||||||
TinyGsmAutoBaud(SerialAT,GSM_AUTOBAUD_MIN,GSM_AUTOBAUD_MAX);
|
TinyGsmAutoBaud(SerialAT,GSM_AUTOBAUD_MIN,GSM_AUTOBAUD_MAX);
|
||||||
//SerialAT.begin(9600);
|
//SerialAT.begin(9600);
|
||||||
|
delay(3000);
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
@@ -120,26 +121,34 @@ void loop() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String modemInfo = modem.getModemInfo();
|
String name = modem.getModemName();
|
||||||
DBG("Modem:", modemInfo);
|
DBG("Modem Name:", name);
|
||||||
|
|
||||||
#if TINY_GSM_USE_GPRS
|
String modemInfo = modem.getModemInfo();
|
||||||
|
DBG("Modem Info:", modemInfo);
|
||||||
|
|
||||||
|
#if TINY_GSM_TEST_GPRS
|
||||||
// Unlock your SIM card with a PIN if needed
|
// Unlock your SIM card with a PIN if needed
|
||||||
if ( GSM_PIN && modem.getSimStatus() != 3 ) {
|
if ( GSM_PIN && modem.getSimStatus() != 3 ) {
|
||||||
modem.simUnlock(GSM_PIN);
|
modem.simUnlock(GSM_PIN);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if TINY_GSM_USE_WIFI
|
#if TINY_GSM_TEST_WIFI
|
||||||
SerialMon.print(F("Setting SSID/password..."));
|
DBG("Setting SSID/password...");
|
||||||
if (!modem.networkConnect(wifiSSID, wifiPass)) {
|
if (!modem.networkConnect(wifiSSID, wifiPass)) {
|
||||||
SerialMon.println(" fail");
|
DBG(" fail");
|
||||||
delay(10000);
|
delay(10000);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
SerialMon.println(" OK");
|
SerialMon.println(" OK");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if TINY_GSM_TEST_GPRS && defined TINY_GSM_MODEM_XBEE
|
||||||
|
// The XBee must run the gprsConnect function BEFORE waiting for network!
|
||||||
|
modem.gprsConnect(apn, gprsUser, gprsPass);
|
||||||
|
#endif
|
||||||
|
|
||||||
DBG("Waiting for network...");
|
DBG("Waiting for network...");
|
||||||
if (!modem.waitForNetwork()) {
|
if (!modem.waitForNetwork()) {
|
||||||
delay(10000);
|
delay(10000);
|
||||||
@@ -150,9 +159,9 @@ void loop() {
|
|||||||
DBG("Network connected");
|
DBG("Network connected");
|
||||||
}
|
}
|
||||||
|
|
||||||
#if TINY_GSM_USE_GPRS
|
#if TINY_GSM_TEST_GPRS
|
||||||
DBG("Connecting to", apn);
|
DBG("Connecting to", apn);
|
||||||
if (!modem.gprsConnect(apn, user, pass)) {
|
if (!modem.gprsConnect(apn, gprsUser, gprsPass)) {
|
||||||
delay(10000);
|
delay(10000);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -175,17 +184,9 @@ void loop() {
|
|||||||
int csq = modem.getSignalQuality();
|
int csq = modem.getSignalQuality();
|
||||||
DBG("Signal quality:", csq);
|
DBG("Signal quality:", csq);
|
||||||
|
|
||||||
// This is NOT supported on M590
|
|
||||||
int battLevel = modem.getBattPercent();
|
|
||||||
DBG("Battery lavel:", battLevel);
|
|
||||||
|
|
||||||
// This is only supported on SIMxxx series
|
// This is only supported on SIMxxx series
|
||||||
float battVoltage = modem.getBattVoltage() / 1000.0F;
|
// String gsmLoc = modem.getGsmLocation();
|
||||||
DBG("Battery voltage:", battVoltage);
|
// DBG("GSM location:", gsmLoc);
|
||||||
|
|
||||||
// This is only supported on SIMxxx series
|
|
||||||
String gsmLoc = modem.getGsmLocation();
|
|
||||||
DBG("GSM location:", gsmLoc);
|
|
||||||
|
|
||||||
// This is only supported on SIMxxx series
|
// This is only supported on SIMxxx series
|
||||||
// String gsmTime = modem.getGSMDateTime(DATE_TIME);
|
// String gsmTime = modem.getGSMDateTime(DATE_TIME);
|
||||||
@@ -207,7 +208,7 @@ void loop() {
|
|||||||
DBG("GPS raw data:", gps_raw);
|
DBG("GPS raw data:", gps_raw);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if TINY_GSM_USE_SMS && defined(SMS_TARGET)
|
#if TINY_GSM_TEST_SMS && defined(SMS_TARGET)
|
||||||
res = modem.sendSMS(SMS_TARGET, String("Hello from ") + imei);
|
res = modem.sendSMS(SMS_TARGET, String("Hello from ") + imei);
|
||||||
DBG("SMS:", res ? "OK" : "fail");
|
DBG("SMS:", res ? "OK" : "fail");
|
||||||
|
|
||||||
@@ -216,7 +217,7 @@ void loop() {
|
|||||||
DBG("UTF16 SMS:", res ? "OK" : "fail");
|
DBG("UTF16 SMS:", res ? "OK" : "fail");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if TINY_GSM_USE_CALL && defined(CALL_TARGET)
|
#if TINY_GSM_TEST_CALL && defined(CALL_TARGET)
|
||||||
DBG("Calling:", CALL_TARGET);
|
DBG("Calling:", CALL_TARGET);
|
||||||
|
|
||||||
// This is NOT supported on M590
|
// This is NOT supported on M590
|
||||||
@@ -241,7 +242,20 @@ void loop() {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if TINY_GSM_USE_GPRS
|
#if TINY_GSM_TEST_BATTERY
|
||||||
|
uint8_t chargeState = -99;
|
||||||
|
int8_t percent = -99;
|
||||||
|
uint16_t milliVolts = -9999;
|
||||||
|
modem.getBattStats(chargeState, percent, milliVolts)
|
||||||
|
DBG("Battery charge state:", chargeState);
|
||||||
|
DBG("Battery charge 'percent':", percent);
|
||||||
|
DBG("Battery voltage:", milliVolts / 1000.0F);
|
||||||
|
|
||||||
|
float temp = modem.getTemperature();
|
||||||
|
DBG("Chip temperature:", temp);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if TINY_GSM_TEST_GPRS
|
||||||
modem.gprsDisconnect();
|
modem.gprsDisconnect();
|
||||||
if (!modem.isGprsConnected()) {
|
if (!modem.isGprsConnected()) {
|
||||||
DBG("GPRS disconnected");
|
DBG("GPRS disconnected");
|
||||||
@@ -250,7 +264,7 @@ void loop() {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if TINY_GSM_USE_WIFI
|
#if TINY_GSM_TEST_WIFI
|
||||||
modem.networkDisconnect();
|
modem.networkDisconnect();
|
||||||
DBG("WiFi disconnected");
|
DBG("WiFi disconnected");
|
||||||
#endif
|
#endif
|
||||||
|
@@ -48,7 +48,7 @@
|
|||||||
// #define TINY_GSM_MODEM_SEQUANS_MONARCH
|
// #define TINY_GSM_MODEM_SEQUANS_MONARCH
|
||||||
|
|
||||||
#include <TinyGsmClient.h>
|
#include <TinyGsmClient.h>
|
||||||
#include <BlynkSimpleSIM800.h>
|
#include <BlynkSimpleTinyGSM.h>
|
||||||
|
|
||||||
// Set serial for debug console (to the Serial Monitor, default speed 115200)
|
// Set serial for debug console (to the Serial Monitor, default speed 115200)
|
||||||
#define SerialMon Serial
|
#define SerialMon Serial
|
||||||
|
@@ -12,9 +12,10 @@
|
|||||||
*
|
*
|
||||||
* For more HTTP API examples, see ArduinoHttpClient library
|
* For more HTTP API examples, see ArduinoHttpClient library
|
||||||
*
|
*
|
||||||
* NOTE: This example does NOT work with the XBee because the
|
* NOTE: This example may NOT work with the XBee because the
|
||||||
* HttpClient library does not empty to serial buffer fast enough
|
* HttpClient library does not empty to serial buffer fast enough
|
||||||
* and the buffer overflow causes the HttpClient library to stall.
|
* and the buffer overflow causes the HttpClient library to stall.
|
||||||
|
* Boards with faster processors may work, 8MHz boards will not.
|
||||||
**************************************************************/
|
**************************************************************/
|
||||||
|
|
||||||
// Select your modem:
|
// Select your modem:
|
||||||
@@ -45,16 +46,13 @@
|
|||||||
// See all AT commands, if wanted
|
// See all AT commands, if wanted
|
||||||
//#define DUMP_AT_COMMANDS
|
//#define DUMP_AT_COMMANDS
|
||||||
|
|
||||||
// See the debugging, if wanted
|
// Define the serial console for debug prints, if needed
|
||||||
//#define TINY_GSM_DEBUG Serial
|
//#define TINY_GSM_DEBUG Serial
|
||||||
//#define LOGGING
|
//#define LOGGING // <- Logging is for the HTTP library
|
||||||
|
|
||||||
// Add a reception delay, if needed
|
// Add a reception delay, if needed
|
||||||
//#define TINY_GSM_YIELD() { delay(1); }
|
//#define TINY_GSM_YIELD() { delay(1); }
|
||||||
|
|
||||||
#include <TinyGsmClient.h>
|
|
||||||
#include <ArduinoHttpClient.h>
|
|
||||||
|
|
||||||
// Set serial for debug console (to the Serial Monitor, default speed 115200)
|
// Set serial for debug console (to the Serial Monitor, default speed 115200)
|
||||||
#define SerialMon Serial
|
#define SerialMon Serial
|
||||||
|
|
||||||
@@ -85,6 +83,9 @@ const char server[] = "vsh.pp.ua";
|
|||||||
const char resource[] = "/TinyGSM/logo.txt";
|
const char resource[] = "/TinyGSM/logo.txt";
|
||||||
const int port = 80;
|
const int port = 80;
|
||||||
|
|
||||||
|
#include <TinyGsmClient.h>
|
||||||
|
#include <ArduinoHttpClient.h>
|
||||||
|
|
||||||
#ifdef DUMP_AT_COMMANDS
|
#ifdef DUMP_AT_COMMANDS
|
||||||
#include <StreamDebugger.h>
|
#include <StreamDebugger.h>
|
||||||
StreamDebugger debugger(SerialAT, SerialMon);
|
StreamDebugger debugger(SerialAT, SerialMon);
|
||||||
@@ -118,6 +119,7 @@ void setup() {
|
|||||||
// To skip it, call init() instead of restart()
|
// To skip it, call init() instead of restart()
|
||||||
SerialMon.println("Initializing modem...");
|
SerialMon.println("Initializing modem...");
|
||||||
modem.restart();
|
modem.restart();
|
||||||
|
// modem.init();
|
||||||
|
|
||||||
String modemInfo = modem.getModemInfo();
|
String modemInfo = modem.getModemInfo();
|
||||||
SerialMon.print("Modem: ");
|
SerialMon.print("Modem: ");
|
||||||
@@ -129,7 +131,7 @@ void setup() {
|
|||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
|
|
||||||
#if TINY_GSM_USE_WIFI
|
#if defined TINY_GSM_USE_WIFI && defined TINY_GSM_MODEM_HAS_WIFI
|
||||||
SerialMon.print(F("Setting SSID/password..."));
|
SerialMon.print(F("Setting SSID/password..."));
|
||||||
if (!modem.networkConnect(wifiSSID, wifiPass)) {
|
if (!modem.networkConnect(wifiSSID, wifiPass)) {
|
||||||
SerialMon.println(" fail");
|
SerialMon.println(" fail");
|
||||||
@@ -139,6 +141,11 @@ void loop() {
|
|||||||
SerialMon.println(" OK");
|
SerialMon.println(" OK");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if TINY_GSM_USE_GPRS && defined TINY_GSM_MODEM_XBEE
|
||||||
|
// The XBee must run the gprsConnect function BEFORE waiting for network!
|
||||||
|
modem.gprsConnect(apn, gprsUser, gprsPass);
|
||||||
|
#endif
|
||||||
|
|
||||||
SerialMon.print("Waiting for network...");
|
SerialMon.print("Waiting for network...");
|
||||||
if (!modem.waitForNetwork()) {
|
if (!modem.waitForNetwork()) {
|
||||||
SerialMon.println(" fail");
|
SerialMon.println(" fail");
|
||||||
@@ -148,10 +155,10 @@ void loop() {
|
|||||||
SerialMon.println(" OK");
|
SerialMon.println(" OK");
|
||||||
|
|
||||||
if (modem.isNetworkConnected()) {
|
if (modem.isNetworkConnected()) {
|
||||||
SerialMon.print("Network connected");
|
SerialMon.println("Network connected");
|
||||||
}
|
}
|
||||||
|
|
||||||
#if TINY_GSM_USE_GPRS
|
#if TINY_GSM_USE_GPRS && defined TINY_GSM_MODEM_HAS_GPRS
|
||||||
SerialMon.print(F("Connecting to "));
|
SerialMon.print(F("Connecting to "));
|
||||||
SerialMon.print(apn);
|
SerialMon.print(apn);
|
||||||
if (!modem.gprsConnect(apn, gprsUser, gprsPass)) {
|
if (!modem.gprsConnect(apn, gprsUser, gprsPass)) {
|
||||||
|
@@ -10,22 +10,30 @@
|
|||||||
* TinyGSM Getting Started guide:
|
* TinyGSM Getting Started guide:
|
||||||
* https://tiny.cc/tinygsm-readme
|
* https://tiny.cc/tinygsm-readme
|
||||||
*
|
*
|
||||||
* SSL/TLS is currently supported only with: SIM8xx, uBlox, ESP8266
|
* SSL/TLS is not yet supported on the Quectel modems
|
||||||
|
* The A6/A7/A20 and M590 are not capable of SSL/TLS
|
||||||
*
|
*
|
||||||
* For more HTTP API examples, see ArduinoHttpClient library
|
* For more HTTP API examples, see ArduinoHttpClient library
|
||||||
*
|
*
|
||||||
|
* NOTE: This example may NOT work with the XBee because the
|
||||||
|
* HttpClient library does not empty to serial buffer fast enough
|
||||||
|
* and the buffer overflow causes the HttpClient library to stall.
|
||||||
|
* Boards with faster processors may work, 8MHz boards will not.
|
||||||
**************************************************************/
|
**************************************************************/
|
||||||
|
|
||||||
// Select your modem:
|
// Select your modem:
|
||||||
#define TINY_GSM_MODEM_SIM800
|
#define TINY_GSM_MODEM_SIM800
|
||||||
// #define TINY_GSM_MODEM_SIM808
|
// #define TINY_GSM_MODEM_SIM808
|
||||||
// #define TINY_GSM_MODEM_SIM868
|
// #define TINY_GSM_MODEM_SIM868
|
||||||
|
// #define TINY_GSM_MODEM_SIM7000
|
||||||
// #define TINY_GSM_MODEM_UBLOX
|
// #define TINY_GSM_MODEM_UBLOX
|
||||||
// #define TINY_GSM_MODEM_SARAR4
|
// #define TINY_GSM_MODEM_SARAR4
|
||||||
// #define TINY_GSM_MODEM_ESP8266
|
// #define TINY_GSM_MODEM_ESP8266
|
||||||
|
// #define TINY_GSM_MODEM_XBEE
|
||||||
|
// #define TINY_GSM_MODEM_SEQUANS_MONARCH
|
||||||
|
|
||||||
// Increase RX buffer to capture the entire response
|
// Increase RX buffer to capture the entire response
|
||||||
// Chips without internal buffering (ESP8266)
|
// Chips without internal buffering (A6/A7, ESP8266, M590)
|
||||||
// need enough space in the buffer for the entire response
|
// need enough space in the buffer for the entire response
|
||||||
// else data will be lost (and the http library will fail).
|
// else data will be lost (and the http library will fail).
|
||||||
#define TINY_GSM_RX_BUFFER 650
|
#define TINY_GSM_RX_BUFFER 650
|
||||||
@@ -33,16 +41,13 @@
|
|||||||
// See all AT commands, if wanted
|
// See all AT commands, if wanted
|
||||||
//#define DUMP_AT_COMMANDS
|
//#define DUMP_AT_COMMANDS
|
||||||
|
|
||||||
// See the debugging, if wanted
|
// Define the serial console for debug prints, if needed
|
||||||
//#define TINY_GSM_DEBUG Serial
|
//#define TINY_GSM_DEBUG Serial
|
||||||
//#define LOGGING
|
//#define LOGGING // <- Logging is for the HTTP library
|
||||||
|
|
||||||
// Add a reception delay, if needed
|
// Add a reception delay, if needed
|
||||||
//#define TINY_GSM_YIELD() { delay(1); }
|
//#define TINY_GSM_YIELD() { delay(1); }
|
||||||
|
|
||||||
#include <TinyGsmClient.h>
|
|
||||||
#include <ArduinoHttpClient.h>
|
|
||||||
|
|
||||||
// Set serial for debug console (to the Serial Monitor, default speed 115200)
|
// Set serial for debug console (to the Serial Monitor, default speed 115200)
|
||||||
#define SerialMon Serial
|
#define SerialMon Serial
|
||||||
|
|
||||||
@@ -73,6 +78,9 @@ const char server[] = "vsh.pp.ua";
|
|||||||
const char resource[] = "/TinyGSM/logo.txt";
|
const char resource[] = "/TinyGSM/logo.txt";
|
||||||
const int port = 443;
|
const int port = 443;
|
||||||
|
|
||||||
|
#include <TinyGsmClient.h>
|
||||||
|
#include <ArduinoHttpClient.h>
|
||||||
|
|
||||||
#ifdef DUMP_AT_COMMANDS
|
#ifdef DUMP_AT_COMMANDS
|
||||||
#include <StreamDebugger.h>
|
#include <StreamDebugger.h>
|
||||||
StreamDebugger debugger(SerialAT, SerialMon);
|
StreamDebugger debugger(SerialAT, SerialMon);
|
||||||
@@ -106,6 +114,7 @@ void setup() {
|
|||||||
// To skip it, call init() instead of restart()
|
// To skip it, call init() instead of restart()
|
||||||
SerialMon.println("Initializing modem...");
|
SerialMon.println("Initializing modem...");
|
||||||
modem.restart();
|
modem.restart();
|
||||||
|
// modem.init();
|
||||||
|
|
||||||
String modemInfo = modem.getModemInfo();
|
String modemInfo = modem.getModemInfo();
|
||||||
SerialMon.print("Modem: ");
|
SerialMon.print("Modem: ");
|
||||||
@@ -122,7 +131,7 @@ void setup() {
|
|||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
|
|
||||||
#if TINY_GSM_USE_WIFI
|
#if defined TINY_GSM_USE_WIFI && defined TINY_GSM_MODEM_HAS_WIFI
|
||||||
SerialMon.print(F("Setting SSID/password..."));
|
SerialMon.print(F("Setting SSID/password..."));
|
||||||
if (!modem.networkConnect(wifiSSID, wifiPass)) {
|
if (!modem.networkConnect(wifiSSID, wifiPass)) {
|
||||||
SerialMon.println(" fail");
|
SerialMon.println(" fail");
|
||||||
@@ -132,6 +141,11 @@ void loop() {
|
|||||||
SerialMon.println(" OK");
|
SerialMon.println(" OK");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if TINY_GSM_USE_GPRS && defined TINY_GSM_MODEM_XBEE
|
||||||
|
// The XBee must run the gprsConnect function BEFORE waiting for network!
|
||||||
|
modem.gprsConnect(apn, gprsUser, gprsPass);
|
||||||
|
#endif
|
||||||
|
|
||||||
SerialMon.print("Waiting for network...");
|
SerialMon.print("Waiting for network...");
|
||||||
if (!modem.waitForNetwork()) {
|
if (!modem.waitForNetwork()) {
|
||||||
SerialMon.println(" fail");
|
SerialMon.println(" fail");
|
||||||
@@ -141,10 +155,10 @@ void loop() {
|
|||||||
SerialMon.println(" OK");
|
SerialMon.println(" OK");
|
||||||
|
|
||||||
if (modem.isNetworkConnected()) {
|
if (modem.isNetworkConnected()) {
|
||||||
SerialMon.print("Network connected");
|
SerialMon.println("Network connected");
|
||||||
}
|
}
|
||||||
|
|
||||||
#if TINY_GSM_USE_GPRS
|
#if TINY_GSM_USE_GPRS && defined TINY_GSM_MODEM_HAS_GPRS
|
||||||
SerialMon.print(F("Connecting to "));
|
SerialMon.print(F("Connecting to "));
|
||||||
SerialMon.print(apn);
|
SerialMon.print(apn);
|
||||||
if (!modem.gprsConnect(apn, gprsUser, gprsPass)) {
|
if (!modem.gprsConnect(apn, gprsUser, gprsPass)) {
|
||||||
|
@@ -46,12 +46,23 @@
|
|||||||
// #define TINY_GSM_MODEM_XBEE
|
// #define TINY_GSM_MODEM_XBEE
|
||||||
// #define TINY_GSM_MODEM_SEQUANS_MONARCH
|
// #define TINY_GSM_MODEM_SEQUANS_MONARCH
|
||||||
|
|
||||||
#include <TinyGsmClient.h>
|
// See all AT commands, if wanted
|
||||||
#include <PubSubClient.h>
|
// #define DUMP_AT_COMMANDS
|
||||||
|
|
||||||
|
// Define the serial console for debug prints, if needed
|
||||||
|
#define TINY_GSM_DEBUG SerialMon
|
||||||
|
|
||||||
|
// Range to attempt to autobaud
|
||||||
|
#define GSM_AUTOBAUD_MIN 9600
|
||||||
|
#define GSM_AUTOBAUD_MAX 38400
|
||||||
|
|
||||||
|
// Add a reception delay, if needed
|
||||||
|
#define TINY_GSM_YIELD() { delay(2); }
|
||||||
|
|
||||||
// Set serial for debug console (to the Serial Monitor, default speed 115200)
|
// Set serial for debug console (to the Serial Monitor, default speed 115200)
|
||||||
#define SerialMon Serial
|
#define SerialMon Serial
|
||||||
|
|
||||||
|
// Set serial for AT commands (to the module)
|
||||||
// Use Hardware Serial on Mega, Leonardo, Micro
|
// Use Hardware Serial on Mega, Leonardo, Micro
|
||||||
#define SerialAT Serial1
|
#define SerialAT Serial1
|
||||||
|
|
||||||
@@ -73,7 +84,17 @@ const char* topicLed = "GsmClientTest/led";
|
|||||||
const char* topicInit = "GsmClientTest/init";
|
const char* topicInit = "GsmClientTest/init";
|
||||||
const char* topicLedStatus = "GsmClientTest/ledStatus";
|
const char* topicLedStatus = "GsmClientTest/ledStatus";
|
||||||
|
|
||||||
|
#include <TinyGsmClient.h>
|
||||||
|
#include <PubSubClient.h>
|
||||||
|
|
||||||
|
#ifdef DUMP_AT_COMMANDS
|
||||||
|
#include <StreamDebugger.h>
|
||||||
|
StreamDebugger debugger(SerialAT, SerialMon);
|
||||||
|
TinyGsm modem(debugger);
|
||||||
|
#else
|
||||||
|
|
||||||
TinyGsm modem(SerialAT);
|
TinyGsm modem(SerialAT);
|
||||||
|
#endif
|
||||||
TinyGsmClient client(modem);
|
TinyGsmClient client(modem);
|
||||||
PubSubClient mqtt(client);
|
PubSubClient mqtt(client);
|
||||||
|
|
||||||
@@ -83,12 +104,22 @@ int ledStatus = LOW;
|
|||||||
long lastReconnectAttempt = 0;
|
long lastReconnectAttempt = 0;
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
pinMode(LED_PIN, OUTPUT);
|
|
||||||
|
|
||||||
// Set console baud rate
|
// Set console baud rate
|
||||||
SerialMon.begin(115200);
|
SerialMon.begin(115200);
|
||||||
delay(10);
|
delay(10);
|
||||||
|
|
||||||
|
// Set your reset, enable, power pins here
|
||||||
|
pinMode(LED_PIN, OUTPUT);
|
||||||
|
|
||||||
|
pinMode(20, OUTPUT);
|
||||||
|
digitalWrite(20, HIGH);
|
||||||
|
|
||||||
|
pinMode(23, OUTPUT);
|
||||||
|
digitalWrite(23, LOW);
|
||||||
|
|
||||||
|
SerialMon.println("Wait...");
|
||||||
|
|
||||||
// Set GSM module baud rate
|
// Set GSM module baud rate
|
||||||
SerialAT.begin(115200);
|
SerialAT.begin(115200);
|
||||||
delay(3000);
|
delay(3000);
|
||||||
@@ -97,6 +128,7 @@ void setup() {
|
|||||||
// To skip it, call init() instead of restart()
|
// To skip it, call init() instead of restart()
|
||||||
SerialMon.println("Initializing modem...");
|
SerialMon.println("Initializing modem...");
|
||||||
modem.restart();
|
modem.restart();
|
||||||
|
// modem.init();
|
||||||
|
|
||||||
String modemInfo = modem.getModemInfo();
|
String modemInfo = modem.getModemInfo();
|
||||||
SerialMon.print("Modem: ");
|
SerialMon.print("Modem: ");
|
||||||
@@ -105,20 +137,43 @@ void setup() {
|
|||||||
// Unlock your SIM card with a PIN
|
// Unlock your SIM card with a PIN
|
||||||
//modem.simUnlock("1234");
|
//modem.simUnlock("1234");
|
||||||
|
|
||||||
SerialMon.print("Waiting for network...");
|
#if TINY_GSM_USE_WIFI
|
||||||
if (!modem.waitForNetwork()) {
|
SerialMon.print(F("Setting SSID/password..."));
|
||||||
|
if (!modem.networkConnect(wifiSSID, wifiPass)) {
|
||||||
SerialMon.println(" fail");
|
SerialMon.println(" fail");
|
||||||
while (true);
|
delay(10000);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
SerialMon.println(" OK");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if TINY_GSM_USE_GPRS && defined TINY_GSM_MODEM_XBEE
|
||||||
|
// The XBee must run the gprsConnect function BEFORE waiting for network!
|
||||||
|
modem.gprsConnect(apn, gprsUser, gprsPass);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
SerialMon.print("Waiting for network...");
|
||||||
|
if (!modem.waitForNetwork(240000L)) {
|
||||||
|
SerialMon.println(" fail");
|
||||||
|
delay(10000);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
SerialMon.println(" OK");
|
SerialMon.println(" OK");
|
||||||
|
|
||||||
SerialMon.print("Connecting to ");
|
if (modem.isNetworkConnected()) {
|
||||||
|
SerialMon.println("Network connected");
|
||||||
|
}
|
||||||
|
|
||||||
|
#if TINY_GSM_USE_GPRS && defined TINY_GSM_MODEM_HAS_GPRS
|
||||||
|
SerialMon.print(F("Connecting to "));
|
||||||
SerialMon.print(apn);
|
SerialMon.print(apn);
|
||||||
if (!modem.gprsConnect(apn, user, pass)) {
|
if (!modem.gprsConnect(apn, gprsUser, gprsPass)) {
|
||||||
SerialMon.println(" fail");
|
SerialMon.println(" fail");
|
||||||
while (true);
|
delay(10000);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
SerialMon.println(" OK");
|
SerialMon.println(" OK");
|
||||||
|
#endif
|
||||||
|
|
||||||
// MQTT Broker setup
|
// MQTT Broker setup
|
||||||
mqtt.setServer(broker, 1883);
|
mqtt.setServer(broker, 1883);
|
||||||
|
@@ -30,6 +30,16 @@
|
|||||||
// Increase RX buffer if needed
|
// Increase RX buffer if needed
|
||||||
// #define TINY_GSM_RX_BUFFER 512
|
// #define TINY_GSM_RX_BUFFER 512
|
||||||
|
|
||||||
|
// See all AT commands, if wanted
|
||||||
|
// #define DUMP_AT_COMMANDS
|
||||||
|
|
||||||
|
// Define the serial console for debug prints, if needed
|
||||||
|
#define TINY_GSM_DEBUG SerialMon
|
||||||
|
|
||||||
|
// Range to attempt to autobaud
|
||||||
|
#define GSM_AUTOBAUD_MIN 9600
|
||||||
|
#define GSM_AUTOBAUD_MAX 115200
|
||||||
|
|
||||||
// Add a reception delay, if needed
|
// Add a reception delay, if needed
|
||||||
// #define TINY_GSM_YIELD() { delay(1); }
|
// #define TINY_GSM_YIELD() { delay(1); }
|
||||||
|
|
||||||
@@ -47,16 +57,6 @@
|
|||||||
//#include <SoftwareSerial.h>
|
//#include <SoftwareSerial.h>
|
||||||
//SoftwareSerial SerialAT(2, 3); // RX, TX
|
//SoftwareSerial SerialAT(2, 3); // RX, TX
|
||||||
|
|
||||||
// See all AT commands, if wanted
|
|
||||||
//#define DUMP_AT_COMMANDS
|
|
||||||
|
|
||||||
// See the debugging, if wanted
|
|
||||||
// #define TINY_GSM_DEBUG SerialMon
|
|
||||||
|
|
||||||
// Range to attempt to autobaud
|
|
||||||
#define GSM_AUTOBAUD_MIN 9600
|
|
||||||
#define GSM_AUTOBAUD_MAX 38400
|
|
||||||
|
|
||||||
#define TINY_GSM_USE_GPRS true
|
#define TINY_GSM_USE_GPRS true
|
||||||
#define TINY_GSM_USE_WIFI false
|
#define TINY_GSM_USE_WIFI false
|
||||||
|
|
||||||
@@ -122,8 +122,12 @@ void setup() {
|
|||||||
SerialMon.print("Modem: ");
|
SerialMon.print("Modem: ");
|
||||||
SerialMon.println(modemInfo);
|
SerialMon.println(modemInfo);
|
||||||
|
|
||||||
// Unlock your SIM card with a PIN
|
#if TINY_GSM_USE_GPRS
|
||||||
//modem.simUnlock("1234");
|
// Unlock your SIM card with a PIN if needed
|
||||||
|
if ( GSM_PIN && modem.getSimStatus() != 3 ) {
|
||||||
|
modem.simUnlock(GSM_PIN);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
@@ -138,6 +142,11 @@ void loop() {
|
|||||||
SerialMon.println(" OK");
|
SerialMon.println(" OK");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if TINY_GSM_USE_GPRS && defined TINY_GSM_MODEM_XBEE
|
||||||
|
// The XBee must run the gprsConnect function BEFORE waiting for network!
|
||||||
|
modem.gprsConnect(apn, gprsUser, gprsPass);
|
||||||
|
#endif
|
||||||
|
|
||||||
SerialMon.print("Waiting for network...");
|
SerialMon.print("Waiting for network...");
|
||||||
if (!modem.waitForNetwork(240000L)) {
|
if (!modem.waitForNetwork(240000L)) {
|
||||||
SerialMon.println(" fail");
|
SerialMon.println(" fail");
|
||||||
@@ -150,9 +159,9 @@ void loop() {
|
|||||||
SerialMon.println("Network connected");
|
SerialMon.println("Network connected");
|
||||||
}
|
}
|
||||||
|
|
||||||
#if TINY_GSM_USE_GPRS
|
#if TINY_GSM_USE_GPRS && defined TINY_GSM_MODEM_HAS_GPRS
|
||||||
SerialMon.print(F("Connecting to "));
|
SerialMon.print(F("Connecting to "));
|
||||||
SerialMon.println(apn);
|
SerialMon.print(apn);
|
||||||
if (!modem.gprsConnect(apn, gprsUser, gprsPass)) {
|
if (!modem.gprsConnect(apn, gprsUser, gprsPass)) {
|
||||||
SerialMon.println(" fail");
|
SerialMon.println(" fail");
|
||||||
delay(10000);
|
delay(10000);
|
||||||
@@ -172,9 +181,10 @@ void loop() {
|
|||||||
|
|
||||||
// Make a HTTP GET request:
|
// Make a HTTP GET request:
|
||||||
SerialMon.println("Performing HTTP GET request...");
|
SerialMon.println("Performing HTTP GET request...");
|
||||||
client.print(String("GET ") + resource + " HTTP/1.0\r\n");
|
client.print(String("GET ") + resource + " HTTP/1.1\r\n");
|
||||||
client.print(String("Host: ") + server + "\r\n");
|
client.print(String("Host: ") + server + "\r\n");
|
||||||
client.print("Connection: close\r\n\r\n");
|
client.print("Connection: close\r\n\r\n");
|
||||||
|
client.println();
|
||||||
|
|
||||||
unsigned long timeout = millis();
|
unsigned long timeout = millis();
|
||||||
while (client.connected() && millis() - timeout < 10000L) {
|
while (client.connected() && millis() - timeout < 10000L) {
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "TinyGSM",
|
"name": "TinyGSM",
|
||||||
"version": "0.7.4",
|
"version": "0.7.7",
|
||||||
"description": "A small Arduino library for GPRS modules, that just works. Includes examples for Blynk, MQTT, File Download, and Web Client. Supports many GSM, LTE, and WiFi modules with AT command interfaces.",
|
"description": "A small Arduino library for GPRS modules, that just works. Includes examples for Blynk, MQTT, File Download, and Web Client. Supports many GSM, LTE, and WiFi modules with AT command interfaces.",
|
||||||
"keywords": "GSM, AT commands, AT, SIM800, SIM900, A6, A7, M590, ESP8266, SIM7000, SIM800A, SIM800C, SIM800L, SIM800H, SIM808, SIM868, SIM900A, SIM900D, SIM908, SIM968, M95, MC60, MC60E, BG96, ublox, Quectel, SIMCOM, AI Thinker, LTE, LTE-M",
|
"keywords": "GSM, AT commands, AT, SIM800, SIM900, A6, A7, M590, ESP8266, SIM7000, SIM800A, SIM800C, SIM800L, SIM800H, SIM808, SIM868, SIM900A, SIM900D, SIM908, SIM968, M95, MC60, MC60E, BG96, ublox, Quectel, SIMCOM, AI Thinker, LTE, LTE-M",
|
||||||
"authors":
|
"authors":
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
name=TinyGSM
|
name=TinyGSM
|
||||||
version=0.7.4
|
version=0.7.7
|
||||||
author=Volodymyr Shymanskyy
|
author=Volodymyr Shymanskyy
|
||||||
maintainer=Volodymyr Shymanskyy
|
maintainer=Volodymyr Shymanskyy
|
||||||
sentence=A small Arduino library for GPRS modules, that just works.
|
sentence=A small Arduino library for GPRS modules, that just works.
|
||||||
|
@@ -62,6 +62,7 @@ public:
|
|||||||
this->at = modem;
|
this->at = modem;
|
||||||
this->mux = mux;
|
this->mux = mux;
|
||||||
sock_available = 0;
|
sock_available = 0;
|
||||||
|
prev_check = 0;
|
||||||
sock_connected = false;
|
sock_connected = false;
|
||||||
got_data = false;
|
got_data = false;
|
||||||
|
|
||||||
@@ -102,9 +103,9 @@ TINY_GSM_CLIENT_CONNECT_OVERLOADS()
|
|||||||
|
|
||||||
TINY_GSM_CLIENT_WRITE()
|
TINY_GSM_CLIENT_WRITE()
|
||||||
|
|
||||||
TINY_GSM_CLIENT_AVAILABLE_NO_BUFFER_CHECK()
|
TINY_GSM_CLIENT_AVAILABLE_WITH_BUFFER_CHECK()
|
||||||
|
|
||||||
TINY_GSM_CLIENT_READ_NO_BUFFER_CHECK()
|
TINY_GSM_CLIENT_READ_WITH_BUFFER_CHECK()
|
||||||
|
|
||||||
TINY_GSM_CLIENT_PEEK_FLUSH_CONNECTED()
|
TINY_GSM_CLIENT_PEEK_FLUSH_CONNECTED()
|
||||||
|
|
||||||
@@ -118,6 +119,7 @@ private:
|
|||||||
TinyGsmBG96* at;
|
TinyGsmBG96* at;
|
||||||
uint8_t mux;
|
uint8_t mux;
|
||||||
uint16_t sock_available;
|
uint16_t sock_available;
|
||||||
|
uint32_t prev_check;
|
||||||
bool sock_connected;
|
bool sock_connected;
|
||||||
bool got_data;
|
bool got_data;
|
||||||
RxFifo rx;
|
RxFifo rx;
|
||||||
@@ -544,7 +546,6 @@ protected:
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
size_t len = stream.readStringUntil('\n').toInt();
|
size_t len = stream.readStringUntil('\n').toInt();
|
||||||
sockets[mux]->sock_available = len;
|
|
||||||
|
|
||||||
for (size_t i=0; i<len; i++) {
|
for (size_t i=0; i<len; i++) {
|
||||||
TINY_GSM_MODEM_STREAM_TO_MUX_FIFO_WITH_DOUBLE_TIMEOUT
|
TINY_GSM_MODEM_STREAM_TO_MUX_FIFO_WITH_DOUBLE_TIMEOUT
|
||||||
|
@@ -186,7 +186,7 @@ TINY_GSM_MODEM_SET_BAUD_IPR()
|
|||||||
|
|
||||||
TINY_GSM_MODEM_TEST_AT()
|
TINY_GSM_MODEM_TEST_AT()
|
||||||
|
|
||||||
TINY_GSM_MODEM_MAINTAIN_CHECK_SOCKS()
|
TINY_GSM_MODEM_MAINTAIN_LISTEN()
|
||||||
|
|
||||||
bool factoryDefault() {
|
bool factoryDefault() {
|
||||||
sendAT(GF("&FZE0&W")); // Factory + Reset + Echo Off + Write
|
sendAT(GF("&FZE0&W")); // Factory + Reset + Echo Off + Write
|
||||||
@@ -606,37 +606,33 @@ protected:
|
|||||||
}
|
}
|
||||||
|
|
||||||
size_t modemRead(size_t size, uint8_t mux) {
|
size_t modemRead(size_t size, uint8_t mux) {
|
||||||
sendAT(GF("+QIRD="), mux, ',', size);
|
// TODO: Does this work????
|
||||||
|
// AT+QIRD=<id>,<sc>,<sid>,<len>
|
||||||
|
// id = GPRS context number - 0, set in GPRS connect
|
||||||
|
// sc = roll in connection - 1, client of connection
|
||||||
|
// sid = index of connection - mux
|
||||||
|
// len = maximum length of data to send
|
||||||
|
sendAT(GF("+QIRD=0,1,"), mux, ',', size);
|
||||||
|
// sendAT(GF("+QIRD="), mux, ',', size);
|
||||||
if (waitResponse(GF("+QIRD:")) != 1) {
|
if (waitResponse(GF("+QIRD:")) != 1) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
size_t len = stream.readStringUntil('\n').toInt();
|
streamSkipUntil(':'); // skip IP address
|
||||||
|
streamSkipUntil(','); // skip port
|
||||||
|
streamSkipUntil(','); // skip connection type (TCP/UDP)
|
||||||
|
size_t len = stream.readStringUntil('\n').toInt(); // read length
|
||||||
sockets[mux]->sock_available = len;
|
sockets[mux]->sock_available = len;
|
||||||
|
|
||||||
for (size_t i=0; i<len; i++) {
|
for (size_t i=0; i<len; i++) {
|
||||||
TINY_GSM_MODEM_STREAM_TO_MUX_FIFO_WITH_DOUBLE_TIMEOUT
|
TINY_GSM_MODEM_STREAM_TO_MUX_FIFO_WITH_DOUBLE_TIMEOUT
|
||||||
|
sockets[mux]->sock_available--;
|
||||||
|
// ^^ One less character available after moving from modem's FIFO to our FIFO
|
||||||
}
|
}
|
||||||
waitResponse();
|
waitResponse(); // ends with an OK
|
||||||
DBG("### READ:", len, "from", mux);
|
DBG("### READ:", len, "from", mux);
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t modemGetAvailable(uint8_t mux) {
|
|
||||||
sendAT(GF("+QIRD="), mux, GF(",0"));
|
|
||||||
size_t result = 0;
|
|
||||||
if (waitResponse(GF("+QIRD:")) == 1) {
|
|
||||||
streamSkipUntil(','); // Skip total received
|
|
||||||
streamSkipUntil(','); // Skip have read
|
|
||||||
result = stream.readStringUntil('\n').toInt();
|
|
||||||
if (result) DBG("### DATA AVAILABLE:", result, "on", mux);
|
|
||||||
waitResponse();
|
|
||||||
}
|
|
||||||
if (!result) {
|
|
||||||
sockets[mux]->sock_connected = modemGetConnected(mux);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool modemGetConnected(uint8_t mux) {
|
bool modemGetConnected(uint8_t mux) {
|
||||||
sendAT(GF("+QISTATE=1,"), mux);
|
sendAT(GF("+QISTATE=1,"), mux);
|
||||||
//+QISTATE: 0,"TCP","151.139.237.11",80,5087,4,1,0,0,"uart1"
|
//+QISTATE: 0,"TCP","151.139.237.11",80,5087,4,1,0,0,"uart1"
|
||||||
@@ -700,7 +696,7 @@ TINY_GSM_MODEM_STREAM_UTILITIES()
|
|||||||
} else if (r5 && data.endsWith(r5)) {
|
} else if (r5 && data.endsWith(r5)) {
|
||||||
index = 5;
|
index = 5;
|
||||||
goto finish;
|
goto finish;
|
||||||
} else if (data.endsWith(GF(GSM_NL "+QIRD:"))) {
|
} else if (data.endsWith(GF(GSM_NL "+QIRD:"))) { // TODO: QIRD? or QIRDI?
|
||||||
streamSkipUntil(','); // Skip the context
|
streamSkipUntil(','); // Skip the context
|
||||||
streamSkipUntil(','); // Skip the role
|
streamSkipUntil(','); // Skip the role
|
||||||
int mux = stream.readStringUntil('\n').toInt();
|
int mux = stream.readStringUntil('\n').toInt();
|
||||||
|
@@ -193,7 +193,7 @@ TINY_GSM_MODEM_SET_BAUD_IPR()
|
|||||||
|
|
||||||
TINY_GSM_MODEM_TEST_AT()
|
TINY_GSM_MODEM_TEST_AT()
|
||||||
|
|
||||||
TINY_GSM_MODEM_MAINTAIN_CHECK_SOCKS()
|
TINY_GSM_MODEM_MAINTAIN_LISTEN()
|
||||||
|
|
||||||
bool factoryDefault() {
|
bool factoryDefault() {
|
||||||
sendAT(GF("&FZE0&W")); // Factory + Reset + Echo Off + Write
|
sendAT(GF("&FZE0&W")); // Factory + Reset + Echo Off + Write
|
||||||
@@ -613,37 +613,33 @@ protected:
|
|||||||
}
|
}
|
||||||
|
|
||||||
size_t modemRead(size_t size, uint8_t mux) {
|
size_t modemRead(size_t size, uint8_t mux) {
|
||||||
sendAT(GF("+QIRD="), mux, ',', size);
|
// TODO: Does this work????
|
||||||
|
// AT+QIRD=<id>,<sc>,<sid>,<len>
|
||||||
|
// id = GPRS context number - 0, set in GPRS connect
|
||||||
|
// sc = roll in connection - 1, client of connection
|
||||||
|
// sid = index of connection - mux
|
||||||
|
// len = maximum length of data to send
|
||||||
|
sendAT(GF("+QIRD=0,1,"), mux, ',', size);
|
||||||
|
// sendAT(GF("+QIRD="), mux, ',', size);
|
||||||
if (waitResponse(GF("+QIRD:")) != 1) {
|
if (waitResponse(GF("+QIRD:")) != 1) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
size_t len = stream.readStringUntil('\n').toInt();
|
streamSkipUntil(':'); // skip IP address
|
||||||
|
streamSkipUntil(','); // skip port
|
||||||
|
streamSkipUntil(','); // skip connection type (TCP/UDP)
|
||||||
|
size_t len = stream.readStringUntil('\n').toInt(); // read length
|
||||||
sockets[mux]->sock_available = len;
|
sockets[mux]->sock_available = len;
|
||||||
|
|
||||||
for (size_t i=0; i<len; i++) {
|
for (size_t i=0; i<len; i++) {
|
||||||
TINY_GSM_MODEM_STREAM_TO_MUX_FIFO_WITH_DOUBLE_TIMEOUT
|
TINY_GSM_MODEM_STREAM_TO_MUX_FIFO_WITH_DOUBLE_TIMEOUT
|
||||||
|
sockets[mux]->sock_available--;
|
||||||
|
// ^^ One less character available after moving from modem's FIFO to our FIFO
|
||||||
}
|
}
|
||||||
waitResponse();
|
waitResponse();
|
||||||
DBG("### READ:", len, "from", mux);
|
DBG("### READ:", len, "from", mux);
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t modemGetAvailable(uint8_t mux) {
|
|
||||||
sendAT(GF("+QIRD="), mux, GF(",0"));
|
|
||||||
size_t result = 0;
|
|
||||||
if (waitResponse(GF("+QIRD:")) == 1) {
|
|
||||||
streamSkipUntil(','); // Skip total received
|
|
||||||
streamSkipUntil(','); // Skip have read
|
|
||||||
result = stream.readStringUntil('\n').toInt();
|
|
||||||
if (result) DBG("### DATA AVAILABLE:", result, "on", mux);
|
|
||||||
waitResponse();
|
|
||||||
}
|
|
||||||
if (!result) {
|
|
||||||
sockets[mux]->sock_connected = modemGetConnected(mux);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool modemGetConnected(uint8_t mux) {
|
bool modemGetConnected(uint8_t mux) {
|
||||||
sendAT(GF("+QISTATE=1,"), mux);
|
sendAT(GF("+QISTATE=1,"), mux);
|
||||||
//+QISTATE: 0,"TCP","151.139.237.11",80,5087,4,1,0,0,"uart1"
|
//+QISTATE: 0,"TCP","151.139.237.11",80,5087,4,1,0,0,"uart1"
|
||||||
@@ -711,7 +707,7 @@ TINY_GSM_MODEM_STREAM_UTILITIES()
|
|||||||
} else if (r6 && data.endsWith(r6)) {
|
} else if (r6 && data.endsWith(r6)) {
|
||||||
index = 6;
|
index = 6;
|
||||||
goto finish;
|
goto finish;
|
||||||
} else if (data.endsWith(GF(GSM_NL "+QIRD:"))) {
|
} else if (data.endsWith(GF(GSM_NL "+QIRD:"))) { // TODO: QIRD? or QIRDI?
|
||||||
streamSkipUntil(','); // Skip the context
|
streamSkipUntil(','); // Skip the context
|
||||||
streamSkipUntil(','); // Skip the role
|
streamSkipUntil(','); // Skip the role
|
||||||
int mux = stream.readStringUntil('\n').toInt();
|
int mux = stream.readStringUntil('\n').toInt();
|
||||||
|
@@ -481,7 +481,6 @@ TINY_GSM_MODEM_WAIT_FOR_NETWORK()
|
|||||||
return TinyGsmIpFromString(getLocalIP());
|
return TinyGsmIpFromString(getLocalIP());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Phone Call functions
|
* Phone Call functions
|
||||||
*/
|
*/
|
||||||
@@ -726,7 +725,7 @@ TINY_GSM_MODEM_WAIT_FOR_NETWORK()
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Battery functions
|
* Battery & temperature functions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Use: float vBatt = modem.getBattVoltage() / 1000.0;
|
// Use: float vBatt = modem.getBattVoltage() / 1000.0;
|
||||||
@@ -739,6 +738,7 @@ TINY_GSM_MODEM_WAIT_FOR_NETWORK()
|
|||||||
streamSkipUntil(','); // Skip battery charge level
|
streamSkipUntil(','); // Skip battery charge level
|
||||||
// return voltage in mV
|
// return voltage in mV
|
||||||
uint16_t res = stream.readStringUntil(',').toInt();
|
uint16_t res = stream.readStringUntil(',').toInt();
|
||||||
|
// Wait for final OK
|
||||||
waitResponse();
|
waitResponse();
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
@@ -751,6 +751,7 @@ TINY_GSM_MODEM_WAIT_FOR_NETWORK()
|
|||||||
streamSkipUntil(','); // Skip battery charge status
|
streamSkipUntil(','); // Skip battery charge status
|
||||||
// Read battery charge level
|
// Read battery charge level
|
||||||
int res = stream.readStringUntil(',').toInt();
|
int res = stream.readStringUntil(',').toInt();
|
||||||
|
// Wait for final OK
|
||||||
waitResponse();
|
waitResponse();
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
@@ -835,14 +836,10 @@ protected:
|
|||||||
size_t len_requested = stream.readStringUntil(',').toInt();
|
size_t len_requested = stream.readStringUntil(',').toInt();
|
||||||
// ^^ Requested number of data bytes (1-1460 bytes)to be read
|
// ^^ Requested number of data bytes (1-1460 bytes)to be read
|
||||||
size_t len_confirmed = stream.readStringUntil('\n').toInt();
|
size_t len_confirmed = stream.readStringUntil('\n').toInt();
|
||||||
if (len_confirmed < len_requested) {
|
|
||||||
DBG(len_requested - len_confirmed, "fewer bytes confirmed than requested!");
|
|
||||||
}
|
|
||||||
sockets[mux]->sock_available = len_confirmed;
|
|
||||||
// ^^ Confirmed number of data bytes to be read, which may be less than requested.
|
// ^^ Confirmed number of data bytes to be read, which may be less than requested.
|
||||||
// 0 indicates that no data can be read.
|
// 0 indicates that no data can be read.
|
||||||
|
// This is actually be the number of bytes that will be remaining after the read
|
||||||
for (size_t i=0; i<TinyGsmMin(len_confirmed, len_requested) ; i++) {
|
for (size_t i=0; i<len_requested; i++) {
|
||||||
uint32_t startMillis = millis();
|
uint32_t startMillis = millis();
|
||||||
#ifdef TINY_GSM_USE_HEX
|
#ifdef TINY_GSM_USE_HEX
|
||||||
while (stream.available() < 2 && (millis() - startMillis < sockets[mux]->_timeout)) { TINY_GSM_YIELD(); }
|
while (stream.available() < 2 && (millis() - startMillis < sockets[mux]->_timeout)) { TINY_GSM_YIELD(); }
|
||||||
@@ -856,9 +853,11 @@ protected:
|
|||||||
#endif
|
#endif
|
||||||
sockets[mux]->rx.put(c);
|
sockets[mux]->rx.put(c);
|
||||||
}
|
}
|
||||||
|
DBG("### READ:", len_requested, "from", mux);
|
||||||
|
// sockets[mux]->sock_available = modemGetAvailable(mux);
|
||||||
|
sockets[mux]->sock_available = len_confirmed;
|
||||||
waitResponse();
|
waitResponse();
|
||||||
DBG("### READ:", TinyGsmMin(len_confirmed, len_requested), "from", mux);
|
return len_requested;
|
||||||
return TinyGsmMin(len_confirmed, len_requested);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t modemGetAvailable(uint8_t mux) {
|
size_t modemGetAvailable(uint8_t mux) {
|
||||||
@@ -870,6 +869,7 @@ protected:
|
|||||||
result = stream.readStringUntil('\n').toInt();
|
result = stream.readStringUntil('\n').toInt();
|
||||||
waitResponse();
|
waitResponse();
|
||||||
}
|
}
|
||||||
|
DBG("### Available:", result, "on", mux);
|
||||||
if (!result) {
|
if (!result) {
|
||||||
sockets[mux]->sock_connected = modemGetConnected(mux);
|
sockets[mux]->sock_connected = modemGetConnected(mux);
|
||||||
}
|
}
|
||||||
|
@@ -308,7 +308,7 @@ TINY_GSM_MODEM_GET_IMEI_GSN()
|
|||||||
delay(1000);
|
delay(1000);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
int status = waitResponse(GF("READY"), GF("SIM PIN"), GF("SIM PUK"), GF("NOT INSERTED"));
|
int status = waitResponse(GF("READY"), GF("SIM PIN"), GF("SIM PUK"), GF("NOT INSERTED"), GF("NOT READY"));
|
||||||
waitResponse();
|
waitResponse();
|
||||||
switch (status) {
|
switch (status) {
|
||||||
case 2:
|
case 2:
|
||||||
@@ -459,7 +459,6 @@ TINY_GSM_MODEM_WAIT_FOR_NETWORK()
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* IP Address functions
|
* IP Address functions
|
||||||
*/
|
*/
|
||||||
@@ -765,14 +764,10 @@ protected:
|
|||||||
size_t len_requested = stream.readStringUntil(',').toInt();
|
size_t len_requested = stream.readStringUntil(',').toInt();
|
||||||
// ^^ Requested number of data bytes (1-1460 bytes)to be read
|
// ^^ Requested number of data bytes (1-1460 bytes)to be read
|
||||||
size_t len_confirmed = stream.readStringUntil('\n').toInt();
|
size_t len_confirmed = stream.readStringUntil('\n').toInt();
|
||||||
if (len_confirmed < len_requested) {
|
|
||||||
DBG(len_requested - len_confirmed, "fewer bytes confirmed than requested!");
|
|
||||||
}
|
|
||||||
sockets[mux]->sock_available = len_confirmed;
|
|
||||||
// ^^ Confirmed number of data bytes to be read, which may be less than requested.
|
// ^^ Confirmed number of data bytes to be read, which may be less than requested.
|
||||||
// 0 indicates that no data can be read.
|
// 0 indicates that no data can be read.
|
||||||
|
// This is actually be the number of bytes that will be remaining after the read
|
||||||
for (size_t i=0; i<TinyGsmMin(len_confirmed, len_requested) ; i++) {
|
for (size_t i=0; i<len_requested; i++) {
|
||||||
uint32_t startMillis = millis();
|
uint32_t startMillis = millis();
|
||||||
#ifdef TINY_GSM_USE_HEX
|
#ifdef TINY_GSM_USE_HEX
|
||||||
while (stream.available() < 2 && (millis() - startMillis < sockets[mux]->_timeout)) { TINY_GSM_YIELD(); }
|
while (stream.available() < 2 && (millis() - startMillis < sockets[mux]->_timeout)) { TINY_GSM_YIELD(); }
|
||||||
@@ -786,9 +781,11 @@ protected:
|
|||||||
#endif
|
#endif
|
||||||
sockets[mux]->rx.put(c);
|
sockets[mux]->rx.put(c);
|
||||||
}
|
}
|
||||||
|
DBG("### READ:", len_requested, "from", mux);
|
||||||
|
// sockets[mux]->sock_available = modemGetAvailable(mux);
|
||||||
|
sockets[mux]->sock_available = len_confirmed;
|
||||||
waitResponse();
|
waitResponse();
|
||||||
DBG("### READ:", TinyGsmMin(len_confirmed, len_requested), "from", mux);
|
return len_requested;
|
||||||
return TinyGsmMin(len_confirmed, len_requested);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t modemGetAvailable(uint8_t mux) {
|
size_t modemGetAvailable(uint8_t mux) {
|
||||||
@@ -800,6 +797,7 @@ protected:
|
|||||||
result = stream.readStringUntil('\n').toInt();
|
result = stream.readStringUntil('\n').toInt();
|
||||||
waitResponse();
|
waitResponse();
|
||||||
}
|
}
|
||||||
|
DBG("### Available:", result, "on", mux);
|
||||||
if (!result) {
|
if (!result) {
|
||||||
sockets[mux]->sock_connected = modemGetConnected(mux);
|
sockets[mux]->sock_connected = modemGetConnected(mux);
|
||||||
}
|
}
|
||||||
@@ -808,7 +806,9 @@ protected:
|
|||||||
|
|
||||||
bool modemGetConnected(uint8_t mux) {
|
bool modemGetConnected(uint8_t mux) {
|
||||||
sendAT(GF("+CIPSTATUS="), mux);
|
sendAT(GF("+CIPSTATUS="), mux);
|
||||||
int res = waitResponse(GF(",\"CONNECTED\""), GF(",\"CLOSED\""), GF(",\"CLOSING\""), GF(",\"INITIAL\""));
|
waitResponse(GF("+CIPSTATUS"));
|
||||||
|
int res = waitResponse(GF(",\"CONNECTED\""), GF(",\"CLOSED\""), GF(",\"CLOSING\""),
|
||||||
|
GF(",\"REMOTE CLOSING\""), GF(",\"INITIAL\""));
|
||||||
waitResponse();
|
waitResponse();
|
||||||
return 1 == res;
|
return 1 == res;
|
||||||
}
|
}
|
||||||
|
@@ -605,7 +605,6 @@ protected:
|
|||||||
}
|
}
|
||||||
streamSkipUntil(','); // Skip mux
|
streamSkipUntil(','); // Skip mux
|
||||||
size_t len = stream.readStringUntil(',').toInt();
|
size_t len = stream.readStringUntil(',').toInt();
|
||||||
sockets[mux]->sock_available = len;
|
|
||||||
streamSkipUntil('\"');
|
streamSkipUntil('\"');
|
||||||
|
|
||||||
for (size_t i=0; i<len; i++) {
|
for (size_t i=0; i<len; i++) {
|
||||||
|
@@ -622,9 +622,9 @@ protected:
|
|||||||
char c = stream.read(); \
|
char c = stream.read(); \
|
||||||
sockets[mux % TINY_GSM_MUX_COUNT]->rx.put(c);
|
sockets[mux % TINY_GSM_MUX_COUNT]->rx.put(c);
|
||||||
}
|
}
|
||||||
// DBG("### Read:", len, "from", mux);
|
DBG("### Read:", len, "from", mux);
|
||||||
waitResponse();
|
waitResponse();
|
||||||
sockets[mux % TINY_GSM_MUX_COUNT]->sock_available = modemGetAvailable(mux);
|
// sockets[mux % TINY_GSM_MUX_COUNT]->sock_available = modemGetAvailable(mux);
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -638,7 +638,7 @@ protected:
|
|||||||
result = stream.readStringUntil(',').toInt(); // keep data not yet read
|
result = stream.readStringUntil(',').toInt(); // keep data not yet read
|
||||||
waitResponse();
|
waitResponse();
|
||||||
}
|
}
|
||||||
// DBG("### Available:", result, "on", mux);
|
DBG("### Available:", result, "on", mux);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -593,7 +593,6 @@ protected:
|
|||||||
}
|
}
|
||||||
streamSkipUntil(','); // Skip mux
|
streamSkipUntil(','); // Skip mux
|
||||||
size_t len = stream.readStringUntil(',').toInt();
|
size_t len = stream.readStringUntil(',').toInt();
|
||||||
sockets[mux]->sock_available = len;
|
|
||||||
streamSkipUntil('\"');
|
streamSkipUntil('\"');
|
||||||
|
|
||||||
for (size_t i=0; i<len; i++) {
|
for (size_t i=0; i<len; i++) {
|
||||||
|
@@ -109,7 +109,7 @@ public:
|
|||||||
virtual int connect(IPAddress ip, uint16_t port, int timeout_s) {
|
virtual int connect(IPAddress ip, uint16_t port, int timeout_s) {
|
||||||
// NOTE: Not caling stop() or yeild() here
|
// NOTE: Not caling stop() or yeild() here
|
||||||
at->streamClear(); // Empty anything in the buffer before starting
|
at->streamClear(); // Empty anything in the buffer before starting
|
||||||
sock_connected = at->modemConnect(ip, port, mux, timeout_s);
|
sock_connected = at->modemConnect(ip, port, mux, false, timeout_s);
|
||||||
return sock_connected;
|
return sock_connected;
|
||||||
}
|
}
|
||||||
virtual int connect(IPAddress ip, uint16_t port) {
|
virtual int connect(IPAddress ip, uint16_t port) {
|
||||||
@@ -247,7 +247,7 @@ public:
|
|||||||
virtual int connect(IPAddress ip, uint16_t port, int timeout_s) {
|
virtual int connect(IPAddress ip, uint16_t port, int timeout_s) {
|
||||||
// NOTE: Not caling stop() or yeild() here
|
// NOTE: Not caling stop() or yeild() here
|
||||||
at->streamClear(); // Empty anything in the buffer before starting
|
at->streamClear(); // Empty anything in the buffer before starting
|
||||||
sock_connected = at->modemConnect(ip, port, mux, timeout_s);
|
sock_connected = at->modemConnect(ip, port, mux, true, timeout_s);
|
||||||
return sock_connected;
|
return sock_connected;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@@ -10,7 +10,7 @@
|
|||||||
#define TinyGsmCommon_h
|
#define TinyGsmCommon_h
|
||||||
|
|
||||||
// The current library version number
|
// The current library version number
|
||||||
#define TINYGSM_VERSION "0.7.4"
|
#define TINYGSM_VERSION "0.7.7"
|
||||||
|
|
||||||
#if defined(SPARK) || defined(PARTICLE)
|
#if defined(SPARK) || defined(PARTICLE)
|
||||||
#include "Particle.h"
|
#include "Particle.h"
|
||||||
@@ -100,7 +100,7 @@ uint32_t TinyGsmAutoBaud(T& SerialAT, uint32_t minimum = 9600, uint32_t maximum
|
|||||||
DBG("Trying baud rate", rate, "...");
|
DBG("Trying baud rate", rate, "...");
|
||||||
SerialAT.begin(rate);
|
SerialAT.begin(rate);
|
||||||
delay(10);
|
delay(10);
|
||||||
for (int i=0; i<3; i++) {
|
for (int i=0; i<10; i++) {
|
||||||
SerialAT.print("AT\r\n");
|
SerialAT.print("AT\r\n");
|
||||||
String input = SerialAT.readString();
|
String input = SerialAT.readString();
|
||||||
if (input.indexOf("OK") >= 0) {
|
if (input.indexOf("OK") >= 0) {
|
||||||
@@ -249,7 +249,7 @@ String TinyGsmDecodeHex16bit(String &instr) {
|
|||||||
/* Workaround: sometimes module forgets to notify about data arrival.
|
/* Workaround: sometimes module forgets to notify about data arrival.
|
||||||
TODO: Currently we ping the module periodically,
|
TODO: Currently we ping the module periodically,
|
||||||
but maybe there's a better indicator that we need to poll */ \
|
but maybe there's a better indicator that we need to poll */ \
|
||||||
if (millis() - prev_check > 250) { \
|
if (millis() - prev_check > 500) { \
|
||||||
got_data = true; \
|
got_data = true; \
|
||||||
prev_check = millis(); \
|
prev_check = millis(); \
|
||||||
} \
|
} \
|
||||||
@@ -311,7 +311,7 @@ String TinyGsmDecodeHex16bit(String &instr) {
|
|||||||
/* Workaround: sometimes module forgets to notify about data arrival.
|
/* Workaround: sometimes module forgets to notify about data arrival.
|
||||||
TODO: Currently we ping the module periodically,
|
TODO: Currently we ping the module periodically,
|
||||||
but maybe there's a better indicator that we need to poll */ \
|
but maybe there's a better indicator that we need to poll */ \
|
||||||
if (millis() - prev_check > 250) { \
|
if (millis() - prev_check > 500) { \
|
||||||
got_data = true; \
|
got_data = true; \
|
||||||
prev_check = millis(); \
|
prev_check = millis(); \
|
||||||
} \
|
} \
|
||||||
|
@@ -14,7 +14,10 @@
|
|||||||
// #define TINY_GSM_MODEM_SIM900
|
// #define TINY_GSM_MODEM_SIM900
|
||||||
// #define TINY_GSM_MODEM_SIM808
|
// #define TINY_GSM_MODEM_SIM808
|
||||||
// #define TINY_GSM_MODEM_SIM868
|
// #define TINY_GSM_MODEM_SIM868
|
||||||
|
// #define TINY_GSM_MODEM_SIM900
|
||||||
|
// #define TINY_GSM_MODEM_SIM7000
|
||||||
// #define TINY_GSM_MODEM_UBLOX
|
// #define TINY_GSM_MODEM_UBLOX
|
||||||
|
// #define TINY_GSM_MODEM_SARAR4
|
||||||
// #define TINY_GSM_MODEM_M95
|
// #define TINY_GSM_MODEM_M95
|
||||||
// #define TINY_GSM_MODEM_BG96
|
// #define TINY_GSM_MODEM_BG96
|
||||||
// #define TINY_GSM_MODEM_A6
|
// #define TINY_GSM_MODEM_A6
|
||||||
@@ -24,22 +27,28 @@
|
|||||||
// #define TINY_GSM_MODEM_MC60E
|
// #define TINY_GSM_MODEM_MC60E
|
||||||
// #define TINY_GSM_MODEM_ESP8266
|
// #define TINY_GSM_MODEM_ESP8266
|
||||||
// #define TINY_GSM_MODEM_XBEE
|
// #define TINY_GSM_MODEM_XBEE
|
||||||
|
// #define TINY_GSM_MODEM_SEQUANS_MONARCH
|
||||||
|
|
||||||
// Increase the buffer
|
// Increase RX buffer if needed
|
||||||
#define TINY_GSM_RX_BUFFER 512
|
#define TINY_GSM_RX_BUFFER 512
|
||||||
|
|
||||||
|
// See all AT commands, if wanted
|
||||||
|
#define DUMP_AT_COMMANDS
|
||||||
|
|
||||||
// Define the serial console for debug prints, if needed
|
// Define the serial console for debug prints, if needed
|
||||||
//#define TINY_GSM_DEBUG Serial
|
#define TINY_GSM_DEBUG Serial
|
||||||
|
|
||||||
#include <TinyGsmClient.h>
|
// Range to attempt to autobaud
|
||||||
|
#define GSM_AUTOBAUD_MIN 9600
|
||||||
|
#define GSM_AUTOBAUD_MAX 115200
|
||||||
|
|
||||||
// Your GPRS credentials
|
// Add a reception delay, if needed
|
||||||
// Leave empty, if missing user or pass
|
#define TINY_GSM_YIELD() { delay(2); }
|
||||||
const char apn[] = "YourAPN";
|
|
||||||
const char user[] = "";
|
|
||||||
const char pass[] = "";
|
|
||||||
|
|
||||||
// Set serial for debug console (to the Serial Monitor, speed 115200)
|
// Uncomment this if you want to use SSL
|
||||||
|
//#define USE_SSL
|
||||||
|
|
||||||
|
// Set serial for debug console (to the Serial Monitor, default speed 115200)
|
||||||
#define SerialMon Serial
|
#define SerialMon Serial
|
||||||
|
|
||||||
// Set serial for AT commands (to the module)
|
// Set serial for AT commands (to the module)
|
||||||
@@ -50,28 +59,59 @@ const char pass[] = "";
|
|||||||
//#include <SoftwareSerial.h>
|
//#include <SoftwareSerial.h>
|
||||||
//SoftwareSerial SerialAT(2, 3); // RX, TX
|
//SoftwareSerial SerialAT(2, 3); // RX, TX
|
||||||
|
|
||||||
|
#define TINY_GSM_USE_GPRS true
|
||||||
|
#define TINY_GSM_USE_WIFI false
|
||||||
|
|
||||||
#include <StreamDebugger.h>
|
// set GSM PIN, if any
|
||||||
StreamDebugger debugger(SerialAT, SerialMon);
|
#define GSM_PIN ""
|
||||||
TinyGsm modem(debugger);
|
|
||||||
|
|
||||||
|
// Your GPRS credentials
|
||||||
|
// Leave empty, if missing user or pass
|
||||||
|
const char apn[] = "YourAPN";
|
||||||
|
const char gprsUser[] = "";
|
||||||
|
const char gprsPass[] = "";
|
||||||
|
const char wifiSSID[] = "YourSSID";
|
||||||
|
const char wifiPass[] = "YourWiFiPass";
|
||||||
|
|
||||||
|
// Server details
|
||||||
const char server[] = "vsh.pp.ua";
|
const char server[] = "vsh.pp.ua";
|
||||||
const char resource[] = "/TinyGSM/logo.txt";
|
const char resource[] = "/TinyGSM/logo.txt";
|
||||||
|
|
||||||
const int port = 80;
|
#include <TinyGsmClient.h>
|
||||||
TinyGsmClient client(modem);
|
|
||||||
|
|
||||||
// For SSL:
|
#ifdef DUMP_AT_COMMANDS
|
||||||
//const int port = 443;
|
#include <StreamDebugger.h>
|
||||||
//TinyGsmClientSecure client(modem);
|
StreamDebugger debugger(SerialAT, SerialMon);
|
||||||
|
TinyGsm modem(debugger);
|
||||||
|
#else
|
||||||
|
TinyGsm modem(SerialAT);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef USE_SSL
|
||||||
|
TinyGsmClientSecure client(modem);
|
||||||
|
const int port = 443;
|
||||||
|
#else
|
||||||
|
TinyGsmClient client(modem);
|
||||||
|
const int port = 80;
|
||||||
|
#endif
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
// Set console baud rate
|
// Set console baud rate
|
||||||
SerialMon.begin(115200);
|
SerialMon.begin(115200);
|
||||||
delay(10);
|
delay(10);
|
||||||
|
|
||||||
|
// Set your reset, enable, power pins here
|
||||||
|
pinMode(20, OUTPUT);
|
||||||
|
digitalWrite(20, HIGH);
|
||||||
|
|
||||||
|
pinMode(23, OUTPUT);
|
||||||
|
digitalWrite(23, HIGH);
|
||||||
|
|
||||||
|
SerialMon.println("Wait...");
|
||||||
|
|
||||||
// Set GSM module baud rate
|
// Set GSM module baud rate
|
||||||
SerialAT.begin(115200);
|
TinyGsmAutoBaud(SerialAT,GSM_AUTOBAUD_MIN,GSM_AUTOBAUD_MAX);
|
||||||
|
// SerialAT.begin(115200);
|
||||||
delay(3000);
|
delay(3000);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -80,6 +120,7 @@ void loop() {
|
|||||||
// To skip it, call init() instead of restart()
|
// To skip it, call init() instead of restart()
|
||||||
SerialMon.print("Initializing modem...");
|
SerialMon.print("Initializing modem...");
|
||||||
if (!modem.restart()) {
|
if (!modem.restart()) {
|
||||||
|
// if (!modem.init()) {
|
||||||
SerialMon.println(F(" [fail]"));
|
SerialMon.println(F(" [fail]"));
|
||||||
SerialMon.println(F("************************"));
|
SerialMon.println(F("************************"));
|
||||||
SerialMon.println(F(" Is your modem connected properly?"));
|
SerialMon.println(F(" Is your modem connected properly?"));
|
||||||
@@ -97,11 +138,30 @@ void loop() {
|
|||||||
SerialMon.print("Modem: ");
|
SerialMon.print("Modem: ");
|
||||||
SerialMon.println(modemInfo);
|
SerialMon.println(modemInfo);
|
||||||
|
|
||||||
// Unlock your SIM card with a PIN
|
#if TINY_GSM_USE_GPRS
|
||||||
//modem.simUnlock("1234");
|
// Unlock your SIM card with a PIN if needed
|
||||||
|
if ( GSM_PIN && modem.getSimStatus() != 3 ) {
|
||||||
|
modem.simUnlock(GSM_PIN);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if TINY_GSM_USE_WIFI
|
||||||
|
SerialMon.print(F("Setting SSID/password..."));
|
||||||
|
if (!modem.networkConnect(wifiSSID, wifiPass)) {
|
||||||
|
SerialMon.println(" fail");
|
||||||
|
delay(10000);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
SerialMon.println(" OK");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if TINY_GSM_USE_GPRS && defined TINY_GSM_MODEM_XBEE
|
||||||
|
// The XBee must run the gprsConnect function BEFORE waiting for network!
|
||||||
|
modem.gprsConnect(apn, gprsUser, gprsPass);
|
||||||
|
#endif
|
||||||
|
|
||||||
SerialMon.print("Waiting for network...");
|
SerialMon.print("Waiting for network...");
|
||||||
if (!modem.waitForNetwork()) {
|
if (!modem.waitForNetwork(600000L)) { // You may need lengthen this in poor service areas
|
||||||
SerialMon.println(F(" [fail]"));
|
SerialMon.println(F(" [fail]"));
|
||||||
SerialMon.println(F("************************"));
|
SerialMon.println(F("************************"));
|
||||||
SerialMon.println(F(" Is your sim card locked?"));
|
SerialMon.println(F(" Is your sim card locked?"));
|
||||||
@@ -114,9 +174,10 @@ void loop() {
|
|||||||
}
|
}
|
||||||
SerialMon.println(F(" [OK]"));
|
SerialMon.println(F(" [OK]"));
|
||||||
|
|
||||||
|
#if TINY_GSM_USE_GPRS && defined TINY_GSM_MODEM_HAS_GPRS
|
||||||
SerialMon.print("Connecting to ");
|
SerialMon.print("Connecting to ");
|
||||||
SerialMon.print(apn);
|
SerialMon.print(apn);
|
||||||
if (!modem.gprsConnect(apn, user, pass)) {
|
if (!modem.gprsConnect(apn, gprsUser, gprsPass)) {
|
||||||
SerialMon.println(F(" [fail]"));
|
SerialMon.println(F(" [fail]"));
|
||||||
SerialMon.println(F("************************"));
|
SerialMon.println(F("************************"));
|
||||||
SerialMon.println(F(" Is GPRS enabled by network provider?"));
|
SerialMon.println(F(" Is GPRS enabled by network provider?"));
|
||||||
@@ -126,6 +187,7 @@ void loop() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
SerialMon.println(F(" [OK]"));
|
SerialMon.println(F(" [OK]"));
|
||||||
|
#endif
|
||||||
|
|
||||||
IPAddress local = modem.localIP();
|
IPAddress local = modem.localIP();
|
||||||
SerialMon.print("Local IP: ");
|
SerialMon.print("Local IP: ");
|
||||||
|
Reference in New Issue
Block a user