Ethernetwebsoc

Dependencies:   C12832_lcd LM75B WebSocketClient mbed-rtos mbed Socket lwip-eth lwip-sys lwip

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 "Websocket.h"
00004 #include "LM75B.h"
00005 #include "C12832_lcd.h"
00006 PwmOut r (p23);
00007 PwmOut g (p24);
00008 PwmOut b (p25);
00009 
00010 C12832_LCD lcd;
00011 LM75B tmp(p28,p27);
00012 
00013 int main()
00014 {
00015     
00016 char t[100];
00017     EthernetInterface eth;
00018     eth.init(); //Use DHCP
00019     eth.connect();
00020     lcd.printf("IP Address is %s\n\r", eth.getIPAddress());
00021 
00022     wait(2.0);
00023 
00024     Websocket ws("ws://sockets.mbed.org:443/ws/rs/wo");
00025     ws.connect();
00026     wait(2.0);
00027     
00028     ws.send("Welcome to RS Components IOT demo: message broadcasting");
00029     wait(1.0);
00030     
00031     while (1) {
00032     
00033     float tp=tmp.read();
00034     sprintf(t, "[RS Components]Current Room Temperature :%.2f", (float)tp);
00035     ws.send(t);
00036 
00037         for(float i = 0; i < 1.0 ; i += 0.01) {
00038             float p = (((tmp.read()/100)-0.34)*500);// 0.34 is the offset of the Temp.of 34 oC and 500 is the scale of change in color
00039 
00040             r = 1.0 - ((p < 1.0) ? 1.0 - p : (p > 2.0) ? p - 2.0 : 0.0);
00041             g = 1.0 - ((p < 1.0) ? p : (p > 2.0) ? 0.0 : 2.0 - p);
00042             b = 1.0 - ((p < 1.0) ? 0.0 : (p > 2.0) ? 3.0 - p : p - 1.0);  ;
00043             wait (0.005);
00044 
00045             lcd.cls();
00046             lcd.locate(0,3);
00047             lcd.printf("Current Room Temp. :%.2foC",tmp.read());
00048             wait(0.1);
00049         }
00050     }
00051 }