20170825 Test
Dependencies: DHT11 NetworkSocketAPI WizFi310Interface mbed
Fork of WizFi310_STATION_HelloWorld by
main.cpp
00001 /* 00002 * Copyright (C) 2015 Wiznet, MIT License 00003 * 00004 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software 00005 * and associated documentation files (the "Software"), to deal in the Software without restriction, 00006 * including without limitation the rights to use, copy, modify, merge, publish, distribute, 00007 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 00008 * furnished to do so, subject to the following conditions: 00009 * 00010 * The above copyright notice and this permission notice shall be included in all copies or 00011 * substantial portions of the Software. 00012 * 00013 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING 00014 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 00015 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 00016 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00017 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 00018 */ 00019 00020 #include <stdio.h> 00021 #include "mbed.h" 00022 #include "WizFi310Interface.h" 00023 #include "Dht11.h" 00024 00025 #define AP_SSID "SSID" 00026 #define AP_PASSWORD "PASSWORD" 00027 #define AP_SECURITY NSAPI_SECURITY_WPA2 00028 00029 #define USER_ID "USER ID" 00030 #define CREDENTIAL_ID "Credential ID" 00031 #define SERVICE_ID "Service ID" 00032 #define DEVICE_ID "Device ID" 00033 #define COMMAND_NM "Command Name" 00034 #define CONTAINER_NAME "Container Name" 00035 00036 #define CDS_SENSOR CDS_Sensor 00037 #define DHT_SENSOR DHT_Sensor 00038 00039 #if defined(TARGET_WIZwiki_W7500) 00040 Serial pc(USBTX, USBRX); 00041 WizFi310Interface wifi(D1, D0, D7, D6, D9, NC, 115200); 00042 00043 AnalogIn myLux( CDS_SENSOR ); 00044 Dht11 myTemp( DHT_SENSOR ); 00045 #endif 00046 00047 int main() 00048 { 00049 int error = 0; 00050 char str[50] = ""; 00051 00052 int lux; 00053 double temp; 00054 int humid; 00055 00056 pc.baud(115200); 00057 00058 printf("WizFi310 ThingPlug Connect. \r\n"); 00059 if ( wifi.connect(AP_SSID, AP_PASSWORD, AP_SECURITY)) return -1; 00060 printf("IP Address is %s\r\n\r\n", wifi.get_ip_address()); 00061 00062 wifi.conTP(USER_ID, CREDENTIAL_ID, SERVICE_ID, DEVICE_ID, CONTAINER_NAME, COMMAND_NM); 00063 while(true) 00064 { 00065 printf("Send - s, , Response - r, Quit - q\r\n"); 00066 printf("Input : "); 00067 00068 char c = pc.getc(); 00069 printf("%c\r\n", c); 00070 00071 if(c =='s' || c == 'S') 00072 { 00073 error = myTemp.read(); 00074 if( error == 0 ) 00075 { 00076 lux = (int)(myLux.read()*1000); 00077 temp = (double)(myTemp.getCelsius()); 00078 humid = (int)myTemp.getHumidity(); 00079 00080 sprintf((char *)str, "0106%08x0206%08x0306%08x", 00081 lux, (int)temp, humid); 00082 00083 printf("lux value : %04d, temp value : %.1lf, humidity value : %04d\r\n", 00084 lux, temp, humid); 00085 00086 printf("Send Data : %s\r\n\r\n\r\n", str); 00087 00088 wifi.sendTP(CONTAINER_NAME, str); 00089 } 00090 00091 else 00092 printf("Send failed\r\n\r\n"); 00093 00094 wait_ms(3000); 00095 } 00096 00097 else if(c == 'r' || c == 'R') 00098 { 00099 wifi.recvTP(COMMAND_NM, 3, 0); 00100 00101 wait_ms(3000); 00102 } 00103 00104 else if(c == 'q' || c == 'Q') 00105 { 00106 wifi.disConTP(); 00107 break; 00108 } 00109 } 00110 wifi.disconnect(); 00111 }
Generated on Fri Jul 15 2022 11:29:53 by 1.7.2