Merge branch 'master' of https://github.com/vshymanskyy/TinyGSM into v_master
This commit is contained in:
57
src/TinyGsmBluetooth.tpp
Normal file
57
src/TinyGsmBluetooth.tpp
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
/**
|
||||||
|
* @file TinyGsmGPS.tpp
|
||||||
|
* @author Adrian Cervera Andes
|
||||||
|
* @license LGPL-3.0
|
||||||
|
* @copyright Copyright (c) 2021 Adrian Cervera Andes
|
||||||
|
* @date Jan 2021
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef SRC_TINYGSMBLUETOOTH_H_
|
||||||
|
#define SRC_TINYGSMBLUETOOTH_H_
|
||||||
|
|
||||||
|
#include "TinyGsmCommon.h"
|
||||||
|
|
||||||
|
#define TINY_GSM_MODEM_HAS_BLUETOOTH
|
||||||
|
|
||||||
|
template <class modemType>
|
||||||
|
class TinyGsmBluetooth {
|
||||||
|
public:
|
||||||
|
/*
|
||||||
|
* Bluetooth functions
|
||||||
|
*/
|
||||||
|
bool enableBluetooth() {
|
||||||
|
return thisModem().enableBluetoothImpl();
|
||||||
|
}
|
||||||
|
bool disableBluetooth() {
|
||||||
|
return thisModem().disableBluetoothImpl();
|
||||||
|
}
|
||||||
|
bool setBluetoothVisibility(bool visible) {
|
||||||
|
return thisModem().setBluetoothVisibilityImpl(visible);
|
||||||
|
}
|
||||||
|
bool setBluetoothHostName(const char* name) {
|
||||||
|
return thisModem().setBluetoothHostNameImpl(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* CRTP Helper
|
||||||
|
*/
|
||||||
|
protected:
|
||||||
|
inline const modemType& thisModem() const {
|
||||||
|
return static_cast<const modemType&>(*this);
|
||||||
|
}
|
||||||
|
inline modemType& thisModem() {
|
||||||
|
return static_cast<modemType&>(*this);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Bluetooth functions
|
||||||
|
*/
|
||||||
|
|
||||||
|
bool enableBluetoothImpl() TINY_GSM_ATTR_NOT_IMPLEMENTED;
|
||||||
|
bool disableBluetoothImpl() TINY_GSM_ATTR_NOT_IMPLEMENTED;
|
||||||
|
bool setBluetoothVisibilityImpl(bool visible) TINY_GSM_ATTR_NOT_IMPLEMENTED;
|
||||||
|
bool setBluetoothHostNameImpl(const char* name) TINY_GSM_ATTR_NOT_IMPLEMENTED;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif // SRC_TINYGSMBLUETOOTH_H_
|
||||||
@@ -176,11 +176,11 @@ class TinyGsmA6 : public TinyGsmModem<TinyGsmA6>,
|
|||||||
* Power functions
|
* Power functions
|
||||||
*/
|
*/
|
||||||
protected:
|
protected:
|
||||||
bool restartImpl() {
|
bool restartImpl(const char* pin = NULL) {
|
||||||
if (!testAT()) { return false; }
|
if (!testAT()) { return false; }
|
||||||
sendAT(GF("+RST=1"));
|
sendAT(GF("+RST=1"));
|
||||||
delay(3000);
|
delay(3000);
|
||||||
return init();
|
return init(pin);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool powerOffImpl() {
|
bool powerOffImpl() {
|
||||||
|
|||||||
@@ -202,11 +202,11 @@ class TinyGsmBG96 : public TinyGsmModem<TinyGsmBG96>,
|
|||||||
* Power functions
|
* Power functions
|
||||||
*/
|
*/
|
||||||
protected:
|
protected:
|
||||||
bool restartImpl() {
|
bool restartImpl(const char* pin = NULL) {
|
||||||
if (!testAT()) { return false; }
|
if (!testAT()) { return false; }
|
||||||
if (!setPhoneFunctionality(1, true)) { return false; }
|
if (!setPhoneFunctionality(1, true)) { return false; }
|
||||||
waitResponse(10000L, GF("APP RDY"));
|
waitResponse(10000L, GF("APP RDY"));
|
||||||
return init();
|
return init(pin);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool powerOffImpl() {
|
bool powerOffImpl() {
|
||||||
@@ -235,7 +235,16 @@ class TinyGsmBG96 : public TinyGsmModem<TinyGsmBG96>,
|
|||||||
*/
|
*/
|
||||||
public:
|
public:
|
||||||
RegStatus getRegistrationStatus() {
|
RegStatus getRegistrationStatus() {
|
||||||
return (RegStatus)getRegistrationStatusXREG("CREG");
|
// Check first for EPS registration
|
||||||
|
RegStatus epsStatus = (RegStatus)getRegistrationStatusXREG("CEREG");
|
||||||
|
|
||||||
|
// If we're connected on EPS, great!
|
||||||
|
if (epsStatus == REG_OK_HOME || epsStatus == REG_OK_ROAMING) {
|
||||||
|
return epsStatus;
|
||||||
|
} else {
|
||||||
|
// Otherwise, check generic network status
|
||||||
|
return (RegStatus)getRegistrationStatusXREG("CREG");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|||||||
@@ -182,13 +182,13 @@ class TinyGsmESP8266 : public TinyGsmModem<TinyGsmESP8266>,
|
|||||||
* Power functions
|
* Power functions
|
||||||
*/
|
*/
|
||||||
protected:
|
protected:
|
||||||
bool restartImpl() {
|
bool restartImpl(const char* pin = NULL) {
|
||||||
if (!testAT()) { return false; }
|
if (!testAT()) { return false; }
|
||||||
sendAT(GF("+RST"));
|
sendAT(GF("+RST"));
|
||||||
if (waitResponse(10000L) != 1) { return false; }
|
if (waitResponse(10000L) != 1) { return false; }
|
||||||
if (waitResponse(10000L, GF(GSM_NL "ready" GSM_NL)) != 1) { return false; }
|
if (waitResponse(10000L, GF(GSM_NL "ready" GSM_NL)) != 1) { return false; }
|
||||||
delay(500);
|
delay(500);
|
||||||
return init();
|
return init(pin);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool powerOffImpl() {
|
bool powerOffImpl() {
|
||||||
|
|||||||
@@ -171,12 +171,12 @@ class TinyGsmM590 : public TinyGsmModem<TinyGsmM590>,
|
|||||||
* Power functions
|
* Power functions
|
||||||
*/
|
*/
|
||||||
protected:
|
protected:
|
||||||
bool restartImpl() {
|
bool restartImpl(const char* pin = NULL) {
|
||||||
if (!testAT()) { return false; }
|
if (!testAT()) { return false; }
|
||||||
if (!setPhoneFunctionality(15)) { return false; }
|
if (!setPhoneFunctionality(15)) { return false; }
|
||||||
// MODEM:STARTUP
|
// MODEM:STARTUP
|
||||||
waitResponse(60000L, GF(GSM_NL "+PBREADY" GSM_NL));
|
waitResponse(60000L, GF(GSM_NL "+PBREADY" GSM_NL));
|
||||||
return init();
|
return init(pin);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool powerOffImpl() {
|
bool powerOffImpl() {
|
||||||
|
|||||||
@@ -198,7 +198,7 @@ class TinyGsmM95 : public TinyGsmModem<TinyGsmM95>,
|
|||||||
* Power functions
|
* Power functions
|
||||||
*/
|
*/
|
||||||
protected:
|
protected:
|
||||||
bool restartImpl() {
|
bool restartImpl(const char* pin = NULL) {
|
||||||
if (!testAT()) { return false; }
|
if (!testAT()) { return false; }
|
||||||
sendAT(GF("+CFUN=0"));
|
sendAT(GF("+CFUN=0"));
|
||||||
if (waitResponse(10000L, GF("NORMAL POWER DOWN"), GF("OK"), GF("FAIL")) ==
|
if (waitResponse(10000L, GF("NORMAL POWER DOWN"), GF("OK"), GF("FAIL")) ==
|
||||||
@@ -209,7 +209,7 @@ class TinyGsmM95 : public TinyGsmModem<TinyGsmM95>,
|
|||||||
if (waitResponse(10000L, GF("Call Ready"), GF("OK"), GF("FAIL")) == 3) {
|
if (waitResponse(10000L, GF("Call Ready"), GF("OK"), GF("FAIL")) == 3) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return init();
|
return init(pin);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool powerOffImpl() {
|
bool powerOffImpl() {
|
||||||
|
|||||||
@@ -197,12 +197,12 @@ class TinyGsmMC60 : public TinyGsmModem<TinyGsmMC60>,
|
|||||||
* Power functions
|
* Power functions
|
||||||
*/
|
*/
|
||||||
protected:
|
protected:
|
||||||
bool restartImpl() {
|
bool restartImpl(const char* pin = NULL) {
|
||||||
if (!testAT()) { return false; }
|
if (!testAT()) { return false; }
|
||||||
if (!setPhoneFunctionality(0)) { return false; }
|
if (!setPhoneFunctionality(0)) { return false; }
|
||||||
if (!setPhoneFunctionality(1, true)) { return false; }
|
if (!setPhoneFunctionality(1, true)) { return false; }
|
||||||
delay(3000);
|
delay(3000);
|
||||||
return init();
|
return init(pin);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool powerOffImpl() {
|
bool powerOffImpl() {
|
||||||
|
|||||||
@@ -215,7 +215,7 @@ class TinyGsmSim5360 : public TinyGsmModem<TinyGsmSim5360>,
|
|||||||
* Power functions
|
* Power functions
|
||||||
*/
|
*/
|
||||||
protected:
|
protected:
|
||||||
bool restartImpl() {
|
bool restartImpl(const char* pin = NULL) {
|
||||||
if (!testAT()) { return false; }
|
if (!testAT()) { return false; }
|
||||||
sendAT(GF("+REBOOT"));
|
sendAT(GF("+REBOOT"));
|
||||||
// Should return an 'OK' after reboot command is sent
|
// Should return an 'OK' after reboot command is sent
|
||||||
@@ -223,7 +223,7 @@ class TinyGsmSim5360 : public TinyGsmModem<TinyGsmSim5360>,
|
|||||||
// After booting, modem sends out messages as each of its
|
// After booting, modem sends out messages as each of its
|
||||||
// internal modules loads. The final message is "PB DONE".
|
// internal modules loads. The final message is "PB DONE".
|
||||||
if (waitResponse(40000L, GF(GSM_NL "PB DONE")) != 1) { return false; }
|
if (waitResponse(40000L, GF(GSM_NL "PB DONE")) != 1) { return false; }
|
||||||
return init();
|
return init(pin);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool powerOffImpl() {
|
bool powerOffImpl() {
|
||||||
|
|||||||
@@ -212,11 +212,11 @@ class TinyGsmSim7000 : public TinyGsmModem<TinyGsmSim7000>,
|
|||||||
* Power functions
|
* Power functions
|
||||||
*/
|
*/
|
||||||
protected:
|
protected:
|
||||||
bool restartImpl() {
|
bool restartImpl(const char* pin = NULL) {
|
||||||
if (!setPhoneFunctionality(0)) { return false; }
|
if (!setPhoneFunctionality(0)) { return false; }
|
||||||
if (!setPhoneFunctionality(1, true)) { return false; }
|
if (!setPhoneFunctionality(1, true)) { return false; }
|
||||||
waitResponse(10000L, GF("SMS Ready"), GF("RDY"));
|
waitResponse(10000L, GF("SMS Ready"), GF("RDY"));
|
||||||
return init();
|
return init(pin);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool powerOffImpl() {
|
bool powerOffImpl() {
|
||||||
|
|||||||
@@ -219,12 +219,12 @@ class TinyGsmSim7600 : public TinyGsmModem<TinyGsmSim7600>,
|
|||||||
* Power functions
|
* Power functions
|
||||||
*/
|
*/
|
||||||
protected:
|
protected:
|
||||||
bool restartImpl() {
|
bool restartImpl(const char* pin = NULL) {
|
||||||
if (!testAT()) { return false; }
|
if (!testAT()) { return false; }
|
||||||
sendAT(GF("+CRESET"));
|
sendAT(GF("+CRESET"));
|
||||||
if (waitResponse(10000L) != 1) { return false; }
|
if (waitResponse(10000L) != 1) { return false; }
|
||||||
delay(5000L); // TODO(?): Test this delay!
|
delay(5000L); // TODO(?): Test this delay!
|
||||||
return init();
|
return init(pin);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool powerOffImpl() {
|
bool powerOffImpl() {
|
||||||
|
|||||||
@@ -250,14 +250,14 @@ class TinyGsmSim800 : public TinyGsmModem<TinyGsmSim800>,
|
|||||||
* Power functions
|
* Power functions
|
||||||
*/
|
*/
|
||||||
protected:
|
protected:
|
||||||
bool restartImpl() {
|
bool restartImpl(const char* pin = NULL) {
|
||||||
if (!testAT()) { return false; }
|
if (!testAT()) { return false; }
|
||||||
sendAT(GF("&W"));
|
sendAT(GF("&W"));
|
||||||
waitResponse();
|
waitResponse();
|
||||||
if (!setPhoneFunctionality(0)) { return false; }
|
if (!setPhoneFunctionality(0)) { return false; }
|
||||||
if (!setPhoneFunctionality(1, true)) { return false; }
|
if (!setPhoneFunctionality(1, true)) { return false; }
|
||||||
delay(3000);
|
delay(3000);
|
||||||
return init();
|
return init(pin);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool powerOffImpl() {
|
bool powerOffImpl() {
|
||||||
|
|||||||
@@ -12,9 +12,11 @@
|
|||||||
|
|
||||||
#include "TinyGsmClientSIM800.h"
|
#include "TinyGsmClientSIM800.h"
|
||||||
#include "TinyGsmGPS.tpp"
|
#include "TinyGsmGPS.tpp"
|
||||||
|
#include "TinyGsmBluetooth.tpp"
|
||||||
|
|
||||||
class TinyGsmSim808 : public TinyGsmSim800, public TinyGsmGPS<TinyGsmSim808> {
|
class TinyGsmSim808 : public TinyGsmSim800, public TinyGsmGPS<TinyGsmSim808>, public TinyGsmBluetooth<TinyGsmSim808> {
|
||||||
friend class TinyGsmGPS<TinyGsmSim808>;
|
friend class TinyGsmGPS<TinyGsmSim808>;
|
||||||
|
friend class TinyGsmBluetooth<TinyGsmSim808>;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit TinyGsmSim808(Stream& stream) : TinyGsmSim800(stream) {}
|
explicit TinyGsmSim808(Stream& stream) : TinyGsmSim800(stream) {}
|
||||||
@@ -127,6 +129,40 @@ class TinyGsmSim808 : public TinyGsmSim800, public TinyGsmGPS<TinyGsmSim808> {
|
|||||||
waitResponse();
|
waitResponse();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Bluetooth functions
|
||||||
|
*/
|
||||||
|
|
||||||
|
bool enableBluetoothImpl() {
|
||||||
|
sendAT(GF("+BTPOWER=1"));
|
||||||
|
if (waitResponse() != 1) { return false; }
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool disableBluetoothImpl() {
|
||||||
|
sendAT(GF("+BTPOWER=0"));
|
||||||
|
if (waitResponse() != 1) { return false; }
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool setBluetoothVisibilityImpl(bool visible) {
|
||||||
|
sendAT(GF("+BTVIS="), visible);
|
||||||
|
if (waitResponse() != 1) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool setBluetoothHostNameImpl(const char* name) {
|
||||||
|
sendAT(GF("+BTHOST="), name);
|
||||||
|
if (waitResponse() != 1) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SRC_TINYGSMCLIENTSIM808_H_
|
#endif // SRC_TINYGSMCLIENTSIM808_H_
|
||||||
|
|||||||
@@ -297,11 +297,11 @@ class TinyGsmSaraR4 : public TinyGsmModem<TinyGsmSaraR4>,
|
|||||||
*/
|
*/
|
||||||
protected:
|
protected:
|
||||||
// using +CFUN=15 instead of the more common CFUN=1,1
|
// using +CFUN=15 instead of the more common CFUN=1,1
|
||||||
bool restartImpl() {
|
bool restartImpl(const char* pin = NULL) {
|
||||||
if (!testAT()) { return false; }
|
if (!testAT()) { return false; }
|
||||||
if (!setPhoneFunctionality(15)) { return false; }
|
if (!setPhoneFunctionality(15)) { return false; }
|
||||||
delay(3000); // TODO(?): Verify delay timing here
|
delay(3000); // TODO(?): Verify delay timing here
|
||||||
return init();
|
return init(pin);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool powerOffImpl() {
|
bool powerOffImpl() {
|
||||||
|
|||||||
@@ -283,7 +283,7 @@ class TinyGsmSequansMonarch
|
|||||||
* Power functions
|
* Power functions
|
||||||
*/
|
*/
|
||||||
protected:
|
protected:
|
||||||
bool restartImpl() {
|
bool restartImpl(const char* pin = NULL) {
|
||||||
if (!testAT()) { return false; }
|
if (!testAT()) { return false; }
|
||||||
|
|
||||||
sendAT(GF("+CFUN=0"));
|
sendAT(GF("+CFUN=0"));
|
||||||
@@ -295,7 +295,7 @@ class TinyGsmSequansMonarch
|
|||||||
res = waitResponse(20000L, GF("+SYSSTART"), GFP(GSM_ERROR));
|
res = waitResponse(20000L, GF("+SYSSTART"), GFP(GSM_ERROR));
|
||||||
if (res != 1 && res != 3) { return false; }
|
if (res != 1 && res != 3) { return false; }
|
||||||
delay(1000);
|
delay(1000);
|
||||||
return init();
|
return init(pin);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool powerOffImpl() {
|
bool powerOffImpl() {
|
||||||
|
|||||||
@@ -243,11 +243,11 @@ class TinyGsmUBLOX : public TinyGsmModem<TinyGsmUBLOX>,
|
|||||||
* Power functions
|
* Power functions
|
||||||
*/
|
*/
|
||||||
protected:
|
protected:
|
||||||
bool restartImpl() {
|
bool restartImpl(const char* pin = NULL) {
|
||||||
if (!testAT()) { return false; }
|
if (!testAT()) { return false; }
|
||||||
if (!setPhoneFunctionality(16)) { return false; }
|
if (!setPhoneFunctionality(16)) { return false; }
|
||||||
delay(3000); // TODO(?): Verify delay timing here
|
delay(3000); // TODO(?): Verify delay timing here
|
||||||
return init();
|
return init(pin);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool powerOffImpl() {
|
bool powerOffImpl() {
|
||||||
|
|||||||
@@ -487,7 +487,7 @@ class TinyGsmXBee : public TinyGsmModem<TinyGsmXBee>,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool restartImpl() {
|
bool restartImpl(const char* pin = NULL) {
|
||||||
if (!commandMode()) { return false; } // Return immediately
|
if (!commandMode()) { return false; } // Return immediately
|
||||||
|
|
||||||
if (beeType == XBEE_UNKNOWN) getSeries(); // how we restart depends on this
|
if (beeType == XBEE_UNKNOWN) getSeries(); // how we restart depends on this
|
||||||
@@ -525,7 +525,7 @@ class TinyGsmXBee : public TinyGsmModem<TinyGsmXBee>,
|
|||||||
|
|
||||||
exitCommand();
|
exitCommand();
|
||||||
|
|
||||||
return init();
|
return init(pin);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setupPinSleep(bool maintainAssociation = false) {
|
void setupPinSleep(bool maintainAssociation = false) {
|
||||||
|
|||||||
@@ -41,7 +41,7 @@
|
|||||||
__attribute__((error("Not available on this modem type")))
|
__attribute__((error("Not available on this modem type")))
|
||||||
#define TINY_GSM_ATTR_NOT_IMPLEMENTED __attribute__((error("Not implemented")))
|
#define TINY_GSM_ATTR_NOT_IMPLEMENTED __attribute__((error("Not implemented")))
|
||||||
|
|
||||||
#if defined(__AVR__)
|
#if defined(__AVR__) && !defined(__AVR_ATmega4809__)
|
||||||
#define TINY_GSM_PROGMEM PROGMEM
|
#define TINY_GSM_PROGMEM PROGMEM
|
||||||
typedef const __FlashStringHelper* GsmConstStr;
|
typedef const __FlashStringHelper* GsmConstStr;
|
||||||
#define GFP(x) (reinterpret_cast<GsmConstStr>(x))
|
#define GFP(x) (reinterpret_cast<GsmConstStr>(x))
|
||||||
|
|||||||
@@ -53,8 +53,8 @@ class TinyGsmModem {
|
|||||||
/*
|
/*
|
||||||
* Power functions
|
* Power functions
|
||||||
*/
|
*/
|
||||||
bool restart() {
|
bool restart(const char* pin = NULL) {
|
||||||
return thisModem().restartImpl();
|
return thisModem().restartImpl(pin);
|
||||||
}
|
}
|
||||||
bool poweroff() {
|
bool poweroff() {
|
||||||
return thisModem().powerOffImpl();
|
return thisModem().powerOffImpl();
|
||||||
|
|||||||
Reference in New Issue
Block a user