ThingPlug Ex
Dependencies: DHT11 NetworkSocketAPI WizFi310Interface mbed
Fork of WizFi310_ThingPlug_Test by
Revision 10:6a4b8caced6b, committed 2017-11-15
- Comitter:
- cliff1
- Date:
- Wed Nov 15 06:30:22 2017 +0000
- Parent:
- 9:473f0a73f0c0
- Child:
- 11:06675e22e37d
- Commit message:
- New Version
Changed in this revision
| WizFi310Interface.lib | Show annotated file Show diff for this revision Revisions of this file |
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/WizFi310Interface.lib Thu Oct 19 07:04:10 2017 +0000 +++ b/WizFi310Interface.lib Wed Nov 15 06:30:22 2017 +0000 @@ -1,1 +1,1 @@ -https://developer.mbed.org/users/cliff1/code/WizFi310Interface/#ea405bb59143 +https://developer.mbed.org/users/cliff1/code/WizFi310Interface/#77cd2133312c
--- a/main.cpp Thu Oct 19 07:04:10 2017 +0000
+++ b/main.cpp Wed Nov 15 06:30:22 2017 +0000
@@ -41,21 +41,14 @@
Serial pc(USBTX, USBRX);
WizFi310Interface wifi(D1, D0, D7, D6, D9, NC, 115200);
- AnalogIn myLux( CDS_SENSOR );
+ AnalogIn myLux ( CDS_SENSOR );
Dht11 myTemp( DHT_SENSOR );
- DigitalOut myled( LED );
+ DigitalOut myled ( LED );
#endif
int main()
-{
- int error = 0;
- char str[50] = "";
-
- int lux;
- double temp;
- int humid;
-
+{
pc.baud(115200);
printf("WizFi310 ThingPlug Connect_Simple Control. \r\n");
@@ -63,66 +56,23 @@
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, COMMAND_NM);
+ printf("Start!\r\n\r\n");
while(true)
- {
- printf("Send - s, , Response - r, Quit - q\r\n");
- printf("Input : ");
+ {
+ int a;
+ a = wifi.recvTP(COMMAND_NM, 3, 0);
- char c = pc.getc();
- printf("%c\r\n", c);
-
- if(c =='s' || c == 'S')
+ if( a == 1 )
{
- error = myTemp.read();
- if( error == 0 )
- {
- lux = (int)(myLux.read()*1000);
- temp = (double)(myTemp.getCelsius());
- humid = (int)myTemp.getHumidity();
-
- sprintf((char *)str, "0106%08x0206%08x0306%08x",
- lux, (int)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);
+ printf("Turn On!\r\n\r\n");
+ myled = 1;
}
- else if(c == 'r' || c == 'R')
+ else if( a == 2)
{
- int a;
-
- a = wifi.recvTP(COMMAND_NM, 3, 0);
-
- if( a == 1 )
- {
- printf("Turn On!\r\n\r\n");
- myled = 1;
- }
-
- else if( a == 2)
- {
- printf("Turn OFF!\r\n\r\n");
- myled = 0;
- }
-
- wait_ms(3000);
- }
-
- else if(c == 'q' || c == 'Q')
- {
- wifi.disConTP();
- break;
- }
+ printf("Turn OFF!\r\n\r\n");
+ myled = 0;
+ }
+ wait_ms(3000);
}
- wifi.disconnect();
}
\ No newline at end of file
