websocket client for mbed

Dependencies:   C12832_lcd EthernetInterface WebSocketClient mbed-rtos mbed

Committer:
MohamadNazrin
Date:
Wed Mar 07 09:06:58 2018 +0000
Revision:
0:f36d489a4172
Child:
1:c15b0540e252
websocket

Who changed what in which revision?

UserRevisionLine numberNew contents of line
MohamadNazrin 0:f36d489a4172 1 #include "mbed.h"
MohamadNazrin 0:f36d489a4172 2 #include "EthernetInterface.h"
MohamadNazrin 0:f36d489a4172 3 #include "C12832_lcd.h" // Include for LCD code
MohamadNazrin 0:f36d489a4172 4 #include "Websocket.h"
MohamadNazrin 0:f36d489a4172 5
MohamadNazrin 0:f36d489a4172 6 C12832_LCD lcd; //Initialize LCD Screen
MohamadNazrin 0:f36d489a4172 7 DigitalOut led(LED1);
MohamadNazrin 0:f36d489a4172 8 int main() {
MohamadNazrin 0:f36d489a4172 9
MohamadNazrin 0:f36d489a4172 10 static const char* mbedIp = "192.168.137.2"; //IP
MohamadNazrin 0:f36d489a4172 11 static const char* mbedMask = "255.255.255.0"; // Mask
MohamadNazrin 0:f36d489a4172 12 static const char* mbedGateway = "192.168.137.1"; //Gateway
MohamadNazrin 0:f36d489a4172 13
MohamadNazrin 0:f36d489a4172 14 EthernetInterface eth;
MohamadNazrin 0:f36d489a4172 15 // eth.init(); //Use DHCP
MohamadNazrin 0:f36d489a4172 16 eth.init(mbedIp,mbedMask,mbedGateway);
MohamadNazrin 0:f36d489a4172 17 eth.connect();
MohamadNazrin 0:f36d489a4172 18 printf("IP Address is %s\n", eth.getIPAddress()); // display at terminal
MohamadNazrin 0:f36d489a4172 19 lcd.printf("IP address: %s \n",eth.getIPAddress()); // display LCD screen
MohamadNazrin 0:f36d489a4172 20 // websocket
MohamadNazrin 0:f36d489a4172 21 Websocket ws("ws://192.168.1.109:8000/ws");
MohamadNazrin 0:f36d489a4172 22 bool c = ws.connect();
MohamadNazrin 0:f36d489a4172 23 printf("Connect result: %s\n", c?"OK":"Failed");
MohamadNazrin 0:f36d489a4172 24
MohamadNazrin 0:f36d489a4172 25 ws.send("hello world");
MohamadNazrin 0:f36d489a4172 26
MohamadNazrin 0:f36d489a4172 27 }