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: GSwifiInterface mbed-rpc mbed
main.cpp
00001 #include "mbed.h" 00002 #include "mbed_rpc.h" 00003 #include "GSwifi.h" 00004 00005 #define SEC GSwifi::SEC_OPEN 00006 #define SSID "MBED" 00007 #define PASS "1234567890" 00008 00009 #ifndef CFG_ENABLE_WEBSOCKET 00010 #error Please enable "#define CFG_ENABLE_WEBSOCKET" in "GSwifi_conf.h" 00011 #endif 00012 00013 DigitalOut led1(LED1), led2(LED2); 00014 Serial pc(USBTX, USBRX); 00015 //GSwifi gs(p13, p14, p12, P0_22, p20, NC, 115200); // mbed LPC1768 00016 GSwifi gs(p13, p14, p12, p11, p20, NC, 115200); // mbed LPC1768 00017 LocalFileSystem local("local"); 00018 00019 void ws_server (int cid) { 00020 int i; 00021 char buf[40], outbuf[40]; 00022 00023 led2 = 1; 00024 i = gs.recv(cid, buf, sizeof(buf)); 00025 if (i < 0) return; 00026 buf[i] = 0; 00027 00028 RPC::call(buf, outbuf); 00029 printf("RPC %d '%s' '%s'\r\n", cid, buf, outbuf); 00030 00031 gs.wsSend(cid, outbuf, strlen(outbuf)); 00032 led2 = 0; 00033 } 00034 00035 int main () { 00036 00037 pc.baud(115200); 00038 00039 gs.setAddress("192.168.1.1", "255.255.255.0", "192.168.1.1", "192.168.1.1", "www.mbed"); 00040 gs.setSsid(SEC, SSID, PASS); 00041 if (gs.limitedap()) { 00042 pc.printf("error: limitedap\r\n"); 00043 return -1; 00044 } 00045 00046 RPC::add_rpc_class<RpcDigitalIn>(); 00047 RPC::add_rpc_class<RpcDigitalOut>(); 00048 RPC::add_rpc_class<RpcDigitalInOut>(); 00049 RPC::add_rpc_class<RpcPwmOut>(); 00050 RPC::add_rpc_class<RpcAnalogIn>(); 00051 RPC::add_rpc_class<RpcAnalogOut>(); 00052 00053 gs.httpd(80); 00054 gs.httpdAttach("/ws/", &ws_server, 1); 00055 gs.httpdAttach("/", "/local/"); 00056 printf("httpd ready\r\n"); 00057 led1 = 1; 00058 00059 for (;;) { 00060 gs.poll(); 00061 00062 if (pc.readable()) { 00063 if (pc.getc() == 'q') break; 00064 } 00065 } 00066 gs.dissociate(); 00067 led1 = 0; 00068 return 0; 00069 }
Generated on Wed Jul 13 2022 10:03:59 by
1.7.2