SARA R410 also "forget" to notify about incoming data
This commit is contained in:
		@@ -94,6 +94,7 @@ public:
 | 
				
			|||||||
    // closes until all data is read from the buffer.
 | 
					    // closes until all data is read from the buffer.
 | 
				
			||||||
    // Doing it this way allows the external mcu to find and get all of the data
 | 
					    // Doing it this way allows the external mcu to find and get all of the data
 | 
				
			||||||
    // that it wants from the socket even if it was closed externally.
 | 
					    // that it wants from the socket even if it was closed externally.
 | 
				
			||||||
 | 
					    rx.clear();
 | 
				
			||||||
    at->maintain();
 | 
					    at->maintain();
 | 
				
			||||||
    while (sock_available > 0) {
 | 
					    while (sock_available > 0) {
 | 
				
			||||||
      sock_available -= at->modemRead(TinyGsmMin((uint16_t)rx.free(), sock_available), mux);
 | 
					      sock_available -= at->modemRead(TinyGsmMin((uint16_t)rx.free(), sock_available), mux);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -94,6 +94,7 @@ public:
 | 
				
			|||||||
    // closes until all data is read from the buffer.
 | 
					    // closes until all data is read from the buffer.
 | 
				
			||||||
    // Doing it this way allows the external mcu to find and get all of the data
 | 
					    // Doing it this way allows the external mcu to find and get all of the data
 | 
				
			||||||
    // that it wants from the socket even if it was closed externally.
 | 
					    // that it wants from the socket even if it was closed externally.
 | 
				
			||||||
 | 
					    rx.clear();
 | 
				
			||||||
    at->maintain();
 | 
					    at->maintain();
 | 
				
			||||||
    while (sock_available > 0) {
 | 
					    while (sock_available > 0) {
 | 
				
			||||||
      sock_available -= at->modemRead(TinyGsmMin((uint16_t)rx.free(), sock_available), mux);
 | 
					      sock_available -= at->modemRead(TinyGsmMin((uint16_t)rx.free(), sock_available), mux);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -98,6 +98,7 @@ public:
 | 
				
			|||||||
    // closes until all data is read from the buffer.
 | 
					    // closes until all data is read from the buffer.
 | 
				
			||||||
    // Doing it this way allows the external mcu to find and get all of the data
 | 
					    // Doing it this way allows the external mcu to find and get all of the data
 | 
				
			||||||
    // that it wants from the socket even if it was closed externally.
 | 
					    // that it wants from the socket even if it was closed externally.
 | 
				
			||||||
 | 
					    rx.clear();
 | 
				
			||||||
    at->maintain();
 | 
					    at->maintain();
 | 
				
			||||||
    while (sock_available > 0) {
 | 
					    while (sock_available > 0) {
 | 
				
			||||||
      sock_available -= at->modemRead(TinyGsmMin((uint16_t)rx.free(), sock_available), mux);
 | 
					      sock_available -= at->modemRead(TinyGsmMin((uint16_t)rx.free(), sock_available), mux);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -100,6 +100,7 @@ public:
 | 
				
			|||||||
    // closes until all data is read from the buffer.
 | 
					    // closes until all data is read from the buffer.
 | 
				
			||||||
    // Doing it this way allows the external mcu to find and get all of the data
 | 
					    // Doing it this way allows the external mcu to find and get all of the data
 | 
				
			||||||
    // that it wants from the socket even if it was closed externally.
 | 
					    // that it wants from the socket even if it was closed externally.
 | 
				
			||||||
 | 
					    rx.clear();
 | 
				
			||||||
    at->maintain();
 | 
					    at->maintain();
 | 
				
			||||||
    while (sock_available > 0) {
 | 
					    while (sock_available > 0) {
 | 
				
			||||||
      sock_available -= at->modemRead(TinyGsmMin((uint16_t)rx.free(), sock_available), mux);
 | 
					      sock_available -= at->modemRead(TinyGsmMin((uint16_t)rx.free(), sock_available), mux);
 | 
				
			||||||
@@ -153,7 +154,6 @@ public:
 | 
				
			|||||||
        cnt += chunk;
 | 
					        cnt += chunk;
 | 
				
			||||||
        continue;
 | 
					        continue;
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
      // TODO: Read directly into user buffer?
 | 
					 | 
				
			||||||
      // Workaround: sometimes SIM800 forgets to notify about data arrival.
 | 
					      // Workaround: sometimes SIM800 forgets to notify about data arrival.
 | 
				
			||||||
      // TODO: Currently we ping the module periodically,
 | 
					      // TODO: Currently we ping the module periodically,
 | 
				
			||||||
      // but maybe there's a better indicator that we need to poll
 | 
					      // but maybe there's a better indicator that we need to poll
 | 
				
			||||||
@@ -162,6 +162,7 @@ public:
 | 
				
			|||||||
        prev_check = millis();
 | 
					        prev_check = millis();
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
      at->maintain();
 | 
					      at->maintain();
 | 
				
			||||||
 | 
					      // TODO: Read directly into user buffer?
 | 
				
			||||||
      if (sock_available > 0) {
 | 
					      if (sock_available > 0) {
 | 
				
			||||||
        sock_available -= at->modemRead(TinyGsmMin((uint16_t)rx.free(), sock_available), mux);
 | 
					        sock_available -= at->modemRead(TinyGsmMin((uint16_t)rx.free(), sock_available), mux);
 | 
				
			||||||
      } else {
 | 
					      } else {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -71,6 +71,7 @@ public:
 | 
				
			|||||||
    rx.clear();
 | 
					    rx.clear();
 | 
				
			||||||
    sock_connected = at->modemConnect(host, port, &mux);
 | 
					    sock_connected = at->modemConnect(host, port, &mux);
 | 
				
			||||||
    at->sockets[mux] = this;
 | 
					    at->sockets[mux] = this;
 | 
				
			||||||
 | 
					    at->maintain();
 | 
				
			||||||
    return sock_connected;
 | 
					    return sock_connected;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -87,11 +88,13 @@ public:
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  virtual void stop() {
 | 
					  virtual void stop() {
 | 
				
			||||||
 | 
					    TINY_GSM_YIELD();
 | 
				
			||||||
    // Read and dump anything remaining in the modem's internal buffer.
 | 
					    // Read and dump anything remaining in the modem's internal buffer.
 | 
				
			||||||
    // The socket will appear open in response to connected() even after it
 | 
					    // The socket will appear open in response to connected() even after it
 | 
				
			||||||
    // closes until all data is read from the buffer.
 | 
					    // closes until all data is read from the buffer.
 | 
				
			||||||
    // Doing it this way allows the external mcu to find and get all of the data
 | 
					    // Doing it this way allows the external mcu to find and get all of the data
 | 
				
			||||||
    // that it wants from the socket even if it was closed externally.
 | 
					    // that it wants from the socket even if it was closed externally.
 | 
				
			||||||
 | 
					    rx.clear();
 | 
				
			||||||
    at->maintain();
 | 
					    at->maintain();
 | 
				
			||||||
    while (sock_available > 0) {
 | 
					    while (sock_available > 0) {
 | 
				
			||||||
      sock_available -= at->modemRead(TinyGsmMin((uint16_t)rx.free(), sock_available), mux);
 | 
					      sock_available -= at->modemRead(TinyGsmMin((uint16_t)rx.free(), sock_available), mux);
 | 
				
			||||||
@@ -120,6 +123,13 @@ public:
 | 
				
			|||||||
  virtual int available() {
 | 
					  virtual int available() {
 | 
				
			||||||
    TINY_GSM_YIELD();
 | 
					    TINY_GSM_YIELD();
 | 
				
			||||||
    if (!rx.size()) {
 | 
					    if (!rx.size()) {
 | 
				
			||||||
 | 
					      // Workaround: sometimes SARA R410 forgets to notify about data arrival.
 | 
				
			||||||
 | 
					      // TODO: Currently we ping the module periodically,
 | 
				
			||||||
 | 
					      // but maybe there's a better indicator that we need to poll
 | 
				
			||||||
 | 
					      if (millis() - prev_check > 250) {
 | 
				
			||||||
 | 
					        got_data = true;
 | 
				
			||||||
 | 
					        prev_check = millis();
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
      at->maintain();
 | 
					      at->maintain();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    return rx.size() + sock_available;
 | 
					    return rx.size() + sock_available;
 | 
				
			||||||
@@ -137,8 +147,15 @@ public:
 | 
				
			|||||||
        cnt += chunk;
 | 
					        cnt += chunk;
 | 
				
			||||||
        continue;
 | 
					        continue;
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
      // TODO: Read directly into user buffer?
 | 
					      // Workaround: sometimes SARA R410 forgets to notify about data arrival.
 | 
				
			||||||
 | 
					      // TODO: Currently we ping the module periodically,
 | 
				
			||||||
 | 
					      // but maybe there's a better indicator that we need to poll
 | 
				
			||||||
 | 
					      if (millis() - prev_check > 250) {
 | 
				
			||||||
 | 
					        got_data = true;
 | 
				
			||||||
 | 
					        prev_check = millis();
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
      at->maintain();
 | 
					      at->maintain();
 | 
				
			||||||
 | 
					      // TODO: Read directly into user buffer?
 | 
				
			||||||
      if (sock_available > 0) {
 | 
					      if (sock_available > 0) {
 | 
				
			||||||
        sock_available -= at->modemRead(TinyGsmMin((uint16_t)rx.free(), sock_available), mux);
 | 
					        sock_available -= at->modemRead(TinyGsmMin((uint16_t)rx.free(), sock_available), mux);
 | 
				
			||||||
      } else {
 | 
					      } else {
 | 
				
			||||||
@@ -177,6 +194,7 @@ private:
 | 
				
			|||||||
  TinyGsmUBLOX* at;
 | 
					  TinyGsmUBLOX* at;
 | 
				
			||||||
  uint8_t       mux;
 | 
					  uint8_t       mux;
 | 
				
			||||||
  uint16_t      sock_available;
 | 
					  uint16_t      sock_available;
 | 
				
			||||||
 | 
					  uint32_t      prev_check;
 | 
				
			||||||
  bool          sock_connected;
 | 
					  bool          sock_connected;
 | 
				
			||||||
  bool          got_data;
 | 
					  bool          got_data;
 | 
				
			||||||
  RxFifo        rx;
 | 
					  RxFifo        rx;
 | 
				
			||||||
@@ -199,6 +217,7 @@ public:
 | 
				
			|||||||
    rx.clear();
 | 
					    rx.clear();
 | 
				
			||||||
    sock_connected = at->modemConnect(host, port, &mux, true);
 | 
					    sock_connected = at->modemConnect(host, port, &mux, true);
 | 
				
			||||||
    at->sockets[mux] = this;
 | 
					    at->sockets[mux] = this;
 | 
				
			||||||
 | 
					    at->maintain();
 | 
				
			||||||
    return sock_connected;
 | 
					    return sock_connected;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
@@ -687,9 +706,9 @@ protected:
 | 
				
			|||||||
    //sendAT(GF("+USOSO="), *mux, GF(",6,2,30000"));
 | 
					    //sendAT(GF("+USOSO="), *mux, GF(",6,2,30000"));
 | 
				
			||||||
    //waitResponse();
 | 
					    //waitResponse();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // connect on socket
 | 
					    // connect on the allocated socket
 | 
				
			||||||
    // TODO:  Use async connection?  Would return OK right away, but we would
 | 
					    // TODO:  Use faster "asynchronous" connection?
 | 
				
			||||||
    // have to wait for the +UUSOCO URC to verify connection
 | 
					    // We would have to wait for the +UUSOCO URC to verify connection
 | 
				
			||||||
    sendAT(GF("+USOCO="), *mux, ",\"", host, "\",", port);
 | 
					    sendAT(GF("+USOCO="), *mux, ",\"", host, "\",", port);
 | 
				
			||||||
    int rsp = waitResponse(120000L);
 | 
					    int rsp = waitResponse(120000L);
 | 
				
			||||||
    return (1 == rsp);
 | 
					    return (1 == rsp);
 | 
				
			||||||
@@ -697,14 +716,19 @@ protected:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  bool modemDisconnect(uint8_t mux) {
 | 
					  bool modemDisconnect(uint8_t mux) {
 | 
				
			||||||
    TINY_GSM_YIELD();
 | 
					    TINY_GSM_YIELD();
 | 
				
			||||||
    if (isCatM) {  //  These modems allow a faster "asynchronous" close
 | 
					    // TODO:  Use faster "asynchronous" close for LTE-M modems?
 | 
				
			||||||
 | 
					    // We would have to wait for the +UUSOCL URC to verify dis-connection
 | 
				
			||||||
 | 
					    // This also can create a nightmare if attempting to use a single client object
 | 
				
			||||||
 | 
					    // because the modem automatically reallocates a new client if the previous
 | 
				
			||||||
 | 
					    // close hasn't finished.
 | 
				
			||||||
 | 
					    /*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 still 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);
 | 
				
			||||||
      return (1 == waitResponse());  // but response should be within 1 second
 | 
					      return (1 == waitResponse(120000L));  // it can take up to 120s to get a response on LTE-M models
 | 
				
			||||||
    }
 | 
					    /*}*/
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  int16_t modemSend(const void* buff, size_t len, uint8_t mux) {
 | 
					  int16_t modemSend(const void* buff, size_t len, uint8_t mux) {
 | 
				
			||||||
@@ -769,8 +793,20 @@ protected:
 | 
				
			|||||||
    streamSkipUntil(','); // Skip mux
 | 
					    streamSkipUntil(','); // Skip mux
 | 
				
			||||||
    streamSkipUntil(','); // Skip type
 | 
					    streamSkipUntil(','); // Skip type
 | 
				
			||||||
    int result = stream.readStringUntil('\n').toInt();
 | 
					    int result = stream.readStringUntil('\n').toInt();
 | 
				
			||||||
 | 
					    // 0: the socket is in INACTIVE status (it corresponds to CLOSED status
 | 
				
			||||||
 | 
					    // defined in RFC793 "TCP Protocol Specification" [112])
 | 
				
			||||||
 | 
					    // 1: the socket is in LISTEN status
 | 
				
			||||||
 | 
					    // 2: the socket is in SYN_SENT status
 | 
				
			||||||
 | 
					    // 3: the socket is in SYN_RCVD status
 | 
				
			||||||
 | 
					    // 4: the socket is in ESTABILISHED status
 | 
				
			||||||
 | 
					    // 5: the socket is in FIN_WAIT_1 status
 | 
				
			||||||
 | 
					    // 6: the socket is in FIN_WAIT_2 status
 | 
				
			||||||
 | 
					    // 7: the sokcet is in CLOSE_WAIT status
 | 
				
			||||||
 | 
					    // 8: the socket is in CLOSING status
 | 
				
			||||||
 | 
					    // 9: the socket is in LAST_ACK status
 | 
				
			||||||
 | 
					    // 10: the socket is in TIME_WAIT status
 | 
				
			||||||
    waitResponse();
 | 
					    waitResponse();
 | 
				
			||||||
    return result != 0;
 | 
					    return (result != 0 && result != 7 && result != 8);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public:
 | 
					public:
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user