ThingPlug Ex
Dependencies: DHT11 NetworkSocketAPI WizFi310Interface mbed
Fork of WizFi310_ThingPlug_Test by
main.cpp@10:6a4b8caced6b, 2017-11-15 (annotated)
- Committer:
- cliff1
- Date:
- Wed Nov 15 06:30:22 2017 +0000
- Revision:
- 10:6a4b8caced6b
- Parent:
- 9:473f0a73f0c0
- Child:
- 11:06675e22e37d
New Version
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
stkim92 | 0:89f7a9e4554f | 1 | /* |
stkim92 | 0:89f7a9e4554f | 2 | * Copyright (C) 2015 Wiznet, MIT License |
stkim92 | 0:89f7a9e4554f | 3 | * |
stkim92 | 0:89f7a9e4554f | 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
stkim92 | 0:89f7a9e4554f | 5 | * and associated documentation files (the "Software"), to deal in the Software without restriction, |
stkim92 | 0:89f7a9e4554f | 6 | * including without limitation the rights to use, copy, modify, merge, publish, distribute, |
stkim92 | 0:89f7a9e4554f | 7 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is |
stkim92 | 0:89f7a9e4554f | 8 | * furnished to do so, subject to the following conditions: |
stkim92 | 0:89f7a9e4554f | 9 | * |
stkim92 | 0:89f7a9e4554f | 10 | * The above copyright notice and this permission notice shall be included in all copies or |
stkim92 | 0:89f7a9e4554f | 11 | * substantial portions of the Software. |
stkim92 | 0:89f7a9e4554f | 12 | * |
stkim92 | 0:89f7a9e4554f | 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
stkim92 | 0:89f7a9e4554f | 14 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
stkim92 | 0:89f7a9e4554f | 15 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
stkim92 | 0:89f7a9e4554f | 16 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
stkim92 | 0:89f7a9e4554f | 17 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
stkim92 | 0:89f7a9e4554f | 18 | */ |
stkim92 | 0:89f7a9e4554f | 19 | |
stkim92 | 0:89f7a9e4554f | 20 | #include <stdio.h> |
stkim92 | 0:89f7a9e4554f | 21 | #include "mbed.h" |
stkim92 | 0:89f7a9e4554f | 22 | #include "WizFi310Interface.h" |
cliff1 | 3:4a3c8d8ad451 | 23 | #include "Dht11.h" |
stkim92 | 0:89f7a9e4554f | 24 | |
cliff1 | 6:ece3b06b9aba | 25 | #define AP_SSID "SSID" |
cliff1 | 6:ece3b06b9aba | 26 | #define AP_PASSWORD "PASSWORD" |
cliff1 | 6:ece3b06b9aba | 27 | #define AP_SECURITY NSAPI_SECURITY_WPA2 |
stkim92 | 0:89f7a9e4554f | 28 | |
cliff1 | 6:ece3b06b9aba | 29 | #define USER_ID "USER ID" |
cliff1 | 6:ece3b06b9aba | 30 | #define CREDENTIAL_ID "Credential ID" |
cliff1 | 6:ece3b06b9aba | 31 | #define SERVICE_ID "Service ID" |
cliff1 | 6:ece3b06b9aba | 32 | #define DEVICE_ID "Device ID" |
cliff1 | 6:ece3b06b9aba | 33 | #define COMMAND_NM "Command Name" |
cliff1 | 6:ece3b06b9aba | 34 | #define CONTAINER_NAME "Container Name" |
cliff1 | 3:4a3c8d8ad451 | 35 | |
cliff1 | 6:ece3b06b9aba | 36 | #define CDS_SENSOR CDS_Sensor |
cliff1 | 6:ece3b06b9aba | 37 | #define DHT_SENSOR DHT_Sensor |
cliff1 | 7:8ad9f9bd39b3 | 38 | #define LED LED_Sensor |
cliff1 | 3:4a3c8d8ad451 | 39 | |
stkim92 | 0:89f7a9e4554f | 40 | #if defined(TARGET_WIZwiki_W7500) |
cliff1 | 3:4a3c8d8ad451 | 41 | Serial pc(USBTX, USBRX); |
cliff1 | 3:4a3c8d8ad451 | 42 | WizFi310Interface wifi(D1, D0, D7, D6, D9, NC, 115200); |
cliff1 | 3:4a3c8d8ad451 | 43 | |
cliff1 | 10:6a4b8caced6b | 44 | AnalogIn myLux ( CDS_SENSOR ); |
cliff1 | 7:8ad9f9bd39b3 | 45 | Dht11 myTemp( DHT_SENSOR ); |
cliff1 | 10:6a4b8caced6b | 46 | DigitalOut myled ( LED ); |
stkim92 | 0:89f7a9e4554f | 47 | #endif |
stkim92 | 0:89f7a9e4554f | 48 | |
stkim92 | 0:89f7a9e4554f | 49 | |
stkim92 | 0:89f7a9e4554f | 50 | int main() |
cliff1 | 10:6a4b8caced6b | 51 | { |
stkim92 | 0:89f7a9e4554f | 52 | pc.baud(115200); |
stkim92 | 0:89f7a9e4554f | 53 | |
cliff1 | 9:473f0a73f0c0 | 54 | printf("WizFi310 ThingPlug Connect_Simple Control. \r\n"); |
stkim92 | 0:89f7a9e4554f | 55 | if ( wifi.connect(AP_SSID, AP_PASSWORD, AP_SECURITY)) return -1; |
cliff1 | 3:4a3c8d8ad451 | 56 | printf("IP Address is %s\r\n\r\n", wifi.get_ip_address()); |
stkim92 | 0:89f7a9e4554f | 57 | |
cliff1 | 4:597b0c6ccba2 | 58 | wifi.conTP(USER_ID, CREDENTIAL_ID, SERVICE_ID, DEVICE_ID, CONTAINER_NAME, COMMAND_NM); |
cliff1 | 10:6a4b8caced6b | 59 | printf("Start!\r\n\r\n"); |
cliff1 | 3:4a3c8d8ad451 | 60 | while(true) |
cliff1 | 10:6a4b8caced6b | 61 | { |
cliff1 | 10:6a4b8caced6b | 62 | int a; |
cliff1 | 10:6a4b8caced6b | 63 | a = wifi.recvTP(COMMAND_NM, 3, 0); |
cliff1 | 3:4a3c8d8ad451 | 64 | |
cliff1 | 10:6a4b8caced6b | 65 | if( a == 1 ) |
cliff1 | 3:4a3c8d8ad451 | 66 | { |
cliff1 | 10:6a4b8caced6b | 67 | printf("Turn On!\r\n\r\n"); |
cliff1 | 10:6a4b8caced6b | 68 | myled = 1; |
cliff1 | 4:597b0c6ccba2 | 69 | } |
cliff1 | 4:597b0c6ccba2 | 70 | |
cliff1 | 10:6a4b8caced6b | 71 | else if( a == 2) |
cliff1 | 4:597b0c6ccba2 | 72 | { |
cliff1 | 10:6a4b8caced6b | 73 | printf("Turn OFF!\r\n\r\n"); |
cliff1 | 10:6a4b8caced6b | 74 | myled = 0; |
cliff1 | 10:6a4b8caced6b | 75 | } |
cliff1 | 10:6a4b8caced6b | 76 | wait_ms(3000); |
cliff1 | 3:4a3c8d8ad451 | 77 | } |
stkim92 | 0:89f7a9e4554f | 78 | } |