This is a NetworkSocketAPI example for LWIPBP3595Interface_STA library. LWIPBP3595Interface_STA library only works with GR-PEACH. The base example is HelloLWIPInterface.
Dependencies: LWIPBP3595Interface_STA LWIPInterface NetworkSocketAPI mbed-rtos mbed
Fork of HelloLWIPBP3595Interface by
main.cpp@2:144dc7ff85e5, 2016-05-31 (annotated)
- Committer:
- tousaki
- Date:
- Tue May 31 06:53:15 2016 +0000
- Revision:
- 2:144dc7ff85e5
- Parent:
- 0:8d78a24b262f
- Child:
- 3:a4b863fd65b8
Modified some comments
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tousaki | 0:8d78a24b262f | 1 | /* main.cpp in HelloLWIPBP3595Interface */ |
tousaki | 0:8d78a24b262f | 2 | /* Copyright (C) 2016 Grape Systems, Inc. */ |
tousaki | 0:8d78a24b262f | 3 | /* The base file is main.cpp in HelloLWIPInterface. */ |
tousaki | 0:8d78a24b262f | 4 | |
tousaki | 0:8d78a24b262f | 5 | /* main.cpp in HelloLWIPInterface */ |
tousaki | 0:8d78a24b262f | 6 | /* NetworkSocketAPI Example Program |
tousaki | 0:8d78a24b262f | 7 | * Copyright (c) 2015 ARM Limited |
tousaki | 0:8d78a24b262f | 8 | * |
tousaki | 0:8d78a24b262f | 9 | * Licensed under the Apache License, Version 2.0 (the "License"); |
tousaki | 0:8d78a24b262f | 10 | * you may not use this file except in compliance with the License. |
tousaki | 0:8d78a24b262f | 11 | * You may obtain a copy of the License at |
tousaki | 0:8d78a24b262f | 12 | * |
tousaki | 0:8d78a24b262f | 13 | * http://www.apache.org/licenses/LICENSE-2.0 |
tousaki | 0:8d78a24b262f | 14 | * |
tousaki | 0:8d78a24b262f | 15 | * Unless required by applicable law or agreed to in writing, software |
tousaki | 0:8d78a24b262f | 16 | * distributed under the License is distributed on an "AS IS" BASIS, |
tousaki | 0:8d78a24b262f | 17 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
tousaki | 0:8d78a24b262f | 18 | * See the License for the specific language governing permissions and |
tousaki | 0:8d78a24b262f | 19 | * limitations under the License. |
tousaki | 0:8d78a24b262f | 20 | */ |
tousaki | 0:8d78a24b262f | 21 | |
tousaki | 2:144dc7ff85e5 | 22 | /* |
tousaki | 2:144dc7ff85e5 | 23 | This program works with the following library. |
tousaki | 2:144dc7ff85e5 | 24 | mbed-rtos : revision 107 |
tousaki | 2:144dc7ff85e5 | 25 | */ |
tousaki | 2:144dc7ff85e5 | 26 | |
tousaki | 0:8d78a24b262f | 27 | #include "mbed.h" |
tousaki | 0:8d78a24b262f | 28 | #include "LWIPBP3595Interface.h" |
tousaki | 0:8d78a24b262f | 29 | #include "TCPSocket.h" |
tousaki | 0:8d78a24b262f | 30 | |
tousaki | 0:8d78a24b262f | 31 | LWIPBP3595Interface wifi; |
tousaki | 0:8d78a24b262f | 32 | |
tousaki | 0:8d78a24b262f | 33 | DigitalOut led(LED_GREEN); |
tousaki | 0:8d78a24b262f | 34 | void blink() |
tousaki | 0:8d78a24b262f | 35 | { |
tousaki | 0:8d78a24b262f | 36 | led = !led; |
tousaki | 0:8d78a24b262f | 37 | } |
tousaki | 0:8d78a24b262f | 38 | |
tousaki | 0:8d78a24b262f | 39 | int main() |
tousaki | 0:8d78a24b262f | 40 | { |
tousaki | 0:8d78a24b262f | 41 | Ticker blinky; |
tousaki | 0:8d78a24b262f | 42 | blinky.attach(blink, 0.4f); |
tousaki | 0:8d78a24b262f | 43 | |
tousaki | 0:8d78a24b262f | 44 | printf("NetworkSocketAPI Example\r\n"); |
tousaki | 0:8d78a24b262f | 45 | |
tousaki | 0:8d78a24b262f | 46 | wifi.connect("ssid", "password"); |
tousaki | 0:8d78a24b262f | 47 | const char *ip = wifi.get_ip_address(); |
tousaki | 0:8d78a24b262f | 48 | const char *mac = wifi.get_mac_address(); |
tousaki | 0:8d78a24b262f | 49 | printf("IP address is: %s\r\n", ip ? ip : "No IP"); |
tousaki | 0:8d78a24b262f | 50 | printf("MAC address is: %s\r\n", mac ? mac : "No MAC"); |
tousaki | 0:8d78a24b262f | 51 | |
tousaki | 0:8d78a24b262f | 52 | SocketAddress addr(&wifi, "mbed.org"); |
tousaki | 0:8d78a24b262f | 53 | printf("mbed.org resolved to: %s\r\n", addr.get_ip_address()); |
tousaki | 0:8d78a24b262f | 54 | |
tousaki | 0:8d78a24b262f | 55 | TCPSocket socket(&wifi); |
tousaki | 0:8d78a24b262f | 56 | socket.connect("4.ifcfg.me", 23); |
tousaki | 0:8d78a24b262f | 57 | |
tousaki | 0:8d78a24b262f | 58 | char buffer[64]; |
tousaki | 0:8d78a24b262f | 59 | int count = socket.recv(buffer, sizeof buffer); |
tousaki | 0:8d78a24b262f | 60 | printf("public IP address is: %.15s\r\n", &buffer[15]); |
tousaki | 0:8d78a24b262f | 61 | |
tousaki | 0:8d78a24b262f | 62 | socket.close(); |
tousaki | 0:8d78a24b262f | 63 | wifi.disconnect(); |
tousaki | 0:8d78a24b262f | 64 | |
tousaki | 0:8d78a24b262f | 65 | printf("Done\r\n"); |
tousaki | 0:8d78a24b262f | 66 | } |