20170825 Test
Dependencies: DHT11 NetworkSocketAPI WizFi310Interface mbed
Fork of WizFi310_STATION_HelloWorld by
main.cpp@3:4a3c8d8ad451, 2017-08-25 (annotated)
- Committer:
- cliff1
- Date:
- Fri Aug 25 00:58:16 2017 +0000
- Revision:
- 3:4a3c8d8ad451
- Parent:
- 2:a4fe5b857755
- Child:
- 4:597b0c6ccba2
20170825 ThingPlug test
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 | 3:4a3c8d8ad451 | 25 | #define AP_SSID "Dap" // Input SSID |
cliff1 | 3:4a3c8d8ad451 | 26 | #define AP_PASSWORD "00001111" // Input PW |
stkim92 | 0:89f7a9e4554f | 27 | #define AP_SECURITY NSAPI_SECURITY_WPA2 |
stkim92 | 0:89f7a9e4554f | 28 | |
cliff1 | 3:4a3c8d8ad451 | 29 | #define USER_ID "cliff13" |
cliff1 | 3:4a3c8d8ad451 | 30 | #define CREDENTIAL_ID "R0NNaXc1TGZmV2JVb0JzZEp3QnorSDZrYXZWanFod3hlZ0VkMEFycktRN0Z4SFpCb1JSUmdnMENUL0h4K3VZVg==" |
cliff1 | 3:4a3c8d8ad451 | 31 | #define SERVICE_ID "cliff_service" |
cliff1 | 3:4a3c8d8ad451 | 32 | #define DEVICE_ID "WIZnet_Device_01" |
cliff1 | 3:4a3c8d8ad451 | 33 | #define CONTAINER_NAME "WIZnet" |
cliff1 | 3:4a3c8d8ad451 | 34 | |
cliff1 | 3:4a3c8d8ad451 | 35 | #define CDS_SENSOR PC_15 |
cliff1 | 3:4a3c8d8ad451 | 36 | #define DHT_SENSOR PC_7 |
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 | 3:4a3c8d8ad451 | 41 | |
cliff1 | 3:4a3c8d8ad451 | 42 | AnalogIn myLux( CDS_SENSOR ); |
cliff1 | 3:4a3c8d8ad451 | 43 | Dht11 myTemp ( DHT_SENSOR ); |
stkim92 | 0:89f7a9e4554f | 44 | #endif |
stkim92 | 0:89f7a9e4554f | 45 | |
stkim92 | 0:89f7a9e4554f | 46 | |
stkim92 | 0:89f7a9e4554f | 47 | int main() |
stkim92 | 0:89f7a9e4554f | 48 | { |
stkim92 | 0:89f7a9e4554f | 49 | pc.baud(115200); |
stkim92 | 0:89f7a9e4554f | 50 | |
cliff1 | 3:4a3c8d8ad451 | 51 | printf("WizFi310 ThingPlug Connect. \r\n"); |
stkim92 | 0:89f7a9e4554f | 52 | if ( wifi.connect(AP_SSID, AP_PASSWORD, AP_SECURITY)) return -1; |
cliff1 | 3:4a3c8d8ad451 | 53 | printf("IP Address is %s\r\n\r\n", wifi.get_ip_address()); |
stkim92 | 0:89f7a9e4554f | 54 | |
cliff1 | 3:4a3c8d8ad451 | 55 | wifi.conTP(USER_ID, CREDENTIAL_ID, SERVICE_ID, DEVICE_ID, CONTAINER_NAME); |
cliff1 | 3:4a3c8d8ad451 | 56 | while(true) |
cliff1 | 3:4a3c8d8ad451 | 57 | { |
cliff1 | 3:4a3c8d8ad451 | 58 | printf("Send - s, Quit - q\r\n"); |
cliff1 | 3:4a3c8d8ad451 | 59 | printf("Input : "); |
cliff1 | 3:4a3c8d8ad451 | 60 | |
cliff1 | 3:4a3c8d8ad451 | 61 | char c = pc.getc(); |
cliff1 | 3:4a3c8d8ad451 | 62 | printf("%c\r\n", c); |
cliff1 | 3:4a3c8d8ad451 | 63 | |
cliff1 | 3:4a3c8d8ad451 | 64 | if(c =='s' || c == 'S') |
cliff1 | 3:4a3c8d8ad451 | 65 | { |
cliff1 | 3:4a3c8d8ad451 | 66 | wifi.sendTP(CONTAINER_NAME, "010600000026020600000022"); |
cliff1 | 3:4a3c8d8ad451 | 67 | } |
cliff1 | 3:4a3c8d8ad451 | 68 | |
cliff1 | 3:4a3c8d8ad451 | 69 | else if(c == 'q' || c == 'Q') |
cliff1 | 3:4a3c8d8ad451 | 70 | { |
cliff1 | 3:4a3c8d8ad451 | 71 | wifi.disConTP(); |
cliff1 | 3:4a3c8d8ad451 | 72 | break; |
cliff1 | 3:4a3c8d8ad451 | 73 | } |
cliff1 | 3:4a3c8d8ad451 | 74 | |
cliff1 | 3:4a3c8d8ad451 | 75 | wait_ms(5000); |
cliff1 | 3:4a3c8d8ad451 | 76 | } |
stkim92 | 0:89f7a9e4554f | 77 | wifi.disconnect(); |
stkim92 | 0:89f7a9e4554f | 78 | } |