1

Dependencies:   ATParser

Dependents:   UDPNode

Revision:
1:af8bf1171171
Parent:
0:eb6507dc4669
Child:
2:3518f7c570de
--- a/ESP8266.cpp	Wed Jun 27 06:50:30 2018 +0000
+++ b/ESP8266.cpp	Wed Jun 27 07:17:17 2018 +0000
@@ -17,7 +17,7 @@
 #include "ESP8266.h"
 
 ESP8266::ESP8266(PinName tx, PinName rx, bool debug)
-    : _serial(tx, rx, 1024), _parser(_serial) {
+    : _serial(tx, rx, 1024), _parser(_serial), localOutPort(3001), localInPort(3002) {
     _serial.baud(115200);
     _parser.debugOn(debug);
 }
@@ -49,7 +49,9 @@
 
 bool ESP8266::connect(const char *ap, const char *passPhrase) {
     return _parser.send("AT+CWJAP_CUR=\"%s\",\"%s\"", ap, passPhrase)
-        && _parser.recv("OK");
+        && _parser.recv("OK")
+        && open(1,localOutPort)
+        && open(2,localInPort);
 }
 
 bool ESP8266::disconnect(void) {
@@ -85,10 +87,10 @@
         && _parser.recv("OK");
 }
 
-bool ESP8266::send(const void* data, uint32_t linkId, uint32_t amount, const char* addr, int port) {
+bool ESP8266::send(const void* data, uint32_t amount, const char* addr, int port) {
     //May take a second try if device is busy
     for (unsigned i = 0; i < 2; i++) {
-        if (_parser.send("AT+CIPSEND=%d,%d,\"%s\",%d", linkId, amount, addr, port)
+        if (_parser.send("AT+CIPSEND=%d,%d,\"%s\",%d", 1, amount, addr, port)
             && _parser.recv(">")
             && (_parser.write((char*)data, (int)amount) >= 0)
             && _parser.recv("SEND OK")) {