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.

762 lines
17 KiB

8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
  1. /**
  2. * @file TinyGsmClientSIM800.h
  3. * @author Volodymyr Shymanskyy
  4. * @license LGPL-3.0
  5. * @copyright Copyright (c) 2016 Volodymyr Shymanskyy
  6. * @date Nov 2016
  7. */
  8. #ifndef TinyGsmClientSIM800_h
  9. #define TinyGsmClientSIM800_h
  10. // #define TINY_GSM_DEBUG Serial
  11. // #define TINY_GSM_USE_HEX
  12. #if !defined(TINY_GSM_RX_BUFFER)
  13. #define TINY_GSM_RX_BUFFER 64
  14. #endif
  15. #include <TinyGsmCommon.h>
  16. #define GSM_NL "\r\n"
  17. static const char GSM_OK[] TINY_GSM_PROGMEM = "OK" GSM_NL;
  18. static const char GSM_ERROR[] TINY_GSM_PROGMEM = "ERROR" GSM_NL;
  19. enum SimStatus {
  20. SIM_ERROR = 0,
  21. SIM_READY = 1,
  22. SIM_LOCKED = 2,
  23. };
  24. enum RegStatus {
  25. REG_UNREGISTERED = 0,
  26. REG_SEARCHING = 2,
  27. REG_DENIED = 3,
  28. REG_OK_HOME = 1,
  29. REG_OK_ROAMING = 5,
  30. REG_UNKNOWN = 4,
  31. };
  32. class TinyGsm
  33. {
  34. public:
  35. TinyGsm(Stream& stream)
  36. : stream(stream)
  37. {}
  38. public:
  39. class GsmClient : public Client
  40. {
  41. friend class TinyGsm;
  42. typedef TinyGsmFifo<uint8_t, TINY_GSM_RX_BUFFER> RxFifo;
  43. public:
  44. GsmClient() {}
  45. GsmClient(TinyGsm& modem, uint8_t mux = 1) {
  46. init(&modem, mux);
  47. }
  48. bool init(TinyGsm* modem, uint8_t mux = 1) {
  49. this->at = modem;
  50. this->mux = mux;
  51. sock_available = 0;
  52. sock_connected = false;
  53. at->sockets[mux] = this;
  54. return true;
  55. }
  56. public:
  57. virtual int connect(const char *host, uint16_t port) {
  58. TINY_GSM_YIELD();
  59. rx.clear();
  60. sock_connected = at->modemConnect(host, port, mux);
  61. return sock_connected;
  62. }
  63. virtual int connect(IPAddress ip, uint16_t port) {
  64. String host; host.reserve(16);
  65. host += ip[0];
  66. host += ".";
  67. host += ip[1];
  68. host += ".";
  69. host += ip[2];
  70. host += ".";
  71. host += ip[3];
  72. return connect(host.c_str(), port);
  73. }
  74. virtual void stop() {
  75. TINY_GSM_YIELD();
  76. at->sendAT(GF("+CIPCLOSE="), mux);
  77. sock_connected = false;
  78. at->waitResponse();
  79. }
  80. virtual size_t write(const uint8_t *buf, size_t size) {
  81. TINY_GSM_YIELD();
  82. at->maintain();
  83. return at->modemSend(buf, size, mux);
  84. }
  85. virtual size_t write(uint8_t c) {
  86. return write(&c, 1);
  87. }
  88. virtual int available() {
  89. TINY_GSM_YIELD();
  90. if (!rx.size()) {
  91. at->maintain();
  92. }
  93. return rx.size() + sock_available;
  94. }
  95. virtual int read(uint8_t *buf, size_t size) {
  96. TINY_GSM_YIELD();
  97. at->maintain();
  98. size_t cnt = 0;
  99. while (cnt < size) {
  100. size_t chunk = TinyGsmMin(size-cnt, rx.size());
  101. if (chunk > 0) {
  102. rx.get(buf, chunk);
  103. buf += chunk;
  104. cnt += chunk;
  105. continue;
  106. }
  107. // TODO: Read directly into user buffer?
  108. at->maintain();
  109. if (sock_available > 0) {
  110. at->modemRead(rx.free(), mux);
  111. } else {
  112. break;
  113. }
  114. }
  115. return cnt;
  116. }
  117. virtual int read() {
  118. uint8_t c;
  119. if (read(&c, 1) == 1) {
  120. return c;
  121. }
  122. return -1;
  123. }
  124. virtual int peek() { return -1; } //TODO
  125. virtual void flush() { at->stream.flush(); }
  126. virtual uint8_t connected() {
  127. if (available()) {
  128. return true;
  129. }
  130. return sock_connected;
  131. }
  132. virtual operator bool() { return connected(); }
  133. private:
  134. TinyGsm* at;
  135. uint8_t mux;
  136. uint16_t sock_available;
  137. bool sock_connected;
  138. RxFifo rx;
  139. };
  140. public:
  141. /*
  142. * Basic functions
  143. */
  144. bool begin() {
  145. return init();
  146. }
  147. bool init() {
  148. if (!autoBaud()) {
  149. return false;
  150. }
  151. sendAT(GF("&FZE0")); // Factory + Reset + Echo Off
  152. if (waitResponse() != 1) {
  153. return false;
  154. }
  155. getSimStatus();
  156. return true;
  157. }
  158. bool autoBaud(unsigned long timeout = 10000L) {
  159. streamWrite(GF("AAAAAAAAAAAAA")); // extra A's to help detect the baud rate
  160. for (unsigned long start = millis(); millis() - start < timeout; ) {
  161. sendAT(GF(""));
  162. if (waitResponse(200) == 1) {
  163. delay(100);
  164. return true;
  165. }
  166. delay(100);
  167. }
  168. return false;
  169. }
  170. void maintain() {
  171. while (stream.available()) {
  172. waitResponse(10, NULL, NULL);
  173. }
  174. }
  175. bool factoryDefault() {
  176. sendAT(GF("&FZE0&W")); // Factory + Reset + Echo Off + Write
  177. waitResponse();
  178. sendAT(GF("+IPR=0")); // Auto-baud
  179. waitResponse();
  180. sendAT(GF("+IFC=0,0")); // No Flow Control
  181. waitResponse();
  182. sendAT(GF("+ICF=3,3")); // 8 data 0 parity 1 stop
  183. waitResponse();
  184. sendAT(GF("+CSCLK=0")); // Disable Slow Clock
  185. waitResponse();
  186. sendAT(GF("&W")); // Write configuration
  187. return waitResponse() == 1;
  188. }
  189. /*
  190. * Power functions
  191. */
  192. bool restart() {
  193. if (!autoBaud()) {
  194. return false;
  195. }
  196. sendAT(GF("+CFUN=0"));
  197. if (waitResponse(10000L) != 1) {
  198. return false;
  199. }
  200. sendAT(GF("+CFUN=1,1"));
  201. if (waitResponse(10000L) != 1) {
  202. return false;
  203. }
  204. delay(3000);
  205. return init();
  206. }
  207. /*
  208. * SIM card & Networ Operator functions
  209. */
  210. bool simUnlock(const char *pin) {
  211. sendAT(GF("+CPIN=\""), pin, GF("\""));
  212. return waitResponse() == 1;
  213. }
  214. String getSimCCID() {
  215. sendAT(GF("+ICCID"));
  216. if (waitResponse(GF(GSM_NL "+ICCID:")) != 1) {
  217. return "";
  218. }
  219. String res = streamReadUntil('\n');
  220. waitResponse();
  221. return res;
  222. }
  223. String getIMEI() {
  224. sendAT(GF("+GSN"));
  225. if (waitResponse(GF(GSM_NL)) != 1) {
  226. return "";
  227. }
  228. String res = streamReadUntil('\n');
  229. waitResponse();
  230. return res;
  231. }
  232. int getSignalQuality() {
  233. sendAT(GF("+CSQ"));
  234. if (waitResponse(GF(GSM_NL "+CSQ:")) != 1) {
  235. return 99;
  236. }
  237. int res = streamReadUntil(',').toInt();
  238. waitResponse();
  239. return res;
  240. }
  241. SimStatus getSimStatus(unsigned long timeout = 10000L) {
  242. for (unsigned long start = millis(); millis() - start < timeout; ) {
  243. sendAT(GF("+CPIN?"));
  244. if (waitResponse(GF(GSM_NL "+CPIN:")) != 1) {
  245. delay(1000);
  246. continue;
  247. }
  248. int status = waitResponse(GF("READY"), GF("SIM PIN"), GF("SIM PUK"), GF("NOT INSERTED"));
  249. waitResponse();
  250. switch (status) {
  251. case 2:
  252. case 3: return SIM_LOCKED;
  253. case 1: return SIM_READY;
  254. default: return SIM_ERROR;
  255. }
  256. }
  257. return SIM_ERROR;
  258. }
  259. RegStatus getRegistrationStatus() {
  260. sendAT(GF("+CREG?"));
  261. if (waitResponse(GF(GSM_NL "+CREG:")) != 1) {
  262. return REG_UNKNOWN;
  263. }
  264. streamSkipUntil(','); // Skip format (0)
  265. int status = streamReadUntil('\n').toInt();
  266. waitResponse();
  267. return (RegStatus)status;
  268. }
  269. String getOperator() {
  270. sendAT(GF("+COPS?"));
  271. if (waitResponse(GF(GSM_NL "+COPS:")) != 1) {
  272. return "";
  273. }
  274. streamSkipUntil('"'); // Skip mode and format
  275. String res = streamReadUntil('"');
  276. waitResponse();
  277. return res;
  278. }
  279. bool waitForNetwork(unsigned long timeout = 60000L) {
  280. for (unsigned long start = millis(); millis() - start < timeout; ) {
  281. RegStatus s = getRegistrationStatus();
  282. if (s == REG_OK_HOME || s == REG_OK_ROAMING) {
  283. return true;
  284. }
  285. delay(1000);
  286. }
  287. return false;
  288. }
  289. /*
  290. * WiFi functions
  291. */
  292. bool networkConnect(const char* ssid, const char* pwd) {
  293. return false;
  294. }
  295. bool networkDisconnect() {
  296. return false;
  297. }
  298. /*
  299. * GPRS functions
  300. */
  301. bool gprsConnect(const char* apn, const char* user, const char* pwd) {
  302. gprsDisconnect();
  303. sendAT(GF("+SAPBR=3,1,\"Contype\",\"GPRS\""));
  304. waitResponse();
  305. sendAT(GF("+SAPBR=3,1,\"APN\",\""), apn, '"');
  306. waitResponse();
  307. if (user) {
  308. sendAT(GF("+SAPBR=3,1,\"USER\",\""), user, '"');
  309. waitResponse();
  310. }
  311. if (pwd) {
  312. sendAT(GF("+SAPBR=3,1,\"PWD\",\""), pwd, '"');
  313. waitResponse();
  314. }
  315. sendAT(GF("+CGDCONT=1,\"IP\",\""), apn, '"');
  316. waitResponse();
  317. sendAT(GF("+CGACT=1,1"));
  318. waitResponse(60000L);
  319. // Open a GPRS context
  320. sendAT(GF("+SAPBR=1,1"));
  321. waitResponse(85000L);
  322. // Query the GPRS context
  323. sendAT(GF("+SAPBR=2,1"));
  324. if (waitResponse(30000L) != 1)
  325. return false;
  326. sendAT(GF("+CGATT=1"));
  327. if (waitResponse(60000L) != 1)
  328. return false;
  329. // TODO: wait AT+CGATT?
  330. sendAT(GF("+CIPMUX=1"));
  331. if (waitResponse() != 1) {
  332. return false;
  333. }
  334. sendAT(GF("+CIPQSEND=1"));
  335. if (waitResponse() != 1) {
  336. return false;
  337. }
  338. sendAT(GF("+CIPRXGET=1"));
  339. if (waitResponse() != 1) {
  340. return false;
  341. }
  342. sendAT(GF("+CSTT=\""), apn, GF("\",\""), user, GF("\",\""), pwd, GF("\""));
  343. if (waitResponse(60000L) != 1) {
  344. return false;
  345. }
  346. sendAT(GF("+CIICR"));
  347. if (waitResponse(60000L) != 1) {
  348. return false;
  349. }
  350. sendAT(GF("+CIFSR;E0"));
  351. String data;
  352. if (waitResponse(10000L, data) != 1) {
  353. data.replace(GSM_NL, "");
  354. return false;
  355. }
  356. sendAT(GF("+CDNSCFG=\"8.8.8.8\",\"8.8.4.4\""));
  357. if (waitResponse() != 1) {
  358. return false;
  359. }
  360. return true;
  361. }
  362. bool gprsDisconnect() {
  363. sendAT(GF("+CIPSHUT"));
  364. return waitResponse(60000L) == 1;
  365. }
  366. /*
  367. * Phone Call functions
  368. */
  369. bool setGsmBusy(bool busy = true) {
  370. sendAT(GF("+GSMBUSY="), busy ? 1 : 0);
  371. return waitResponse() == 1;
  372. }
  373. bool callAnswer() {
  374. sendAT(GF("A"));
  375. return waitResponse() == 1;
  376. }
  377. bool callNumber(const String& number) {
  378. sendAT(GF("D"), number);
  379. return waitResponse() == 1;
  380. }
  381. bool callHangup(const String& number) {
  382. sendAT(GF("H"), number);
  383. return waitResponse() == 1;
  384. }
  385. /*
  386. * Messaging functions
  387. */
  388. void sendUSSD() {
  389. }
  390. void sendSMS() {
  391. }
  392. bool sendSMS(const String& number, const String& text) {
  393. sendAT(GF("+CMGF=1"));
  394. waitResponse();
  395. sendAT(GF("+CMGS=\""), number, GF("\""));
  396. if (waitResponse(GF(">")) != 1) {
  397. return false;
  398. }
  399. stream.print(text);
  400. stream.write((char)0x1A);
  401. return waitResponse(60000L) == 1;
  402. }
  403. bool sendSMS_UTF16(const String& number, const void* text, size_t len) {
  404. sendAT(GF("+CMGF=1"));
  405. waitResponse();
  406. sendAT(GF("+CSCS=\"HEX\""));
  407. waitResponse();
  408. sendAT(GF("+CSMP=17,167,0,8"));
  409. waitResponse();
  410. sendAT(GF("+CMGS=\""), number, GF("\""));
  411. if (waitResponse(GF(">")) != 1) {
  412. return false;
  413. }
  414. uint16_t* t = (uint16_t*)text;
  415. for (size_t i=0; i<len; i++) {
  416. uint8_t c = t[i] >> 8;
  417. if (c < 0x10) { stream.print('0'); }
  418. stream.print(c, HEX);
  419. c = t[i] & 0xFF;
  420. if (c < 0x10) { stream.print('0'); }
  421. stream.print(c, HEX);
  422. }
  423. stream.write((char)0x1A);
  424. return waitResponse(60000L) == 1;
  425. }
  426. /*
  427. * Location functions
  428. */
  429. void getLocation() {
  430. }
  431. String getGsmLocation() {
  432. sendAT(GF("+CIPGSMLOC=1,1"));
  433. if (waitResponse(GF(GSM_NL "+CIPGSMLOC:")) != 1) {
  434. return "";
  435. }
  436. String res = streamReadUntil('\n');
  437. waitResponse();
  438. return res;
  439. }
  440. /*
  441. * Battery functions
  442. */
  443. // Use: float vBatt = modem.getBattVoltage() / 1000.0;
  444. uint16_t getBattVoltage() {
  445. sendAT(GF("+CBC"));
  446. if (waitResponse(GF(GSM_NL "+CBC:")) != 1) {
  447. return 0;
  448. }
  449. streamSkipUntil(','); // Skip
  450. streamSkipUntil(','); // Skip
  451. uint16_t res = streamReadUntil(',').toInt();
  452. waitResponse();
  453. return res;
  454. }
  455. /* Public Utilities */
  456. template<typename... Args>
  457. void sendAT(Args... cmd) {
  458. streamWrite("AT", cmd..., GSM_NL);
  459. stream.flush();
  460. TINY_GSM_YIELD();
  461. DBG(GSM_NL, ">>> AT:", cmd...);
  462. }
  463. // TODO: Optimize this!
  464. uint8_t waitResponse(uint32_t timeout, String& data,
  465. GsmConstStr r1=GFP(GSM_OK), GsmConstStr r2=GFP(GSM_ERROR),
  466. GsmConstStr r3=NULL, GsmConstStr r4=NULL, GsmConstStr r5=NULL)
  467. {
  468. /*String r1s(r1); r1s.trim();
  469. String r2s(r2); r2s.trim();
  470. String r3s(r3); r3s.trim();
  471. String r4s(r4); r4s.trim();
  472. String r5s(r5); r5s.trim();
  473. DBG("### ..:", r1s, ",", r2s, ",", r3s, ",", r4s, ",", r5s);*/
  474. data.reserve(64);
  475. bool gotData = false;
  476. int mux = -1;
  477. int index = 0;
  478. unsigned long startMillis = millis();
  479. do {
  480. TINY_GSM_YIELD();
  481. while (stream.available() > 0) {
  482. int a = streamRead();
  483. if (a <= 0) continue; // Skip 0x00 bytes, just in case
  484. data += (char)a;
  485. if (r1 && data.endsWith(r1)) {
  486. index = 1;
  487. goto finish;
  488. } else if (r2 && data.endsWith(r2)) {
  489. index = 2;
  490. goto finish;
  491. } else if (r3 && data.endsWith(r3)) {
  492. index = 3;
  493. goto finish;
  494. } else if (r4 && data.endsWith(r4)) {
  495. index = 4;
  496. goto finish;
  497. } else if (r5 && data.endsWith(r5)) {
  498. index = 5;
  499. goto finish;
  500. } else if (data.endsWith(GF(GSM_NL "+CIPRXGET:"))) {
  501. index = 6;
  502. String mode = streamReadUntil(',');
  503. if (mode.toInt() == 1) {
  504. mux = streamReadUntil('\n').toInt();
  505. gotData = true;
  506. } else {
  507. data += mode;
  508. }
  509. } else if (data.endsWith(GF("CLOSED" GSM_NL))) {
  510. index = 7;
  511. int nl = data.lastIndexOf(GSM_NL, data.length()-8);
  512. int coma = data.indexOf(',', nl+2);
  513. mux = data.substring(nl+2, coma).toInt();
  514. if (mux) {
  515. sockets[mux]->sock_connected = false;
  516. }
  517. }
  518. }
  519. } while (millis() - startMillis < timeout);
  520. finish:
  521. if (!index) {
  522. data.trim();
  523. if (data.length()) {
  524. DBG("### Unhandled:", data);
  525. }
  526. }
  527. else {
  528. data.trim();
  529. data.replace(GSM_NL GSM_NL, GSM_NL);
  530. data.replace(GSM_NL, GSM_NL " ");
  531. if (data.length()) {
  532. DBG(GSM_NL, "<<< ", data);
  533. }
  534. }
  535. if (gotData) {
  536. sockets[mux]->sock_available = modemGetAvailable(mux);
  537. }
  538. data = "";
  539. return index;
  540. }
  541. uint8_t waitResponse(uint32_t timeout,
  542. GsmConstStr r1=GFP(GSM_OK), GsmConstStr r2=GFP(GSM_ERROR),
  543. GsmConstStr r3=NULL, GsmConstStr r4=NULL, GsmConstStr r5=NULL)
  544. {
  545. String data;
  546. return waitResponse(timeout, data, r1, r2, r3, r4, r5);
  547. }
  548. uint8_t waitResponse(GsmConstStr r1=GFP(GSM_OK), GsmConstStr r2=GFP(GSM_ERROR),
  549. GsmConstStr r3=NULL, GsmConstStr r4=NULL, GsmConstStr r5=NULL)
  550. {
  551. return waitResponse(1000, r1, r2, r3, r4, r5);
  552. }
  553. private:
  554. int modemConnect(const char* host, uint16_t port, uint8_t mux) {
  555. sendAT(GF("+CIPSTART="), mux, ',', GF("\"TCP"), GF("\",\""), host, GF("\","), port);
  556. int rsp = waitResponse(75000L,
  557. GF("CONNECT OK" GSM_NL),
  558. GF("CONNECT FAIL" GSM_NL),
  559. GF("ALREADY CONNECT" GSM_NL));
  560. return (1 == rsp);
  561. }
  562. int modemSend(const void* buff, size_t len, uint8_t mux) {
  563. sendAT(GF("+CIPSEND="), mux, ',', len);
  564. if (waitResponse(GF(">")) != 1) {
  565. return -1;
  566. }
  567. stream.write((uint8_t*)buff, len);
  568. stream.flush();
  569. if (waitResponse(GF(GSM_NL "DATA ACCEPT:")) != 1) {
  570. return -1;
  571. }
  572. streamSkipUntil(','); // Skip mux
  573. return streamReadUntil('\n').toInt();
  574. }
  575. size_t modemRead(size_t size, uint8_t mux) {
  576. #ifdef TINY_GSM_USE_HEX
  577. sendAT(GF("+CIPRXGET=3,"), mux, ',', size);
  578. if (waitResponse(GF("+CIPRXGET:")) != 1) {
  579. return 0;
  580. }
  581. #else
  582. sendAT(GF("+CIPRXGET=2,"), mux, ',', size);
  583. if (waitResponse(GF("+CIPRXGET:")) != 1) {
  584. return 0;
  585. }
  586. #endif
  587. streamSkipUntil(','); // Skip mode 2/3
  588. streamSkipUntil(','); // Skip mux
  589. size_t len = streamReadUntil(',').toInt();
  590. sockets[mux]->sock_available = streamReadUntil('\n').toInt();
  591. for (size_t i=0; i<len; i++) {
  592. #ifdef TINY_GSM_USE_HEX
  593. while (stream.available() < 2) {}
  594. char buf[4] = { 0, };
  595. buf[0] = streamRead();
  596. buf[1] = streamRead();
  597. char c = strtol(buf, NULL, 16);
  598. DBG(c);
  599. #else
  600. while (!stream.available()) {}
  601. char c = streamRead();
  602. DBG(c);
  603. #endif
  604. sockets[mux]->rx.put(c);
  605. }
  606. waitResponse();
  607. return len;
  608. }
  609. size_t modemGetAvailable(uint8_t mux) {
  610. sendAT(GF("+CIPRXGET=4,"), mux);
  611. size_t result = 0;
  612. if (waitResponse(GF("+CIPRXGET:")) == 1) {
  613. streamSkipUntil(','); // Skip mode 4
  614. streamSkipUntil(','); // Skip mux
  615. result = streamReadUntil('\n').toInt();
  616. waitResponse();
  617. }
  618. if (!result) {
  619. sockets[mux]->sock_connected = modemGetConnected(mux);
  620. }
  621. return result;
  622. }
  623. bool modemGetConnected(uint8_t mux) {
  624. sendAT(GF("+CIPSTATUS="), mux);
  625. int res = waitResponse(GF(",\"CONNECTED\""), GF(",\"CLOSED\""), GF(",\"CLOSING\""), GF(",\"INITIAL\""));
  626. waitResponse();
  627. return 1 == res;
  628. }
  629. /* Private Utilities */
  630. template<typename T>
  631. void streamWrite(T last) {
  632. stream.print(last);
  633. }
  634. template<typename T, typename... Args>
  635. void streamWrite(T head, Args... tail) {
  636. stream.print(head);
  637. streamWrite(tail...);
  638. }
  639. int streamRead() { return stream.read(); }
  640. String streamReadUntil(char c) {
  641. String return_string = stream.readStringUntil(c);
  642. return_string.trim();
  643. if (String(c) == GSM_NL || String(c) == "\n"){
  644. DBG(return_string, c, " ");
  645. } else DBG(return_string, c);
  646. return return_string;
  647. }
  648. bool streamSkipUntil(char c) {
  649. String skipped = stream.readStringUntil(c);
  650. skipped.trim();
  651. if (skipped.length()) {
  652. if (String(c) == GSM_NL || String(c) == "\n"){
  653. DBG(skipped, c, " ");
  654. } else DBG(skipped, c);
  655. return true;
  656. } else return false;
  657. }
  658. private:
  659. Stream& stream;
  660. GsmClient* sockets[5];
  661. };
  662. typedef TinyGsm::GsmClient TinyGsmClient;
  663. #endif