testing
Dependencies: HTTPClient PowerControl SNICInterface_mod mbed-rtos mbed
Fork of Fx0Hackson by
Diff: main.cpp
- Revision:
- 7:bf74da76618b
- Parent:
- 6:1273e99a6058
- Child:
- 8:846dfefd3110
--- a/main.cpp Sat Feb 14 09:06:17 2015 +0000 +++ b/main.cpp Sun Feb 15 00:27:59 2015 +0000 @@ -9,6 +9,7 @@ #define DEMO_AP_SSID "nad11-10e168" #define DEMO_AP_SECURITY_TYPE e_SEC_WPA2_AES #define DEMO_AP_SECUTIRY_KEY "18e36c5e791f9" +#define WAIT 10.0 C_SNIC_WifiInterface wifi( p9, p10, NC, NC, p30 ); @@ -16,6 +17,8 @@ Serial pc(USBTX, USBRX); #endif +DigitalIn PIR(p8); +I2C temphum(p28, p27); HTTPClient http; char str[512]; @@ -34,32 +37,66 @@ } wait(0.3); - // Connect AP + + // Connect AP wifi.connect( DEMO_AP_SSID - , strlen(DEMO_AP_SSID) - , DEMO_AP_SECURITY_TYPE - , DEMO_AP_SECUTIRY_KEY - , strlen(DEMO_AP_SECUTIRY_KEY) ); + , strlen(DEMO_AP_SSID) + , DEMO_AP_SECURITY_TYPE + , DEMO_AP_SECUTIRY_KEY + , strlen(DEMO_AP_SECUTIRY_KEY) ); wait(0.5); wifi.setIPConfig( true ); wait(0.5); printf("IP Address is %s\n", wifi.getIPAddress()); - //GET data - printf("\nTrying to fetch page...\n"); - int ret = http.get("http://developer.mbed.org/media/uploads/donatien/hello.txt", str, 128); - if (!ret) + //define var + int value; + char* sensortype; + + while(1) { - printf("Page fetched successfully - read %d characters\n", strlen(str)); - printf("Result: %s\n", str); + //for PIR sensor + //GET value from PIR sensor + sensortype = "PIR"; + rightvalue = PIR; + //GET data + printf("\nTrying to fetch page...\n"); + char buf[128]; + sprintf(buf, "http://192.168.179.7/put?type=%s&value=%d",sensortype, value); + int ret = http.get(buf, str, 128); + if (!ret) + { + printf("Page fetched successfully - read %d characters\n", strlen(str)); + printf("Result: %s\n", str); + } + else + { + printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode()); + } + wait(WAIT); + /* + //for tempsensor + //GET value from PIR sensor + sensortype = "Temp"; + value = Temp; + //GET data + printf("\nTrying to fetch page...\n"); + char buf[128]; + sprintf(buf, "http://192.168.179.7/put?type=%s&value=%d",sensortype, value); + int ret = http.get(buf, str, 128); + if (!ret) + { + printf("Page fetched successfully - read %d characters\n", strlen(str)); + printf("Result: %s\n", str); + } + else + { + printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode()); + } + wait(WAIT); + */ } - else - { - printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode()); - } + + wifi.disconnect(); - wifi.disconnect(); - - while(1) { - } }