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: WIFI_API_32kRAM WebSocketClient mbed
main.cpp@0:47ec083185d0, 2015-10-07 (annotated)
- Committer:
- wgd8700
- Date:
- Wed Oct 07 05:16:10 2015 +0000
- Revision:
- 0:47ec083185d0
- Child:
- 1:610f3dc5679e
First commit
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| wgd8700 | 0:47ec083185d0 | 1 | #include "mbed.h" |
| wgd8700 | 0:47ec083185d0 | 2 | #include "EthernetInterface.h" |
| wgd8700 | 0:47ec083185d0 | 3 | #include "Websocket.h" |
| wgd8700 | 0:47ec083185d0 | 4 | |
| wgd8700 | 0:47ec083185d0 | 5 | #include "WIFIDevice.h" |
| wgd8700 | 0:47ec083185d0 | 6 | |
| wgd8700 | 0:47ec083185d0 | 7 | WIFIDevice wifi; |
| wgd8700 | 0:47ec083185d0 | 8 | Serial pc(USBTX, USBRX); |
| wgd8700 | 0:47ec083185d0 | 9 | |
| wgd8700 | 0:47ec083185d0 | 10 | int main() { |
| wgd8700 | 0:47ec083185d0 | 11 | char recv[30]; |
| wgd8700 | 0:47ec083185d0 | 12 | |
| wgd8700 | 0:47ec083185d0 | 13 | pc.baud(115200); |
| wgd8700 | 0:47ec083185d0 | 14 | pc.printf("Init...\n"); |
| wgd8700 | 0:47ec083185d0 | 15 | |
| wgd8700 | 0:47ec083185d0 | 16 | EthernetInterface eth; |
| wgd8700 | 0:47ec083185d0 | 17 | eth.init(); //Use DHCP |
| wgd8700 | 0:47ec083185d0 | 18 | |
| wgd8700 | 0:47ec083185d0 | 19 | // set given SSID and PW as the highest priority |
| wgd8700 | 0:47ec083185d0 | 20 | wifi.setNetwork("Tsungta_iPhone", "icq87001", 0); |
| wgd8700 | 0:47ec083185d0 | 21 | |
| wgd8700 | 0:47ec083185d0 | 22 | eth.connect(40000); |
| wgd8700 | 0:47ec083185d0 | 23 | pc.printf("IP Address:%s\n",eth.getIPAddress()); |
| wgd8700 | 0:47ec083185d0 | 24 | pc.printf("MAC Address:%s\n",eth.getMACAddress()); |
| wgd8700 | 0:47ec083185d0 | 25 | |
| wgd8700 | 0:47ec083185d0 | 26 | Websocket ws("ws://172.20.10.11:8888/ws"); |
| wgd8700 | 0:47ec083185d0 | 27 | ws.connect(); |
| wgd8700 | 0:47ec083185d0 | 28 | |
| wgd8700 | 0:47ec083185d0 | 29 | while (1) { |
| wgd8700 | 0:47ec083185d0 | 30 | ws.send("WebSocket Hello World over Ethernet"); |
| wgd8700 | 0:47ec083185d0 | 31 | wait(1.0); |
| wgd8700 | 0:47ec083185d0 | 32 | } |
| wgd8700 | 0:47ec083185d0 | 33 | } |