Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: LWIPInterface NetworkSocketAPI mbed-rtos mbed
main.cpp
- Committer:
- geky
- Date:
- 2016-02-01
- Revision:
- 25:eef7d93d9f5b
- Parent:
- 24:471a07e886ae
- Child:
- 26:4242277cf9c7
File content as of revision 25:eef7d93d9f5b:
/* 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);
}