Example program for the C027Interface
Dependencies: C027Interface NetworkSocketAPI mbed
main.cpp@21:979b1db5d7da, 2015-07-27 (annotated)
- Committer:
- sarahmarshy
- Date:
- Mon Jul 27 15:18:45 2015 +0000
- Revision:
- 21:979b1db5d7da
- Parent:
- 19:03f1da306347
- Child:
- 42:d8ea089e5606
DnsQuery and IP
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" |
sarahmarshy | 16:bb0a5b830dc5 | 18 | #include "ESP8266Interface.h" |
sam_grove | 0:1984a177ff56 | 19 | |
sam_grove | 0:1984a177ff56 | 20 | DigitalOut myled(LED1); |
sam_grove | 0:1984a177ff56 | 21 | |
sarahmarshy | 16:bb0a5b830dc5 | 22 | ESP8266Interface wifi(D1, D0); |
sam_grove | 2:7283ce112304 | 23 | |
sam_grove | 0:1984a177ff56 | 24 | int main() |
bridadan | 14:c47437f5dae8 | 25 | { |
bridadan | 14:c47437f5dae8 | 26 | printf("NetworkSocketAPI Example\r\n"); |
sam_grove | 4:cb8a17dd6746 | 27 | |
sam_grove | 2:7283ce112304 | 28 | wifi.init(); |
sarahmarshy | 16:bb0a5b830dc5 | 29 | wifi.connect("Buffalo-G-1280", "13808136"); |
sarahmarshy | 16:bb0a5b830dc5 | 30 | |
sarahmarshy | 18:a5830a6d3e11 | 31 | char* ip; |
sarahmarshy | 18:a5830a6d3e11 | 32 | ip = wifi.getIPAddress(); |
sarahmarshy | 18:a5830a6d3e11 | 33 | if(ip!=NULL) |
sarahmarshy | 21:979b1db5d7da | 34 | printf("\nIP Address is: %s\n",ip); |
sarahmarshy | 18:a5830a6d3e11 | 35 | else |
sarahmarshy | 18:a5830a6d3e11 | 36 | printf("No IP"); |
sam_grove | 9:da5a230fa4f4 | 37 | |
sarahmarshy | 21:979b1db5d7da | 38 | char ip_goog[20]; |
sarahmarshy | 21:979b1db5d7da | 39 | wifi.getHostByName("google.com", ip_goog); |
sarahmarshy | 21:979b1db5d7da | 40 | printf("Got %s\n",ip_goog); |
sarahmarshy | 21:979b1db5d7da | 41 | |
sarahmarshy | 21:979b1db5d7da | 42 | /* |
sarahmarshy | 21:979b1db5d7da | 43 | SocketInterface* mySocket = wifi.allocateSocket(SOCK_TCP); |
sarahmarshy | 19:03f1da306347 | 44 | |
bridadan | 14:c47437f5dae8 | 45 | |
sarahmarshy | 21:979b1db5d7da | 46 | mySocket->setAddressPort("192.168.13.5", 7); |
sarahmarshy | 17:72de842c27b4 | 47 | |
sarahmarshy | 17:72de842c27b4 | 48 | mySocket->open(); |
sarahmarshy | 21:979b1db5d7da | 49 | |
sarahmarshy | 21:979b1db5d7da | 50 | mySocket->send("hello",5,10000); |
sarahmarshy | 21:979b1db5d7da | 51 | char recieved[6]; |
sarahmarshy | 17:72de842c27b4 | 52 | recieved[5] = 0; |
sarahmarshy | 21:979b1db5d7da | 53 | int recv_amnt = mySocket->recv(recieved, 5, 10000); |
sarahmarshy | 16:bb0a5b830dc5 | 54 | printf("Recieved: %d, %s\n",recv_amnt,recieved); |
sarahmarshy | 17:72de842c27b4 | 55 | mySocket->close(); |
sarahmarshy | 21:979b1db5d7da | 56 | */ |
bridadan | 14:c47437f5dae8 | 57 | |
sam_grove | 2:7283ce112304 | 58 | wifi.disconnect(); |
bridadan | 14:c47437f5dae8 | 59 | |
sam_grove | 0:1984a177ff56 | 60 | while(1) { |
sam_grove | 2:7283ce112304 | 61 | myled = !myled; |
sam_grove | 0:1984a177ff56 | 62 | } |
sam_grove | 0:1984a177ff56 | 63 | } |