You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

753 lines
18 KiB

5 years ago
5 years ago
5 years ago
5 years ago
  1. /**
  2. * @file TinyGsmClientSaraR4.h
  3. * @author Volodymyr Shymanskyy
  4. * @license LGPL-3.0
  5. * @copyright Copyright (c) 2016 Volodymyr Shymanskyy
  6. * @date Nov 2016
  7. */
  8. #ifndef TinyGsmClientSaraR4_h
  9. #define TinyGsmClientSaraR4_h
  10. //#pragma message("TinyGSM: TinyGsmClientSaraR4")
  11. //#define TINY_GSM_DEBUG Serial
  12. #if !defined(TINY_GSM_RX_BUFFER)
  13. #define TINY_GSM_RX_BUFFER 64
  14. #endif
  15. #define TINY_GSM_MUX_COUNT 7
  16. #include <TinyGsmCommon.h>
  17. #define GSM_NL "\r\n"
  18. static const char GSM_OK[] TINY_GSM_PROGMEM = "OK" GSM_NL;
  19. static const char GSM_ERROR[] TINY_GSM_PROGMEM = "ERROR" GSM_NL;
  20. static const char GSM_CME_ERROR[] TINY_GSM_PROGMEM = GSM_NL "+CME ERROR:";
  21. enum SimStatus {
  22. SIM_ERROR = 0,
  23. SIM_READY = 1,
  24. SIM_LOCKED = 2,
  25. };
  26. enum RegStatus {
  27. REG_UNREGISTERED = 0,
  28. REG_SEARCHING = 2,
  29. REG_DENIED = 3,
  30. REG_OK_HOME = 1,
  31. REG_OK_ROAMING = 5,
  32. REG_UNKNOWN = 4,
  33. };
  34. class TinyGsmSaraR4
  35. {
  36. public:
  37. class GsmClient : public Client
  38. {
  39. friend class TinyGsmSaraR4;
  40. typedef TinyGsmFifo<uint8_t, TINY_GSM_RX_BUFFER> RxFifo;
  41. public:
  42. GsmClient() {}
  43. GsmClient(TinyGsmSaraR4& modem, uint8_t mux = 0) {
  44. init(&modem, mux);
  45. }
  46. virtual ~GsmClient(){}
  47. bool init(TinyGsmSaraR4* modem, uint8_t mux = 0) {
  48. this->at = modem;
  49. this->mux = mux;
  50. sock_available = 0;
  51. prev_check = 0;
  52. sock_connected = false;
  53. got_data = false;
  54. at->sockets[mux] = this;
  55. return true;
  56. }
  57. public:
  58. virtual int connect(const char *host, uint16_t port, int timeout_s) {
  59. stop();
  60. TINY_GSM_YIELD();
  61. rx.clear();
  62. uint8_t oldMux = mux;
  63. sock_connected = at->modemConnect(host, port, &mux, false, timeout_s);
  64. if (mux != oldMux) {
  65. DBG("WARNING: Mux number changed from", oldMux, "to", mux);
  66. at->sockets[oldMux] = NULL;
  67. }
  68. at->sockets[mux] = this;
  69. at->maintain();
  70. return sock_connected;
  71. }
  72. TINY_GSM_CLIENT_CONNECT_OVERLOADS()
  73. virtual void stop(uint32_t maxWaitMs) {
  74. TINY_GSM_CLIENT_DUMP_MODEM_BUFFER()
  75. at->sendAT(GF("+USOCL="), mux);
  76. at->waitResponse((maxWaitMs - (millis() - startMillis))); // NOTE: can take up to 120s to get a response
  77. sock_connected = false;
  78. }
  79. virtual void stop() { stop(135000L); }
  80. TINY_GSM_CLIENT_WRITE()
  81. TINY_GSM_CLIENT_AVAILABLE_WITH_BUFFER_CHECK()
  82. TINY_GSM_CLIENT_READ_WITH_BUFFER_CHECK()
  83. TINY_GSM_CLIENT_PEEK_FLUSH_CONNECTED()
  84. /*
  85. * Extended API
  86. */
  87. String remoteIP() TINY_GSM_ATTR_NOT_IMPLEMENTED;
  88. private:
  89. TinyGsmSaraR4* at;
  90. uint8_t mux;
  91. uint16_t sock_available;
  92. uint32_t prev_check;
  93. bool sock_connected;
  94. bool got_data;
  95. RxFifo rx;
  96. };
  97. class GsmClientSecure : public GsmClient
  98. {
  99. public:
  100. GsmClientSecure() {}
  101. GsmClientSecure(TinyGsmSaraR4& modem, uint8_t mux = 1)
  102. : GsmClient(modem, mux)
  103. {}
  104. virtual ~GsmClientSecure(){}
  105. public:
  106. virtual int connect(const char *host, uint16_t port, int timeout_s) {
  107. stop();
  108. TINY_GSM_YIELD();
  109. rx.clear();
  110. uint8_t oldMux = mux;
  111. sock_connected = at->modemConnect(host, port, &mux, true, timeout_s);
  112. if (mux != oldMux) {
  113. DBG("WARNING: Mux number changed from", oldMux, "to", mux);
  114. at->sockets[oldMux] = NULL;
  115. }
  116. at->sockets[mux] = this;
  117. at->maintain();
  118. return sock_connected;
  119. }
  120. };
  121. public:
  122. TinyGsmSaraR4(Stream& stream)
  123. : stream(stream)
  124. {
  125. memset(sockets, 0, sizeof(sockets));
  126. }
  127. virtual ~TinyGsmSaraR4(){}
  128. /*
  129. * Basic functions
  130. */
  131. bool begin(const char* pin = NULL) {
  132. return init(pin);
  133. }
  134. bool init(const char* pin = NULL) {
  135. DBG(GF("### TinyGSM Version:"), TINYGSM_VERSION);
  136. if (!testAT()) {
  137. return false;
  138. }
  139. sendAT(GF("E0")); // Echo Off
  140. if (waitResponse() != 1) {
  141. return false;
  142. }
  143. #ifdef TINY_GSM_DEBUG
  144. sendAT(GF("+CMEE=2")); // turn on verbose error codes
  145. #else
  146. sendAT(GF("+CMEE=0")); // turn off error codes
  147. #endif
  148. waitResponse();
  149. getModemName();
  150. int ret = getSimStatus();
  151. // if the sim isn't ready and a pin has been provided, try to unlock the sim
  152. if (ret != SIM_READY && pin != NULL && strlen(pin) > 0) {
  153. simUnlock(pin);
  154. return (getSimStatus() == SIM_READY);
  155. }
  156. // if the sim is ready, or it's locked but no pin has been provided, return true
  157. else {
  158. return (ret == SIM_READY || ret == SIM_LOCKED);
  159. }
  160. }
  161. String getModemName() {
  162. sendAT(GF("+CGMI"));
  163. String res1;
  164. if (waitResponse(1000L, res1) != 1) {
  165. return "u-blox Cellular Modem";
  166. }
  167. res1.replace(GSM_NL "OK" GSM_NL, "");
  168. res1.trim();
  169. sendAT(GF("+GMM"));
  170. String res2;
  171. if (waitResponse(1000L, res2) != 1) {
  172. return "u-blox Cellular Modem";
  173. }
  174. res2.replace(GSM_NL "OK" GSM_NL, "");
  175. res2.trim();
  176. String name = res1 + String(' ') + res2;
  177. DBG("### Modem:", name);
  178. if (!name.startsWith("u-blox SARA-R4") && !name.startsWith("u-blox SARA-N4")) {
  179. DBG("### WARNING: You are using the wrong TinyGSM modem!");
  180. }
  181. return name;
  182. }
  183. TINY_GSM_MODEM_SET_BAUD_IPR()
  184. TINY_GSM_MODEM_TEST_AT()
  185. TINY_GSM_MODEM_MAINTAIN_CHECK_SOCKS()
  186. bool factoryDefault() {
  187. sendAT(GF("&F")); // Resets the current profile, other NVM not affected
  188. return waitResponse() == 1;
  189. }
  190. TINY_GSM_MODEM_GET_INFO_ATI()
  191. bool hasSSL() {
  192. return true;
  193. }
  194. bool hasWifi() {
  195. return false;
  196. }
  197. bool hasGPRS() {
  198. return true;
  199. }
  200. /*
  201. * Power functions
  202. */
  203. bool restart() {
  204. if (!testAT()) {
  205. return false;
  206. }
  207. sendAT(GF("+CFUN=15"));
  208. if (waitResponse(10000L) != 1) {
  209. return false;
  210. }
  211. delay(3000); // TODO: Verify delay timing here
  212. return init();
  213. }
  214. bool poweroff() {
  215. sendAT(GF("+CPWROFF"));
  216. return waitResponse(40000L) == 1;
  217. }
  218. bool radioOff() {
  219. sendAT(GF("+CFUN=0"));
  220. if (waitResponse(10000L) != 1) {
  221. return false;
  222. }
  223. delay(3000);
  224. return true;
  225. }
  226. bool sleepEnable(bool enable = true) TINY_GSM_ATTR_NOT_IMPLEMENTED;
  227. /*
  228. * SIM card functions
  229. */
  230. TINY_GSM_MODEM_SIM_UNLOCK_CPIN()
  231. TINY_GSM_MODEM_GET_SIMCCID_CCID()
  232. String getIMEI() {
  233. sendAT(GF("+CGSN"));
  234. if (waitResponse(GF(GSM_NL)) != 1) {
  235. return "";
  236. }
  237. String res = stream.readStringUntil('\n');
  238. waitResponse();
  239. res.trim();
  240. return res;
  241. }
  242. SimStatus getSimStatus(unsigned long timeout_ms = 10000L) {
  243. for (unsigned long start = millis(); millis() - start < timeout_ms; ) {
  244. sendAT(GF("+CPIN?"));
  245. if (waitResponse(GF(GSM_NL "+CPIN:")) != 1) {
  246. delay(1000);
  247. continue;
  248. }
  249. int status = waitResponse(GF("READY"), GF("SIM PIN"), GF("SIM PUK"), GF("NOT INSERTED"));
  250. waitResponse();
  251. switch (status) {
  252. case 2:
  253. case 3: return SIM_LOCKED;
  254. case 1: return SIM_READY;
  255. default: return SIM_ERROR;
  256. }
  257. }
  258. return SIM_ERROR;
  259. }
  260. TINY_GSM_MODEM_GET_REGISTRATION_XREG(CEREG)
  261. TINY_GSM_MODEM_GET_OPERATOR_COPS()
  262. /*
  263. * Generic network functions
  264. */
  265. TINY_GSM_MODEM_GET_CSQ()
  266. bool isNetworkConnected() {
  267. RegStatus s = getRegistrationStatus();
  268. if (s == REG_OK_HOME || s == REG_OK_ROAMING)
  269. return true;
  270. else if (s == REG_UNKNOWN) // for some reason, it can hang at unknown..
  271. return isGprsConnected();
  272. else return false;
  273. }
  274. TINY_GSM_MODEM_WAIT_FOR_NETWORK()
  275. bool setURAT( uint8_t urat ) {
  276. // AT+URAT=<SelectedAcT>[,<PreferredAct>[,<2ndPreferredAct>]]
  277. sendAT(GF("+COPS=2")); // Deregister from network
  278. if (waitResponse() != 1) {
  279. return false;
  280. }
  281. sendAT(GF("+URAT="), urat); // Radio Access Technology (RAT) selection
  282. if (waitResponse() != 1) {
  283. return false;
  284. }
  285. sendAT(GF("+COPS=0")); // Auto-register to the network
  286. if (waitResponse() != 1) {
  287. return false;
  288. }
  289. return restart();
  290. }
  291. /*
  292. * GPRS functions
  293. */
  294. bool gprsConnect(const char* apn, const char* user = NULL, const char* pwd = NULL) {
  295. gprsDisconnect();
  296. sendAT(GF("+CGATT=1")); // attach to GPRS
  297. if (waitResponse(360000L) != 1) {
  298. return false;
  299. }
  300. // Using CGDCONT sets up an "external" PCP context, i.e. a data connection
  301. // using the external IP stack (e.g. Windows dial up) and PPP link over the
  302. // serial interface. This is the only command set supported by the LTE-M
  303. // and LTE NB-IoT modules (SARA-R4xx, SARA-N4xx)
  304. if (user && strlen(user) > 0) {
  305. sendAT(GF("+CGAUTH=1,0,\""), user, GF("\",\""), pwd, '"'); // Set the authentication
  306. waitResponse();
  307. }
  308. sendAT(GF("+CGDCONT=1,\"IP\",\""), apn, '"'); // Define PDP context 1
  309. waitResponse();
  310. sendAT(GF("+CGACT=1,1")); // activate PDP profile/context 1
  311. if (waitResponse(150000L) != 1) {
  312. return false;
  313. }
  314. return true;
  315. }
  316. bool gprsDisconnect() {
  317. sendAT(GF("+CGACT=1,0")); // Deactivate PDP context 1
  318. if (waitResponse(40000L) != 1) {
  319. return false;
  320. }
  321. sendAT(GF("+CGATT=0")); // detach from GPRS
  322. if (waitResponse(360000L) != 1) {
  323. return false;
  324. }
  325. return true;
  326. }
  327. TINY_GSM_MODEM_GET_GPRS_IP_CONNECTED()
  328. /*
  329. * IP Address functions
  330. */
  331. String getLocalIP() {
  332. sendAT(GF("+CGPADDR"));
  333. if (waitResponse(GF(GSM_NL "+CGPADDR:")) != 1) {
  334. return "";
  335. }
  336. streamSkipUntil(','); // Skip context id
  337. String res = stream.readStringUntil('\r');
  338. if (waitResponse() != 1) {
  339. return "";
  340. }
  341. return res;
  342. }
  343. IPAddress localIP() {
  344. return TinyGsmIpFromString(getLocalIP());
  345. }
  346. /*
  347. * Phone Call functions
  348. */
  349. bool setGsmBusy(bool busy = true) TINY_GSM_ATTR_NOT_AVAILABLE;
  350. bool callAnswer() TINY_GSM_ATTR_NOT_IMPLEMENTED;
  351. bool callNumber(const String& number) TINY_GSM_ATTR_NOT_IMPLEMENTED;
  352. bool callHangup() TINY_GSM_ATTR_NOT_IMPLEMENTED;
  353. /*
  354. * Messaging functions
  355. */
  356. String sendUSSD(const String& code) TINY_GSM_ATTR_NOT_IMPLEMENTED;
  357. bool sendSMS(const String& number, const String& text) {
  358. sendAT(GF("+CSCS=\"GSM\"")); // Set GSM default alphabet
  359. waitResponse();
  360. sendAT(GF("+CMGF=1")); // Set preferred message format to text mode
  361. waitResponse();
  362. sendAT(GF("+CMGS=\""), number, GF("\"")); // set the phone number
  363. if (waitResponse(GF(">")) != 1) {
  364. return false;
  365. }
  366. stream.print(text); // Actually send the message
  367. stream.write((char)0x1A);
  368. stream.flush();
  369. return waitResponse(60000L) == 1;
  370. }
  371. bool sendSMS_UTF16(const String& number, const void* text, size_t len) TINY_GSM_ATTR_NOT_IMPLEMENTED;
  372. /*
  373. * Location functions
  374. */
  375. String getGsmLocation() {
  376. sendAT(GF("+ULOC=2,3,0,120,1"));
  377. if (waitResponse(30000L, GF(GSM_NL "+UULOC:")) != 1) {
  378. return "";
  379. }
  380. String res = stream.readStringUntil('\n');
  381. waitResponse();
  382. res.trim();
  383. return res;
  384. }
  385. /*
  386. * Battery & temperature functions
  387. */
  388. uint16_t getBattVoltage() TINY_GSM_ATTR_NOT_AVAILABLE;
  389. int8_t getBattPercent() {
  390. sendAT(GF("+CIND?"));
  391. if (waitResponse(GF(GSM_NL "+CIND:")) != 1) {
  392. return 0;
  393. }
  394. int res = stream.readStringUntil(',').toInt();
  395. int8_t percent = res*20; // return is 0-5
  396. // Wait for final OK
  397. waitResponse();
  398. return percent;
  399. }
  400. uint8_t getBattChargeState() TINY_GSM_ATTR_NOT_AVAILABLE;
  401. bool getBattStats(uint8_t &chargeState, int8_t &percent, uint16_t &milliVolts) {
  402. percent = getBattPercent();
  403. return true;
  404. }
  405. float getTemperature() {
  406. // First make sure the temperature is set to be in celsius
  407. sendAT(GF("+UTEMP=0")); // Would use 1 for Fahrenheit
  408. if (waitResponse() != 1) {
  409. return (float)-9999;
  410. }
  411. sendAT(GF("+UTEMP?"));
  412. if (waitResponse(GF(GSM_NL "+UTEMP:")) != 1) {
  413. return (float)-9999;
  414. }
  415. streamSkipUntil(','); // Skip units (C/F)
  416. int16_t res = stream.readStringUntil('\n').toInt();
  417. float temp = -9999;
  418. if (res != 655355) {
  419. temp = ((float)res)/10;
  420. }
  421. return temp;
  422. }
  423. /*
  424. * Client related functions
  425. */
  426. protected:
  427. bool modemConnect(const char* host, uint16_t port, uint8_t* mux,
  428. bool ssl = false, int timeout_s = 120)
  429. {
  430. uint32_t timeout_ms = ((uint32_t)timeout_s)*1000;
  431. sendAT(GF("+USOCR=6")); // create a socket
  432. if (waitResponse(GF(GSM_NL "+USOCR:")) != 1) { // reply is +USOCR: ## of socket created
  433. return false;
  434. }
  435. *mux = stream.readStringUntil('\n').toInt();
  436. waitResponse();
  437. if (ssl) {
  438. sendAT(GF("+USOSEC="), *mux, ",1");
  439. waitResponse();
  440. }
  441. // Enable NODELAY
  442. sendAT(GF("+USOSO="), *mux, GF(",6,1,1"));
  443. waitResponse();
  444. // Enable KEEPALIVE, 30 sec
  445. //sendAT(GF("+USOSO="), *mux, GF(",6,2,30000"));
  446. //waitResponse();
  447. // connect on the allocated socket
  448. sendAT(GF("+USOCO="), *mux, ",\"", host, "\",", port);
  449. int rsp = waitResponse(timeout_ms);
  450. return (1 == rsp);
  451. }
  452. int16_t modemSend(const void* buff, size_t len, uint8_t mux) {
  453. sendAT(GF("+USOWR="), mux, ',', len);
  454. if (waitResponse(GF("@")) != 1) {
  455. return 0;
  456. }
  457. // 50ms delay, see AT manual section 25.10.4
  458. delay(50);
  459. stream.write((uint8_t*)buff, len);
  460. stream.flush();
  461. if (waitResponse(GF(GSM_NL "+USOWR:")) != 1) {
  462. return 0;
  463. }
  464. streamSkipUntil(','); // Skip mux
  465. int sent = stream.readStringUntil('\n').toInt();
  466. waitResponse(); // sends back OK after the confirmation of number sent
  467. return sent;
  468. }
  469. size_t modemRead(size_t size, uint8_t mux) {
  470. sendAT(GF("+USORD="), mux, ',', size);
  471. if (waitResponse(GF(GSM_NL "+USORD:")) != 1) {
  472. return 0;
  473. }
  474. streamSkipUntil(','); // Skip mux
  475. size_t len = stream.readStringUntil(',').toInt();
  476. streamSkipUntil('\"');
  477. for (size_t i=0; i<len; i++) {
  478. TINY_GSM_MODEM_STREAM_TO_MUX_FIFO_WITH_DOUBLE_TIMEOUT
  479. }
  480. streamSkipUntil('\"');
  481. waitResponse();
  482. DBG("### READ:", len, "from", mux);
  483. sockets[mux]->sock_available = modemGetAvailable(mux);
  484. return len;
  485. }
  486. size_t modemGetAvailable(uint8_t mux) {
  487. // NOTE: Querying a closed socket gives an error "operation not allowed"
  488. sendAT(GF("+USORD="), mux, ",0");
  489. size_t result = 0;
  490. uint8_t res = waitResponse(GF(GSM_NL "+USORD:"));
  491. // Will give error "operation not allowed" when attempting to read a socket
  492. // that you have already told to close
  493. if (res == 1) {
  494. streamSkipUntil(','); // Skip mux
  495. result = stream.readStringUntil('\n').toInt();
  496. // if (result) DBG("### DATA AVAILABLE:", result, "on", mux);
  497. waitResponse();
  498. }
  499. if (!result) {
  500. sockets[mux]->sock_connected = modemGetConnected(mux);
  501. }
  502. DBG("### AVAILABLE:", result, "on", mux);
  503. return result;
  504. }
  505. bool modemGetConnected(uint8_t mux) {
  506. // NOTE: Querying a closed socket gives an error "operation not allowed"
  507. sendAT(GF("+USOCTL="), mux, ",10");
  508. uint8_t res = waitResponse(GF(GSM_NL "+USOCTL:"));
  509. if (res != 1)
  510. return false;
  511. streamSkipUntil(','); // Skip mux
  512. streamSkipUntil(','); // Skip type
  513. int result = stream.readStringUntil('\n').toInt();
  514. // 0: the socket is in INACTIVE status (it corresponds to CLOSED status
  515. // defined in RFC793 "TCP Protocol Specification" [112])
  516. // 1: the socket is in LISTEN status
  517. // 2: the socket is in SYN_SENT status
  518. // 3: the socket is in SYN_RCVD status
  519. // 4: the socket is in ESTABILISHED status
  520. // 5: the socket is in FIN_WAIT_1 status
  521. // 6: the socket is in FIN_WAIT_2 status
  522. // 7: the sokcet is in CLOSE_WAIT status
  523. // 8: the socket is in CLOSING status
  524. // 9: the socket is in LAST_ACK status
  525. // 10: the socket is in TIME_WAIT status
  526. waitResponse();
  527. return (result != 0);
  528. }
  529. public:
  530. /*
  531. Utilities
  532. */
  533. TINY_GSM_MODEM_STREAM_UTILITIES()
  534. // TODO: Optimize this!
  535. uint8_t waitResponse(uint32_t timeout_ms, String& data,
  536. GsmConstStr r1=GFP(GSM_OK), GsmConstStr r2=GFP(GSM_ERROR),
  537. GsmConstStr r3=GFP(GSM_CME_ERROR), GsmConstStr r4=NULL, GsmConstStr r5=NULL)
  538. {
  539. /*String r1s(r1); r1s.trim();
  540. String r2s(r2); r2s.trim();
  541. String r3s(r3); r3s.trim();
  542. String r4s(r4); r4s.trim();
  543. String r5s(r5); r5s.trim();
  544. DBG("### ..:", r1s, ",", r2s, ",", r3s, ",", r4s, ",", r5s);*/
  545. data.reserve(64);
  546. int index = 0;
  547. unsigned long startMillis = millis();
  548. do {
  549. TINY_GSM_YIELD();
  550. while (stream.available() > 0) {
  551. TINY_GSM_YIELD();
  552. int a = stream.read();
  553. if (a <= 0) continue; // Skip 0x00 bytes, just in case
  554. data += (char)a;
  555. if (r1 && data.endsWith(r1)) {
  556. index = 1;
  557. goto finish;
  558. } else if (r2 && data.endsWith(r2)) {
  559. index = 2;
  560. goto finish;
  561. } else if (r3 && data.endsWith(r3)) {
  562. index = 3;
  563. if (r3 == GFP(GSM_CME_ERROR)) {
  564. streamSkipUntil('\n'); // Read out the error
  565. }
  566. goto finish;
  567. } else if (r4 && data.endsWith(r4)) {
  568. index = 4;
  569. goto finish;
  570. } else if (r5 && data.endsWith(r5)) {
  571. index = 5;
  572. goto finish;
  573. } else if (data.endsWith(GF("+UUSORD:"))) {
  574. int mux = stream.readStringUntil(',').toInt();
  575. int len = stream.readStringUntil('\n').toInt();
  576. if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) {
  577. sockets[mux]->got_data = true;
  578. sockets[mux]->sock_available = len;
  579. }
  580. data = "";
  581. DBG("### URC Data Received:", len, "on", mux);
  582. } else if (data.endsWith(GF("+UUSOCL:"))) {
  583. int mux = stream.readStringUntil('\n').toInt();
  584. if (mux >= 0 && mux < TINY_GSM_MUX_COUNT && sockets[mux]) {
  585. sockets[mux]->sock_connected = false;
  586. }
  587. data = "";
  588. DBG("### URC Sock Closed: ", mux);
  589. }
  590. }
  591. } while (millis() - startMillis < timeout_ms);
  592. finish:
  593. if (!index) {
  594. data.trim();
  595. if (data.length()) {
  596. DBG("### Unhandled:", data);
  597. }
  598. data = "";
  599. }
  600. //data.replace(GSM_NL, "/");
  601. //DBG('<', index, '>', data);
  602. return index;
  603. }
  604. uint8_t waitResponse(uint32_t timeout_ms,
  605. GsmConstStr r1=GFP(GSM_OK), GsmConstStr r2=GFP(GSM_ERROR),
  606. GsmConstStr r3=GFP(GSM_CME_ERROR), GsmConstStr r4=NULL, GsmConstStr r5=NULL)
  607. {
  608. String data;
  609. return waitResponse(timeout_ms, data, r1, r2, r3, r4, r5);
  610. }
  611. uint8_t waitResponse(GsmConstStr r1=GFP(GSM_OK), GsmConstStr r2=GFP(GSM_ERROR),
  612. GsmConstStr r3=GFP(GSM_CME_ERROR), GsmConstStr r4=NULL, GsmConstStr r5=NULL)
  613. {
  614. return waitResponse(1000, r1, r2, r3, r4, r5);
  615. }
  616. public:
  617. Stream& stream;
  618. protected:
  619. GsmClient* sockets[TINY_GSM_MUX_COUNT];
  620. };
  621. #endif