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: mbed WS_SERVER EthernetInterface HTTP_SERVER
main.cpp
00001 #include "mbed.h" 00002 #include "WS_SERVER.h" 00003 #include "HTTP_SERVER.h" 00004 #include "rtos.h" 00005 #ifndef DEBUG 00006 //#define DEBUG 00007 #endif 00008 00009 WSS wss(1024); 00010 HttpServer httpsvr; 00011 DigitalOut led1(LED1); 00012 DigitalOut led2(LED2); 00013 DigitalOut led3(LED3); 00014 DigitalOut led4(LED4); 00015 Serial pc(USBTX, USBRX); 00016 00017 void httpServerThread(void const* argument) 00018 { 00019 if(httpsvr.init()) { 00020 if(httpsvr.run() == 0) 00021 printf("end\r\n"); 00022 else 00023 printf("error end\r\n"); 00024 } 00025 } 00026 void test(void const* argument) 00027 { 00028 while(true) { //wss.isListening()) { 00029 led1 = !led1; 00030 Thread::wait(500); 00031 } 00032 } 00033 00034 void websocketServerThread()//void const* argument) 00035 { 00036 // 00037 // Websocket communication 00038 // 00039 //wss.txPing(); 00040 if(wss.init()) { 00041 while(wss.isListening())wss.run(); 00042 } 00043 00044 // -----Websocket com end----- 00045 led3=led4=0; 00046 } 00047 00048 void printRxData(void const* argument) 00049 { 00050 char l_data; 00051 wss.txPing(); 00052 while(1) { 00053 if(wss.isReadable()) { 00054 l_data = (char)wss.getRxData(); 00055 printf("(printRxData) %c(%d) \r\n", l_data, l_data); 00056 } 00057 else{ 00058 printf("no printings\r\n"); 00059 Thread::wait(500); 00060 } 00061 } 00062 } 00063 00064 int main() 00065 { 00066 //Thread httpListener(httpServerThread, NULL, osPriorityNormal, (DEFAULT_STACK_SIZE * 2.25)); 00067 //httpServerThread(); 00068 Thread wssListener(websocketServerThread, NULL, osPriorityNormal, (DEFAULT_STACK_SIZE * 2.25)); 00069 //Thread::wait(5000); 00070 Thread printTaske(printRxData); 00071 //websocketServerThread(); 00072 //wssListener.start(websocketServerThread); 00073 //printTaske.start(printRxData); 00074 //wssListener.terminate(); 00075 //printTaske.terminate(); 00076 return 0; 00077 } 00078
Generated on Sat Jul 16 2022 06:43:50 by
1.7.2