Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: EthernetNetIf TextLCD mbed DNSResolver
main.cpp
00001 #include "mbed.h" 00002 #include "Websocket.h" 00003 #include "TextLCD.h" 00004 00005 #define WS_SERVER_URL "ws://sockets.mbed.org/ws/webdbpress/rw" 00006 00007 Websocket *ws; 00008 TextLCD lcd(p24, p26, p27, p28, p29, p30); 00009 AnalogIn ain(p15); 00010 float temp; 00011 00012 int main() { 00013 int i = 0; 00014 char buf[512]; 00015 Timer timer; 00016 00017 lcd.printf("init network...\n"); 00018 ws = new Websocket(WS_SERVER_URL); 00019 00020 lcd.printf("connecting...\n"); 00021 while(!ws->connect()) { 00022 printf("retrying...\r\n"); 00023 wait(5); 00024 } 00025 00026 timer.start(); 00027 while(1) { 00028 Net::poll(); 00029 wait(0.1); 00030 00031 if (timer.read_ms() >= 10000) { 00032 temp = ain * 3.3 * 100; 00033 sprintf(buf, "No.%d: temp:%4.2f", i++, temp); 00034 ws->send(buf); 00035 timer.reset(); 00036 } 00037 00038 if (ws->read(buf)) { 00039 lcd.cls(); 00040 lcd.printf("recv: %s\n", buf); 00041 } 00042 00043 if (! ws->connected()) { 00044 lcd.cls(); 00045 lcd.printf("disconnected\n"); 00046 break; 00047 } 00048 } 00049 }
Generated on Wed Jul 27 2022 06:56:53 by
1.7.2