Correctly turning off airplane mode after restart
Also removed some extra stream-clear functions
This commit is contained in:
5
.gitignore
vendored
5
.gitignore
vendored
@@ -20,7 +20,10 @@
|
|||||||
.gcc-flags.json
|
.gcc-flags.json
|
||||||
platformio.ini
|
platformio.ini
|
||||||
lib/readme.txt
|
lib/readme.txt
|
||||||
.vscode
|
.vscode/*
|
||||||
|
.vscode/.browse.c_cpp.db*
|
||||||
|
.vscode/c_cpp_properties.json
|
||||||
|
.vscode/launch.json
|
||||||
|
|
||||||
# Markers
|
# Markers
|
||||||
.development
|
.development
|
||||||
|
@@ -78,45 +78,45 @@ public:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
virtual int connect(const char *host, uint16_t port) {
|
virtual int connect(const char *host, uint16_t port) {
|
||||||
at->streamClear(); // Empty anything remaining in the buffer;
|
at->streamClear(); // Empty anything in the buffer before starting
|
||||||
bool sock_connected = false;
|
|
||||||
if (at->commandMode()) { // Don't try if we didn't successfully get into command mode
|
if (at->commandMode()) { // Don't try if we didn't successfully get into command mode
|
||||||
sock_connected = at->modemConnect(host, port, mux, false);
|
sock_connected = at->modemConnect(host, port, mux, false);
|
||||||
at->writeChanges();
|
at->writeChanges();
|
||||||
at->exitCommand();
|
at->exitCommand();
|
||||||
}
|
}
|
||||||
at->streamClear(); // Empty anything remaining in the buffer;
|
else
|
||||||
|
sock_connected = false;
|
||||||
return sock_connected;
|
return sock_connected;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual int connect(IPAddress ip, uint16_t port) {
|
virtual int connect(IPAddress ip, uint16_t port) {
|
||||||
at->streamClear(); // Empty anything remaining in the buffer;
|
at->streamClear(); // Empty anything in the buffer before starting
|
||||||
bool sock_connected = false;
|
|
||||||
if (at->commandMode()) { // Don't try if we didn't successfully get into command mode
|
if (at->commandMode()) { // Don't try if we didn't successfully get into command mode
|
||||||
sock_connected = at->modemConnect(ip, port, mux, false);
|
sock_connected = at->modemConnect(ip, port, mux, false);
|
||||||
at->writeChanges();
|
at->writeChanges();
|
||||||
at->exitCommand();
|
at->exitCommand();
|
||||||
}
|
}
|
||||||
at->streamClear(); // Empty anything remaining in the buffer;
|
else
|
||||||
|
sock_connected = false;
|
||||||
return sock_connected;
|
return sock_connected;
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is a hack to shut the socket by setting the timeout to zero and
|
// This is a hack to shut the socket by setting the timeout to zero and
|
||||||
// then sending an empty line to the server.
|
// then sending an empty line to the server.
|
||||||
virtual void stop() {
|
virtual void stop() {
|
||||||
at->streamClear(); // Empty anything remaining in the buffer;
|
at->streamClear(); // Empty anything in the buffer
|
||||||
at->commandMode();
|
at->commandMode();
|
||||||
at->sendAT(GF("TM0")); // Set socket timeout to 0;
|
at->sendAT(GF("TM0")); // Set socket timeout to 0;
|
||||||
at->waitResponse();
|
at->waitResponse();
|
||||||
at->writeChanges();
|
at->writeChanges();
|
||||||
at->exitCommand();
|
at->exitCommand();
|
||||||
at->modemSend("", 1, mux);
|
at->streamWrite("");
|
||||||
at->commandMode();
|
at->commandMode();
|
||||||
at->sendAT(GF("TM64")); // Set socket timeout back to 10 seconds;
|
at->sendAT(GF("TM64")); // Set socket timeout back to 10 seconds;
|
||||||
at->waitResponse();
|
at->waitResponse();
|
||||||
at->writeChanges();
|
at->writeChanges();
|
||||||
at->exitCommand();
|
at->exitCommand();
|
||||||
at->streamClear(); // Empty anything remaining in the buffer;
|
at->streamClear(); // Empty anything remaining in the buffer
|
||||||
sock_connected = false;
|
sock_connected = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -141,7 +141,7 @@ public:
|
|||||||
|
|
||||||
virtual int read(uint8_t *buf, size_t size) {
|
virtual int read(uint8_t *buf, size_t size) {
|
||||||
TINY_GSM_YIELD();
|
TINY_GSM_YIELD();
|
||||||
return at->stream.readBytes((char*)buf, size);
|
return at->stream.readBytes((char *)buf, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual int read() {
|
virtual int read() {
|
||||||
@@ -178,32 +178,32 @@ class GsmClientSecure : public GsmClient
|
|||||||
public:
|
public:
|
||||||
GsmClientSecure() {}
|
GsmClientSecure() {}
|
||||||
|
|
||||||
GsmClientSecure(TinyGsmXBee& modem, uint8_t mux = 1)
|
GsmClientSecure(TinyGsmXBee& modem, uint8_t mux = 0)
|
||||||
: GsmClient(modem, mux)
|
: GsmClient(modem, mux)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual int connect(const char *host, uint16_t port) {
|
virtual int connect(const char *host, uint16_t port) {
|
||||||
at->streamClear(); // Empty anything remaining in the buffer;
|
at->streamClear(); // Empty anything in the buffer before starting
|
||||||
bool sock_connected = false;
|
|
||||||
if (at->commandMode()) { // Don't try if we didn't successfully get into command mode
|
if (at->commandMode()) { // Don't try if we didn't successfully get into command mode
|
||||||
sock_connected = at->modemConnect(host, port, mux, true);
|
sock_connected = at->modemConnect(host, port, mux, true);
|
||||||
at->writeChanges();
|
at->writeChanges();
|
||||||
at->exitCommand();
|
at->exitCommand();
|
||||||
}
|
}
|
||||||
at->streamClear(); // Empty anything remaining in the buffer;
|
else
|
||||||
|
sock_connected = false;
|
||||||
return sock_connected;
|
return sock_connected;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual int connect(IPAddress ip, uint16_t port) {
|
virtual int connect(IPAddress ip, uint16_t port) {
|
||||||
at->streamClear(); // Empty anything remaining in the buffer;
|
at->streamClear(); // Empty anything in the buffer before starting
|
||||||
bool sock_connected = false;
|
|
||||||
if (at->commandMode()) { // Don't try if we didn't successfully get into command mode
|
if (at->commandMode()) { // Don't try if we didn't successfully get into command mode
|
||||||
sock_connected = at->modemConnect(ip, port, mux, true);
|
sock_connected = at->modemConnect(ip, port, mux, true);
|
||||||
at->writeChanges();
|
at->writeChanges();
|
||||||
at->exitCommand();
|
at->exitCommand();
|
||||||
}
|
}
|
||||||
at->streamClear(); // Empty anything remaining in the buffer;
|
else
|
||||||
|
sock_connected = false;
|
||||||
return sock_connected;
|
return sock_connected;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -216,6 +216,7 @@ public:
|
|||||||
{
|
{
|
||||||
beeType = XBEE_UNKNOWN; // Start not knowing what kind of bee it is
|
beeType = XBEE_UNKNOWN; // Start not knowing what kind of bee it is
|
||||||
guardTime = TINY_GSM_XBEE_GUARD_TIME; // Start with the default guard time of 1 second
|
guardTime = TINY_GSM_XBEE_GUARD_TIME; // Start with the default guard time of 1 second
|
||||||
|
memset(sockets, 0, sizeof(sockets));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -369,7 +370,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (beeType != XBEE_S6B_WIFI) {
|
if (beeType != XBEE_S6B_WIFI) {
|
||||||
sendAT(GF("AM1")); // Turn of airplane mode
|
sendAT(GF("AM0")); // Turn off airplane mode
|
||||||
if (waitResponse() != 1) return exitAndFail();
|
if (waitResponse() != 1) return exitAndFail();
|
||||||
if (!writeChanges()) return exitAndFail();
|
if (!writeChanges()) return exitAndFail();
|
||||||
}
|
}
|
||||||
@@ -681,7 +682,7 @@ protected:
|
|||||||
while (!gotIP && millis() - startMillis < 45000L) // the lookup can take a while
|
while (!gotIP && millis() - startMillis < 45000L) // the lookup can take a while
|
||||||
{
|
{
|
||||||
sendAT(GF("LA"), host);
|
sendAT(GF("LA"), host);
|
||||||
while (stream.available() < 4) {}; // wait for any response
|
while (stream.available() < 4 && millis() - startMillis < 45000L) {}; // wait for any response
|
||||||
strIP = stream.readStringUntil('\r'); // read result
|
strIP = stream.readStringUntil('\r'); // read result
|
||||||
strIP.trim();
|
strIP.trim();
|
||||||
if (!strIP.endsWith(GF("ERROR"))) gotIP = true;
|
if (!strIP.endsWith(GF("ERROR"))) gotIP = true;
|
||||||
@@ -740,7 +741,7 @@ public:
|
|||||||
|
|
||||||
void streamClear(void) {
|
void streamClear(void) {
|
||||||
TINY_GSM_YIELD();
|
TINY_GSM_YIELD();
|
||||||
while (stream.available()) { stream.read(); }
|
while (stream.available()) { stream.read();}
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename... Args>
|
template<typename... Args>
|
||||||
|
Reference in New Issue
Block a user