Browse Source

Some notes on ublox

v_master
Sara Damiano 6 years ago
parent
commit
4225ed7c5e
1 changed files with 17 additions and 10 deletions
  1. +17
    -10
      src/TinyGsmClientUBLOX.h

+ 17
- 10
src/TinyGsmClientUBLOX.h View File

@ -12,7 +12,7 @@
//#define TINY_GSM_DEBUG Serial //#define TINY_GSM_DEBUG Serial
#define TINY_GSM_MUX_COUNT 5
#define TINY_GSM_MUX_COUNT 7
#include <TinyGsmCommon.h> #include <TinyGsmCommon.h>
@ -50,14 +50,15 @@ class GsmClient : public Client
public: public:
GsmClient() {} GsmClient() {}
GsmClient(TinyGsmUBLOX& modem, uint8_t mux = 1) {
GsmClient(TinyGsmUBLOX& modem, uint8_t mux = 0) {
init(&modem, mux); init(&modem, mux);
} }
bool init(TinyGsmUBLOX* modem, uint8_t mux = 1) {
bool init(TinyGsmUBLOX* modem, uint8_t mux = 0) {
this->at = modem; this->at = modem;
this->mux = mux; this->mux = mux;
sock_available = 0; sock_available = 0;
prev_check = 0;
sock_connected = false; sock_connected = false;
got_data = false; got_data = false;
return true; return true;
@ -481,7 +482,7 @@ public:
waitResponse(); waitResponse();
} }
sendAT(GF("+CGDCONT=1,\"IP\",\""), apn, '"'); // Define the PDP context
sendAT(GF("+CGDCONT=1,\"IP\",\""), apn, '"'); // Define PDP context 1
waitResponse(); waitResponse();
sendAT(GF("+CGACT=1,1")); // activate PDP profile/context 1 sendAT(GF("+CGACT=1,1")); // activate PDP profile/context 1
@ -527,7 +528,7 @@ public:
// LTE-M and NB-IoT modules do not support UPSx commands // LTE-M and NB-IoT modules do not support UPSx commands
if (isCatM) { if (isCatM) {
sendAT(GF("+CGACT=1,0")); // Deactivate PDP context 0
sendAT(GF("+CGACT=1,0")); // Deactivate PDP context 1
if (waitResponse(40000L) != 1) { if (waitResponse(40000L) != 1) {
return false; return false;
} }
@ -686,8 +687,11 @@ protected:
//sendAT(GF("+USOSO="), *mux, GF(",6,2,30000")); //sendAT(GF("+USOSO="), *mux, GF(",6,2,30000"));
//waitResponse(); //waitResponse();
sendAT(GF("+USOCO="), *mux, ",\"", host, "\",", port); // connect on socket
int rsp = waitResponse(75000L);
// connect on socket
// TODO: Use async connection? Would return OK right away, but we would
// have to wait for the +UUSOCO URC to verify connection
sendAT(GF("+USOCO="), *mux, ",\"", host, "\",", port);
int rsp = waitResponse(120000L);
return (1 == rsp); return (1 == rsp);
} }
@ -695,7 +699,7 @@ protected:
TINY_GSM_YIELD(); TINY_GSM_YIELD();
if (isCatM) { // These modems allow a faster "asynchronous" close if (isCatM) { // These modems allow a faster "asynchronous" close
sendAT(GF("+USOCL="), mux, GF(",1")); sendAT(GF("+USOCL="), mux, GF(",1"));
return (1 == waitResponse(120000L)); // but it can take up to 120s to get a response
return (1 == waitResponse(120000L)); // but it still can take up to 120s to get a response
} }
else { // no async close else { // no async close
sendAT(GF("+USOCL="), mux); sendAT(GF("+USOCL="), mux);
@ -718,6 +722,7 @@ protected:
streamSkipUntil(','); // Skip mux streamSkipUntil(','); // Skip mux
int sent = stream.readStringUntil('\n').toInt(); int sent = stream.readStringUntil('\n').toInt();
waitResponse(); waitResponse();
maintain(); // look for a very quick response
return sent; return sent;
} }
@ -743,7 +748,8 @@ protected:
size_t modemGetAvailable(uint8_t mux) { size_t modemGetAvailable(uint8_t mux) {
sendAT(GF("+USORD="), mux, ",0"); sendAT(GF("+USORD="), mux, ",0");
size_t result = 0; size_t result = 0;
if (waitResponse(GF(GSM_NL "+USORD:")) == 1) {
uint8_t res = waitResponse(GF(GSM_NL "+USORD:"), GF(GSM_NL "ERROR"), GF(GSM_NL "+CME ERROR: Operation not allowed"));
if (res == 1) {
streamSkipUntil(','); // Skip mux streamSkipUntil(','); // Skip mux
result = stream.readStringUntil('\n').toInt(); result = stream.readStringUntil('\n').toInt();
waitResponse(); waitResponse();
@ -756,7 +762,8 @@ protected:
bool modemGetConnected(uint8_t mux) { bool modemGetConnected(uint8_t mux) {
sendAT(GF("+USOCTL="), mux, ",10"); sendAT(GF("+USOCTL="), mux, ",10");
if (waitResponse(GF(GSM_NL "+USOCTL:")) != 1)
uint8_t res = waitResponse(GF(GSM_NL "+USOCTL:"), GF(GSM_NL "ERROR"), GF(GSM_NL "+CME ERROR: Operation not allowed"));
if (res != 1)
return false; return false;
streamSkipUntil(','); // Skip mux streamSkipUntil(','); // Skip mux


Loading…
Cancel
Save