first
Dependencies: SHTx SNTPClient WIZnetInterface mbed
main.cpp
00001 #include "mbed.h" 00002 #include "EthernetInterface.h" 00003 #include "SNTPClient.h" 00004 #include "SHTx/sht15.hpp" 00005 00006 uint8_t mac_addr[6] = {0x00, 0x08, 0xDC, 0x11, 0x22, 0xab}; 00007 00008 Serial pc(USBTX,USBRX); 00009 EthernetInterface eth; 00010 datetime ntptime; 00011 DigitalOut busy(LED1); 00012 SHTx::SHT15 sensor(D2, D3); 00013 00014 struct tm timeinfo; 00015 00016 int main() 00017 { 00018 pc.baud(115200); 00019 wait(0.5f); 00020 pc.printf("Hello WIZwiki-W7500!\n\r"); 00021 pc.printf("===========================================\n\r"); 00022 00023 00024 eth.init(mac_addr); //Use DHCP 00025 printf("Check Ethernet Link\r\n"); 00026 while(1) //Wait link up 00027 { 00028 if(eth.link() == true) 00029 break; 00030 } 00031 00032 printf("Link up\r\n"); 00033 printf("Getting IP address by DHCP...\r\n"); 00034 eth.connect(); 00035 printf("Server IP Address is %s\r\n", eth.getIPAddress()); 00036 00037 printf("Getting time information by using NTP...\r\n"); 00038 00039 SNTPClient sntp("time.nist.gov", 40); // timezone: Korea, Republic of 00040 sntp.connect(); 00041 if(sntp.getTime(&ntptime) == true) 00042 { 00043 printf("%d-%d-%d, %02d:%02d:%02d\r\n", ntptime.yy, ntptime.mo, ntptime.dd, ntptime.hh, ntptime.mm, ntptime.ss); 00044 printf("Completed Get and Set Time\r\n\r\n"); 00045 } 00046 else 00047 { 00048 while(sntp.getTime(&ntptime) == true) 00049 { 00050 break; 00051 } 00052 } 00053 00054 sensor.setOTPReload(false); 00055 sensor.setResolution(true); 00056 while(1) 00057 { 00058 busy = true; 00059 sensor.update(); 00060 busy = false; 00061 00062 sntp.getTime(&ntptime); 00063 printf("< The current time : %d-%d-%d, %02d:%02d:%02d >\r\n", ntptime.yy, ntptime.mo, ntptime.dd, ntptime.hh, ntptime.mm, ntptime.ss); 00064 00065 // Temperature in celcius 00066 sensor.setScale(false); 00067 pc.printf("Temperature [ %3.2f C ]\r\n", sensor.getTemperature()); 00068 00069 // Temperature in fahrenheit 00070 sensor.setScale(true); 00071 pc.printf(" [ %3.2f F ]\r\n", sensor.getTemperature()); 00072 00073 // Relative Humidity 00074 pc.printf("Humdity [ %3.2f %% ]\r\n", sensor.getHumidity()); 00075 00076 pc.printf("===========================================\n\r"); 00077 wait(5); 00078 00079 } 00080 00081 }
Generated on Fri Jul 29 2022 18:22:42 by
1.7.2