Update API
This commit is contained in:
123
TinyGsmClient.h
123
TinyGsmClient.h
@@ -151,10 +151,42 @@ public:
|
|||||||
virtual operator bool() { return connected(); }
|
virtual operator bool() { return connected(); }
|
||||||
|
|
||||||
public:
|
public:
|
||||||
bool factoryDefault() {
|
|
||||||
|
/*
|
||||||
|
* Basic functions
|
||||||
|
*/
|
||||||
|
bool begin() {
|
||||||
if (!autoBaud()) {
|
if (!autoBaud()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
sendAT(F("&FZE0")); // Factory + Reset + Echo Off
|
||||||
|
return waitResponse() == 1;
|
||||||
|
|
||||||
|
// +ICCID
|
||||||
|
// AT+CPIN?
|
||||||
|
// AT+CPIN=pin-code
|
||||||
|
// AT+CREG?
|
||||||
|
}
|
||||||
|
|
||||||
|
bool autoBaud(unsigned long timeout = 10000L) {
|
||||||
|
for (unsigned long start = millis(); millis() - start < timeout; ) {
|
||||||
|
sendAT("");
|
||||||
|
if (waitResponse(200) == 1) {
|
||||||
|
delay(100);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
delay(100);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void maintain() {
|
||||||
|
while (stream.available()) {
|
||||||
|
waitResponse(10);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool factoryDefault() {
|
||||||
sendAT(F("&FZE0&W")); // Factory + Reset + Echo Off + Write
|
sendAT(F("&FZE0&W")); // Factory + Reset + Echo Off + Write
|
||||||
waitResponse();
|
waitResponse();
|
||||||
sendAT(F("+IPR=0")); // Auto-baud
|
sendAT(F("+IPR=0")); // Auto-baud
|
||||||
@@ -169,7 +201,15 @@ public:
|
|||||||
return waitResponse() == 1;
|
return waitResponse() == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Power functions
|
||||||
|
*/
|
||||||
|
|
||||||
bool restart() {
|
bool restart() {
|
||||||
|
return resetSoft();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool resetSoft() {
|
||||||
if (!autoBaud()) {
|
if (!autoBaud()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -192,19 +232,29 @@ public:
|
|||||||
return waitResponse(60000L, F("Ready" GSM_NL)) == 1;
|
return waitResponse(60000L, F("Ready" GSM_NL)) == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool init() {
|
// Reboot the module by setting the specified pin LOW, then HIGH.
|
||||||
if (!autoBaud()) {
|
// (The pin should be connected to a P-MOSFET)
|
||||||
return false;
|
bool resetHard(int pwrPin) {
|
||||||
}
|
powerOff(pwrPin);
|
||||||
sendAT(F("&FZE0")); // Factory + Reset + Echo Off
|
delay(100);
|
||||||
return waitResponse() == 1;
|
return powerOn(pwrPin);
|
||||||
|
|
||||||
// +ICCID
|
|
||||||
// AT+CPIN?
|
|
||||||
// AT+CPIN=pin-code
|
|
||||||
// AT+CREG?
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void powerOff(int pwrPin) {
|
||||||
|
pinMode(pwrPin, OUTPUT);
|
||||||
|
digitalWrite(pwrPin, LOW);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool powerOn(int pwrPin) {
|
||||||
|
pinMode(pwrPin, OUTPUT);
|
||||||
|
digitalWrite(pwrPin, HIGH);
|
||||||
|
delay(3000);
|
||||||
|
return autoBaud();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* GPRS functions
|
||||||
|
*/
|
||||||
bool networkConnect(const char* apn, const char* user, const char* pwd) {
|
bool networkConnect(const char* apn, const char* user, const char* pwd) {
|
||||||
networkDisconnect();
|
networkDisconnect();
|
||||||
|
|
||||||
@@ -258,26 +308,10 @@ public:
|
|||||||
return waitResponse(60000L) == 1;
|
return waitResponse(60000L) == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool autoBaud(unsigned long timeout = 10000L) {
|
/*
|
||||||
for (unsigned long start = millis(); millis() - start < timeout; ) {
|
* SIM card functions
|
||||||
sendAT("");
|
*/
|
||||||
if (waitResponse() == 1) {
|
bool simUnlock(const char *pin) {
|
||||||
delay(100);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
delay(100);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void maintain() {
|
|
||||||
while (stream.available()) {
|
|
||||||
waitResponse(10);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool simUnlock(const char *pin)
|
|
||||||
{
|
|
||||||
sendAT(F("+CPIN="), pin);
|
sendAT(F("+CPIN="), pin);
|
||||||
return waitResponse() == 1;
|
return waitResponse() == 1;
|
||||||
}
|
}
|
||||||
@@ -287,6 +321,31 @@ public:
|
|||||||
//TODO...
|
//TODO...
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool getIMEI() {
|
||||||
|
}
|
||||||
|
|
||||||
|
bool getNetworkOperator() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Phone Call functions
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Messaging functions
|
||||||
|
*/
|
||||||
|
|
||||||
|
void sendUSSD() {
|
||||||
|
}
|
||||||
|
|
||||||
|
void sendSMS() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Location functions
|
||||||
|
*/
|
||||||
|
void getLocation() {
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int modemConnect(const char* host, uint16_t port) {
|
int modemConnect(const char* host, uint16_t port) {
|
||||||
|
|||||||
Reference in New Issue
Block a user