Added ESP getRegStatus, fixed same for XBee
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "TinyGSM",
|
"name": "TinyGSM",
|
||||||
"version": "0.3.5",
|
"version": "0.3.6",
|
||||||
"description": "A small Arduino library for GPRS modules, that just works. Includes examples for Blynk, MQTT, File Download, and Web Client. Supports GSM modules with AT command interface: SIM800, SIM800A, SIM800C, SIM800L, SIM800H, SIM808, SIM868, SIM900, SIM900A, SIM900D, SIM908, SIM968",
|
"description": "A small Arduino library for GPRS modules, that just works. Includes examples for Blynk, MQTT, File Download, and Web Client. Supports GSM modules with AT command interface: SIM800, SIM800A, SIM800C, SIM800L, SIM800H, SIM808, SIM868, SIM900, SIM900A, SIM900D, SIM908, SIM968",
|
||||||
"keywords": "GSM, AT commands, AT, SIM800, SIM900, A6, A7, M590, ESP8266, SIM800A, SIM800C, SIM800L, SIM800H, SIM808, SIM868, SIM900A, SIM900D, SIM908, SIM968",
|
"keywords": "GSM, AT commands, AT, SIM800, SIM900, A6, A7, M590, ESP8266, SIM800A, SIM800C, SIM800L, SIM800H, SIM808, SIM868, SIM900A, SIM900D, SIM908, SIM968",
|
||||||
"authors":
|
"authors":
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
name=TinyGSM
|
name=TinyGSM
|
||||||
version=0.3.5
|
version=0.3.6
|
||||||
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.
|
||||||
|
@@ -24,6 +24,15 @@ static const char GSM_OK[] TINY_GSM_PROGMEM = "OK" GSM_NL;
|
|||||||
static const char GSM_ERROR[] TINY_GSM_PROGMEM = "ERROR" GSM_NL;
|
static const char GSM_ERROR[] TINY_GSM_PROGMEM = "ERROR" GSM_NL;
|
||||||
static unsigned TINY_GSM_TCP_KEEP_ALIVE = 120;
|
static unsigned TINY_GSM_TCP_KEEP_ALIVE = 120;
|
||||||
|
|
||||||
|
enum RegStatus {
|
||||||
|
REG_UNREGISTERED = 0,
|
||||||
|
REG_SEARCHING = 2,
|
||||||
|
REG_DENIED = 3,
|
||||||
|
REG_OK_HOME = 1,
|
||||||
|
REG_OK_ROAMING = 5,
|
||||||
|
REG_UNKNOWN = 4,
|
||||||
|
};
|
||||||
|
|
||||||
class TinyGsmESP8266
|
class TinyGsmESP8266
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -234,6 +243,26 @@ public:
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RegStatus getRegistrationStatus() {
|
||||||
|
sendAT(GF("+CIPSTATUS"));
|
||||||
|
int res1 = waitResponse(3000, GF("STATUS:"));
|
||||||
|
int res2 = 0;
|
||||||
|
if (res1 == 1) {
|
||||||
|
res2 = waitResponse(GFP(GSM_ERROR), GF("2"), GF("3"), GF("4"), GF("5"));
|
||||||
|
}
|
||||||
|
// <stat> status of ESP8266 station interface
|
||||||
|
// 2 : ESP8266 station connected to an AP and has obtained IP
|
||||||
|
// 3 : ESP8266 station created a TCP or UDP transmission
|
||||||
|
// 4 : the TCP or UDP transmission of ESP8266 station disconnected
|
||||||
|
// 5 : ESP8266 station did NOT connect to an AP
|
||||||
|
waitResponse(); // Returns an OK after the status
|
||||||
|
if (res2 == 2) return REG_OK_HOME;
|
||||||
|
if (res2 == 3) return REG_OK_HOME;
|
||||||
|
if (res2 == 4) return REG_UNREGISTERED;
|
||||||
|
if (res2 == 5) return REG_DENIED;
|
||||||
|
else return REG_UNKNOWN;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Power functions
|
* Power functions
|
||||||
*/
|
*/
|
||||||
@@ -273,21 +302,9 @@ public:
|
|||||||
return res2;
|
return res2;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isNetworkConnected() {
|
bool isNetworkConnected() {
|
||||||
sendAT(GF("+CIPSTATUS"));
|
RegStatus s = getRegistrationStatus();
|
||||||
int res1 = waitResponse(3000, GF("STATUS:"));
|
return (s == REG_OK_HOME || s == REG_OK_ROAMING);
|
||||||
int res2 = 0;
|
|
||||||
if (res1 == 1) {
|
|
||||||
res2 = waitResponse(GFP(GSM_ERROR), GF("2"), GF("3"), GF("4"), GF("5"));
|
|
||||||
}
|
|
||||||
// <stat> status of ESP8266 station interface
|
|
||||||
// 2 : ESP8266 station connected to an AP and has obtained IP
|
|
||||||
// 3 : ESP8266 station created a TCP or UDP transmission
|
|
||||||
// 4 : the TCP or UDP transmission of ESP8266 station disconnected
|
|
||||||
// 5 : ESP8266 station did NOT connect to an AP
|
|
||||||
waitResponse(); // Returns an OK after the status
|
|
||||||
if (res2 == 2 || res2 == 3) return true;
|
|
||||||
else return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool waitForNetwork(unsigned long timeout = 60000L) {
|
bool waitForNetwork(unsigned long timeout = 60000L) {
|
||||||
@@ -382,20 +399,8 @@ protected:
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool modemGetConnected(uint8_t mux) {
|
bool modemGetConnected(uint8_t mux) {
|
||||||
sendAT(GF("+CIPSTATUS="), mux);
|
RegStatus s = getRegistrationStatus();
|
||||||
int res1 = waitResponse(3000, GF("STATUS:"));
|
return (s == REG_OK_HOME || s == REG_OK_ROAMING);
|
||||||
int res2;
|
|
||||||
if (res1 == 1) {
|
|
||||||
res2 = waitResponse(GFP(GSM_ERROR), GF("2"), GF("3"), GF("4"), GF("5"));
|
|
||||||
}
|
|
||||||
// <stat> status of ESP8266 station interface
|
|
||||||
// 2 : ESP8266 station connected to an AP and has obtained IP
|
|
||||||
// 3 : ESP8266 station created a TCP or UDP transmission
|
|
||||||
// 4 : the TCP or UDP transmission of ESP8266 station disconnected
|
|
||||||
// 5 : ESP8266 station did NOT connect to an AP
|
|
||||||
waitResponse(); // Returns an OK after the status
|
|
||||||
if (res2 == 2 || res2 == 3) return true;
|
|
||||||
else return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@@ -30,8 +30,8 @@ enum SimStatus {
|
|||||||
};
|
};
|
||||||
|
|
||||||
enum XBeeType {
|
enum XBeeType {
|
||||||
CELL = 0,
|
XBEE_CELL = 0,
|
||||||
WIFI = 1,
|
XBEE_WIFI = 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum RegStatus {
|
enum RegStatus {
|
||||||
@@ -232,8 +232,8 @@ public:
|
|||||||
|
|
||||||
sendAT(GF("HS")); // Get the "Hardware Series"; 0x601 for S6B (Wifi)
|
sendAT(GF("HS")); // Get the "Hardware Series"; 0x601 for S6B (Wifi)
|
||||||
int res = waitResponse(GF("601"));
|
int res = waitResponse(GF("601"));
|
||||||
if (res == 1) beeType = WIFI;
|
if (res == 1) beeType = XBEE_WIFI;
|
||||||
else beeType = CELL;
|
else beeType = XBEE_CELL;
|
||||||
|
|
||||||
exitCommand();
|
exitCommand();
|
||||||
return ret_val;
|
return ret_val;
|
||||||
@@ -291,10 +291,15 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool hasSSL() {
|
bool hasSSL() {
|
||||||
if (beeType == WIFI) return false;
|
if (beeType == XBEE_WIFI) return false;
|
||||||
else return true;
|
else return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String getBeeType() {
|
||||||
|
if (beeType == XBEE_WIFI) return "S6B Wifi";
|
||||||
|
else return "Cellular";
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Power functions
|
* Power functions
|
||||||
*/
|
*/
|
||||||
@@ -331,7 +336,7 @@ public:
|
|||||||
if (!commandMode()) return; // Return immediately
|
if (!commandMode()) return; // Return immediately
|
||||||
sendAT(GF("SM"),1); // Pin sleep
|
sendAT(GF("SM"),1); // Pin sleep
|
||||||
waitResponse();
|
waitResponse();
|
||||||
if (beeType == WIFI && !maintainAssociation) {
|
if (beeType == XBEE_WIFI && !maintainAssociation) {
|
||||||
sendAT(GF("SO"),200); // For lowest power, dissassociated deep sleep
|
sendAT(GF("SO"),200); // For lowest power, dissassociated deep sleep
|
||||||
waitResponse();
|
waitResponse();
|
||||||
}
|
}
|
||||||
@@ -373,26 +378,72 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
RegStatus getRegistrationStatus() {
|
RegStatus getRegistrationStatus() {
|
||||||
if (!commandMode()) return REG_UNREGISTERED; // Return immediately
|
if (!commandMode()) return REG_UNKNOWN; // Return immediately
|
||||||
|
|
||||||
sendAT(GF("AI"));
|
sendAT(GF("AI"));
|
||||||
String res = readResponse();
|
String res = readResponse();
|
||||||
|
RegStatus stat;
|
||||||
|
|
||||||
|
switch (beeType){
|
||||||
|
case XBEE_WIFI: {
|
||||||
|
if(res == GF("0")) // 0x00 Successfully joined an access point, established IP addresses and IP listening sockets
|
||||||
|
stat = REG_OK_HOME;
|
||||||
|
else if(res == GF("1")) // 0x01 Wi-Fi transceiver initialization in progress.
|
||||||
|
stat = REG_SEARCHING;
|
||||||
|
else if(res == GF("2")) // 0x02 Wi-Fi transceiver initialized, but not yet scanning for access point.
|
||||||
|
stat = REG_SEARCHING;
|
||||||
|
else if(res == GF("13")) { // 0x13 Disconnecting from access point.
|
||||||
|
sendAT(GF("NR")); // Do a network reset; the S6B tends to get stuck "disconnecting"
|
||||||
|
writeChanges();
|
||||||
|
stat = REG_UNREGISTERED;
|
||||||
|
}
|
||||||
|
else if(res == GF("23")) // 0x23 SSID not configured.
|
||||||
|
stat = REG_UNREGISTERED;
|
||||||
|
else if(res == GF("24")) // 0x24 Encryption key invalid (either NULL or invalid length for WEP).
|
||||||
|
stat = REG_DENIED;
|
||||||
|
else if(res == GF("27")) // 0x27 SSID was found, but join failed.
|
||||||
|
stat = REG_DENIED;
|
||||||
|
else if(res == GF("40")) // 0x40 Waiting for WPA or WPA2 Authentication.
|
||||||
|
stat = REG_SEARCHING;
|
||||||
|
else if(res == GF("41")) // 0x41 Device joined a network and is waiting for IP configuration to complete
|
||||||
|
stat = REG_SEARCHING;
|
||||||
|
else if(res == GF("42")) // 0x42 Device is joined, IP is configured, and listening sockets are being set up.
|
||||||
|
stat = REG_SEARCHING;
|
||||||
|
else if(res == GF("FF")) // 0xFF Device is currently scanning for the configured SSID.
|
||||||
|
stat = REG_SEARCHING;
|
||||||
|
else stat = REG_UNKNOWN;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case XBEE_CELL: {
|
||||||
|
if(res == GF("0")) // 0x00 Connected to the Internet.
|
||||||
|
stat = REG_OK_HOME;
|
||||||
|
else if(res == GF("22")) // 0x22 Registering to cellular network.
|
||||||
|
stat = REG_SEARCHING;
|
||||||
|
else if(res == GF("23")) // 0x23 Connecting to the Internet.
|
||||||
|
stat = REG_SEARCHING;
|
||||||
|
else if(res == GF("24")) // 0x24 The cellular component is missing, corrupt, or otherwise in error.
|
||||||
|
stat = REG_UNKNOWN;
|
||||||
|
else if(res == GF("25")) // 0x25 Cellular network registration denied.
|
||||||
|
stat = REG_DENIED;
|
||||||
|
else if(res == GF("2A")) { // 0x2A Airplane mode.
|
||||||
|
sendAT(GF("AM0")); // Turn off airplane mode
|
||||||
|
writeChanges();
|
||||||
|
stat = REG_UNKNOWN;
|
||||||
|
}
|
||||||
|
else if(res == GF("2F")) { // 0x2F Bypass mode active.
|
||||||
|
sendAT(GF("AP0")); // Set back to transparent mode
|
||||||
|
writeChanges();
|
||||||
|
stat = REG_UNKNOWN;
|
||||||
|
}
|
||||||
|
else if(res == GF("FF")) // 0xFF Device is currently scanning for the configured SSID.
|
||||||
|
stat = REG_SEARCHING;
|
||||||
|
else stat = REG_UNKNOWN;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
exitCommand();
|
exitCommand();
|
||||||
|
return stat;
|
||||||
if(res == GF("0"))
|
|
||||||
return REG_OK_HOME;
|
|
||||||
|
|
||||||
else if(res == GF("13") || res == GF("2A"))
|
|
||||||
return REG_UNREGISTERED;
|
|
||||||
|
|
||||||
else if(res == GF("FF") || res == GF("22") || res == GF("23") ||
|
|
||||||
res == GF("40") || res == GF("41") || res == GF("42"))
|
|
||||||
return REG_SEARCHING;
|
|
||||||
|
|
||||||
else if(res == GF("24") || res == GF("25") || res == GF("27"))
|
|
||||||
return REG_DENIED;
|
|
||||||
|
|
||||||
else return REG_UNKNOWN;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String getOperator() {
|
String getOperator() {
|
||||||
@@ -409,7 +460,7 @@ public:
|
|||||||
|
|
||||||
int getSignalQuality() {
|
int getSignalQuality() {
|
||||||
if (!commandMode()) return 0; // Return immediately
|
if (!commandMode()) return 0; // Return immediately
|
||||||
if (beeType == WIFI) sendAT(GF("LM")); // ask for the "link margin" - the dB above sensitivity
|
if (beeType == XBEE_WIFI) sendAT(GF("LM")); // ask for the "link margin" - the dB above sensitivity
|
||||||
else sendAT(GF("DB")); // ask for the cell strength in dBm
|
else sendAT(GF("DB")); // ask for the cell strength in dBm
|
||||||
// wait for the response
|
// wait for the response
|
||||||
unsigned long startMillis = millis();
|
unsigned long startMillis = millis();
|
||||||
@@ -420,7 +471,7 @@ public:
|
|||||||
// DBG(buf[0], buf[1], "\n");
|
// DBG(buf[0], buf[1], "\n");
|
||||||
exitCommand();
|
exitCommand();
|
||||||
int intr = strtol(buf, 0, 16);
|
int intr = strtol(buf, 0, 16);
|
||||||
if (beeType == WIFI) return -93 + intr; // the maximum sensitivity is -93dBm
|
if (beeType == XBEE_WIFI) return -93 + intr; // the maximum sensitivity is -93dBm
|
||||||
else return -1*intr; // need to convert to negative number
|
else return -1*intr; // need to convert to negative number
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user