Grouped connection quality functions
This commit is contained in:
@@ -225,7 +225,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* SIM card & Network Operator functions
|
* SIM card functions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
bool simUnlock(const char *pin) {
|
bool simUnlock(const char *pin) {
|
||||||
@@ -253,16 +253,6 @@ public:
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
int getSignalQuality() {
|
|
||||||
sendAT(GF("+CSQ"));
|
|
||||||
if (waitResponse(GF(GSM_NL "+CSQ:")) != 1) {
|
|
||||||
return 99;
|
|
||||||
}
|
|
||||||
int res = streamReadUntil(',').toInt();
|
|
||||||
waitResponse();
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
SimStatus getSimStatus(unsigned long timeout = 10000L) {
|
SimStatus getSimStatus(unsigned long timeout = 10000L) {
|
||||||
for (unsigned long start = millis(); millis() - start < timeout; ) {
|
for (unsigned long start = millis(); millis() - start < timeout; ) {
|
||||||
sendAT(GF("+CPIN?"));
|
sendAT(GF("+CPIN?"));
|
||||||
@@ -304,6 +294,20 @@ public:
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Generic network functions
|
||||||
|
*/
|
||||||
|
|
||||||
|
int getSignalQuality() {
|
||||||
|
sendAT(GF("+CSQ"));
|
||||||
|
if (waitResponse(GF(GSM_NL "+CSQ:")) != 1) {
|
||||||
|
return 99;
|
||||||
|
}
|
||||||
|
int res = streamReadUntil(',').toInt();
|
||||||
|
waitResponse();
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
bool waitForNetwork(unsigned long timeout = 60000L) {
|
bool waitForNetwork(unsigned long timeout = 60000L) {
|
||||||
for (unsigned long start = millis(); millis() - start < timeout; ) {
|
for (unsigned long start = millis(); millis() - start < timeout; ) {
|
||||||
RegStatus s = getRegistrationStatus();
|
RegStatus s = getRegistrationStatus();
|
||||||
@@ -392,12 +396,6 @@ public:
|
|||||||
* Messaging functions
|
* Messaging functions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void sendUSSD() {
|
|
||||||
}
|
|
||||||
|
|
||||||
void sendSMS() {
|
|
||||||
}
|
|
||||||
|
|
||||||
bool sendSMS(const String& number, const String& text) {
|
bool sendSMS(const String& number, const String& text) {
|
||||||
sendAT(GF("+CMGF=1"));
|
sendAT(GF("+CMGF=1"));
|
||||||
waitResponse();
|
waitResponse();
|
||||||
@@ -413,8 +411,7 @@ public:
|
|||||||
/*
|
/*
|
||||||
* Location functions
|
* Location functions
|
||||||
*/
|
*/
|
||||||
void getLocation() {
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Battery functions
|
* Battery functions
|
||||||
@@ -505,8 +502,8 @@ private:
|
|||||||
|
|
||||||
// TODO: Optimize this!
|
// TODO: Optimize this!
|
||||||
uint8_t waitResponse(uint32_t timeout, String& data,
|
uint8_t waitResponse(uint32_t timeout, String& data,
|
||||||
GsmConstStr r1=GFP(GSM_OK), GsmConstStr r2=GFP(GSM_ERROR),
|
GsmConstStr r1=GFP(GSM_OK), GsmConstStr r2=GFP(GSM_ERROR),
|
||||||
GsmConstStr r3=NULL, GsmConstStr r4=NULL, GsmConstStr r5=NULL)
|
GsmConstStr r3=NULL, GsmConstStr r4=NULL, GsmConstStr r5=NULL)
|
||||||
{
|
{
|
||||||
/*String r1s(r1); r1s.trim();
|
/*String r1s(r1); r1s.trim();
|
||||||
String r2s(r2); r2s.trim();
|
String r2s(r2); r2s.trim();
|
||||||
@@ -599,15 +596,15 @@ private:
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint8_t waitResponse(uint32_t timeout,
|
uint8_t waitResponse(uint32_t timeout,
|
||||||
GsmConstStr r1=GFP(GSM_OK), GsmConstStr r2=GFP(GSM_ERROR),
|
GsmConstStr r1=GFP(GSM_OK), GsmConstStr r2=GFP(GSM_ERROR),
|
||||||
GsmConstStr r3=NULL, GsmConstStr r4=NULL, GsmConstStr r5=NULL)
|
GsmConstStr r3=NULL, GsmConstStr r4=NULL, GsmConstStr r5=NULL)
|
||||||
{
|
{
|
||||||
String data;
|
String data;
|
||||||
return waitResponse(timeout, data, r1, r2, r3, r4, r5);
|
return waitResponse(timeout, data, r1, r2, r3, r4, r5);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t waitResponse(GsmConstStr r1=GFP(GSM_OK), GsmConstStr r2=GFP(GSM_ERROR),
|
uint8_t waitResponse(GsmConstStr r1=GFP(GSM_OK), GsmConstStr r2=GFP(GSM_ERROR),
|
||||||
GsmConstStr r3=NULL, GsmConstStr r4=NULL, GsmConstStr r5=NULL)
|
GsmConstStr r3=NULL, GsmConstStr r4=NULL, GsmConstStr r5=NULL)
|
||||||
{
|
{
|
||||||
return waitResponse(1000, r1, r2, r3, r4, r5);
|
return waitResponse(1000, r1, r2, r3, r4, r5);
|
||||||
}
|
}
|
||||||
|
@@ -204,7 +204,11 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* SIM card & Network Operator functions
|
* SIM card functions
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Generic network functions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int getSignalQuality() {
|
int getSignalQuality() {
|
||||||
|
@@ -234,7 +234,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* SIM card & Network Operator functions
|
* SIM card functions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
bool simUnlock(const char *pin) {
|
bool simUnlock(const char *pin) {
|
||||||
@@ -262,16 +262,6 @@ public:
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
int getSignalQuality() {
|
|
||||||
sendAT(GF("+CSQ"));
|
|
||||||
if (waitResponse(GF(GSM_NL "+CSQ:")) != 1) {
|
|
||||||
return 99;
|
|
||||||
}
|
|
||||||
int res = streamReadUntil(',').toInt();
|
|
||||||
waitResponse();
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
SimStatus getSimStatus(unsigned long timeout = 10000L) {
|
SimStatus getSimStatus(unsigned long timeout = 10000L) {
|
||||||
for (unsigned long start = millis(); millis() - start < timeout; ) {
|
for (unsigned long start = millis(); millis() - start < timeout; ) {
|
||||||
sendAT(GF("+CPIN?"));
|
sendAT(GF("+CPIN?"));
|
||||||
@@ -313,6 +303,20 @@ public:
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Generic network functions
|
||||||
|
*/
|
||||||
|
|
||||||
|
int getSignalQuality() {
|
||||||
|
sendAT(GF("+CSQ"));
|
||||||
|
if (waitResponse(GF(GSM_NL "+CSQ:")) != 1) {
|
||||||
|
return 99;
|
||||||
|
}
|
||||||
|
int res = streamReadUntil(',').toInt();
|
||||||
|
waitResponse();
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
bool waitForNetwork(unsigned long timeout = 60000L) {
|
bool waitForNetwork(unsigned long timeout = 60000L) {
|
||||||
for (unsigned long start = millis(); millis() - start < timeout; ) {
|
for (unsigned long start = millis(); millis() - start < timeout; ) {
|
||||||
RegStatus s = getRegistrationStatus();
|
RegStatus s = getRegistrationStatus();
|
||||||
@@ -399,12 +403,6 @@ public:
|
|||||||
* Messaging functions
|
* Messaging functions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void sendUSSD() {
|
|
||||||
}
|
|
||||||
|
|
||||||
void sendSMS() {
|
|
||||||
}
|
|
||||||
|
|
||||||
bool sendSMS(const String& number, const String& text) {
|
bool sendSMS(const String& number, const String& text) {
|
||||||
sendAT(GF("+CMGF=1"));
|
sendAT(GF("+CMGF=1"));
|
||||||
waitResponse();
|
waitResponse();
|
||||||
@@ -420,8 +418,6 @@ public:
|
|||||||
/*
|
/*
|
||||||
* Location functions
|
* Location functions
|
||||||
*/
|
*/
|
||||||
void getLocation() {
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Battery functions
|
* Battery functions
|
||||||
|
@@ -241,7 +241,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* SIM card & Network Operator functions
|
* SIM card functions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
bool simUnlock(const char *pin) {
|
bool simUnlock(const char *pin) {
|
||||||
@@ -269,16 +269,6 @@ public:
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
int getSignalQuality() {
|
|
||||||
sendAT(GF("+CSQ"));
|
|
||||||
if (waitResponse(GF(GSM_NL "+CSQ:")) != 1) {
|
|
||||||
return 99;
|
|
||||||
}
|
|
||||||
int res = streamReadUntil(',').toInt();
|
|
||||||
waitResponse();
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
SimStatus getSimStatus(unsigned long timeout = 10000L) {
|
SimStatus getSimStatus(unsigned long timeout = 10000L) {
|
||||||
for (unsigned long start = millis(); millis() - start < timeout; ) {
|
for (unsigned long start = millis(); millis() - start < timeout; ) {
|
||||||
sendAT(GF("+CPIN?"));
|
sendAT(GF("+CPIN?"));
|
||||||
@@ -320,6 +310,20 @@ public:
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Generic network functions
|
||||||
|
*/
|
||||||
|
|
||||||
|
int getSignalQuality() {
|
||||||
|
sendAT(GF("+CSQ"));
|
||||||
|
if (waitResponse(GF(GSM_NL "+CSQ:")) != 1) {
|
||||||
|
return 99;
|
||||||
|
}
|
||||||
|
int res = streamReadUntil(',').toInt();
|
||||||
|
waitResponse();
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
bool waitForNetwork(unsigned long timeout = 60000L) {
|
bool waitForNetwork(unsigned long timeout = 60000L) {
|
||||||
for (unsigned long start = millis(); millis() - start < timeout; ) {
|
for (unsigned long start = millis(); millis() - start < timeout; ) {
|
||||||
RegStatus s = getRegistrationStatus();
|
RegStatus s = getRegistrationStatus();
|
||||||
@@ -456,12 +460,6 @@ public:
|
|||||||
* Messaging functions
|
* Messaging functions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void sendUSSD() {
|
|
||||||
}
|
|
||||||
|
|
||||||
void sendSMS() {
|
|
||||||
}
|
|
||||||
|
|
||||||
bool sendSMS(const String& number, const String& text) {
|
bool sendSMS(const String& number, const String& text) {
|
||||||
sendAT(GF("+CMGF=1"));
|
sendAT(GF("+CMGF=1"));
|
||||||
waitResponse();
|
waitResponse();
|
||||||
@@ -504,8 +502,6 @@ public:
|
|||||||
/*
|
/*
|
||||||
* Location functions
|
* Location functions
|
||||||
*/
|
*/
|
||||||
void getLocation() {
|
|
||||||
}
|
|
||||||
|
|
||||||
String getGsmLocation() {
|
String getGsmLocation() {
|
||||||
sendAT(GF("+CIPGSMLOC=1,1"));
|
sendAT(GF("+CIPGSMLOC=1,1"));
|
||||||
|
@@ -224,7 +224,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* SIM card & Network Operator functions
|
* SIM card functions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
bool simUnlock(const char *pin) { // Not supported
|
bool simUnlock(const char *pin) { // Not supported
|
||||||
@@ -253,23 +253,6 @@ public:
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
int getSignalQuality() {
|
|
||||||
commandMode();
|
|
||||||
if (beeType == S6B) sendAT(GF("LM")); // ask for the "link margin" - the dB above sensitivity
|
|
||||||
else sendAT(GF("DB")); // ask for the cell strenght in dBm
|
|
||||||
// wait for the response
|
|
||||||
unsigned long startMillis = millis();
|
|
||||||
while (!stream.available() && millis() - startMillis < 1000) {};
|
|
||||||
char buf[2] = {0}; // Set up buffer for response
|
|
||||||
buf[0] = streamRead();
|
|
||||||
buf[1] = streamRead();
|
|
||||||
DBG(buf[0], buf[1], "\n");
|
|
||||||
exitCommand();
|
|
||||||
int intr = strtol(buf, 0, 16);
|
|
||||||
if (beeType == S6B) return -93 + intr; // the maximum sensitivity is -93dBm
|
|
||||||
else return -1*intr; // need to convert to negative number
|
|
||||||
}
|
|
||||||
|
|
||||||
SimStatus getSimStatus(unsigned long timeout = 10000L) {
|
SimStatus getSimStatus(unsigned long timeout = 10000L) {
|
||||||
return SIM_READY; // unsupported
|
return SIM_READY; // unsupported
|
||||||
}
|
}
|
||||||
@@ -311,6 +294,26 @@ public:
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Generic network functions
|
||||||
|
*/
|
||||||
|
|
||||||
|
int getSignalQuality() {
|
||||||
|
commandMode();
|
||||||
|
if (beeType == S6B) sendAT(GF("LM")); // ask for the "link margin" - the dB above sensitivity
|
||||||
|
else sendAT(GF("DB")); // ask for the cell strenght in dBm
|
||||||
|
// wait for the response
|
||||||
|
unsigned long startMillis = millis();
|
||||||
|
while (!stream.available() && millis() - startMillis < 1000) {};
|
||||||
|
char buf[2] = {0}; // Set up buffer for response
|
||||||
|
buf[0] = streamRead();
|
||||||
|
buf[1] = streamRead();
|
||||||
|
DBG(buf[0], buf[1], "\n");
|
||||||
|
exitCommand();
|
||||||
|
int intr = strtol(buf, 0, 16);
|
||||||
|
if (beeType == S6B) return -93 + intr; // the maximum sensitivity is -93dBm
|
||||||
|
else return -1*intr; // need to convert to negative number
|
||||||
|
}
|
||||||
|
|
||||||
bool waitForNetwork(unsigned long timeout = 60000L) {
|
bool waitForNetwork(unsigned long timeout = 60000L) {
|
||||||
for (unsigned long start = millis(); millis() - start < timeout; ) {
|
for (unsigned long start = millis(); millis() - start < timeout; ) {
|
||||||
|
@@ -5,10 +5,10 @@
|
|||||||
**************************************************************/
|
**************************************************************/
|
||||||
|
|
||||||
// #define TINY_GSM_MODEM_SIM800
|
// #define TINY_GSM_MODEM_SIM800
|
||||||
//#define TINY_GSM_MODEM_A6
|
// #define TINY_GSM_MODEM_A6
|
||||||
//#define TINY_GSM_MODEM_M590
|
// #define TINY_GSM_MODEM_M590
|
||||||
//#define TINY_GSM_MODEM_ESP8266
|
// #define TINY_GSM_MODEM_ESP8266
|
||||||
//#define TINY_GSM_MODEM_XBEE
|
// #define TINY_GSM_MODEM_XBEE
|
||||||
|
|
||||||
#include <TinyGsmClient.h>
|
#include <TinyGsmClient.h>
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user