Moved modem functions to pre-processor macros
This commit is contained in:
@@ -150,22 +150,11 @@ public:
|
|||||||
return "AI-Thinker A6";
|
return "AI-Thinker A6";
|
||||||
}
|
}
|
||||||
|
|
||||||
void setBaud(unsigned long baud) {
|
TINY_GSM_MODEM_SET_BAUD_IPR()
|
||||||
sendAT(GF("+IPR="), baud);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool testAT(unsigned long timeout = 10000L) {
|
TINY_GSM_MODEM_TEST_AT()
|
||||||
for (unsigned long start = millis(); millis() - start < timeout; ) {
|
|
||||||
sendAT(GF(""));
|
|
||||||
if (waitResponse(200) == 1) return true;
|
|
||||||
delay(100);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void maintain() {
|
TINY_GSM_MODEM_MAINTAIN_LISTEN()
|
||||||
waitResponse(10, NULL, NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool factoryDefault() {
|
bool factoryDefault() {
|
||||||
sendAT(GF("&FZE0&W")); // Factory + Reset + Echo Off + Write
|
sendAT(GF("&FZE0&W")); // Factory + Reset + Echo Off + Write
|
||||||
@@ -174,17 +163,7 @@ public:
|
|||||||
return waitResponse() == 1;
|
return waitResponse() == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
String getModemInfo() {
|
TINY_GSM_MODEM_GET_INFO_ATI()
|
||||||
sendAT(GF("I"));
|
|
||||||
String res;
|
|
||||||
if (waitResponse(1000L, res) != 1) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
res.replace(GSM_NL "OK" GSM_NL, "");
|
|
||||||
res.replace(GSM_NL, " ");
|
|
||||||
res.trim();
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool hasSSL() {
|
bool hasSSL() {
|
||||||
return false;
|
return false;
|
||||||
@@ -224,10 +203,7 @@ public:
|
|||||||
* SIM card functions
|
* SIM card functions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
bool simUnlock(const char *pin) {
|
TINY_GSM_MODEM_SIM_UNLOCK_CPIN()
|
||||||
sendAT(GF("+CPIN=\""), pin, GF("\""));
|
|
||||||
return waitResponse() == 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
String getSimCCID() {
|
String getSimCCID() {
|
||||||
sendAT(GF("+CCID"));
|
sendAT(GF("+CCID"));
|
||||||
@@ -240,16 +216,7 @@ public:
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
String getIMEI() {
|
TINY_GSM_MODEM_GET_IMEI_GSN()
|
||||||
sendAT(GF("+GSN"));
|
|
||||||
if (waitResponse(GF(GSM_NL)) != 1) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
String res = stream.readStringUntil('\n');
|
|
||||||
waitResponse();
|
|
||||||
res.trim();
|
|
||||||
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; ) {
|
||||||
@@ -270,16 +237,7 @@ public:
|
|||||||
return SIM_ERROR;
|
return SIM_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
RegStatus getRegistrationStatus() {
|
TINY_GSM_MODEM_GET_REGISTRATION_XREG(CREG)
|
||||||
sendAT(GF("+CREG?"));
|
|
||||||
if (waitResponse(GF(GSM_NL "+CREG:")) != 1) {
|
|
||||||
return REG_UNKNOWN;
|
|
||||||
}
|
|
||||||
streamSkipUntil(','); // Skip format (0)
|
|
||||||
int status = stream.readStringUntil('\n').toInt();
|
|
||||||
waitResponse();
|
|
||||||
return (RegStatus)status;
|
|
||||||
}
|
|
||||||
|
|
||||||
String getOperator() {
|
String getOperator() {
|
||||||
sendAT(GF("+COPS=3,0")); // Set format
|
sendAT(GF("+COPS=3,0")); // Set format
|
||||||
@@ -299,30 +257,14 @@ public:
|
|||||||
* Generic network functions
|
* Generic network functions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int16_t getSignalQuality() {
|
TINY_GSP_MODEM_GET_CSQ()
|
||||||
sendAT(GF("+CSQ"));
|
|
||||||
if (waitResponse(GF(GSM_NL "+CSQ:")) != 1) {
|
|
||||||
return 99;
|
|
||||||
}
|
|
||||||
int res = stream.readStringUntil(',').toInt();
|
|
||||||
waitResponse();
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isNetworkConnected() {
|
bool isNetworkConnected() {
|
||||||
RegStatus s = getRegistrationStatus();
|
RegStatus s = getRegistrationStatus();
|
||||||
return (s == REG_OK_HOME || s == REG_OK_ROAMING);
|
return (s == REG_OK_HOME || s == REG_OK_ROAMING);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool waitForNetwork(unsigned long timeout = 60000L) {
|
TINY_GSM_MODEM_WAIT_FOR_NETWORK()
|
||||||
for (unsigned long start = millis(); millis() - start < timeout; ) {
|
|
||||||
if (isNetworkConnected()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
delay(250);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* GPRS functions
|
* GPRS functions
|
||||||
@@ -603,37 +545,7 @@ public:
|
|||||||
Utilities
|
Utilities
|
||||||
*/
|
*/
|
||||||
|
|
||||||
template<typename T>
|
TINY_GSP_MODEM_STREAM_UTILITIES()
|
||||||
void streamWrite(T last) {
|
|
||||||
stream.print(last);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T, typename... Args>
|
|
||||||
void streamWrite(T head, Args... tail) {
|
|
||||||
stream.print(head);
|
|
||||||
streamWrite(tail...);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename... Args>
|
|
||||||
void sendAT(Args... cmd) {
|
|
||||||
streamWrite("AT", cmd..., GSM_NL);
|
|
||||||
stream.flush();
|
|
||||||
TINY_GSM_YIELD();
|
|
||||||
//DBG("### AT:", cmd...);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool streamSkipUntil(const char c, const unsigned long timeout = 1000L) {
|
|
||||||
unsigned long startMillis = millis();
|
|
||||||
while (millis() - startMillis < timeout) {
|
|
||||||
while (millis() - startMillis < timeout && !stream.available()) {
|
|
||||||
TINY_GSM_YIELD();
|
|
||||||
}
|
|
||||||
if (stream.read() == c) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: Optimize this!
|
// TODO: Optimize this!
|
||||||
uint8_t waitResponse(uint32_t timeout, String& data,
|
uint8_t waitResponse(uint32_t timeout, String& data,
|
||||||
|
@@ -174,31 +174,11 @@ public:
|
|||||||
return "Quectel BG96";
|
return "Quectel BG96";
|
||||||
}
|
}
|
||||||
|
|
||||||
void setBaud(unsigned long baud) {
|
TINY_GSM_MODEM_SET_BAUD_IPR()
|
||||||
sendAT(GF("+IPR="), baud);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool testAT(unsigned long timeout = 10000L) {
|
TINY_GSM_MODEM_TEST_AT()
|
||||||
for (unsigned long start = millis(); millis() - start < timeout; ) {
|
|
||||||
sendAT(GF(""));
|
|
||||||
if (waitResponse(200) == 1) return true;
|
|
||||||
delay(100);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void maintain() {
|
TINY_GSM_MODEM_MAINTAIN_CHECK_SOCKS()
|
||||||
for (int mux = 0; mux < TINY_GSM_MUX_COUNT; mux++) {
|
|
||||||
GsmClient* sock = sockets[mux];
|
|
||||||
if (sock && sock->got_data) {
|
|
||||||
sock->got_data = false;
|
|
||||||
sock->sock_available = modemGetAvailable(mux);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
while (stream.available()) {
|
|
||||||
waitResponse(10, NULL, NULL);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool factoryDefault() {
|
bool factoryDefault() {
|
||||||
sendAT(GF("&FZE0&W")); // Factory + Reset + Echo Off + Write
|
sendAT(GF("&FZE0&W")); // Factory + Reset + Echo Off + Write
|
||||||
@@ -209,17 +189,7 @@ public:
|
|||||||
return waitResponse() == 1;
|
return waitResponse() == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
String getModemInfo() {
|
TINY_GSM_MODEM_GET_INFO_ATI()
|
||||||
sendAT(GF("I"));
|
|
||||||
String res;
|
|
||||||
if (waitResponse(1000L, res) != 1) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
res.replace(GSM_NL "OK" GSM_NL, "");
|
|
||||||
res.replace(GSM_NL, " ");
|
|
||||||
res.trim();
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool hasSSL() {
|
bool hasSSL() {
|
||||||
return false; // TODO: For now
|
return false; // TODO: For now
|
||||||
@@ -268,14 +238,11 @@ public:
|
|||||||
* SIM card functions
|
* SIM card functions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
bool simUnlock(const char *pin) {
|
TINY_GSM_MODEM_SIM_UNLOCK_CPIN()
|
||||||
sendAT(GF("+CPIN=\""), pin, GF("\""));
|
|
||||||
return waitResponse() == 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
String getSimCCID() {
|
String getSimCCID() {
|
||||||
sendAT(GF("+ICCID"));
|
sendAT(GF("+QCCID"));
|
||||||
if (waitResponse(GF(GSM_NL "+ICCID:")) != 1) {
|
if (waitResponse(GF(GSM_NL "+QCCID:")) != 1) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
String res = stream.readStringUntil('\n');
|
String res = stream.readStringUntil('\n');
|
||||||
@@ -284,16 +251,7 @@ public:
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
String getIMEI() {
|
TINY_GSM_MODEM_GET_IMEI_GSN()
|
||||||
sendAT(GF("+GSN"));
|
|
||||||
if (waitResponse(GF(GSM_NL)) != 1) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
String res = stream.readStringUntil('\n');
|
|
||||||
waitResponse();
|
|
||||||
res.trim();
|
|
||||||
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; ) {
|
||||||
@@ -314,56 +272,22 @@ public:
|
|||||||
return SIM_ERROR;
|
return SIM_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
RegStatus getRegistrationStatus() {
|
TINY_GSM_MODEM_GET_REGISTRATION_XREG(CREG)
|
||||||
sendAT(GF("+CREG?"));
|
|
||||||
if (waitResponse(GF(GSM_NL "+CREG:")) != 1) {
|
|
||||||
return REG_UNKNOWN;
|
|
||||||
}
|
|
||||||
streamSkipUntil(','); // Skip format (0)
|
|
||||||
int status = stream.readStringUntil('\n').toInt();
|
|
||||||
waitResponse();
|
|
||||||
return (RegStatus)status;
|
|
||||||
}
|
|
||||||
|
|
||||||
String getOperator() {
|
TINY_GSM_MODEM_GET_OPERATOR_COPS()
|
||||||
sendAT(GF("+COPS?"));
|
|
||||||
if (waitResponse(GF(GSM_NL "+COPS:")) != 1) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
streamSkipUntil('"'); // Skip mode and format
|
|
||||||
String res = stream.readStringUntil('"');
|
|
||||||
waitResponse();
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Generic network functions
|
* Generic network functions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int16_t getSignalQuality() {
|
TINY_GSP_MODEM_GET_CSQ()
|
||||||
sendAT(GF("+CSQ"));
|
|
||||||
if (waitResponse(GF(GSM_NL "+CSQ:")) != 1) {
|
|
||||||
return 99;
|
|
||||||
}
|
|
||||||
int res = stream.readStringUntil(',').toInt();
|
|
||||||
waitResponse();
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isNetworkConnected() {
|
bool isNetworkConnected() {
|
||||||
RegStatus s = getRegistrationStatus();
|
RegStatus s = getRegistrationStatus();
|
||||||
return (s == REG_OK_HOME || s == REG_OK_ROAMING);
|
return (s == REG_OK_HOME || s == REG_OK_ROAMING);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool waitForNetwork(unsigned long timeout = 60000L) {
|
TINY_GSM_MODEM_WAIT_FOR_NETWORK()
|
||||||
for (unsigned long start = millis(); millis() - start < timeout; ) {
|
|
||||||
if (isNetworkConnected()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
delay(250);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* GPRS functions
|
* GPRS functions
|
||||||
@@ -400,18 +324,7 @@ public:
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isGprsConnected() {
|
TINY_GSP_MODEM_GET_GPRS_IP_CONNECTED()
|
||||||
sendAT(GF("+CGATT?"));
|
|
||||||
if (waitResponse(GF(GSM_NL "+CGATT:")) != 1) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
int res = stream.readStringUntil('\n').toInt();
|
|
||||||
waitResponse();
|
|
||||||
if (res != 1)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return localIP() != IPAddress(0,0,0,0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* IP Address functions
|
* IP Address functions
|
||||||
@@ -646,37 +559,7 @@ public:
|
|||||||
Utilities
|
Utilities
|
||||||
*/
|
*/
|
||||||
|
|
||||||
template<typename T>
|
TINY_GSP_MODEM_STREAM_UTILITIES()
|
||||||
void streamWrite(T last) {
|
|
||||||
stream.print(last);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T, typename... Args>
|
|
||||||
void streamWrite(T head, Args... tail) {
|
|
||||||
stream.print(head);
|
|
||||||
streamWrite(tail...);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename... Args>
|
|
||||||
void sendAT(Args... cmd) {
|
|
||||||
streamWrite("AT", cmd..., GSM_NL);
|
|
||||||
stream.flush();
|
|
||||||
TINY_GSM_YIELD();
|
|
||||||
//DBG("### AT:", cmd...);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool streamSkipUntil(const char c, const unsigned long timeout = 1000L) {
|
|
||||||
unsigned long startMillis = millis();
|
|
||||||
while (millis() - startMillis < timeout) {
|
|
||||||
while (millis() - startMillis < timeout && !stream.available()) {
|
|
||||||
TINY_GSM_YIELD();
|
|
||||||
}
|
|
||||||
if (stream.read() == c) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: Optimize this!
|
// TODO: Optimize this!
|
||||||
uint8_t waitResponse(uint32_t timeout, String& data,
|
uint8_t waitResponse(uint32_t timeout, String& data,
|
||||||
|
@@ -173,18 +173,9 @@ public:
|
|||||||
sendAT(GF("+UART_CUR="), baud, "8,1,0,0");
|
sendAT(GF("+UART_CUR="), baud, "8,1,0,0");
|
||||||
}
|
}
|
||||||
|
|
||||||
bool testAT(unsigned long timeout = 10000L) {
|
TINY_GSM_MODEM_TEST_AT()
|
||||||
for (unsigned long start = millis(); millis() - start < timeout; ) {
|
|
||||||
sendAT(GF(""));
|
|
||||||
if (waitResponse(200) == 1) return true;
|
|
||||||
delay(100);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void maintain() {
|
TINY_GSM_MODEM_MAINTAIN_LISTEN()
|
||||||
waitResponse(10, NULL, NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool factoryDefault() {
|
bool factoryDefault() {
|
||||||
sendAT(GF("+RESTORE"));
|
sendAT(GF("+RESTORE"));
|
||||||
@@ -378,37 +369,7 @@ public:
|
|||||||
Utilities
|
Utilities
|
||||||
*/
|
*/
|
||||||
|
|
||||||
template<typename T>
|
TINY_GSP_MODEM_STREAM_UTILITIES()
|
||||||
void streamWrite(T last) {
|
|
||||||
stream.print(last);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T, typename... Args>
|
|
||||||
void streamWrite(T head, Args... tail) {
|
|
||||||
stream.print(head);
|
|
||||||
streamWrite(tail...);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename... Args>
|
|
||||||
void sendAT(Args... cmd) {
|
|
||||||
streamWrite("AT", cmd..., GSM_NL);
|
|
||||||
stream.flush();
|
|
||||||
TINY_GSM_YIELD();
|
|
||||||
//DBG("### AT:", cmd...);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool streamSkipUntil(const char c, const unsigned long timeout = 1000L) {
|
|
||||||
unsigned long startMillis = millis();
|
|
||||||
while (millis() - startMillis < timeout) {
|
|
||||||
while (millis() - startMillis < timeout && !stream.available()) {
|
|
||||||
TINY_GSM_YIELD();
|
|
||||||
}
|
|
||||||
if (stream.read() == c) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: Optimize this!
|
// TODO: Optimize this!
|
||||||
uint8_t waitResponse(uint32_t timeout, String& data,
|
uint8_t waitResponse(uint32_t timeout, String& data,
|
||||||
|
@@ -143,24 +143,11 @@ public:
|
|||||||
return "Neoway M590";
|
return "Neoway M590";
|
||||||
}
|
}
|
||||||
|
|
||||||
void setBaud(unsigned long baud) {
|
TINY_GSM_MODEM_SET_BAUD_IPR()
|
||||||
sendAT(GF("+IPR="), baud);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool testAT(unsigned long timeout = 10000L) {
|
TINY_GSM_MODEM_TEST_AT()
|
||||||
for (unsigned long start = millis(); millis() - start < timeout; ) {
|
|
||||||
sendAT(GF(""));
|
|
||||||
if (waitResponse(200) == 1) return true;
|
|
||||||
delay(100);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void maintain() {
|
TINY_GSM_MODEM_MAINTAIN_LISTEN()
|
||||||
//while (stream.available()) {
|
|
||||||
waitResponse(10, NULL, NULL);
|
|
||||||
//}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool factoryDefault() {
|
bool factoryDefault() {
|
||||||
sendAT(GF("&FZE0&W")); // Factory + Reset + Echo Off + Write
|
sendAT(GF("&FZE0&W")); // Factory + Reset + Echo Off + Write
|
||||||
@@ -175,17 +162,7 @@ public:
|
|||||||
return waitResponse() == 1;
|
return waitResponse() == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
String getModemInfo() {
|
TINY_GSM_MODEM_GET_INFO_ATI()
|
||||||
sendAT(GF("I"));
|
|
||||||
String res;
|
|
||||||
if (waitResponse(1000L, res) != 1) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
res.replace(GSM_NL "OK" GSM_NL, "");
|
|
||||||
res.replace(GSM_NL, " ");
|
|
||||||
res.trim();
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool hasSSL() {
|
bool hasSSL() {
|
||||||
return false;
|
return false;
|
||||||
@@ -232,32 +209,11 @@ public:
|
|||||||
* SIM card functions
|
* SIM card functions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
bool simUnlock(const char *pin) {
|
TINY_GSM_MODEM_SIM_UNLOCK_CPIN()
|
||||||
sendAT(GF("+CPIN=\""), pin, GF("\""));
|
|
||||||
return waitResponse() == 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
String getSimCCID() {
|
TINY_GSM_MODEM_GET_SIMCCID_CCID()
|
||||||
sendAT(GF("+CCID"));
|
|
||||||
if (waitResponse(GF(GSM_NL "+CCID:")) != 1) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
String res = stream.readStringUntil('\n');
|
|
||||||
waitResponse();
|
|
||||||
res.trim();
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
String getIMEI() {
|
TINY_GSM_MODEM_GET_IMEI_GSN()
|
||||||
sendAT(GF("+GSN"));
|
|
||||||
if (waitResponse(GF(GSM_NL)) != 1) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
String res = stream.readStringUntil('\n');
|
|
||||||
waitResponse();
|
|
||||||
res.trim();
|
|
||||||
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; ) {
|
||||||
@@ -278,56 +234,22 @@ public:
|
|||||||
return SIM_ERROR;
|
return SIM_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
RegStatus getRegistrationStatus() {
|
TINY_GSM_MODEM_GET_REGISTRATION_XREG(CREG)
|
||||||
sendAT(GF("+CREG?"));
|
|
||||||
if (waitResponse(GF(GSM_NL "+CREG:")) != 1) {
|
|
||||||
return REG_UNKNOWN;
|
|
||||||
}
|
|
||||||
streamSkipUntil(','); // Skip format (0)
|
|
||||||
int status = stream.readStringUntil('\n').toInt();
|
|
||||||
waitResponse();
|
|
||||||
return (RegStatus)status;
|
|
||||||
}
|
|
||||||
|
|
||||||
String getOperator() {
|
TINY_GSM_MODEM_GET_OPERATOR_COPS()
|
||||||
sendAT(GF("+COPS?"));
|
|
||||||
if (waitResponse(GF(GSM_NL "+COPS:")) != 1) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
streamSkipUntil('"'); // Skip mode and format
|
|
||||||
String res = stream.readStringUntil('"');
|
|
||||||
waitResponse();
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Generic network functions
|
* Generic network functions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int16_t getSignalQuality() {
|
TINY_GSP_MODEM_GET_CSQ()
|
||||||
sendAT(GF("+CSQ"));
|
|
||||||
if (waitResponse(GF(GSM_NL "+CSQ:")) != 1) {
|
|
||||||
return 99;
|
|
||||||
}
|
|
||||||
int res = stream.readStringUntil(',').toInt();
|
|
||||||
waitResponse();
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isNetworkConnected() {
|
bool isNetworkConnected() {
|
||||||
RegStatus s = getRegistrationStatus();
|
RegStatus s = getRegistrationStatus();
|
||||||
return (s == REG_OK_HOME || s == REG_OK_ROAMING);
|
return (s == REG_OK_HOME || s == REG_OK_ROAMING);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool waitForNetwork(unsigned long timeout = 60000L) {
|
TINY_GSM_MODEM_WAIT_FOR_NETWORK()
|
||||||
for (unsigned long start = millis(); millis() - start < timeout; ) {
|
|
||||||
if (isNetworkConnected()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
delay(250);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* GPRS functions
|
* GPRS functions
|
||||||
@@ -545,37 +467,7 @@ public:
|
|||||||
Utilities
|
Utilities
|
||||||
*/
|
*/
|
||||||
|
|
||||||
template<typename T>
|
TINY_GSP_MODEM_STREAM_UTILITIES()
|
||||||
void streamWrite(T last) {
|
|
||||||
stream.print(last);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T, typename... Args>
|
|
||||||
void streamWrite(T head, Args... tail) {
|
|
||||||
stream.print(head);
|
|
||||||
streamWrite(tail...);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename... Args>
|
|
||||||
void sendAT(Args... cmd) {
|
|
||||||
streamWrite("AT", cmd..., GSM_NL);
|
|
||||||
stream.flush();
|
|
||||||
TINY_GSM_YIELD();
|
|
||||||
//DBG("### AT:", cmd...);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool streamSkipUntil(const char c, const unsigned long timeout = 1000L) {
|
|
||||||
unsigned long startMillis = millis();
|
|
||||||
while (millis() - startMillis < timeout) {
|
|
||||||
while (millis() - startMillis < timeout && !stream.available()) {
|
|
||||||
TINY_GSM_YIELD();
|
|
||||||
}
|
|
||||||
if (stream.read() == c) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: Optimize this!
|
// TODO: Optimize this!
|
||||||
uint8_t waitResponse(uint32_t timeout, String& data,
|
uint8_t waitResponse(uint32_t timeout, String& data,
|
||||||
|
@@ -178,31 +178,11 @@ public:
|
|||||||
return "Quectel M95";
|
return "Quectel M95";
|
||||||
}
|
}
|
||||||
|
|
||||||
void setBaud(unsigned long baud) {
|
TINY_GSM_MODEM_SET_BAUD_IPR()
|
||||||
sendAT(GF("+IPR="), baud);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool testAT(unsigned long timeout = 10000L) {
|
TINY_GSM_MODEM_TEST_AT()
|
||||||
for (unsigned long start = millis(); millis() - start < timeout; ) {
|
|
||||||
sendAT(GF(""));
|
|
||||||
if (waitResponse(200) == 1) return true;
|
|
||||||
delay(100);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void maintain() {
|
TINY_GSM_MODEM_MAINTAIN_CHECK_SOCKS()
|
||||||
for (int mux = 0; mux < TINY_GSM_MUX_COUNT; mux++) {
|
|
||||||
GsmClient* sock = sockets[mux];
|
|
||||||
if (sock && sock->got_data) {
|
|
||||||
sock->got_data = false;
|
|
||||||
sock->sock_available = modemGetAvailable(mux);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
while (stream.available()) {
|
|
||||||
waitResponse(10, NULL, NULL);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool factoryDefault() {
|
bool factoryDefault() {
|
||||||
sendAT(GF("&FZE0&W")); // Factory + Reset + Echo Off + Write
|
sendAT(GF("&FZE0&W")); // Factory + Reset + Echo Off + Write
|
||||||
@@ -213,17 +193,7 @@ public:
|
|||||||
return waitResponse() == 1;
|
return waitResponse() == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
String getModemInfo() {
|
TINY_GSM_MODEM_GET_INFO_ATI()
|
||||||
sendAT(GF("I"));
|
|
||||||
String res;
|
|
||||||
if (waitResponse(1000L, res) != 1) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
res.replace(GSM_NL "OK" GSM_NL, "");
|
|
||||||
res.replace(GSM_NL, " ");
|
|
||||||
res.trim();
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool hasSSL() {
|
bool hasSSL() {
|
||||||
return false; // TODO: For now
|
return false; // TODO: For now
|
||||||
@@ -276,14 +246,11 @@ public:
|
|||||||
* SIM card functions
|
* SIM card functions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
bool simUnlock(const char *pin) {
|
TINY_GSM_MODEM_SIM_UNLOCK_CPIN()
|
||||||
sendAT(GF("+CPIN=\""), pin, GF("\""));
|
|
||||||
return waitResponse() == 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
String getSimCCID() {
|
String getSimCCID() {
|
||||||
sendAT(GF("+ICCID"));
|
sendAT(GF("+QCCID"));
|
||||||
if (waitResponse(GF(GSM_NL "+ICCID:")) != 1) {
|
if (waitResponse(GF(GSM_NL "+QCCID:")) != 1) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
String res = stream.readStringUntil('\n');
|
String res = stream.readStringUntil('\n');
|
||||||
@@ -292,16 +259,7 @@ public:
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
String getIMEI() {
|
TINY_GSM_MODEM_GET_IMEI_GSN()
|
||||||
sendAT(GF("+GSN"));
|
|
||||||
if (waitResponse(GF(GSM_NL)) != 1) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
String res = stream.readStringUntil('\n');
|
|
||||||
waitResponse();
|
|
||||||
res.trim();
|
|
||||||
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; ) {
|
||||||
@@ -322,41 +280,15 @@ public:
|
|||||||
return SIM_ERROR;
|
return SIM_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
RegStatus getRegistrationStatus() {
|
TINY_GSM_MODEM_GET_REGISTRATION_XREG(CREG)
|
||||||
sendAT(GF("+CREG?"));
|
|
||||||
if (waitResponse(GF(GSM_NL "+CREG:")) != 1) {
|
|
||||||
return REG_UNKNOWN;
|
|
||||||
}
|
|
||||||
streamSkipUntil(','); // Skip format (0)
|
|
||||||
int status = stream.readStringUntil('\n').toInt();
|
|
||||||
waitResponse();
|
|
||||||
return (RegStatus)status;
|
|
||||||
}
|
|
||||||
|
|
||||||
String getOperator() {
|
TINY_GSM_MODEM_GET_OPERATOR_COPS()
|
||||||
sendAT(GF("+COPS?"));
|
|
||||||
if (waitResponse(GF(GSM_NL "+COPS:")) != 1) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
streamSkipUntil('"'); // Skip mode and format
|
|
||||||
String res = stream.readStringUntil('"');
|
|
||||||
waitResponse();
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Generic network functions
|
* Generic network functions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int16_t getSignalQuality() {
|
TINY_GSP_MODEM_GET_CSQ()
|
||||||
sendAT(GF("+CSQ"));
|
|
||||||
if (waitResponse(GF(GSM_NL "+CSQ:")) != 1) {
|
|
||||||
return 99;
|
|
||||||
}
|
|
||||||
int res = stream.readStringUntil(',').toInt();
|
|
||||||
waitResponse();
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isNetworkConnected() {
|
bool isNetworkConnected() {
|
||||||
RegStatus s = getRegistrationStatus();
|
RegStatus s = getRegistrationStatus();
|
||||||
@@ -372,15 +304,7 @@ public:
|
|||||||
waitResponse();
|
waitResponse();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool waitForNetwork(unsigned long timeout = 60000L) {
|
TINY_GSM_MODEM_WAIT_FOR_NETWORK()
|
||||||
for (unsigned long start = millis(); millis() - start < timeout; ) {
|
|
||||||
if (isNetworkConnected()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
delay(250);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* GPRS functions
|
* GPRS functions
|
||||||
@@ -438,18 +362,7 @@ public:
|
|||||||
return waitResponse(60000L, GF("DEACT OK"), GF("ERROR")) == 1;
|
return waitResponse(60000L, GF("DEACT OK"), GF("ERROR")) == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isGprsConnected() {
|
TINY_GSP_MODEM_GET_GPRS_IP_CONNECTED()
|
||||||
sendAT(GF("+CGATT?"));
|
|
||||||
if (waitResponse(GF(GSM_NL "+CGATT:")) != 1) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
int res = stream.readStringUntil('\n').toInt();
|
|
||||||
waitResponse();
|
|
||||||
if (res != 1)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return localIP() != IPAddress(0,0,0,0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* IP Address functions
|
* IP Address functions
|
||||||
@@ -701,37 +614,7 @@ public:
|
|||||||
Utilities
|
Utilities
|
||||||
*/
|
*/
|
||||||
|
|
||||||
template<typename T>
|
TINY_GSP_MODEM_STREAM_UTILITIES()
|
||||||
void streamWrite(T last) {
|
|
||||||
stream.print(last);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T, typename... Args>
|
|
||||||
void streamWrite(T head, Args... tail) {
|
|
||||||
stream.print(head);
|
|
||||||
streamWrite(tail...);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename... Args>
|
|
||||||
void sendAT(Args... cmd) {
|
|
||||||
streamWrite("AT", cmd..., GSM_NL);
|
|
||||||
stream.flush();
|
|
||||||
TINY_GSM_YIELD();
|
|
||||||
//DBG("### AT:", cmd...);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool streamSkipUntil(const char c, const unsigned long timeout = 1000L) {
|
|
||||||
unsigned long startMillis = millis();
|
|
||||||
while (millis() - startMillis < timeout) {
|
|
||||||
while (millis() - startMillis < timeout && !stream.available()) {
|
|
||||||
TINY_GSM_YIELD();
|
|
||||||
}
|
|
||||||
if (stream.read() == c) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: Optimize this!
|
// TODO: Optimize this!
|
||||||
uint8_t waitResponse(uint32_t timeout, String& data,
|
uint8_t waitResponse(uint32_t timeout, String& data,
|
||||||
|
@@ -185,31 +185,11 @@ public:
|
|||||||
return "Quectel MC60";
|
return "Quectel MC60";
|
||||||
}
|
}
|
||||||
|
|
||||||
void setBaud(unsigned long baud) {
|
TINY_GSM_MODEM_SET_BAUD_IPR()
|
||||||
sendAT(GF("+IPR="), baud);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool testAT(unsigned long timeout = 10000L) {
|
TINY_GSM_MODEM_TEST_AT()
|
||||||
for (unsigned long start = millis(); millis() - start < timeout; ) {
|
|
||||||
sendAT(GF(""));
|
|
||||||
if (waitResponse(200) == 1) return true;
|
|
||||||
delay(100);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void maintain() {
|
TINY_GSM_MODEM_MAINTAIN_CHECK_SOCKS()
|
||||||
for (int mux = 0; mux < TINY_GSM_MUX_COUNT; mux++) {
|
|
||||||
GsmClient* sock = sockets[mux];
|
|
||||||
if (sock && sock->got_data) {
|
|
||||||
sock->got_data = false;
|
|
||||||
sock->sock_available = modemGetAvailable(mux);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
while (stream.available()) {
|
|
||||||
waitResponse(10, NULL, NULL);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool factoryDefault() {
|
bool factoryDefault() {
|
||||||
sendAT(GF("&FZE0&W")); // Factory + Reset + Echo Off + Write
|
sendAT(GF("&FZE0&W")); // Factory + Reset + Echo Off + Write
|
||||||
@@ -220,17 +200,7 @@ public:
|
|||||||
return waitResponse() == 1;
|
return waitResponse() == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
String getModemInfo() {
|
TINY_GSM_MODEM_GET_INFO_ATI()
|
||||||
sendAT(GF("I"));
|
|
||||||
String res;
|
|
||||||
if (waitResponse(1000L, res) != 1) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
res.replace(GSM_NL "OK" GSM_NL, "");
|
|
||||||
res.replace(GSM_NL, " ");
|
|
||||||
res.trim();
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* under development
|
* under development
|
||||||
@@ -298,32 +268,11 @@ public:
|
|||||||
* SIM card functions
|
* SIM card functions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
bool simUnlock(const char *pin) {
|
TINY_GSM_MODEM_SIM_UNLOCK_CPIN()
|
||||||
sendAT(GF("+CPIN=\""), pin, GF("\""));
|
|
||||||
return waitResponse() == 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
String getSimCCID() {
|
TINY_GSM_MODEM_GET_SIMCCID_CCID()
|
||||||
sendAT(GF("+ICCID"));
|
|
||||||
if (waitResponse(GF(GSM_NL "+ICCID:")) != 1) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
String res = stream.readStringUntil('\n');
|
|
||||||
waitResponse();
|
|
||||||
res.trim();
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
String getIMEI() {
|
TINY_GSM_MODEM_GET_IMEI_GSN()
|
||||||
sendAT(GF("+GSN"));
|
|
||||||
if (waitResponse(GF(GSM_NL)) != 1) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
String res = stream.readStringUntil('\n');
|
|
||||||
waitResponse();
|
|
||||||
res.trim();
|
|
||||||
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; ) {
|
||||||
@@ -346,56 +295,22 @@ public:
|
|||||||
return SIM_ERROR;
|
return SIM_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
RegStatus getRegistrationStatus() {
|
TINY_GSM_MODEM_GET_REGISTRATION_XREG(CREG)
|
||||||
sendAT(GF("+CREG?"));
|
|
||||||
if (waitResponse(GF(GSM_NL "+CREG:")) != 1) {
|
|
||||||
return REG_UNKNOWN;
|
|
||||||
}
|
|
||||||
streamSkipUntil(','); // Skip format (0)
|
|
||||||
int status = stream.readStringUntil('\n').toInt();
|
|
||||||
waitResponse();
|
|
||||||
return (RegStatus)status;
|
|
||||||
}
|
|
||||||
|
|
||||||
String getOperator() {
|
TINY_GSM_MODEM_GET_OPERATOR_COPS()
|
||||||
sendAT(GF("+COPS?"));
|
|
||||||
if (waitResponse(GF(GSM_NL "+COPS:")) != 1) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
streamSkipUntil('"'); // Skip mode and format
|
|
||||||
String res = stream.readStringUntil('"');
|
|
||||||
waitResponse();
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Generic network functions
|
* Generic network functions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int16_t getSignalQuality() {
|
TINY_GSP_MODEM_GET_CSQ()
|
||||||
sendAT(GF("+CSQ"));
|
|
||||||
if (waitResponse(GF(GSM_NL "+CSQ:")) != 1) {
|
|
||||||
return 99;
|
|
||||||
}
|
|
||||||
int res = stream.readStringUntil(',').toInt();
|
|
||||||
waitResponse();
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isNetworkConnected() {
|
bool isNetworkConnected() {
|
||||||
RegStatus s = getRegistrationStatus();
|
RegStatus s = getRegistrationStatus();
|
||||||
return (s == REG_OK_HOME || s == REG_OK_ROAMING);
|
return (s == REG_OK_HOME || s == REG_OK_ROAMING);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool waitForNetwork(unsigned long timeout = 60000L) {
|
TINY_GSM_MODEM_WAIT_FOR_NETWORK()
|
||||||
for (unsigned long start = millis(); millis() - start < timeout; ) {
|
|
||||||
if (isNetworkConnected()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
delay(250);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* GPRS functions
|
* GPRS functions
|
||||||
@@ -466,18 +381,7 @@ public:
|
|||||||
return waitResponse(60000L, GF("DEACT OK"), GF("ERROR")) == 1;
|
return waitResponse(60000L, GF("DEACT OK"), GF("ERROR")) == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isGprsConnected() {
|
TINY_GSP_MODEM_GET_GPRS_IP_CONNECTED()
|
||||||
sendAT(GF("+CGATT?"));
|
|
||||||
if (waitResponse(GF(GSM_NL "+CGATT:")) != 1) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
int res = stream.readStringUntil('\n').toInt();
|
|
||||||
waitResponse();
|
|
||||||
if (res != 1)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return localIP() != IPAddress(0,0,0,0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* IP Address functions
|
* IP Address functions
|
||||||
@@ -730,37 +634,7 @@ public:
|
|||||||
Utilities
|
Utilities
|
||||||
*/
|
*/
|
||||||
|
|
||||||
template<typename T>
|
TINY_GSP_MODEM_STREAM_UTILITIES()
|
||||||
void streamWrite(T last) {
|
|
||||||
stream.print(last);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T, typename... Args>
|
|
||||||
void streamWrite(T head, Args... tail) {
|
|
||||||
stream.print(head);
|
|
||||||
streamWrite(tail...);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename... Args>
|
|
||||||
void sendAT(Args... cmd) {
|
|
||||||
streamWrite("AT", cmd..., GSM_NL);
|
|
||||||
stream.flush();
|
|
||||||
TINY_GSM_YIELD();
|
|
||||||
//DBG("### AT:", cmd...);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool streamSkipUntil(const char c, const unsigned long timeout = 1000L) {
|
|
||||||
unsigned long startMillis = millis();
|
|
||||||
while (millis() - startMillis < timeout) {
|
|
||||||
while (millis() - startMillis < timeout && !stream.available()) {
|
|
||||||
TINY_GSM_YIELD();
|
|
||||||
}
|
|
||||||
if (stream.read() == c) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: Optimize this!
|
// TODO: Optimize this!
|
||||||
uint8_t waitResponse(uint32_t timeout, String& data,
|
uint8_t waitResponse(uint32_t timeout, String& data,
|
||||||
|
@@ -187,48 +187,17 @@ public:
|
|||||||
return "SIMCom SIM7000";
|
return "SIMCom SIM7000";
|
||||||
}
|
}
|
||||||
|
|
||||||
void setBaud(unsigned long baud) {
|
TINY_GSM_MODEM_SET_BAUD_IPR()
|
||||||
sendAT(GF("+IPR="), baud);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool testAT(unsigned long timeout = 10000L) {
|
TINY_GSM_MODEM_TEST_AT()
|
||||||
//streamWrite(GF("AAAAA" GSM_NL)); // TODO: extra A's to help detect the baud rate
|
|
||||||
for (unsigned long start = millis(); millis() - start < timeout; ) {
|
|
||||||
sendAT(GF(""));
|
|
||||||
if (waitResponse(200) == 1) return true;
|
|
||||||
delay(100);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void maintain() {
|
TINY_GSM_MODEM_MAINTAIN_CHECK_SOCKS()
|
||||||
for (int mux = 0; mux < TINY_GSM_MUX_COUNT; mux++) {
|
|
||||||
GsmClient* sock = sockets[mux];
|
|
||||||
if (sock && sock->got_data) {
|
|
||||||
sock->got_data = false;
|
|
||||||
sock->sock_available = modemGetAvailable(mux);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
while (stream.available()) {
|
|
||||||
waitResponse(10, NULL, NULL);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool factoryDefault() { // these commands aren't supported
|
bool factoryDefault() { // these commands aren't supported
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
String getModemInfo() {
|
TINY_GSM_MODEM_GET_INFO_ATI()
|
||||||
sendAT(GF("I"));
|
|
||||||
String res;
|
|
||||||
if (waitResponse(1000L, res) != 1) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
res.replace(GSM_NL "OK" GSM_NL, "");
|
|
||||||
res.replace(GSM_NL, " ");
|
|
||||||
res.trim();
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool hasSSL() {
|
bool hasSSL() {
|
||||||
return false; // TODO: Module supports SSL, but not yet implemented
|
return false; // TODO: Module supports SSL, but not yet implemented
|
||||||
@@ -297,32 +266,11 @@ public:
|
|||||||
* SIM card functions
|
* SIM card functions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
bool simUnlock(const char *pin) {
|
TINY_GSM_MODEM_SIM_UNLOCK_CPIN()
|
||||||
sendAT(GF("+CPIN=\""), pin, GF("\""));
|
|
||||||
return waitResponse() == 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
String getSimCCID() {
|
TINY_GSM_MODEM_GET_SIMCCID_CCID()
|
||||||
sendAT(GF("+ICCID"));
|
|
||||||
if (waitResponse(GF(GSM_NL "+ICCID:")) != 1) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
String res = stream.readStringUntil('\n');
|
|
||||||
waitResponse();
|
|
||||||
res.trim();
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
String getIMEI() {
|
TINY_GSM_MODEM_GET_IMEI_GSN()
|
||||||
sendAT(GF("+GSN"));
|
|
||||||
if (waitResponse(GF(GSM_NL)) != 1) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
String res = stream.readStringUntil('\n');
|
|
||||||
waitResponse();
|
|
||||||
res.trim();
|
|
||||||
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; ) {
|
||||||
@@ -343,42 +291,15 @@ public:
|
|||||||
return SIM_ERROR;
|
return SIM_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
RegStatus getRegistrationStatus() {
|
TINY_GSM_MODEM_GET_REGISTRATION_XREG(CGREG)
|
||||||
sendAT(GF("+CGREG?"));
|
|
||||||
// TODO: Shouldn't this be CEREG for the EPS status of this 4G module?
|
|
||||||
if (waitResponse(GF(GSM_NL "+CGREG:")) != 1) {
|
|
||||||
return REG_UNKNOWN;
|
|
||||||
}
|
|
||||||
streamSkipUntil(','); // Skip format (0)
|
|
||||||
int status = stream.readStringUntil('\n').toInt();
|
|
||||||
waitResponse();
|
|
||||||
return (RegStatus)status;
|
|
||||||
}
|
|
||||||
|
|
||||||
String getOperator() {
|
TINY_GSM_MODEM_GET_OPERATOR_COPS()
|
||||||
sendAT(GF("+COPS?"));
|
|
||||||
if (waitResponse(GF(GSM_NL "+COPS:")) != 1) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
streamSkipUntil('"'); // Skip mode and format
|
|
||||||
String res = stream.readStringUntil('"');
|
|
||||||
waitResponse();
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Generic network functions
|
* Generic network functions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int16_t getSignalQuality() {
|
TINY_GSP_MODEM_GET_CSQ()
|
||||||
sendAT(GF("+CSQ"));
|
|
||||||
if (waitResponse(GF(GSM_NL "+CSQ:")) != 1) {
|
|
||||||
return 99;
|
|
||||||
}
|
|
||||||
int res = stream.readStringUntil(',').toInt();
|
|
||||||
waitResponse();
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isNetworkConnected() {
|
bool isNetworkConnected() {
|
||||||
RegStatus s = getRegistrationStatus();
|
RegStatus s = getRegistrationStatus();
|
||||||
@@ -395,15 +316,7 @@ public:
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool waitForNetwork(unsigned long timeout = 60000L) {
|
TINY_GSM_MODEM_WAIT_FOR_NETWORK()
|
||||||
for (unsigned long start = millis(); millis() - start < timeout; ) {
|
|
||||||
if (isNetworkConnected()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
delay(250);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
String setNetworkMode(uint8_t mode) {
|
String setNetworkMode(uint8_t mode) {
|
||||||
sendAT(GF("+CNMP="), mode);
|
sendAT(GF("+CNMP="), mode);
|
||||||
@@ -944,37 +857,7 @@ public:
|
|||||||
Utilities
|
Utilities
|
||||||
*/
|
*/
|
||||||
|
|
||||||
template<typename T>
|
TINY_GSP_MODEM_STREAM_UTILITIES()
|
||||||
void streamWrite(T last) {
|
|
||||||
stream.print(last);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T, typename... Args>
|
|
||||||
void streamWrite(T head, Args... tail) {
|
|
||||||
stream.print(head);
|
|
||||||
streamWrite(tail...);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename... Args>
|
|
||||||
void sendAT(Args... cmd) {
|
|
||||||
streamWrite("AT", cmd..., GSM_NL);
|
|
||||||
stream.flush();
|
|
||||||
TINY_GSM_YIELD();
|
|
||||||
//DBG("### AT:", cmd...);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool streamSkipUntil(const char c, const unsigned long timeout = 1000L) {
|
|
||||||
unsigned long startMillis = millis();
|
|
||||||
while (millis() - startMillis < timeout) {
|
|
||||||
while (millis() - startMillis < timeout && !stream.available()) {
|
|
||||||
TINY_GSM_YIELD();
|
|
||||||
}
|
|
||||||
if (stream.read() == c) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: Optimize this!
|
// TODO: Optimize this!
|
||||||
uint8_t waitResponse(uint32_t timeout, String& data,
|
uint8_t waitResponse(uint32_t timeout, String& data,
|
||||||
|
@@ -195,32 +195,11 @@ public:
|
|||||||
return "SIMCom SIM800";
|
return "SIMCom SIM800";
|
||||||
}
|
}
|
||||||
|
|
||||||
void setBaud(unsigned long baud) {
|
TINY_GSM_MODEM_SET_BAUD_IPR()
|
||||||
sendAT(GF("+IPR="), baud);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool testAT(unsigned long timeout = 10000L) {
|
TINY_GSM_MODEM_TEST_AT()
|
||||||
//streamWrite(GF("AAAAA" GSM_NL)); // TODO: extra A's to help detect the baud rate
|
|
||||||
for (unsigned long start = millis(); millis() - start < timeout; ) {
|
|
||||||
sendAT(GF(""));
|
|
||||||
if (waitResponse(200) == 1) return true;
|
|
||||||
delay(100);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void maintain() {
|
TINY_GSM_MODEM_MAINTAIN_CHECK_SOCKS()
|
||||||
for (int mux = 0; mux < TINY_GSM_MUX_COUNT; mux++) {
|
|
||||||
GsmClient* sock = sockets[mux];
|
|
||||||
if (sock && sock->got_data) {
|
|
||||||
sock->got_data = false;
|
|
||||||
sock->sock_available = modemGetAvailable(mux);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
while (stream.available()) {
|
|
||||||
waitResponse(10, NULL, NULL);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool factoryDefault() {
|
bool factoryDefault() {
|
||||||
sendAT(GF("&FZE0&W")); // Factory + Reset + Echo Off + Write
|
sendAT(GF("&FZE0&W")); // Factory + Reset + Echo Off + Write
|
||||||
@@ -237,17 +216,7 @@ public:
|
|||||||
return waitResponse() == 1;
|
return waitResponse() == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
String getModemInfo() {
|
TINY_GSM_MODEM_GET_INFO_ATI()
|
||||||
sendAT(GF("I"));
|
|
||||||
String res;
|
|
||||||
if (waitResponse(1000L, res) != 1) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
res.replace(GSM_NL "OK" GSM_NL, "");
|
|
||||||
res.replace(GSM_NL, " ");
|
|
||||||
res.trim();
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool hasSSL() {
|
bool hasSSL() {
|
||||||
#if defined(TINY_GSM_MODEM_SIM900)
|
#if defined(TINY_GSM_MODEM_SIM900)
|
||||||
@@ -325,32 +294,11 @@ public:
|
|||||||
* SIM card functions
|
* SIM card functions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
bool simUnlock(const char *pin) {
|
TINY_GSM_MODEM_SIM_UNLOCK_CPIN()
|
||||||
sendAT(GF("+CPIN=\""), pin, GF("\""));
|
|
||||||
return waitResponse() == 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
String getSimCCID() {
|
TINY_GSM_MODEM_GET_SIMCCID_CCID()
|
||||||
sendAT(GF("+ICCID"));
|
|
||||||
if (waitResponse(GF(GSM_NL "+ICCID:")) != 1) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
String res = stream.readStringUntil('\n');
|
|
||||||
waitResponse();
|
|
||||||
res.trim();
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
String getIMEI() {
|
TINY_GSM_MODEM_GET_IMEI_GSN()
|
||||||
sendAT(GF("+GSN"));
|
|
||||||
if (waitResponse(GF(GSM_NL)) != 1) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
String res = stream.readStringUntil('\n');
|
|
||||||
waitResponse();
|
|
||||||
res.trim();
|
|
||||||
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; ) {
|
||||||
@@ -371,56 +319,22 @@ public:
|
|||||||
return SIM_ERROR;
|
return SIM_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
RegStatus getRegistrationStatus() {
|
TINY_GSM_MODEM_GET_REGISTRATION_XREG(CREG)
|
||||||
sendAT(GF("+CREG?"));
|
|
||||||
if (waitResponse(GF(GSM_NL "+CREG:")) != 1) {
|
|
||||||
return REG_UNKNOWN;
|
|
||||||
}
|
|
||||||
streamSkipUntil(','); // Skip format (0)
|
|
||||||
int status = stream.readStringUntil('\n').toInt();
|
|
||||||
waitResponse();
|
|
||||||
return (RegStatus)status;
|
|
||||||
}
|
|
||||||
|
|
||||||
String getOperator() {
|
TINY_GSM_MODEM_GET_OPERATOR_COPS()
|
||||||
sendAT(GF("+COPS?"));
|
|
||||||
if (waitResponse(GF(GSM_NL "+COPS:")) != 1) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
streamSkipUntil('"'); // Skip mode and format
|
|
||||||
String res = stream.readStringUntil('"');
|
|
||||||
waitResponse();
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Generic network functions
|
* Generic network functions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int16_t getSignalQuality() {
|
TINY_GSP_MODEM_GET_CSQ()
|
||||||
sendAT(GF("+CSQ"));
|
|
||||||
if (waitResponse(GF(GSM_NL "+CSQ:")) != 1) {
|
|
||||||
return 99;
|
|
||||||
}
|
|
||||||
int res = stream.readStringUntil(',').toInt();
|
|
||||||
waitResponse();
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isNetworkConnected() {
|
bool isNetworkConnected() {
|
||||||
RegStatus s = getRegistrationStatus();
|
RegStatus s = getRegistrationStatus();
|
||||||
return (s == REG_OK_HOME || s == REG_OK_ROAMING);
|
return (s == REG_OK_HOME || s == REG_OK_ROAMING);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool waitForNetwork(unsigned long timeout = 60000L) {
|
TINY_GSM_MODEM_WAIT_FOR_NETWORK()
|
||||||
for (unsigned long start = millis(); millis() - start < timeout; ) {
|
|
||||||
if (isNetworkConnected()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
delay(250);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* GPRS functions
|
* GPRS functions
|
||||||
@@ -869,37 +783,7 @@ public:
|
|||||||
Utilities
|
Utilities
|
||||||
*/
|
*/
|
||||||
|
|
||||||
template<typename T>
|
TINY_GSP_MODEM_STREAM_UTILITIES()
|
||||||
void streamWrite(T last) {
|
|
||||||
stream.print(last);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T, typename... Args>
|
|
||||||
void streamWrite(T head, Args... tail) {
|
|
||||||
stream.print(head);
|
|
||||||
streamWrite(tail...);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename... Args>
|
|
||||||
void sendAT(Args... cmd) {
|
|
||||||
streamWrite("AT", cmd..., GSM_NL);
|
|
||||||
stream.flush();
|
|
||||||
TINY_GSM_YIELD();
|
|
||||||
//DBG("### AT:", cmd...);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool streamSkipUntil(const char c, const unsigned long timeout = 1000L) {
|
|
||||||
unsigned long startMillis = millis();
|
|
||||||
while (millis() - startMillis < timeout) {
|
|
||||||
while (millis() - startMillis < timeout && !stream.available()) {
|
|
||||||
TINY_GSM_YIELD();
|
|
||||||
}
|
|
||||||
if (stream.read() == c) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: Optimize this!
|
// TODO: Optimize this!
|
||||||
uint8_t waitResponse(uint32_t timeout, String& data,
|
uint8_t waitResponse(uint32_t timeout, String& data,
|
||||||
|
@@ -242,48 +242,18 @@ public:
|
|||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setBaud(unsigned long baud) {
|
TINY_GSM_MODEM_SET_BAUD_IPR()
|
||||||
sendAT(GF("+IPR="), baud);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool testAT(unsigned long timeout = 10000L) {
|
TINY_GSM_MODEM_TEST_AT()
|
||||||
for (unsigned long start = millis(); millis() - start < timeout; ) {
|
|
||||||
sendAT(GF(""));
|
|
||||||
if (waitResponse(200) == 1) return true;
|
|
||||||
delay(100);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void maintain() {
|
TINY_GSM_MODEM_MAINTAIN_CHECK_SOCKS()
|
||||||
for (int mux = 0; mux < TINY_GSM_MUX_COUNT; mux++) {
|
|
||||||
GsmClient* sock = sockets[mux];
|
|
||||||
if (sock && sock->got_data) {
|
|
||||||
sock->got_data = false;
|
|
||||||
sock->sock_available = modemGetAvailable(mux);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
while (stream.available()) {
|
|
||||||
waitResponse(15, NULL, NULL);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool factoryDefault() {
|
bool factoryDefault() {
|
||||||
sendAT(GF("&F")); // Resets the current profile, other NVM not affected
|
sendAT(GF("&F")); // Resets the current profile, other NVM not affected
|
||||||
return waitResponse() == 1;
|
return waitResponse() == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
String getModemInfo() {
|
TINY_GSM_MODEM_GET_INFO_ATI()
|
||||||
sendAT(GF("I"));
|
|
||||||
String res;
|
|
||||||
if (waitResponse(1000L, res) != 1) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
res.replace(GSM_NL "OK" GSM_NL, "");
|
|
||||||
res.replace(GSM_NL, " ");
|
|
||||||
res.trim();
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool hasSSL() {
|
bool hasSSL() {
|
||||||
return true;
|
return true;
|
||||||
@@ -333,21 +303,9 @@ public:
|
|||||||
* SIM card functions
|
* SIM card functions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
bool simUnlock(const char *pin) {
|
TINY_GSM_MODEM_SIM_UNLOCK_CPIN()
|
||||||
sendAT(GF("+CPIN=\""), pin, GF("\""));
|
|
||||||
return waitResponse() == 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
String getSimCCID() {
|
TINY_GSM_MODEM_GET_SIMCCID_CCID()
|
||||||
sendAT(GF("+CCID"));
|
|
||||||
if (waitResponse(GF(GSM_NL "+CCID:")) != 1) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
String res = stream.readStringUntil('\n');
|
|
||||||
waitResponse();
|
|
||||||
res.trim();
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
String getIMEI() {
|
String getIMEI() {
|
||||||
sendAT(GF("+CGSN"));
|
sendAT(GF("+CGSN"));
|
||||||
@@ -379,42 +337,16 @@ public:
|
|||||||
return SIM_ERROR;
|
return SIM_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
RegStatus getRegistrationStatus() {
|
|
||||||
// Check EPS registration for LTE modules
|
|
||||||
sendAT(GF("+CEREG?"));
|
|
||||||
if (waitResponse(GF(GSM_NL "+CEREG:")) != 1) {
|
|
||||||
return REG_UNKNOWN;
|
|
||||||
}
|
|
||||||
streamSkipUntil(','); // Skip format (0)
|
|
||||||
int status = stream.readStringUntil('\n').toInt();
|
|
||||||
waitResponse();
|
|
||||||
return (RegStatus)status;
|
|
||||||
}
|
|
||||||
|
|
||||||
String getOperator() {
|
TINY_GSM_MODEM_GET_REGISTRATION_XREG(CEREG)
|
||||||
sendAT(GF("+COPS?"));
|
|
||||||
if (waitResponse(GF(GSM_NL "+COPS:")) != 1) {
|
TINY_GSM_MODEM_GET_OPERATOR_COPS()
|
||||||
return "";
|
|
||||||
}
|
|
||||||
streamSkipUntil('"'); // Skip mode and format
|
|
||||||
String res = stream.readStringUntil('"');
|
|
||||||
waitResponse();
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Generic network functions
|
* Generic network functions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int16_t getSignalQuality() {
|
TINY_GSP_MODEM_GET_CSQ()
|
||||||
sendAT(GF("+CSQ"));
|
|
||||||
if (waitResponse(GF(GSM_NL "+CSQ:")) != 1) {
|
|
||||||
return 99;
|
|
||||||
}
|
|
||||||
int res = stream.readStringUntil(',').toInt();
|
|
||||||
waitResponse();
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isNetworkConnected() {
|
bool isNetworkConnected() {
|
||||||
RegStatus s = getRegistrationStatus();
|
RegStatus s = getRegistrationStatus();
|
||||||
@@ -425,15 +357,7 @@ public:
|
|||||||
else return false;
|
else return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool waitForNetwork(unsigned long timeout = 60000L) {
|
TINY_GSM_MODEM_WAIT_FOR_NETWORK()
|
||||||
for (unsigned long start = millis(); millis() - start < timeout; ) {
|
|
||||||
if (isNetworkConnected()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
delay(250);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool setURAT( uint8_t urat ) {
|
bool setURAT( uint8_t urat ) {
|
||||||
// AT+URAT=<SelectedAcT>[,<PreferredAct>[,<2ndPreferredAct>]]
|
// AT+URAT=<SelectedAcT>[,<PreferredAct>[,<2ndPreferredAct>]]
|
||||||
@@ -500,18 +424,7 @@ public:
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isGprsConnected() {
|
TINY_GSP_MODEM_GET_GPRS_IP_CONNECTED()
|
||||||
sendAT(GF("+CGATT?"));
|
|
||||||
if (waitResponse(GF(GSM_NL "+CGATT:")) != 1) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
int res = stream.readStringUntil('\n').toInt();
|
|
||||||
waitResponse();
|
|
||||||
if (res != 1)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return localIP() != IPAddress(0,0,0,0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* IP Address functions
|
* IP Address functions
|
||||||
@@ -738,37 +651,7 @@ public:
|
|||||||
Utilities
|
Utilities
|
||||||
*/
|
*/
|
||||||
|
|
||||||
template<typename T>
|
TINY_GSP_MODEM_STREAM_UTILITIES()
|
||||||
void streamWrite(T last) {
|
|
||||||
stream.print(last);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T, typename... Args>
|
|
||||||
void streamWrite(T head, Args... tail) {
|
|
||||||
stream.print(head);
|
|
||||||
streamWrite(tail...);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename... Args>
|
|
||||||
void sendAT(Args... cmd) {
|
|
||||||
streamWrite("AT", cmd..., GSM_NL);
|
|
||||||
stream.flush();
|
|
||||||
TINY_GSM_YIELD();
|
|
||||||
//DBG("### AT:", cmd...);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool streamSkipUntil(const char c, const unsigned long timeout = 1000L) {
|
|
||||||
unsigned long startMillis = millis();
|
|
||||||
while (millis() - startMillis < timeout) {
|
|
||||||
while (millis() - startMillis < timeout && !stream.available()) {
|
|
||||||
TINY_GSM_YIELD();
|
|
||||||
}
|
|
||||||
if (stream.read() == c) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: Optimize this!
|
// TODO: Optimize this!
|
||||||
uint8_t waitResponse(uint32_t timeout, String& data,
|
uint8_t waitResponse(uint32_t timeout, String& data,
|
||||||
|
@@ -215,9 +215,7 @@ public:
|
|||||||
return "Sequans Monarch";
|
return "Sequans Monarch";
|
||||||
}
|
}
|
||||||
|
|
||||||
void setBaud(unsigned long baud) {
|
TINY_GSM_MODEM_SET_BAUD_IPR()
|
||||||
sendAT(GF("+IPR="), baud);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool testAT(unsigned long timeout = 10000L) {
|
bool testAT(unsigned long timeout = 10000L) {
|
||||||
for (unsigned long start = millis(); millis() - start < timeout; ) {
|
for (unsigned long start = millis(); millis() - start < timeout; ) {
|
||||||
@@ -231,18 +229,7 @@ public:
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void maintain() {
|
TINY_GSM_MODEM_MAINTAIN_CHECK_SOCKS()
|
||||||
for (int mux = 0; mux < TINY_GSM_MUX_COUNT; mux++) {
|
|
||||||
GsmClient* sock = sockets[mux];
|
|
||||||
if (sock && sock->got_data) {
|
|
||||||
sock->got_data = false;
|
|
||||||
sock->sock_available = modemGetAvailable(mux);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
while (stream.available()) {
|
|
||||||
waitResponse(10, NULL, NULL);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool factoryDefault() {
|
bool factoryDefault() {
|
||||||
sendAT(GF("&FZE0&W")); // Factory + Reset + Echo Off + Write
|
sendAT(GF("&FZE0&W")); // Factory + Reset + Echo Off + Write
|
||||||
@@ -259,17 +246,7 @@ public:
|
|||||||
return waitResponse() == 1;
|
return waitResponse() == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
String getModemInfo() {
|
TINY_GSM_MODEM_GET_INFO_ATI()
|
||||||
sendAT(GF("I"));
|
|
||||||
String res;
|
|
||||||
if (waitResponse(1000L, res) != 1) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
res.replace(GSM_NL "OK" GSM_NL, "");
|
|
||||||
res.replace(GSM_NL, " ");
|
|
||||||
res.trim();
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool hasSSL() {
|
bool hasSSL() {
|
||||||
return true;
|
return true;
|
||||||
@@ -325,10 +302,7 @@ public:
|
|||||||
* SIM card functions
|
* SIM card functions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
bool simUnlock(const char *pin) {
|
TINY_GSM_MODEM_SIM_UNLOCK_CPIN()
|
||||||
sendAT(GF("+CPIN=\""), pin, GF("\""));
|
|
||||||
return waitResponse() == 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
String getSimCCID() {
|
String getSimCCID() {
|
||||||
sendAT(GF("+SQNCCID"));
|
sendAT(GF("+SQNCCID"));
|
||||||
@@ -341,16 +315,7 @@ public:
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
String getIMEI() {
|
TINY_GSM_MODEM_GET_IMEI_GSN()
|
||||||
sendAT(GF("+GSN"));
|
|
||||||
if (waitResponse(GF(GSM_NL)) != 1) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
String res = stream.readStringUntil('\n');
|
|
||||||
waitResponse();
|
|
||||||
res.trim();
|
|
||||||
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; ) {
|
||||||
@@ -371,42 +336,15 @@ public:
|
|||||||
return SIM_ERROR;
|
return SIM_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
RegStatus getRegistrationStatus() {
|
TINY_GSM_MODEM_GET_REGISTRATION_XREG(CEREG)
|
||||||
//sendAT(GF("+CREG?"));
|
|
||||||
sendAT(GF("+CEREG?"));
|
|
||||||
if (waitResponse(GF(GSM_NL "+CEREG:")) != 1) {
|
|
||||||
return REG_UNKNOWN;
|
|
||||||
}
|
|
||||||
streamSkipUntil(','); // Skip format (0)
|
|
||||||
int status = stream.readStringUntil(',').toInt();
|
|
||||||
waitResponse();
|
|
||||||
return (RegStatus)status;
|
|
||||||
}
|
|
||||||
|
|
||||||
String getOperator() {
|
TINY_GSM_MODEM_GET_OPERATOR_COPS()
|
||||||
sendAT(GF("+COPS?"));
|
|
||||||
if (waitResponse(GF(GSM_NL "+COPS:")) != 1) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
streamSkipUntil('"'); // Skip mode and format
|
|
||||||
String res = stream.readStringUntil('"');
|
|
||||||
waitResponse();
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Generic network functions
|
* Generic network functions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int16_t getSignalQuality() {
|
TINY_GSP_MODEM_GET_CSQ()
|
||||||
sendAT(GF("+CSQ"));
|
|
||||||
if (waitResponse(GF(GSM_NL "+CSQ:")) != 1) {
|
|
||||||
return 99;
|
|
||||||
}
|
|
||||||
int res = stream.readStringUntil(',').toInt();
|
|
||||||
waitResponse();
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isNetworkConnected() {
|
bool isNetworkConnected() {
|
||||||
RegStatus s = getRegistrationStatus();
|
RegStatus s = getRegistrationStatus();
|
||||||
@@ -418,15 +356,7 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool waitForNetwork(unsigned long timeout = 60000L) {
|
TINY_GSM_MODEM_WAIT_FOR_NETWORK()
|
||||||
for (unsigned long start = millis(); millis() - start < timeout; ) {
|
|
||||||
if (isNetworkConnected()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
delay(250);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* GPRS functions
|
* GPRS functions
|
||||||
@@ -665,37 +595,7 @@ public:
|
|||||||
Utilities
|
Utilities
|
||||||
*/
|
*/
|
||||||
|
|
||||||
template<typename T>
|
TINY_GSP_MODEM_STREAM_UTILITIES()
|
||||||
void streamWrite(T last) {
|
|
||||||
stream.print(last);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T, typename... Args>
|
|
||||||
void streamWrite(T head, Args... tail) {
|
|
||||||
stream.print(head);
|
|
||||||
streamWrite(tail...);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename... Args>
|
|
||||||
void sendAT(Args... cmd) {
|
|
||||||
streamWrite("AT", cmd..., GSM_NL);
|
|
||||||
stream.flush();
|
|
||||||
TINY_GSM_YIELD();
|
|
||||||
//DBG("### AT:", cmd...);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool streamSkipUntil(const char c, const unsigned long timeout = 1000L) {
|
|
||||||
unsigned long startMillis = millis();
|
|
||||||
while (millis() - startMillis < timeout) {
|
|
||||||
while (millis() - startMillis < timeout && !stream.available()) {
|
|
||||||
TINY_GSM_YIELD();
|
|
||||||
}
|
|
||||||
if (stream.read() == c) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: Optimize this!
|
// TODO: Optimize this!
|
||||||
uint8_t waitResponse(uint32_t timeout, String& data,
|
uint8_t waitResponse(uint32_t timeout, String& data,
|
||||||
|
@@ -229,31 +229,11 @@ public:
|
|||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setBaud(unsigned long baud) {
|
TINY_GSM_MODEM_SET_BAUD_IPR()
|
||||||
sendAT(GF("+IPR="), baud);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool testAT(unsigned long timeout = 10000L) {
|
TINY_GSM_MODEM_TEST_AT()
|
||||||
for (unsigned long start = millis(); millis() - start < timeout; ) {
|
|
||||||
sendAT(GF(""));
|
|
||||||
if (waitResponse(200) == 1) return true;
|
|
||||||
delay(100);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void maintain() {
|
TINY_GSM_MODEM_MAINTAIN_CHECK_SOCKS()
|
||||||
for (int mux = 0; mux < TINY_GSM_MUX_COUNT; mux++) {
|
|
||||||
GsmClient* sock = sockets[mux];
|
|
||||||
if (sock && sock->got_data) {
|
|
||||||
sock->got_data = false;
|
|
||||||
sock->sock_available = modemGetAvailable(mux);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
while (stream.available()) {
|
|
||||||
waitResponse(15, NULL, NULL);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool factoryDefault() {
|
bool factoryDefault() {
|
||||||
sendAT(GF("+UFACTORY=0,1")); // No factory restore, erase NVM
|
sendAT(GF("+UFACTORY=0,1")); // No factory restore, erase NVM
|
||||||
@@ -262,17 +242,7 @@ public:
|
|||||||
return waitResponse() == 1;
|
return waitResponse() == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
String getModemInfo() {
|
TINY_GSM_MODEM_GET_INFO_ATI()
|
||||||
sendAT(GF("I"));
|
|
||||||
String res;
|
|
||||||
if (waitResponse(1000L, res) != 1) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
res.replace(GSM_NL "OK" GSM_NL, "");
|
|
||||||
res.replace(GSM_NL, " ");
|
|
||||||
res.trim();
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool hasSSL() {
|
bool hasSSL() {
|
||||||
return true;
|
return true;
|
||||||
@@ -322,21 +292,9 @@ public:
|
|||||||
* SIM card functions
|
* SIM card functions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
bool simUnlock(const char *pin) {
|
TINY_GSM_MODEM_SIM_UNLOCK_CPIN()
|
||||||
sendAT(GF("+CPIN=\""), pin, GF("\""));
|
|
||||||
return waitResponse() == 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
String getSimCCID() {
|
TINY_GSM_MODEM_GET_SIMCCID_CCID()
|
||||||
sendAT(GF("+CCID"));
|
|
||||||
if (waitResponse(GF(GSM_NL "+CCID:")) != 1) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
String res = stream.readStringUntil('\n');
|
|
||||||
waitResponse();
|
|
||||||
res.trim();
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
String getIMEI() {
|
String getIMEI() {
|
||||||
sendAT(GF("+CGSN"));
|
sendAT(GF("+CGSN"));
|
||||||
@@ -368,42 +326,15 @@ public:
|
|||||||
return SIM_ERROR;
|
return SIM_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
RegStatus getRegistrationStatus() {
|
TINY_GSM_MODEM_GET_REGISTRATION_XREG(CGREG)
|
||||||
// Check GPRS registration
|
|
||||||
sendAT(GF("+CGREG?"));
|
|
||||||
if (waitResponse(GF(GSM_NL "+CGREG:")) != 1) {
|
|
||||||
return REG_UNKNOWN;
|
|
||||||
}
|
|
||||||
streamSkipUntil(','); // Skip format (0)
|
|
||||||
int status = stream.readStringUntil('\n').toInt();
|
|
||||||
waitResponse();
|
|
||||||
return (RegStatus)status;
|
|
||||||
}
|
|
||||||
|
|
||||||
String getOperator() {
|
TINY_GSM_MODEM_GET_OPERATOR_COPS()
|
||||||
sendAT(GF("+COPS?"));
|
|
||||||
if (waitResponse(GF(GSM_NL "+COPS:")) != 1) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
streamSkipUntil('"'); // Skip mode and format
|
|
||||||
String res = stream.readStringUntil('"');
|
|
||||||
waitResponse();
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Generic network functions
|
* Generic network functions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int16_t getSignalQuality() {
|
TINY_GSP_MODEM_GET_CSQ()
|
||||||
sendAT(GF("+CSQ"));
|
|
||||||
if (waitResponse(GF(GSM_NL "+CSQ:")) != 1) {
|
|
||||||
return 99;
|
|
||||||
}
|
|
||||||
int res = stream.readStringUntil(',').toInt();
|
|
||||||
waitResponse();
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isNetworkConnected() {
|
bool isNetworkConnected() {
|
||||||
RegStatus s = getRegistrationStatus();
|
RegStatus s = getRegistrationStatus();
|
||||||
@@ -414,15 +345,7 @@ public:
|
|||||||
else return false;
|
else return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool waitForNetwork(unsigned long timeout = 60000L) {
|
TINY_GSM_MODEM_WAIT_FOR_NETWORK()
|
||||||
for (unsigned long start = millis(); millis() - start < timeout; ) {
|
|
||||||
if (isNetworkConnected()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
delay(250);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* GPRS functions
|
* GPRS functions
|
||||||
@@ -483,18 +406,7 @@ public:
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isGprsConnected() {
|
TINY_GSP_MODEM_GET_GPRS_IP_CONNECTED()
|
||||||
sendAT(GF("+CGATT?"));
|
|
||||||
if (waitResponse(GF(GSM_NL "+CGATT:")) != 1) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
int res = stream.readStringUntil('\n').toInt();
|
|
||||||
waitResponse();
|
|
||||||
if (res != 1)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return localIP() != IPAddress(0,0,0,0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* IP Address functions
|
* IP Address functions
|
||||||
@@ -724,37 +636,7 @@ public:
|
|||||||
Utilities
|
Utilities
|
||||||
*/
|
*/
|
||||||
|
|
||||||
template<typename T>
|
TINY_GSP_MODEM_STREAM_UTILITIES()
|
||||||
void streamWrite(T last) {
|
|
||||||
stream.print(last);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T, typename... Args>
|
|
||||||
void streamWrite(T head, Args... tail) {
|
|
||||||
stream.print(head);
|
|
||||||
streamWrite(tail...);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename... Args>
|
|
||||||
void sendAT(Args... cmd) {
|
|
||||||
streamWrite("AT", cmd..., GSM_NL);
|
|
||||||
stream.flush();
|
|
||||||
TINY_GSM_YIELD();
|
|
||||||
//DBG("### AT:", cmd...);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool streamSkipUntil(const char c, const unsigned long timeout = 1000L) {
|
|
||||||
unsigned long startMillis = millis();
|
|
||||||
while (millis() - startMillis < timeout) {
|
|
||||||
while (millis() - startMillis < timeout && !stream.available()) {
|
|
||||||
TINY_GSM_YIELD();
|
|
||||||
}
|
|
||||||
if (stream.read() == c) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: Optimize this!
|
// TODO: Optimize this!
|
||||||
uint8_t waitResponse(uint32_t timeout, String& data,
|
uint8_t waitResponse(uint32_t timeout, String& data,
|
||||||
|
@@ -933,37 +933,7 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
TINY_GSP_MODEM_STREAM_UTILITIES()
|
||||||
void streamWrite(T last) {
|
|
||||||
stream.print(last);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T, typename... Args>
|
|
||||||
void streamWrite(T head, Args... tail) {
|
|
||||||
stream.print(head);
|
|
||||||
streamWrite(tail...);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename... Args>
|
|
||||||
void sendAT(Args... cmd) {
|
|
||||||
streamWrite("AT", cmd..., GSM_NL);
|
|
||||||
stream.flush();
|
|
||||||
TINY_GSM_YIELD();
|
|
||||||
//DBG("### AT:", cmd...);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool streamSkipUntil(const char c, const unsigned long timeout = 1000L) {
|
|
||||||
unsigned long startMillis = millis();
|
|
||||||
while (millis() - startMillis < timeout) {
|
|
||||||
while (millis() - startMillis < timeout && !stream.available()) {
|
|
||||||
TINY_GSM_YIELD();
|
|
||||||
}
|
|
||||||
if (stream.read() == c) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: Optimize this!
|
// TODO: Optimize this!
|
||||||
// NOTE: This function is used while INSIDE command mode, so we're only
|
// NOTE: This function is used while INSIDE command mode, so we're only
|
||||||
|
@@ -389,6 +389,7 @@ String TinyGsmDecodeHex16bit(String &instr) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// The peek, flush, and connected functions
|
||||||
#define TINY_GSM_CLIENT_PEEK_FLUSH_CONNECTED() \
|
#define TINY_GSM_CLIENT_PEEK_FLUSH_CONNECTED() \
|
||||||
virtual int peek() { return -1; } /* TODO */ \
|
virtual int peek() { return -1; } /* TODO */ \
|
||||||
\
|
\
|
||||||
@@ -402,4 +403,209 @@ String TinyGsmDecodeHex16bit(String &instr) {
|
|||||||
} \
|
} \
|
||||||
virtual operator bool() { return connected(); }
|
virtual operator bool() { return connected(); }
|
||||||
|
|
||||||
|
|
||||||
|
// Set baud rate via the V.25TER standard IPR command
|
||||||
|
#define TINY_GSM_MODEM_SET_BAUD_IPR() \
|
||||||
|
void setBaud(unsigned long baud) { \
|
||||||
|
sendAT(GF("+IPR="), baud); \
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Test response to AT commands
|
||||||
|
#define TINY_GSM_MODEM_TEST_AT() \
|
||||||
|
bool testAT(unsigned long timeout = 10000L) { \
|
||||||
|
for (unsigned long start = millis(); millis() - start < timeout; ) { \
|
||||||
|
sendAT(GF("")); \
|
||||||
|
if (waitResponse(200) == 1) return true; \
|
||||||
|
delay(100); \
|
||||||
|
} \
|
||||||
|
return false; \
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Keeps listening for modem URC's and iterates through sockets
|
||||||
|
// to see if any data is avaiable
|
||||||
|
#define TINY_GSM_MODEM_MAINTAIN_CHECK_SOCKS() \
|
||||||
|
void maintain() { \
|
||||||
|
for (int mux = 0; mux < TINY_GSM_MUX_COUNT; mux++) { \
|
||||||
|
GsmClient* sock = sockets[mux]; \
|
||||||
|
if (sock && sock->got_data) { \
|
||||||
|
sock->got_data = false; \
|
||||||
|
sock->sock_available = modemGetAvailable(mux); \
|
||||||
|
} \
|
||||||
|
} \
|
||||||
|
while (stream.available()) { \
|
||||||
|
waitResponse(15, NULL, NULL); \
|
||||||
|
} \
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Keeps listening for modem URC's - doesn't check socks because
|
||||||
|
// modem has no internal fifo
|
||||||
|
#define TINY_GSM_MODEM_MAINTAIN_LISTEN() \
|
||||||
|
void maintain() { \
|
||||||
|
waitResponse(10, NULL, NULL); \
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Asks for modem information via the V.25TER standard ATI command
|
||||||
|
// NOTE: The actual value and style of the response is quite varied
|
||||||
|
#define TINY_GSM_MODEM_GET_INFO_ATI() \
|
||||||
|
String getModemInfo() { \
|
||||||
|
sendAT(GF("I")); \
|
||||||
|
String res; \
|
||||||
|
if (waitResponse(1000L, res) != 1) { \
|
||||||
|
return ""; \
|
||||||
|
} \
|
||||||
|
res.replace(GSM_NL "OK" GSM_NL, ""); \
|
||||||
|
res.replace(GSM_NL, " "); \
|
||||||
|
res.trim(); \
|
||||||
|
return res; \
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Unlocks a sim via the 3GPP TS command AT+CPIN
|
||||||
|
#define TINY_GSM_MODEM_SIM_UNLOCK_CPIN() \
|
||||||
|
bool simUnlock(const char *pin) { \
|
||||||
|
sendAT(GF("+CPIN=\""), pin, GF("\"")); \
|
||||||
|
return waitResponse() == 1; \
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Gets the CCID of a sim card via AT+CCID
|
||||||
|
#define TINY_GSM_MODEM_GET_SIMCCID_CCID() \
|
||||||
|
String getSimCCID() { \
|
||||||
|
sendAT(GF("+CCID")); \
|
||||||
|
if (waitResponse(GF(GSM_NL "+CCID:")) != 1) { \
|
||||||
|
return ""; \
|
||||||
|
} \
|
||||||
|
String res = stream.readStringUntil('\n'); \
|
||||||
|
waitResponse(); \
|
||||||
|
res.trim(); \
|
||||||
|
return res; \
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Asks for TA Serial Number Identification (IMEI) via the V.25TER standard AT+GSN command
|
||||||
|
#define TINY_GSM_MODEM_GET_IMEI_GSN() \
|
||||||
|
String getIMEI() { \
|
||||||
|
sendAT(GF("+GSN")); \
|
||||||
|
if (waitResponse(GF(GSM_NL)) != 1) { \
|
||||||
|
return ""; \
|
||||||
|
} \
|
||||||
|
String res = stream.readStringUntil('\n'); \
|
||||||
|
waitResponse(); \
|
||||||
|
res.trim(); \
|
||||||
|
return res; \
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Gets the modem's registration status via CREG/CGREG/CEREG
|
||||||
|
// CREG = Generic network registration
|
||||||
|
// CGREG = GPRS service registration
|
||||||
|
// CEREG = EPS registration for LTE modules
|
||||||
|
#define TINY_GSM_MODEM_GET_REGISTRATION_XREG(regCommand) \
|
||||||
|
RegStatus getRegistrationStatus() { \
|
||||||
|
sendAT(GF("+" #regCommand "?")); \
|
||||||
|
if (waitResponse(GF(GSM_NL "+" #regCommand ":")) != 1) { \
|
||||||
|
return REG_UNKNOWN; \
|
||||||
|
} \
|
||||||
|
streamSkipUntil(','); /* Skip format (0) */ \
|
||||||
|
int status = stream.readStringUntil('\n').toInt(); \
|
||||||
|
waitResponse(); \
|
||||||
|
return (RegStatus)status; \
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Gets the current network operator via the 3GPP TS command AT+COPS
|
||||||
|
#define TINY_GSM_MODEM_GET_OPERATOR_COPS() \
|
||||||
|
String getOperator() { \
|
||||||
|
sendAT(GF("+COPS?")); \
|
||||||
|
if (waitResponse(GF(GSM_NL "+COPS:")) != 1) { \
|
||||||
|
return ""; \
|
||||||
|
} \
|
||||||
|
streamSkipUntil('"'); /* Skip mode and format */ \
|
||||||
|
String res = stream.readStringUntil('"'); \
|
||||||
|
waitResponse(); \
|
||||||
|
return res; \
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Waits for network attachment
|
||||||
|
#define TINY_GSM_MODEM_WAIT_FOR_NETWORK() \
|
||||||
|
bool waitForNetwork(unsigned long timeout = 60000L) { \
|
||||||
|
for (unsigned long start = millis(); millis() - start < timeout; ) { \
|
||||||
|
if (isNetworkConnected()) { \
|
||||||
|
return true; \
|
||||||
|
} \
|
||||||
|
delay(250); \
|
||||||
|
} \
|
||||||
|
return false; \
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Checks if current attached to GPRS/EPS service
|
||||||
|
#define TINY_GSP_MODEM_GET_GPRS_IP_CONNECTED() \
|
||||||
|
bool isGprsConnected() { \
|
||||||
|
sendAT(GF("+CGATT?")); \
|
||||||
|
if (waitResponse(GF(GSM_NL "+CGATT:")) != 1) { \
|
||||||
|
return false; \
|
||||||
|
} \
|
||||||
|
int res = stream.readStringUntil('\n').toInt(); \
|
||||||
|
waitResponse(); \
|
||||||
|
if (res != 1) \
|
||||||
|
return false; \
|
||||||
|
\
|
||||||
|
return localIP() != IPAddress(0,0,0,0); \
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Gets signal quality report according to 3GPP TS command AT+CSQ
|
||||||
|
#define TINY_GSP_MODEM_GET_CSQ() \
|
||||||
|
int16_t getSignalQuality() { \
|
||||||
|
sendAT(GF("+CSQ")); \
|
||||||
|
if (waitResponse(GF(GSM_NL "+CSQ:")) != 1) { \
|
||||||
|
return 99; \
|
||||||
|
} \
|
||||||
|
int res = stream.readStringUntil(',').toInt(); \
|
||||||
|
waitResponse(); \
|
||||||
|
return res; \
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Utility templates for writing/skipping characters on a stream
|
||||||
|
#define TINY_GSP_MODEM_STREAM_UTILITIES() \
|
||||||
|
template<typename T> \
|
||||||
|
void streamWrite(T last) { \
|
||||||
|
stream.print(last); \
|
||||||
|
} \
|
||||||
|
\
|
||||||
|
template<typename T, typename... Args> \
|
||||||
|
void streamWrite(T head, Args... tail) { \
|
||||||
|
stream.print(head); \
|
||||||
|
streamWrite(tail...); \
|
||||||
|
} \
|
||||||
|
\
|
||||||
|
template<typename... Args> \
|
||||||
|
void sendAT(Args... cmd) { \
|
||||||
|
streamWrite("AT", cmd..., GSM_NL); \
|
||||||
|
stream.flush(); \
|
||||||
|
TINY_GSM_YIELD(); \
|
||||||
|
/* DBG("### AT:", cmd...); */ \
|
||||||
|
} \
|
||||||
|
\
|
||||||
|
bool streamSkipUntil(const char c, const unsigned long timeout = 1000L) { \
|
||||||
|
unsigned long startMillis = millis(); \
|
||||||
|
while (millis() - startMillis < timeout) { \
|
||||||
|
while (millis() - startMillis < timeout && !stream.available()) { \
|
||||||
|
TINY_GSM_YIELD(); \
|
||||||
|
} \
|
||||||
|
if (stream.read() == c) { \
|
||||||
|
return true; \
|
||||||
|
} \
|
||||||
|
} \
|
||||||
|
return false; \
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user