ThingPlug Ex
Dependencies: DHT11 NetworkSocketAPI WizFi310Interface mbed
Fork of WizFi310_ThingPlug_Test by
main.cpp@11:06675e22e37d, 2017-11-15 (annotated)
- Committer:
- cliff1
- Date:
- Wed Nov 15 06:45:16 2017 +0000
- Revision:
- 11:06675e22e37d
- Parent:
- 10:6a4b8caced6b
New V2
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 | 7:8ad9f9bd39b3 | 36 | #define LED LED_Sensor |
cliff1 | 3:4a3c8d8ad451 | 37 | |
stkim92 | 0:89f7a9e4554f | 38 | #if defined(TARGET_WIZwiki_W7500) |
cliff1 | 3:4a3c8d8ad451 | 39 | Serial pc(USBTX, USBRX); |
cliff1 | 3:4a3c8d8ad451 | 40 | WizFi310Interface wifi(D1, D0, D7, D6, D9, NC, 115200); |
cliff1 | 11:06675e22e37d | 41 | |
cliff1 | 10:6a4b8caced6b | 42 | DigitalOut myled ( LED ); |
stkim92 | 0:89f7a9e4554f | 43 | #endif |
stkim92 | 0:89f7a9e4554f | 44 | |
stkim92 | 0:89f7a9e4554f | 45 | |
stkim92 | 0:89f7a9e4554f | 46 | int main() |
cliff1 | 10:6a4b8caced6b | 47 | { |
stkim92 | 0:89f7a9e4554f | 48 | pc.baud(115200); |
stkim92 | 0:89f7a9e4554f | 49 | |
cliff1 | 9:473f0a73f0c0 | 50 | printf("WizFi310 ThingPlug Connect_Simple Control. \r\n"); |
stkim92 | 0:89f7a9e4554f | 51 | if ( wifi.connect(AP_SSID, AP_PASSWORD, AP_SECURITY)) return -1; |
cliff1 | 3:4a3c8d8ad451 | 52 | printf("IP Address is %s\r\n\r\n", wifi.get_ip_address()); |
stkim92 | 0:89f7a9e4554f | 53 | |
cliff1 | 4:597b0c6ccba2 | 54 | wifi.conTP(USER_ID, CREDENTIAL_ID, SERVICE_ID, DEVICE_ID, CONTAINER_NAME, COMMAND_NM); |
cliff1 | 10:6a4b8caced6b | 55 | printf("Start!\r\n\r\n"); |
cliff1 | 3:4a3c8d8ad451 | 56 | while(true) |
cliff1 | 10:6a4b8caced6b | 57 | { |
cliff1 | 10:6a4b8caced6b | 58 | int a; |
cliff1 | 10:6a4b8caced6b | 59 | a = wifi.recvTP(COMMAND_NM, 3, 0); |
cliff1 | 3:4a3c8d8ad451 | 60 | |
cliff1 | 10:6a4b8caced6b | 61 | if( a == 1 ) |
cliff1 | 3:4a3c8d8ad451 | 62 | { |
cliff1 | 10:6a4b8caced6b | 63 | printf("Turn On!\r\n\r\n"); |
cliff1 | 10:6a4b8caced6b | 64 | myled = 1; |
cliff1 | 4:597b0c6ccba2 | 65 | } |
cliff1 | 4:597b0c6ccba2 | 66 | |
cliff1 | 10:6a4b8caced6b | 67 | else if( a == 2) |
cliff1 | 4:597b0c6ccba2 | 68 | { |
cliff1 | 10:6a4b8caced6b | 69 | printf("Turn OFF!\r\n\r\n"); |
cliff1 | 10:6a4b8caced6b | 70 | myled = 0; |
cliff1 | 10:6a4b8caced6b | 71 | } |
cliff1 | 10:6a4b8caced6b | 72 | wait_ms(3000); |
cliff1 | 3:4a3c8d8ad451 | 73 | } |
stkim92 | 0:89f7a9e4554f | 74 | } |