ThingPlug Ex

Dependencies:   DHT11 NetworkSocketAPI WizFi310Interface mbed

Fork of WizFi310_ThingPlug_Test by cliff Hong

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

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 LED             LED_Sensor
00037 
00038 #if defined(TARGET_WIZwiki_W7500)
00039     Serial pc(USBTX, USBRX);
00040     WizFi310Interface wifi(D1, D0, D7, D6, D9, NC, 115200);
00041 
00042     DigitalOut  myled ( LED );
00043 #endif
00044 
00045 
00046 int main()
00047 {       
00048     pc.baud(115200);
00049  
00050     printf("WizFi310 ThingPlug Connect_Simple Control. \r\n");
00051     if ( wifi.connect(AP_SSID, AP_PASSWORD, AP_SECURITY))     return -1;
00052     printf("IP Address is %s\r\n\r\n", wifi.get_ip_address());
00053     
00054     wifi.conTP(USER_ID, CREDENTIAL_ID, SERVICE_ID, DEVICE_ID, CONTAINER_NAME, COMMAND_NM);
00055     printf("Start!\r\n\r\n");
00056     while(true)
00057     {                   
00058         int a;
00059         a = wifi.recvTP(COMMAND_NM, 3, 0);
00060         
00061         if( a == 1 )
00062         {
00063             printf("Turn On!\r\n\r\n");
00064             myled = 1;
00065         }
00066         
00067         else if( a == 2)
00068         {
00069             printf("Turn OFF!\r\n\r\n");
00070             myled = 0;
00071         }        
00072         wait_ms(3000);
00073     }
00074 }