Dependencies: NTPClient_NetServices mbed ZG2100NetIf
ZG2100NetIfExample.cpp.cpp
00001 #include "mbed.h" 00002 00003 DigitalOut led(LED1); 00004 00005 #include "ZG2100NetIf.h" 00006 #include "NTPClient.h" 00007 #include "HTTPClient.h" 00008 00009 Serial pc(USBTX, USBRX); 00010 00011 const byte wep_key[5] = {0x01, 0x02, 0x03, 0x04, 0x05}; 00012 00013 ZG2100NetIf wifi(p5, p6, p7, p8, p9, p10); 00014 HTTPClient http; 00015 NTPClient ntp; 00016 00017 00018 int main() { 00019 00020 pc.baud(115200); 00021 00022 printf("Start\n"); 00023 00024 wifi.init(); 00025 00026 printf("Init\n"); 00027 00028 wifi.setSsid("mbed"); 00029 //wifi.setWpaPass("thisismypassphrase"); 00030 wifi.setWepKey(wep_key, 5); 00031 00032 ZG2100Err result = wifi.connect( ZG_BSS_INFRA, ZG_SECURITY_WEP ); 00033 00034 printf("Connection result %d\n", result); 00035 00036 if( result > 1 ) 00037 { 00038 printf("Connection error\n"); 00039 error("\n"); 00040 } 00041 00042 wifi.setup(); 00043 00044 printf("Setup.\n"); 00045 00046 time_t ctTime = time(NULL); 00047 printf("Current time is : %s UTC\n", ctime(&ctTime)); 00048 00049 Host server(IpAddr(), 123, "0.uk.pool.ntp.org"); 00050 ntp.setTime(server); 00051 00052 /*time_t*/ ctTime = time(NULL); 00053 printf("Time is now : %s UTC\n", ctime(&ctTime)); 00054 00055 HTTPText txt; 00056 00057 HTTPResult r = http.get("http://mbed.org/media/uploads/donatien/hello.txt", &txt); 00058 if(r==HTTP_OK) 00059 { 00060 printf("Result :\"%s\"\n", txt.gets()); 00061 } 00062 else 00063 { 00064 printf("Error %d\n", r); 00065 } 00066 00067 while(1) { 00068 led = 1; 00069 wait(0.2); 00070 led = 0; 00071 wait(0.2); 00072 } 00073 }
Generated on Wed Aug 3 2022 01:24:32 by 1.7.2