Example program for the C027Interface
Dependencies: C027Interface NetworkSocketAPI mbed
main.cpp@6:751245e265f6, 2015-06-17 (annotated)
- Committer:
- sam_grove
- Date:
- Wed Jun 17 20:58:21 2015 +0000
- Revision:
- 6:751245e265f6
- Parent:
- 4:cb8a17dd6746
- Child:
- 7:6787b920b496
updating base for wifi
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sam_grove | 0:1984a177ff56 | 1 | /* NetworkSocketAPI Example Program |
sam_grove | 0:1984a177ff56 | 2 | * Copyright (c) 2015 ARM Limited |
sam_grove | 0:1984a177ff56 | 3 | * |
sam_grove | 0:1984a177ff56 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
sam_grove | 0:1984a177ff56 | 5 | * you may not use this file except in compliance with the License. |
sam_grove | 0:1984a177ff56 | 6 | * You may obtain a copy of the License at |
sam_grove | 0:1984a177ff56 | 7 | * |
sam_grove | 0:1984a177ff56 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
sam_grove | 0:1984a177ff56 | 9 | * |
sam_grove | 0:1984a177ff56 | 10 | * Unless required by applicable law or agreed to in writing, software |
sam_grove | 0:1984a177ff56 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
sam_grove | 0:1984a177ff56 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
sam_grove | 0:1984a177ff56 | 13 | * See the License for the specific language governing permissions and |
sam_grove | 0:1984a177ff56 | 14 | * limitations under the License. |
sam_grove | 0:1984a177ff56 | 15 | */ |
sam_grove | 0:1984a177ff56 | 16 | |
sam_grove | 0:1984a177ff56 | 17 | #include "mbed.h" |
sam_grove | 6:751245e265f6 | 18 | #include "ESP8266Interface.h" |
sam_grove | 0:1984a177ff56 | 19 | |
sam_grove | 0:1984a177ff56 | 20 | DigitalOut myled(LED1); |
sam_grove | 0:1984a177ff56 | 21 | |
sam_grove | 6:751245e265f6 | 22 | ESP8266Interface wifi; |
sam_grove | 2:7283ce112304 | 23 | // or |
sam_grove | 2:7283ce112304 | 24 | //NetworkInterface *wifi = new WiFiInterface; |
sam_grove | 2:7283ce112304 | 25 | |
sam_grove | 4:cb8a17dd6746 | 26 | //TCPSocket tcp(wifi.getInstance()); |
sam_grove | 2:7283ce112304 | 27 | // or |
sam_grove | 2:7283ce112304 | 28 | //SocketInterface tcp = new TCPSocket(wifi->getInstance(); |
sam_grove | 2:7283ce112304 | 29 | |
sam_grove | 4:cb8a17dd6746 | 30 | //UDPSocket udp(wifi.getInstance()); |
sam_grove | 2:7283ce112304 | 31 | // or |
sam_grove | 2:7283ce112304 | 32 | //SocketInterface udp = new UDPSocket(wifi->getInstance(); |
sam_grove | 2:7283ce112304 | 33 | |
sam_grove | 0:1984a177ff56 | 34 | int main() |
sam_grove | 0:1984a177ff56 | 35 | { |
sam_grove | 2:7283ce112304 | 36 | puts("NetworkSocketAPI Example"); |
sam_grove | 4:cb8a17dd6746 | 37 | |
sam_grove | 2:7283ce112304 | 38 | wifi.init(); |
sam_grove | 6:751245e265f6 | 39 | wifi.connect("apname", "phrase", WI_WPA2); |
sam_grove | 6:751245e265f6 | 40 | |
sam_grove | 4:cb8a17dd6746 | 41 | printf("Wifi is %s\n", (wifi.isConnected() > 0) ? "Connected" : "Disconnected"); |
sam_grove | 4:cb8a17dd6746 | 42 | |
sam_grove | 2:7283ce112304 | 43 | printf("IP: %s\n", wifi.getIPAddress()); |
sam_grove | 2:7283ce112304 | 44 | printf("Gateway: %s\n", wifi.getGateway()); |
sam_grove | 2:7283ce112304 | 45 | printf("Mask: %s\n", wifi.getNetworkMask()); |
sam_grove | 2:7283ce112304 | 46 | printf("MAC: %s\n", wifi.getMACAddress()); |
sam_grove | 2:7283ce112304 | 47 | |
sam_grove | 2:7283ce112304 | 48 | wifi.disconnect(); |
sam_grove | 4:cb8a17dd6746 | 49 | |
sam_grove | 0:1984a177ff56 | 50 | while(1) { |
sam_grove | 2:7283ce112304 | 51 | myled = !myled; |
sam_grove | 0:1984a177ff56 | 52 | } |
sam_grove | 0:1984a177ff56 | 53 | } |