Basic websocket demo esp8266
Dependencies: ESP8266Interface HTTPClient-SSL WebSocketClient mbed-rtos mbed-dev
Fork of ESP8266_HTTP_HelloWorld by
Revision 20:42f15f50e2ee, committed 2016-09-18
- Comitter:
- readysteadygo2006
- Date:
- Sun Sep 18 13:20:49 2016 +0000
- Parent:
- 19:15351a791e29
- Child:
- 21:60643d87e419
- Commit message:
- Basic websocket demo esp8266;
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Tue Aug 09 08:11:54 2016 +0000 +++ b/main.cpp Sun Sep 18 13:20:49 2016 +0000 @@ -10,19 +10,20 @@ DigitalOut myled(LED1); Serial pc(USBTX, USBRX); // tx, rx -ESP8266Interface wifi(D8,D2,D7,"EE-mehrg7","MFPHOME0708",115200); // TX,RX,Reset,SSID,Password,Baud +//ESP8266Interface wifi(D8,D2,D7,"EE-mehrg7","MFPHOME0708",115200); // TX,RX,Reset,SSID,Password,Baud +ESP8266Interface wifi(PA_11,PA_12,PB_12,"EE-mehrg7","MFPHOME0708",115200); // TX,RX,Reset,SSID,Password,Baud int main() { pc.baud(921600); wifi.init(); //Reset wifi.connect(); //Use DHCP - wait(2); +// wait(2); printf("IP Address is %s\n\r", wifi.getIPAddress()); - wait(2); +// wait(2); printf("connect ws\n\r", wifi.getIPAddress()); Websocket ws("ws://192.168.1.84:8000/"); - wait(20); +// wait(2); //Check for successful socket connection if(!ws.connect()) @@ -32,7 +33,7 @@ for(int i=0; i<0x7fffffff; ++i) { // string with a message - sprintf(str, "%d WebSocket Hello World over wifi", i); + sprintf(str, "{\"ts\":1, \"readings\": [{\"reading\": \"d\", \"value\": %d}]}", i); printf("send: %s\n\r",str); ws.send(str);