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: EthernetInterface MbedJSONRpc MbedJSONValue WebSocketClient mbed-rtos mbed
main.cpp
00001 #include "mbed.h" 00002 #include "MbedJSONRpc.h" 00003 #include "MbedJSONValue.h" 00004 #include "EthernetInterface.h" 00005 #include "Websocket.h" 00006 00007 Serial pc(USBTX, USBRX); 00008 BusOut l(LED1, LED2, LED3, LED4); 00009 00010 //websocket: configuration with sub-network = demo and mbed_id = mbed_led 00011 Websocket ws("ws://sockets.mbed.org/rpc/demo/mbed_led"); 00012 00013 //RPC object attached to the websocket server 00014 MbedJSONRpc rpc(&ws); 00015 00016 //Test class 00017 class Test { 00018 public: 00019 Test() {}; 00020 void led(MbedJSONValue& in, MbedJSONValue& out) { 00021 int id = in[0].get<int>(); 00022 l = (1 << (id - 1)); 00023 wait(0.2); 00024 l = 0; 00025 } 00026 }; 00027 00028 Test test; 00029 00030 int main() { 00031 00032 EthernetInterface eth; 00033 eth.init(); //Use DHCP 00034 eth.connect(); 00035 printf("IP Address is %s\n\r", eth.getIPAddress()); 00036 00037 ws.connect(); 00038 00039 RPC_TYPE t; 00040 00041 //------------register getAcc---------------// 00042 if((t = rpc.registerMethod("led", &test, &Test::led)) == REGISTER_OK) 00043 printf("led is registered\r\n"); 00044 else 00045 printType(t); 00046 00047 //wait for incoming CALL requests 00048 rpc.work(); 00049 }
Generated on Wed Jul 13 2022 00:58:43 by
1.7.2