diff --git a/src/TinyGsmClientA6.h b/src/TinyGsmClientA6.h index a7c8f35..ae6803e 100644 --- a/src/TinyGsmClientA6.h +++ b/src/TinyGsmClientA6.h @@ -191,6 +191,8 @@ class TinyGsmA6 : public TinyGsmModem, bool sleepEnableImpl(bool enable = true) TINY_GSM_ATTR_NOT_AVAILABLE; + bool setPhoneFunctionalityImpl(uint8_t fun, bool reset = false) TINY_GSM_ATTR_NOT_IMPLEMENTED; + /* * Generic network functions */ diff --git a/src/TinyGsmClientBG96.h b/src/TinyGsmClientBG96.h index e5c7570..b4ae604 100644 --- a/src/TinyGsmClientBG96.h +++ b/src/TinyGsmClientBG96.h @@ -204,8 +204,7 @@ class TinyGsmBG96 : public TinyGsmModem, protected: bool restartImpl() { if (!testAT()) { return false; } - sendAT(GF("+CFUN=1,1")); - if (waitResponse(10000L, GF("OK")) != 1) { return false; } + if (!setPhoneFunctionality(1, true)) { return false; } waitResponse(10000L, GF("APP RDY")); return init(); } @@ -226,6 +225,11 @@ class TinyGsmBG96 : public TinyGsmModem, return waitResponse() == 1; } + bool setPhoneFunctionalityImpl(uint8_t fun, bool reset = false) { + sendAT(GF("+CFUN="), fun, reset ? ",1" : ""); + return waitResponse(10000L, GF("OK")) == 1; + } + /* * Generic network functions */ diff --git a/src/TinyGsmClientESP8266.h b/src/TinyGsmClientESP8266.h index 9a8687a..38d8a50 100644 --- a/src/TinyGsmClientESP8266.h +++ b/src/TinyGsmClientESP8266.h @@ -200,6 +200,8 @@ class TinyGsmESP8266 : public TinyGsmModem, bool sleepEnableImpl(bool enable = true) TINY_GSM_ATTR_NOT_AVAILABLE; + bool setPhoneFunctionalityImpl(uint8_t fun, bool reset = false) TINY_GSM_ATTR_NOT_IMPLEMENTED; + /* * Generic network functions */ diff --git a/src/TinyGsmClientM590.h b/src/TinyGsmClientM590.h index 091735b..094049a 100644 --- a/src/TinyGsmClientM590.h +++ b/src/TinyGsmClientM590.h @@ -173,8 +173,7 @@ class TinyGsmM590 : public TinyGsmModem, protected: bool restartImpl() { if (!testAT()) { return false; } - sendAT(GF("+CFUN=15")); - if (waitResponse(10000L) != 1) { return false; } + if (!setPhoneFunctionality(15)) { return false; } // MODEM:STARTUP waitResponse(60000L, GF(GSM_NL "+PBREADY" GSM_NL)); return init(); @@ -190,6 +189,11 @@ class TinyGsmM590 : public TinyGsmModem, return waitResponse() == 1; } + bool setPhoneFunctionalityImpl(uint8_t fun, bool reset = false) { + sendAT(GF("+CFUN="), fun, reset ? ",1" : ""); + return waitResponse(10000L) == 1; + } + /* * Generic network functions */ diff --git a/src/TinyGsmClientM95.h b/src/TinyGsmClientM95.h index fdb2c45..ad94449 100644 --- a/src/TinyGsmClientM95.h +++ b/src/TinyGsmClientM95.h @@ -227,6 +227,8 @@ class TinyGsmM95 : public TinyGsmModem, return waitResponse() == 1; } + bool setPhoneFunctionalityImpl(uint8_t fun, bool reset = false) TINY_GSM_ATTR_NOT_IMPLEMENTED; + /* * Generic network functions */ diff --git a/src/TinyGsmClientMC60.h b/src/TinyGsmClientMC60.h index ed63281..d9b9cd1 100644 --- a/src/TinyGsmClientMC60.h +++ b/src/TinyGsmClientMC60.h @@ -199,10 +199,8 @@ class TinyGsmMC60 : public TinyGsmModem, protected: bool restartImpl() { if (!testAT()) { return false; } - sendAT(GF("+CFUN=0")); - if (waitResponse(10000L) != 1) { return false; } - sendAT(GF("+CFUN=1,1")); - if (waitResponse(10000L) != 1) { return false; } + if (!setPhoneFunctionality(0)) { return false; } + if (!setPhoneFunctionality(1, true)) { return false; } delay(3000); return init(); } @@ -222,6 +220,11 @@ class TinyGsmMC60 : public TinyGsmModem, return waitResponse() == 1; } + bool setPhoneFunctionalityImpl(uint8_t fun, bool reset = false) { + sendAT(GF("+CFUN="), fun, reset ? ",1" : ""); + return waitResponse(10000L) == 1; + } + /* * Generic network functions */ diff --git a/src/TinyGsmClientSIM5360.h b/src/TinyGsmClientSIM5360.h index a70f740..6b184d4 100644 --- a/src/TinyGsmClientSIM5360.h +++ b/src/TinyGsmClientSIM5360.h @@ -234,8 +234,7 @@ class TinyGsmSim5360 : public TinyGsmModem, } bool radioOffImpl() { - sendAT(GF("+CFUN=4")); - if (waitResponse(10000L) != 1) { return false; } + if (!setPhoneFunctionality(4)) { return false; } delay(3000); return true; } @@ -245,6 +244,11 @@ class TinyGsmSim5360 : public TinyGsmModem, return waitResponse() == 1; } + bool setPhoneFunctionalityImpl(uint8_t fun, bool reset = false) { + sendAT(GF("+CFUN="), fun, reset ? ",1" : ""); + return waitResponse(10000L) == 1; + } + /* * Generic network functions */ diff --git a/src/TinyGsmClientSIM7000.h b/src/TinyGsmClientSIM7000.h index deae5fe..7960ef6 100644 --- a/src/TinyGsmClientSIM7000.h +++ b/src/TinyGsmClientSIM7000.h @@ -213,10 +213,8 @@ class TinyGsmSim7000 : public TinyGsmModem, */ protected: bool restartImpl() { - sendAT(GF("+CFUN=0")); - if (waitResponse(10000L) != 1) { return false; } - sendAT(GF("+CFUN=1,1")); - if (waitResponse(10000L) != 1) { return false; } + if (!setPhoneFunctionality(0)) { return false; } + if (!setPhoneFunctionality(1, true)) { return false; } waitResponse(10000L, GF("SMS Ready"), GF("RDY")); return init(); } @@ -235,6 +233,11 @@ class TinyGsmSim7000 : public TinyGsmModem, return waitResponse() == 1; } + bool setPhoneFunctionalityImpl(uint8_t fun, bool reset = false) { + sendAT(GF("+CFUN="), fun, reset ? ",1" : ""); + return waitResponse(10000L) == 1; + } + /* * Generic network functions */ diff --git a/src/TinyGsmClientSIM7600.h b/src/TinyGsmClientSIM7600.h index 8a3633c..b592853 100644 --- a/src/TinyGsmClientSIM7600.h +++ b/src/TinyGsmClientSIM7600.h @@ -233,8 +233,7 @@ class TinyGsmSim7600 : public TinyGsmModem, } bool radioOffImpl() { - sendAT(GF("+CFUN=4")); - if (waitResponse(10000L) != 1) { return false; } + if (!setPhoneFunctionality(4)) { return false; } delay(3000); return true; } @@ -244,6 +243,11 @@ class TinyGsmSim7600 : public TinyGsmModem, return waitResponse() == 1; } + bool setPhoneFunctionalityImpl(uint8_t fun, bool reset = false) { + sendAT(GF("+CFUN="), fun, reset ? ",1" : ""); + return waitResponse(10000L) == 1; + } + /* * Generic network functions */ diff --git a/src/TinyGsmClientSIM800.h b/src/TinyGsmClientSIM800.h index 88e1429..2e612fd 100644 --- a/src/TinyGsmClientSIM800.h +++ b/src/TinyGsmClientSIM800.h @@ -254,10 +254,8 @@ class TinyGsmSim800 : public TinyGsmModem, if (!testAT()) { return false; } sendAT(GF("&W")); waitResponse(); - sendAT(GF("+CFUN=0")); - if (waitResponse(10000L) != 1) { return false; } - sendAT(GF("+CFUN=1,1")); - if (waitResponse(10000L) != 1) { return false; } + if (!setPhoneFunctionality(0)) { return false; } + if (!setPhoneFunctionality(1, true)) { return false; } delay(3000); return init(); } @@ -276,6 +274,15 @@ class TinyGsmSim800 : public TinyGsmModem, return waitResponse() == 1; } + // 0 Minimum functionality + // 1 Full functionality (Default) + // 4 Disable phone both transmit and receive RF circuits. + // Reset the MT before setting it to power level. + bool setPhoneFunctionalityImpl(uint8_t fun, bool reset = false) { + sendAT(GF("+CFUN="), fun, reset ? ",1" : ""); + return waitResponse(10000L) == 1; + } + /* * Generic network functions */ diff --git a/src/TinyGsmClientSaraR4.h b/src/TinyGsmClientSaraR4.h index 75e85cc..4ac42cf 100644 --- a/src/TinyGsmClientSaraR4.h +++ b/src/TinyGsmClientSaraR4.h @@ -299,8 +299,7 @@ class TinyGsmSaraR4 : public TinyGsmModem, // using +CFUN=15 instead of the more common CFUN=1,1 bool restartImpl() { if (!testAT()) { return false; } - sendAT(GF("+CFUN=15")); - if (waitResponse(10000L) != 1) { return false; } + if (!setPhoneFunctionality(15)) { return false; } delay(3000); // TODO(?): Verify delay timing here return init(); } @@ -312,6 +311,11 @@ class TinyGsmSaraR4 : public TinyGsmModem, bool sleepEnableImpl(bool enable = true) TINY_GSM_ATTR_NOT_AVAILABLE; + bool setPhoneFunctionalityImpl(uint8_t fun, bool reset = false) { + sendAT(GF("+CFUN="), fun, reset ? ",1" : ""); + return waitResponse(10000L) == 1; + } + /* * Generic network functions */ diff --git a/src/TinyGsmClientSequansMonarch.h b/src/TinyGsmClientSequansMonarch.h index 0caff1c..654fc5e 100644 --- a/src/TinyGsmClientSequansMonarch.h +++ b/src/TinyGsmClientSequansMonarch.h @@ -316,6 +316,8 @@ class TinyGsmSequansMonarch return waitResponse() == 1; } + bool setPhoneFunctionality(uint8_t fun, bool reset = false) TINY_GSM_ATTR_NOT_IMPLEMENTED; + /* * Generic network functions */ diff --git a/src/TinyGsmClientUBLOX.h b/src/TinyGsmClientUBLOX.h index 585f630..cb8750d 100644 --- a/src/TinyGsmClientUBLOX.h +++ b/src/TinyGsmClientUBLOX.h @@ -236,8 +236,7 @@ class TinyGsmUBLOX : public TinyGsmModem, bool factoryDefaultImpl() { sendAT(GF("+UFACTORY=0,1")); // No factory restore, erase NVM waitResponse(); - sendAT(GF("+CFUN=16")); // Reset - return waitResponse() == 1; + return setPhoneFunctionality(16); // Reset } /* @@ -246,8 +245,7 @@ class TinyGsmUBLOX : public TinyGsmModem, protected: bool restartImpl() { if (!testAT()) { return false; } - sendAT(GF("+CFUN=16")); - if (waitResponse(10000L) != 1) { return false; } + if (!setPhoneFunctionality(16)) { return false; } delay(3000); // TODO(?): Verify delay timing here return init(); } @@ -259,6 +257,11 @@ class TinyGsmUBLOX : public TinyGsmModem, bool sleepEnableImpl(bool enable = true) TINY_GSM_ATTR_NOT_AVAILABLE; + bool setPhoneFunctionalityImpl(uint8_t fun, bool reset = false) { + sendAT(GF("+CFUN="), fun, reset ? ",1" : ""); + return waitResponse(10000L) == 1; + } + /* * Generic network functions */ diff --git a/src/TinyGsmClientXBee.h b/src/TinyGsmClientXBee.h index e3b39a0..0669351 100644 --- a/src/TinyGsmClientXBee.h +++ b/src/TinyGsmClientXBee.h @@ -572,6 +572,8 @@ class TinyGsmXBee : public TinyGsmModem, bool sleepEnableImpl(bool enable = true) TINY_GSM_ATTR_NOT_IMPLEMENTED; + bool setPhoneFunctionalityImpl(uint8_t fun, bool reset = false) TINY_GSM_ATTR_NOT_IMPLEMENTED; + /* * Generic network functions */ diff --git a/src/TinyGsmModem.tpp b/src/TinyGsmModem.tpp index e6bd28e..0cbfc33 100644 --- a/src/TinyGsmModem.tpp +++ b/src/TinyGsmModem.tpp @@ -65,6 +65,9 @@ class TinyGsmModem { bool sleepEnable(bool enable = true) { return thisModem().sleepEnableImpl(enable); } + bool setPhoneFunctionality(uint8_t fun, bool reset = false) { + return thisModem().setPhoneFunctionalityImpl(fun, reset); + } /* * Generic network functions @@ -164,14 +167,15 @@ class TinyGsmModem { */ protected: bool radioOffImpl() { - thisModem().sendAT(GF("+CFUN=0")); - if (thisModem().waitResponse(10000L) != 1) { return false; } + if (!thisModem().setPhoneFunctionality(0)) { return false; } delay(3000); return true; } bool sleepEnableImpl(bool enable = true) TINY_GSM_ATTR_NOT_IMPLEMENTED; + bool setPhoneFunctionalityImpl(uint8_t fun, bool reset = false) TINY_GSM_ATTR_NOT_IMPLEMENTED; + /* * Generic network functions */