![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
for zabuton
Dependencies: EthernetInterface HTTPClient SocketIO WebSocketClient mbed-rtos mbed picojson
main.cpp@0:6b7be77233ac, 2016-12-16 (annotated)
- Committer:
- 3116redtrain
- Date:
- Fri Dec 16 08:18:08 2016 +0000
- Revision:
- 0:6b7be77233ac
first;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
3116redtrain | 0:6b7be77233ac | 1 | #include "mbed.h" |
3116redtrain | 0:6b7be77233ac | 2 | #include "CushionNodeConnector.h" |
3116redtrain | 0:6b7be77233ac | 3 | #include "EthernetInterface.h" |
3116redtrain | 0:6b7be77233ac | 4 | |
3116redtrain | 0:6b7be77233ac | 5 | int main() { |
3116redtrain | 0:6b7be77233ac | 6 | EthernetInterface eth; |
3116redtrain | 0:6b7be77233ac | 7 | eth.init(); //Use DHCP |
3116redtrain | 0:6b7be77233ac | 8 | eth.connect(); |
3116redtrain | 0:6b7be77233ac | 9 | printf("IP Address is %s\n", eth.getIPAddress()); |
3116redtrain | 0:6b7be77233ac | 10 | |
3116redtrain | 0:6b7be77233ac | 11 | CushionNodeConnector cnc; |
3116redtrain | 0:6b7be77233ac | 12 | bool ret = cnc.connect(); |
3116redtrain | 0:6b7be77233ac | 13 | if (!ret) |
3116redtrain | 0:6b7be77233ac | 14 | exit(1); |
3116redtrain | 0:6b7be77233ac | 15 | |
3116redtrain | 0:6b7be77233ac | 16 | char msg[256]; |
3116redtrain | 0:6b7be77233ac | 17 | while(1) { |
3116redtrain | 0:6b7be77233ac | 18 | int res = cnc.mess_send(1, "down"); |
3116redtrain | 0:6b7be77233ac | 19 | int type=cnc.mess_recv(msg); |
3116redtrain | 0:6b7be77233ac | 20 | if (type > 0) { |
3116redtrain | 0:6b7be77233ac | 21 | printf("messtype:%d rcv: %s\r\n",type, msg); |
3116redtrain | 0:6b7be77233ac | 22 | } |
3116redtrain | 0:6b7be77233ac | 23 | if(!cnc.is_connected()) |
3116redtrain | 0:6b7be77233ac | 24 | break; |
3116redtrain | 0:6b7be77233ac | 25 | wait(0.1); |
3116redtrain | 0:6b7be77233ac | 26 | } |
3116redtrain | 0:6b7be77233ac | 27 | cnc.close(); |
3116redtrain | 0:6b7be77233ac | 28 | eth.disconnect(); |
3116redtrain | 0:6b7be77233ac | 29 | } |