mirror of
https://github.com/KevinMidboe/TinyGSM.git
synced 2025-10-29 18:00:18 +00:00
Fixed upcase, other XBee fixes
This commit is contained in:
@@ -506,7 +506,7 @@ protected:
|
|||||||
|
|
||||||
bool modemConnect(const char* host, uint16_t port, uint8_t* mux, int timeout_s = 75) {
|
bool modemConnect(const char* host, uint16_t port, uint8_t* mux, int timeout_s = 75) {
|
||||||
unsigned long startMillis = millis();
|
unsigned long startMillis = millis();
|
||||||
uint32_t timeout_ms = timeout_s*1000;
|
uint32_t timeout_ms = ((uint32_t)timeout_s)*1000;
|
||||||
|
|
||||||
sendAT(GF("+CIPSTART="), GF("\"TCP"), GF("\",\""), host, GF("\","), port);
|
sendAT(GF("+CIPSTART="), GF("\"TCP"), GF("\",\""), host, GF("\","), port);
|
||||||
if (waitResponse(timeout_ms, GF(GSM_NL "+CIPNUM:")) != 1) {
|
if (waitResponse(timeout_ms, GF(GSM_NL "+CIPNUM:")) != 1) {
|
||||||
|
|||||||
@@ -474,7 +474,7 @@ protected:
|
|||||||
bool ssl = false, int timeout_s = 20)
|
bool ssl = false, int timeout_s = 20)
|
||||||
{
|
{
|
||||||
int rsp;
|
int rsp;
|
||||||
uint32_t timeout_ms = timeout_s*1000;
|
uint32_t timeout_ms = ((uint32_t)timeout_s)*1000;
|
||||||
|
|
||||||
// <PDPcontextID>(1-16), <connectID>(0-11),"TCP/UDP/TCP LISTENER/UDP SERVICE",
|
// <PDPcontextID>(1-16), <connectID>(0-11),"TCP/UDP/TCP LISTENER/UDP SERVICE",
|
||||||
// "<IP_address>/<domain_name>",<remote_port>,<local_port>,<access_mode>(0-2 0=buffer)
|
// "<IP_address>/<domain_name>",<remote_port>,<local_port>,<access_mode>(0-2 0=buffer)
|
||||||
|
|||||||
@@ -334,7 +334,7 @@ protected:
|
|||||||
bool modemConnect(const char* host, uint16_t port, uint8_t mux,
|
bool modemConnect(const char* host, uint16_t port, uint8_t mux,
|
||||||
bool ssl = false, int timeout_s = 75)
|
bool ssl = false, int timeout_s = 75)
|
||||||
{
|
{
|
||||||
uint32_t timeout_ms = timeout_s*1000;
|
uint32_t timeout_ms = ((uint32_t)timeout_s)*1000;
|
||||||
if (ssl) {
|
if (ssl) {
|
||||||
sendAT(GF("+CIPSSLSIZE=4096"));
|
sendAT(GF("+CIPSSLSIZE=4096"));
|
||||||
waitResponse();
|
waitResponse();
|
||||||
|
|||||||
@@ -414,7 +414,7 @@ TINY_GSM_MODEM_WAIT_FOR_NETWORK()
|
|||||||
protected:
|
protected:
|
||||||
|
|
||||||
bool modemConnect(const char* host, uint16_t port, uint8_t mux, int timeout_s = 75) {
|
bool modemConnect(const char* host, uint16_t port, uint8_t mux, int timeout_s = 75) {
|
||||||
uint32_t timeout_ms = timeout_s*1000;
|
uint32_t timeout_ms = ((uint32_t)timeout_s)*1000;
|
||||||
for (int i=0; i<3; i++) { // TODO: no need for loop?
|
for (int i=0; i<3; i++) { // TODO: no need for loop?
|
||||||
String ip = dnsIpQuery(host);
|
String ip = dnsIpQuery(host);
|
||||||
|
|
||||||
|
|||||||
@@ -521,7 +521,7 @@ protected:
|
|||||||
bool modemConnect(const char* host, uint16_t port, uint8_t mux,
|
bool modemConnect(const char* host, uint16_t port, uint8_t mux,
|
||||||
bool ssl = false, int timeout_s = 75)
|
bool ssl = false, int timeout_s = 75)
|
||||||
{
|
{
|
||||||
uint32_t timeout_ms = timeout_s*1000;
|
uint32_t timeout_ms = ((uint32_t)timeout_s)*1000;
|
||||||
sendAT(GF("+QIOPEN="), mux, GF("\"TCP"), GF("\",\""), host, GF("\","), port);
|
sendAT(GF("+QIOPEN="), mux, GF("\"TCP"), GF("\",\""), host, GF("\","), port);
|
||||||
int rsp = waitResponse(timeout_ms,
|
int rsp = waitResponse(timeout_ms,
|
||||||
GF("CONNECT OK" GSM_NL),
|
GF("CONNECT OK" GSM_NL),
|
||||||
|
|||||||
@@ -540,7 +540,7 @@ protected:
|
|||||||
bool modemConnect(const char* host, uint16_t port, uint8_t mux,
|
bool modemConnect(const char* host, uint16_t port, uint8_t mux,
|
||||||
bool ssl = false, int timeout_s = 75)
|
bool ssl = false, int timeout_s = 75)
|
||||||
{
|
{
|
||||||
uint32_t timeout_ms = timeout_s*1000;
|
uint32_t timeout_ms = ((uint32_t)timeout_s)*1000;
|
||||||
sendAT(GF("+QIOPEN="), mux, GF("\"TCP"), GF("\",\""), host, GF("\","), port);
|
sendAT(GF("+QIOPEN="), mux, GF("\"TCP"), GF("\",\""), host, GF("\","), port);
|
||||||
int rsp = waitResponse(timeout_ms,
|
int rsp = waitResponse(timeout_ms,
|
||||||
GF("CONNECT OK" GSM_NL),
|
GF("CONNECT OK" GSM_NL),
|
||||||
|
|||||||
@@ -764,7 +764,7 @@ protected:
|
|||||||
bool ssl = false, int timeout_s = 75)
|
bool ssl = false, int timeout_s = 75)
|
||||||
{
|
{
|
||||||
int rsp;
|
int rsp;
|
||||||
uint32_t timeout_ms = timeout_s*1000;
|
uint32_t timeout_ms = ((uint32_t)timeout_s)*1000;
|
||||||
sendAT(GF("+CIPSTART="), mux, ',', GF("\"TCP"), GF("\",\""), host, GF("\","), port);
|
sendAT(GF("+CIPSTART="), mux, ',', GF("\"TCP"), GF("\",\""), host, GF("\","), port);
|
||||||
rsp = waitResponse(timeout_ms,
|
rsp = waitResponse(timeout_ms,
|
||||||
GF("CONNECT OK" GSM_NL),
|
GF("CONNECT OK" GSM_NL),
|
||||||
|
|||||||
@@ -685,7 +685,7 @@ protected:
|
|||||||
bool ssl = false, int timeout_s = 75)
|
bool ssl = false, int timeout_s = 75)
|
||||||
{
|
{
|
||||||
int rsp;
|
int rsp;
|
||||||
uint32_t timeout_ms = timeout_s*1000;
|
uint32_t timeout_ms = ((uint32_t)timeout_s)*1000;
|
||||||
#if !defined(TINY_GSM_MODEM_SIM900)
|
#if !defined(TINY_GSM_MODEM_SIM900)
|
||||||
sendAT(GF("+CIPSSL="), ssl);
|
sendAT(GF("+CIPSSL="), ssl);
|
||||||
rsp = waitResponse();
|
rsp = waitResponse();
|
||||||
|
|||||||
@@ -531,7 +531,7 @@ protected:
|
|||||||
bool modemConnect(const char* host, uint16_t port, uint8_t* mux,
|
bool modemConnect(const char* host, uint16_t port, uint8_t* mux,
|
||||||
bool ssl = false, int timeout_s = 120)
|
bool ssl = false, int timeout_s = 120)
|
||||||
{
|
{
|
||||||
uint32_t timeout_ms = timeout_s*1000;
|
uint32_t timeout_ms = ((uint32_t)timeout_s)*1000;
|
||||||
sendAT(GF("+USOCR=6")); // create a socket
|
sendAT(GF("+USOCR=6")); // create a socket
|
||||||
if (waitResponse(GF(GSM_NL "+USOCR:")) != 1) { // reply is +USOCR: ## of socket created
|
if (waitResponse(GF(GSM_NL "+USOCR:")) != 1) { // reply is +USOCR: ## of socket created
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -482,7 +482,7 @@ protected:
|
|||||||
{
|
{
|
||||||
int rsp;
|
int rsp;
|
||||||
unsigned long startMillis = millis();
|
unsigned long startMillis = millis();
|
||||||
uint32_t timeout_ms = timeout_s*1000;
|
uint32_t timeout_ms = ((uint32_t)timeout_s)*1000;
|
||||||
|
|
||||||
if (ssl) {
|
if (ssl) {
|
||||||
// enable SSl and use security profile 1
|
// enable SSl and use security profile 1
|
||||||
|
|||||||
@@ -514,7 +514,7 @@ protected:
|
|||||||
bool modemConnect(const char* host, uint16_t port, uint8_t* mux,
|
bool modemConnect(const char* host, uint16_t port, uint8_t* mux,
|
||||||
bool ssl = false, int timeout_s = 120)
|
bool ssl = false, int timeout_s = 120)
|
||||||
{
|
{
|
||||||
uint32_t timeout_ms = timeout_s*1000;
|
uint32_t timeout_ms = ((uint32_t)timeout_s)*1000;
|
||||||
sendAT(GF("+USOCR=6")); // create a socket
|
sendAT(GF("+USOCR=6")); // create a socket
|
||||||
if (waitResponse(GF(GSM_NL "+USOCR:")) != 1) { // reply is +USOCR: ## of socket created
|
if (waitResponse(GF(GSM_NL "+USOCR:")) != 1) { // reply is +USOCR: ## of socket created
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -645,15 +645,17 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool waitForNetwork(unsigned long timeout_ms = 60000L) {
|
bool waitForNetwork(unsigned long timeout_ms = 60000L) {
|
||||||
|
bool retVal = false;
|
||||||
XBEE_COMMAND_START_DECORATOR(5, false)
|
XBEE_COMMAND_START_DECORATOR(5, false)
|
||||||
for (unsigned long start = millis(); millis() - start < timeout_ms; ) {
|
for (unsigned long start = millis(); millis() - start < timeout_ms; ) {
|
||||||
if (isNetworkConnected()) {
|
if (isNetworkConnected()) {
|
||||||
return true;
|
retVal = true;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
delay(250); // per Neil H. - more stable with delay
|
delay(250); // per Neil H. - more stable with delay
|
||||||
}
|
}
|
||||||
XBEE_COMMAND_END_DECORATOR
|
XBEE_COMMAND_END_DECORATOR
|
||||||
return false;
|
return retVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -662,28 +664,30 @@ public:
|
|||||||
|
|
||||||
bool networkConnect(const char* ssid, const char* pwd) {
|
bool networkConnect(const char* ssid, const char* pwd) {
|
||||||
|
|
||||||
|
bool retVal = true;
|
||||||
XBEE_COMMAND_START_DECORATOR(5, false)
|
XBEE_COMMAND_START_DECORATOR(5, false)
|
||||||
|
|
||||||
//nh For no pwd don't set setscurity or pwd
|
//nh For no pwd don't set setscurity or pwd
|
||||||
if (NULL == ssid ) return exitAndFail();
|
if (ssid == NULL) retVal = false;;
|
||||||
|
|
||||||
if (NULL != pwd)
|
if (pwd != NULL)
|
||||||
{
|
{
|
||||||
sendAT(GF("EE"), 2); // Set security to WPA2
|
sendAT(GF("EE"), 2); // Set security to WPA2
|
||||||
if (waitResponse() != 1) return exitAndFail();
|
if (waitResponse() != 1) retVal = false;
|
||||||
sendAT(GF("PK"), pwd);
|
sendAT(GF("PK"), pwd);
|
||||||
} else {
|
} else {
|
||||||
sendAT(GF("EE"), 0); // Set No security
|
sendAT(GF("EE"), 0); // Set No security
|
||||||
}
|
}
|
||||||
if (waitResponse() != 1) return exitAndFail();
|
if (waitResponse() != 1) retVal = false;
|
||||||
|
|
||||||
sendAT(GF("ID"), ssid);
|
sendAT(GF("ID"), ssid);
|
||||||
if (waitResponse() != 1) return exitAndFail();
|
if (waitResponse() != 1) retVal = false;
|
||||||
|
|
||||||
|
if (!writeChanges()) retVal = false;
|
||||||
|
|
||||||
if (!writeChanges()) return exitAndFail();
|
|
||||||
XBEE_COMMAND_END_DECORATOR
|
XBEE_COMMAND_END_DECORATOR
|
||||||
|
|
||||||
return true;
|
return retVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool networkDisconnect() {
|
bool networkDisconnect() {
|
||||||
@@ -794,18 +798,18 @@ protected:
|
|||||||
IPAddress getHostIP(const char* host, int timeout_s = 45) {
|
IPAddress getHostIP(const char* host, int timeout_s = 45) {
|
||||||
String strIP; strIP.reserve(16);
|
String strIP; strIP.reserve(16);
|
||||||
unsigned long startMillis = millis();
|
unsigned long startMillis = millis();
|
||||||
uint32_t timeout_ms = timeout_s*1000;
|
uint32_t timeout_ms = ((uint32_t)timeout_s)*1000;
|
||||||
bool gotIP = false;
|
bool gotIP = false;
|
||||||
XBEE_COMMAND_START_DECORATOR(5, IPAddress(0,0,0,0))
|
XBEE_COMMAND_START_DECORATOR(5, IPAddress(0,0,0,0))
|
||||||
// XBee's require a numeric IP address for connection, but do provide the
|
// XBee's require a numeric IP address for connection, but do provide the
|
||||||
// functionality to look up the IP address from a fully qualified domain name
|
// functionality to look up the IP address from a fully qualified domain name
|
||||||
while (millis() - startMillis < timeout_ms) // the lookup can take a while
|
while ((millis() - startMillis) < timeout_ms) // the lookup can take a while
|
||||||
{
|
{
|
||||||
sendAT(GF("LA"), host);
|
sendAT(GF("LA"), host);
|
||||||
while (stream.available() < 4 && (millis() - startMillis < timeout_ms)) {}; // wait for any response
|
while (stream.available() < 4 && (millis() - startMillis < timeout_ms)) {TINY_GSM_YIELD()};
|
||||||
strIP = stream.readStringUntil('\r'); // read result
|
strIP = stream.readStringUntil('\r'); // read result
|
||||||
strIP.trim();
|
strIP.trim();
|
||||||
if (!strIP.endsWith(GF("ERROR"))) {
|
if (strIP != "" && strIP != GF("ERROR")) {
|
||||||
gotIP = true;
|
gotIP = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -824,7 +828,7 @@ protected:
|
|||||||
bool ssl = false, int timeout_s = 75)
|
bool ssl = false, int timeout_s = 75)
|
||||||
{
|
{
|
||||||
unsigned long startMillis = millis();
|
unsigned long startMillis = millis();
|
||||||
uint32_t timeout_ms = timeout_s*1000;
|
uint32_t timeout_ms = ((uint32_t)timeout_s)*1000;
|
||||||
bool retVal = false;
|
bool retVal = false;
|
||||||
XBEE_COMMAND_START_DECORATOR(5, false)
|
XBEE_COMMAND_START_DECORATOR(5, false)
|
||||||
|
|
||||||
@@ -849,7 +853,7 @@ protected:
|
|||||||
|
|
||||||
savedIP = ip; // Set the newly requested IP address
|
savedIP = ip; // Set the newly requested IP address
|
||||||
bool success = true;
|
bool success = true;
|
||||||
uint32_t timeout_ms = timeout_s*1000;
|
uint32_t timeout_ms = ((uint32_t)timeout_s)*1000;
|
||||||
XBEE_COMMAND_START_DECORATOR(5, false)
|
XBEE_COMMAND_START_DECORATOR(5, false)
|
||||||
String host; host.reserve(16);
|
String host; host.reserve(16);
|
||||||
host += ip[0];
|
host += ip[0];
|
||||||
@@ -896,25 +900,25 @@ protected:
|
|||||||
// really be open, but no data has yet been sent. We return this unknown value
|
// really be open, but no data has yet been sent. We return this unknown value
|
||||||
// as true so there's a possibility it's wrong.
|
// as true so there's a possibility it's wrong.
|
||||||
bool modemGetConnected() {
|
bool modemGetConnected() {
|
||||||
|
|
||||||
XBEE_COMMAND_START_DECORATOR(5, false)
|
|
||||||
|
|
||||||
// If the IP address is 0, it's not valid so we can't be connected
|
// If the IP address is 0, it's not valid so we can't be connected
|
||||||
if (savedIP == IPAddress(0,0,0,0)) return false;
|
if (savedIP == IPAddress(0,0,0,0)) return false;
|
||||||
|
|
||||||
|
XBEE_COMMAND_START_DECORATOR(5, false)
|
||||||
|
|
||||||
// Verify that we're connected to the *right* IP address
|
// Verify that we're connected to the *right* IP address
|
||||||
// We might be connected - but to the wrong thing
|
// We might be connected - but to the wrong thing
|
||||||
// NOTE: In transparent mode, there is only one connection possible - no multiplex
|
// NOTE: In transparent mode, there is only one connection possible - no multiplex
|
||||||
String strIP; strIP.reserve(16);
|
// String strIP; strIP.reserve(16);
|
||||||
sendAT(GF("DL"));
|
// sendAT(GF("DL"));
|
||||||
strIP = stream.readStringUntil('\r'); // read result
|
// strIP = stream.readStringUntil('\r'); // read result
|
||||||
if (TinyGsmIpFromString(strIP) != savedIP) return exitAndFail();
|
// if (TinyGsmIpFromString(strIP) != savedIP) return exitAndFail();
|
||||||
|
|
||||||
if (beeType == XBEE_UNKNOWN) getSeries(); // Need to know the bee type to interpret response
|
if (beeType == XBEE_UNKNOWN) getSeries(); // Need to know the bee type to interpret response
|
||||||
|
|
||||||
switch (beeType){ // The wifi be can only say if it's connected to the netowrk
|
switch (beeType){ // The wifi be can only say if it's connected to the netowrk
|
||||||
case XBEE_S6B_WIFI: {
|
case XBEE_S6B_WIFI: {
|
||||||
RegStatus s = getRegistrationStatus();
|
RegStatus s = getRegistrationStatus();
|
||||||
|
XBEE_COMMAND_END_DECORATOR
|
||||||
if (s != REG_OK) {
|
if (s != REG_OK) {
|
||||||
sockets[0]->sock_connected = false; // no multiplex
|
sockets[0]->sock_connected = false; // no multiplex
|
||||||
}
|
}
|
||||||
@@ -926,6 +930,7 @@ protected:
|
|||||||
XBEE_COMMAND_END_DECORATOR
|
XBEE_COMMAND_END_DECORATOR
|
||||||
switch(intRes) {
|
switch(intRes) {
|
||||||
case 0x00: // 0x00 = The socket is definitely open
|
case 0x00: // 0x00 = The socket is definitely open
|
||||||
|
case 0x28: // 0x28 = "Unknown."
|
||||||
case 0xFF: // 0xFF = No known status - this is always returned prior to sending data
|
case 0xFF: // 0xFF = No known status - this is always returned prior to sending data
|
||||||
return true;
|
return true;
|
||||||
case 0x02: // 0x02 = Invalid parameters (bad IP/host)
|
case 0x02: // 0x02 = Invalid parameters (bad IP/host)
|
||||||
|
|||||||
Reference in New Issue
Block a user