Marcus Parker / Mbed 2 deprecated Nucleo_Wifi

Dependencies:   NVIC_set_all_priorities TextLCD cc3000_hostdriver_mbedsocket mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "TextLCD.h"
00003 #include "cc3000.h"
00004 #include "main.h"
00005 
00006 
00007 using namespace mbed_cc3000;
00008 
00009 #if (MY_BOARD == WIFI_SHEILD_ADAFRUIT)
00010 cc3000 wifi(PB_3, PB_4, PB_6, SPI(PA_7, PA_6, PA_5), "SSID", "PASSWORD", WPA, false); //irq, en, cs, spi, irq-port
00011 Serial pc(USBTX, USBRX); // tx, rx
00012 #endif
00013 
00014 TextLCD lcd(PC_8, PC_6, PC_5, PB_15, PB_14, PB_12); // rs, e, d4-d7
00015 DigitalOut led(PC_10);
00016 
00017 int main() 
00018 {
00019     lcd.cls();
00020     lcd.printf("CC3000 Ping");
00021     
00022     led = 0;
00023     wifi.init();
00024     
00025     if (wifi.connect(5000) == false) 
00026     {
00027         lcd.locate(0, 0);
00028         lcd.printf("Return 1");
00029     } 
00030     else 
00031     {
00032         lcd.cls();
00033         lcd.locate(0, 0);
00034         lcd.printf("IP address:");
00035         lcd.locate(0, 1);
00036         lcd.printf("%s",wifi.getIPAddress());
00037     }
00038     
00039      wait(5);
00040     
00041     uint32_t ip;
00042     uint8_t *site = (uint8_t *)"google.com";
00043     
00044     printf("IP of %s ",site);
00045     if (wifi._socket.gethostbyname(site,strlen((const char *)site), &ip)) 
00046     {
00047         uint8_t add0 = (ip >> 24);
00048         uint8_t add1 = (ip >> 16);
00049         uint8_t add2 = (ip >> 8);
00050         uint8_t add3 = (ip >> 0);
00051         printf("IP address of %s: %d:%d:%d:%d \r\n", site, add0, add1, add2, add3);
00052         led = 1;
00053     } 
00054     else 
00055     {
00056         lcd.locate(0, 0);
00057         lcd.printf("Return 2");
00058     }
00059     wait(3);
00060 
00061     printf("Starting sending ping. \r\n");
00062     uint32_t reply_count = wifi.ping(ip, 5, 500, 32);
00063     lcd.cls();
00064     lcd.locate(0, 0);
00065     lcd.printf("Recieved:");
00066     lcd.locate(0, 1);
00067     lcd.printf("%d", reply_count);
00068     printf("Ping demo completed. \r\n");
00069     wifi.disconnect();
00070 }