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: ESP8266Interface NetworkSocketAPI mbed
Revision 54:4b14327faaaf, committed 2016-04-21
- Comitter:
- Christopher Haster
- Date:
- Thu Apr 21 06:14:45 2016 -0500
- Parent:
- 53:99fe1d0e81fa
- Commit message:
- Updated to match changes to the NSAPI
Changed in this revision
--- a/ESP8266Interface.lib Fri Apr 15 23:59:04 2016 +0000 +++ b/ESP8266Interface.lib Thu Apr 21 06:14:45 2016 -0500 @@ -1,1 +1,1 @@ -https://developer.mbed.org/teams/components/code/ESP8266Interface/#d6244089a657 +https://developer.mbed.org/teams/components/code/ESP8266Interface/#34829ec3a3da
--- a/NetworkSocketAPI.lib Fri Apr 15 23:59:04 2016 +0000 +++ b/NetworkSocketAPI.lib Thu Apr 21 06:14:45 2016 -0500 @@ -1,1 +1,1 @@ -http://developer.mbed.org/teams/NetworkSocketAPI/code/NetworkSocketAPI/#aa343098aa61 +http://developer.mbed.org/teams/NetworkSocketAPI/code/NetworkSocketAPI/#96627c4b83d5
--- a/main.cpp Fri Apr 15 23:59:04 2016 +0000
+++ b/main.cpp Thu Apr 21 06:14:45 2016 -0500
@@ -18,36 +18,39 @@
#include "ESP8266Interface.h"
#include "TCPSocket.h"
-DigitalOut myled(LED_GREEN);
-void flash(){ myled = !myled; }
+ESP8266Interface wifi(D1, D0);
-ESP8266Interface wifi(D1, D0);
-TCPSocket socket(&wifi);
+DigitalOut led(LED_GREEN);
+void blink()
+{
+ led = !led;
+}
int main()
{
- Ticker t;
- t.attach(flash, 0.4f);
+ Ticker blinky;
+ blinky.attach(blink, 0.4f);
+
printf("NetworkSocketAPI Example\r\n");
- wifi.connect("ssid", "password");
+ wifi.connect("Sniffer", "Sandcastle");
+ const char *ip = wifi.get_ip_address();
+ const char *mac = wifi.get_mac_address();
+ printf("IP address is: %s\r\n", ip ? ip : "No IP");
+ printf("MAC address is: %s\r\n", mac ? mac : "No MAC");
- const char *ip = wifi.getIPAddress();
- const char *mac = wifi.getMACAddress();
- printf("IP Address is: %s\r\n", (ip) ? ip : "No IP");
- printf("MAC Address is: %s\r\n", (mac) ? mac : "No MAC");
+ SocketAddress addr(&wifi, "mbed.org");
+ printf("mbed.org resolved to: %s\r\n", addr.get_ip_address());
- socket.open("time-a.nist.gov", 37);
- printf("time-a.nist.gov resolved to: %s\r\n", socket.getIPAddress());
+ TCPSocket socket(&wifi);
+ socket.connect("4.ifcfg.me", 23);
- char recieved[100] = {0};
- int32_t size = 0;
- size = socket.recv(recieved, sizeof(recieved));
-
+ char buffer[64];
+ int count = socket.recv(buffer, sizeof buffer);
+ printf("public IP address is: %.15s\r\n", &buffer[15]);
+
socket.close();
wifi.disconnect();
- printf("Recieved: %ld bytes, %02x%02x%02x%02x\r\n", size,
- recieved[0], recieved[1], recieved[2], recieved[3]);
- printf("NetworkSocketAPI Example Finished\r\n");
+ printf("Done\r\n");
}