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@0:8d78a24b262f, 2016-05-25 (annotated)
- Committer:
- tousaki
- Date:
- Wed May 25 05:01:56 2016 +0000
- Revision:
- 0:8d78a24b262f
- Child:
- 2:144dc7ff85e5
Created 1st version.
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 | 0:8d78a24b262f | 22 | #include "mbed.h" |
tousaki | 0:8d78a24b262f | 23 | #include "LWIPBP3595Interface.h" |
tousaki | 0:8d78a24b262f | 24 | #include "TCPSocket.h" |
tousaki | 0:8d78a24b262f | 25 | |
tousaki | 0:8d78a24b262f | 26 | LWIPBP3595Interface wifi; |
tousaki | 0:8d78a24b262f | 27 | |
tousaki | 0:8d78a24b262f | 28 | DigitalOut led(LED_GREEN); |
tousaki | 0:8d78a24b262f | 29 | void blink() |
tousaki | 0:8d78a24b262f | 30 | { |
tousaki | 0:8d78a24b262f | 31 | led = !led; |
tousaki | 0:8d78a24b262f | 32 | } |
tousaki | 0:8d78a24b262f | 33 | |
tousaki | 0:8d78a24b262f | 34 | int main() |
tousaki | 0:8d78a24b262f | 35 | { |
tousaki | 0:8d78a24b262f | 36 | Ticker blinky; |
tousaki | 0:8d78a24b262f | 37 | blinky.attach(blink, 0.4f); |
tousaki | 0:8d78a24b262f | 38 | |
tousaki | 0:8d78a24b262f | 39 | printf("NetworkSocketAPI Example\r\n"); |
tousaki | 0:8d78a24b262f | 40 | |
tousaki | 0:8d78a24b262f | 41 | wifi.connect("ssid", "password"); |
tousaki | 0:8d78a24b262f | 42 | const char *ip = wifi.get_ip_address(); |
tousaki | 0:8d78a24b262f | 43 | const char *mac = wifi.get_mac_address(); |
tousaki | 0:8d78a24b262f | 44 | printf("IP address is: %s\r\n", ip ? ip : "No IP"); |
tousaki | 0:8d78a24b262f | 45 | printf("MAC address is: %s\r\n", mac ? mac : "No MAC"); |
tousaki | 0:8d78a24b262f | 46 | |
tousaki | 0:8d78a24b262f | 47 | SocketAddress addr(&wifi, "mbed.org"); |
tousaki | 0:8d78a24b262f | 48 | printf("mbed.org resolved to: %s\r\n", addr.get_ip_address()); |
tousaki | 0:8d78a24b262f | 49 | |
tousaki | 0:8d78a24b262f | 50 | TCPSocket socket(&wifi); |
tousaki | 0:8d78a24b262f | 51 | socket.connect("4.ifcfg.me", 23); |
tousaki | 0:8d78a24b262f | 52 | |
tousaki | 0:8d78a24b262f | 53 | char buffer[64]; |
tousaki | 0:8d78a24b262f | 54 | int count = socket.recv(buffer, sizeof buffer); |
tousaki | 0:8d78a24b262f | 55 | printf("public IP address is: %.15s\r\n", &buffer[15]); |
tousaki | 0:8d78a24b262f | 56 | |
tousaki | 0:8d78a24b262f | 57 | socket.close(); |
tousaki | 0:8d78a24b262f | 58 | wifi.disconnect(); |
tousaki | 0:8d78a24b262f | 59 | |
tousaki | 0:8d78a24b262f | 60 | printf("Done\r\n"); |
tousaki | 0:8d78a24b262f | 61 | } |