Websocket demo for app board by C. Styles with updated libraries. DHCP service and a network cable is required.
Dependencies: EthernetInterface LM75B MMA7660 WebSocketClient mbed-rtos mbed
Fork of app-board-Ethernet-Websocket by
main.cpp
00001 #include "mbed.h" 00002 #include "EthernetInterface.h" 00003 #include "Websocket.h" 00004 #include "MMA7660.h" 00005 #include "LM75B.h" 00006 00007 // accelerometer 00008 MMA7660 acc(p28, p27); 00009 00010 // temperature sensor 00011 LM75B tmp(p28,p27); 00012 00013 DigitalOut l1(LED1); 00014 00015 int main() { 00016 char json_str[100]; 00017 00018 if (acc.testConnection()) 00019 l1 = 1; 00020 00021 EthernetInterface eth; 00022 eth.init(); //Use DHCP 00023 wait(2); 00024 eth.connect(60000); 00025 printf("IP Address is %s\n\r", eth.getIPAddress()); 00026 00027 // See the output on http://sockets.mbed.org/app-board/viewer 00028 Websocket ws("ws://sockets.mbed.org:443/ws/app-board/wo"); 00029 ws.connect(); 00030 00031 while (1) { 00032 // create json string with acc/tmp data 00033 sprintf(json_str, "{\"id\":\"app_board_eth_EW2013\",\"ax\":%d,\"ay\":%d,\"az\":%d, \"tmp\":%d}", (int)(acc.x()*360), (int)(acc.y()*360), (int)(acc.z()*360), (int)tmp.read()); 00034 00035 // send str 00036 ws.send(json_str); 00037 00038 wait(0.1); 00039 } 00040 }
Generated on Thu Jul 14 2022 01:19:57 by 1.7.2