Mohamad Nazrin Napiah / Mbed 2 deprecated websocket

Dependencies:   C12832_lcd EthernetInterface WebSocketClient mbed-rtos mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "EthernetInterface.h"
00003 #include "C12832_lcd.h" // Include for LCD code
00004 #include "Websocket.h"
00005 
00006 C12832_LCD lcd; //Initialize LCD Screen
00007 DigitalOut led(LED1);
00008 int main() {
00009     
00010 static const char*          mbedIp       = "192.168.137.2";  //IP
00011 static const char*          mbedMask     = "255.255.255.0";  // Mask
00012 static const char*          mbedGateway  = "192.168.137.1";    //Gateway
00013 
00014     EthernetInterface eth;
00015    // eth.init(); //Use DHCP
00016     eth.init(mbedIp,mbedMask,mbedGateway); 
00017     eth.connect();
00018     printf("IP Address is %s\n", eth.getIPAddress()); // display at terminal
00019     lcd.printf("IP address: %s \n",eth.getIPAddress()); // display LCD screen
00020     
00021     
00022 // websocket
00023     Websocket ws("ws://192.168.1.109:8000/ws");
00024     bool c = ws.connect();
00025     printf("Connect result: %s\n", c?"OK":"Failed");
00026    
00027     ws.send("hello world");
00028       
00029 }