ThingPlug Ex

Dependencies:   DHT11 NetworkSocketAPI WizFi310Interface mbed

Fork of WizFi310_ThingPlug_Test by cliff Hong

Revision:
4:597b0c6ccba2
Parent:
3:4a3c8d8ad451
Child:
5:abbccd77ad5d
--- a/main.cpp	Fri Aug 25 00:58:16 2017 +0000
+++ b/main.cpp	Mon Aug 28 08:25:42 2017 +0000
@@ -22,18 +22,19 @@
 #include "WizFi310Interface.h"
 #include "Dht11.h"
 
-#define AP_SSID "Dap" // Input SSID
-#define AP_PASSWORD "00001111" // Input PW
-#define AP_SECURITY NSAPI_SECURITY_WPA2
+#define AP_SSID        "SSID"                   // Input SSID
+#define AP_PASSWORD    "PASSWORD"               // Input PW
+#define AP_SECURITY    NSAPI_SECURITY_WPA2
 
-#define USER_ID        "cliff13"
-#define CREDENTIAL_ID  "R0NNaXc1TGZmV2JVb0JzZEp3QnorSDZrYXZWanFod3hlZ0VkMEFycktRN0Z4SFpCb1JSUmdnMENUL0h4K3VZVg=="
-#define SERVICE_ID     "cliff_service"
-#define DEVICE_ID      "WIZnet_Device_01"
-#define CONTAINER_NAME "WIZnet"
+#define USER_ID        "User ID"
+#define CREDENTIAL_ID  "Credential ID"
+#define SERVICE_ID     "Service ID"
+#define DEVICE_ID      "Device ID"
+#define COMMAND_NM     "Command Name"
+#define CONTAINER_NAME "Containet Name"
 
-#define CDS_SENSOR PC_15
-#define DHT_SENSOR PC_7
+#define CDS_SENSOR     CDS_SENSOR
+#define DHT_SENSOR     DHT_SENSOR
 
 #if defined(TARGET_WIZwiki_W7500)
     Serial pc(USBTX, USBRX);
@@ -46,16 +47,23 @@
 
 int main()
 {
+    int error = 0;
+    char str[50] = "";
+    
+    int lux;
+    double temp;
+    int humid;
+    
     pc.baud(115200);
  
     printf("WizFi310 ThingPlug Connect. \r\n");
     if ( wifi.connect(AP_SSID, AP_PASSWORD, AP_SECURITY))     return -1;
     printf("IP Address is %s\r\n\r\n", wifi.get_ip_address());
     
-    wifi.conTP(USER_ID, CREDENTIAL_ID, SERVICE_ID, DEVICE_ID, CONTAINER_NAME);
+    wifi.conTP(USER_ID, CREDENTIAL_ID, SERVICE_ID, DEVICE_ID, CONTAINER_NAME, COMMAND_NM);
     while(true)
-    {
-        printf("Send - s, Quit - q\r\n");
+    {   
+        printf("Send - s, , Response - r, Quit - q\r\n");
         printf("Input : ");
         
         char c = pc.getc();
@@ -63,7 +71,35 @@
         
         if(c =='s' || c == 'S')
         {
-            wifi.sendTP(CONTAINER_NAME, "010600000026020600000022");
+            error = myTemp.read();
+            if( error == 0 )
+            {
+                lux = (int)(myLux.read()*1000);
+                temp = (double)(myTemp.getCelsius());
+                humid = (int)myTemp.getHumidity();
+                
+                sprintf((char *)str, "0106%08x020a%08x0306%08x", 
+                lux, temp, humid);
+                
+                printf("lux value : %04d, temp value : %.1lf, humidity value : %04d\r\n", 
+                        lux, temp, humid);
+                        
+                printf("Send Data : %s\r\n\r\n\r\n", str);
+                
+                wifi.sendTP(CONTAINER_NAME, str);
+            }
+                        
+            else
+                printf("Send failed\r\n\r\n");
+                
+            wait_ms(3000);
+        }
+        
+        else if(c == 'r' || c == 'R')
+        {
+            wifi.recvTP(COMMAND_NM, 3, 0);
+            
+            wait_ms(3000);
         }
         
         else if(c == 'q' || c == 'Q')
@@ -71,8 +107,6 @@
             wifi.disConTP();
             break;
         }
-        
-        wait_ms(5000);
     }
     wifi.disconnect();
 }
\ No newline at end of file