Example program for the C027Interface
Dependencies: C027Interface NetworkSocketAPI mbed
main.cpp
- Committer:
- geky
- Date:
- 2016-02-02
- Revision:
- 27:ccedb4ad0033
- Parent:
- 26:4242277cf9c7
- Child:
- 30:f80540b6e2db
File content as of revision 27:ccedb4ad0033:
/* NetworkSocketAPI Example Program * Copyright (c) 2015 ARM Limited * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "mbed.h" #include "ESP8266Interface.h" DigitalOut myled(LED1); void flash(){myled = !myled;} ESP8266Interface wifi(D1, D0); int main() { Ticker t; t.attach(flash, 0.4f); printf("NetworkSocketAPI Example\r\n"); wifi.init(); wifi.connect("WifiDemo", ""); char* ip = wifi.getIPAddress(); printf("IP Address is: %s\n", (ip) ? ip : "No IP"); char host_ip[50]; wifi.getHostByName("time-a.nist.gov", host_ip); printf("time-a.nist.gov resolved to: %s\n", host_ip); SocketInterface* mySocket = wifi.allocateSocket(SOCK_TCP); char recieved[100] = {0}; int recv_amnt = 0; //Sending and receiving from echo server mySocket->setAddressPort(host_ip, 37); mySocket->open(); //mySocket->send("xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx", 50, 10000); recv_amnt = mySocket->recv(recieved, sizeof(recieved), 10000); mySocket->close(); wifi.disconnect(); printf("Recieved: %d bytes, %02x%02x%02x%02x\n", recv_amnt, recieved[0], recieved[1], recieved[2], recieved[3]); printf("NetworkSocketAPI Example Finished\r\n"); while(1); }