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: NetworkSocketAPI SNICInterface mbed-rtos mbed
main.cpp
00001 /* NetworkSocketAPI Example Program 00002 * Copyright (c) 2015 ARM Limited 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 #include "mbed.h" 00018 #include "TCPSocket.h" 00019 00020 #if WIFIMODULE == ESP8266 00021 #include "ESP8266Interface.h" 00022 ESP8266Interface wifi(D1, D0); 00023 #elif WIFIMODULE == Murata 00024 #include "MurataInterface.h" 00025 MurataInterface wifi( D1, D0, NC, NC, D2); 00026 #endif 00027 00028 DigitalOut led(LED_GREEN); 00029 00030 void blink() 00031 { 00032 led = !led; 00033 } 00034 00035 int main() 00036 { 00037 Ticker blinky; 00038 blinky.attach(blink, 0.4f); 00039 00040 printf("NetworkSocketAPI Example\r\n"); 00041 00042 wifi.connect("Maggie", "mlq114759655"); 00043 const char *ip = wifi.get_ip_address(); 00044 const char *mac = wifi.get_mac_address(); 00045 printf("IP address is: %s\r\n", ip ? ip : "No IP"); 00046 printf("MAC address is: %s\r\n", mac ? mac : "No MAC"); 00047 00048 SocketAddress addr(&wifi, "mbed.org"); 00049 printf("mbed.org resolved to: %s\r\n", addr.get_ip_address()); 00050 00051 TCPSocket socket(&wifi); 00052 socket.connect("4.ifcfg.me", 23); 00053 00054 char buffer[64]; 00055 int count = socket.recv(buffer, sizeof buffer); 00056 printf("public IP address is: %.15s\r\n", &buffer[15]); 00057 00058 socket.close(); 00059 wifi.disconnect(); 00060 00061 printf("Done\r\n"); 00062 }
Generated on Tue Jul 19 2022 22:11:47 by
1.7.2