mirror of
https://github.com/KevinMidboe/TinyGSM.git
synced 2025-10-29 18:00:18 +00:00
Add init() function
This commit is contained in:
@@ -35,7 +35,10 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
//#define GSM_USE_HEX
|
//#define GSM_USE_HEX
|
||||||
|
|
||||||
|
#if !defined(GSM_RX_BUFFER)
|
||||||
#define GSM_RX_BUFFER 64
|
#define GSM_RX_BUFFER 64
|
||||||
|
#endif
|
||||||
|
|
||||||
#define GSM_NL "\r\n"
|
#define GSM_NL "\r\n"
|
||||||
static constexpr char GSM_OK[] GSM_PROGMEM = "OK" GSM_NL;
|
static constexpr char GSM_OK[] GSM_PROGMEM = "OK" GSM_NL;
|
||||||
@@ -105,11 +108,7 @@ public:
|
|||||||
|
|
||||||
virtual int available() {
|
virtual int available() {
|
||||||
maintain();
|
maintain();
|
||||||
size_t res = rx.size();
|
return rx.size() + sock_available;
|
||||||
if (res > 0) {
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
return sock_available;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual int read(uint8_t *buf, size_t size) {
|
virtual int read(uint8_t *buf, size_t size) {
|
||||||
@@ -121,8 +120,14 @@ public:
|
|||||||
rx.get(buf, chunk);
|
rx.get(buf, chunk);
|
||||||
buf += chunk;
|
buf += chunk;
|
||||||
cnt += chunk;
|
cnt += chunk;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// TODO: Read directly into user buffer?
|
||||||
|
maintain();
|
||||||
|
if (sock_available > 0) {
|
||||||
|
modemRead(rx.free());
|
||||||
} else {
|
} else {
|
||||||
modemRead(rx.free()); //TODO: min(rx.free(), sock_available)
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return cnt;
|
return cnt;
|
||||||
@@ -165,7 +170,9 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool restart() {
|
bool restart() {
|
||||||
autoBaud();
|
if (!autoBaud()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
sendAT(F("+CFUN=0"));
|
sendAT(F("+CFUN=0"));
|
||||||
if (waitResponse(10000L) != 1) {
|
if (waitResponse(10000L) != 1) {
|
||||||
return false;
|
return false;
|
||||||
@@ -182,15 +189,23 @@ public:
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1 == waitResponse(60000, F("Ready"));
|
return waitResponse(60000L, F("Ready" GSM_NL)) == 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool init() {
|
||||||
|
if (!autoBaud()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
sendAT(F("&FZE0")); // Factory + Reset + Echo Off
|
||||||
|
return waitResponse() == 1;
|
||||||
|
|
||||||
|
// +ICCID
|
||||||
|
// AT+CPIN?
|
||||||
|
// AT+CPIN=pin-code
|
||||||
|
// AT+CREG?
|
||||||
}
|
}
|
||||||
|
|
||||||
bool networkConnect(const char* apn, const char* user, const char* pwd) {
|
bool networkConnect(const char* apn, const char* user, const char* pwd) {
|
||||||
autoBaud();
|
|
||||||
|
|
||||||
// AT+CPIN=pin-code
|
|
||||||
// AT+CREG?
|
|
||||||
|
|
||||||
networkDisconnect();
|
networkDisconnect();
|
||||||
|
|
||||||
// AT+CGATT?
|
// AT+CGATT?
|
||||||
|
|||||||
Reference in New Issue
Block a user