testing

Dependencies:   HTTPClient PowerControl SNICInterface_mod mbed-rtos mbed

Fork of Fx0Hackson by Daisuke Kimura

Committer:
daisukekmr
Date:
Sun Feb 15 01:08:28 2015 +0000
Revision:
8:846dfefd3110
Parent:
7:bf74da76618b
Child:
9:9fc77f7685b7
HTTP?PIR????????????; Value???double???(???)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
donatien 0:0e0debc29569 1 #include "mbed.h"
MACRUM 5:3dbedd084f79 2
MACRUM 3:837766adc429 3 #include "SNIC_WifiInterface.h"
donatien 0:0e0debc29569 4 #include "HTTPClient.h"
MACRUM 3:837766adc429 5 #if defined(TARGET_LPC1768)
MACRUM 3:837766adc429 6 #include "PowerControl/EthernetPowerControl.h"
MACRUM 3:837766adc429 7 #endif
MACRUM 3:837766adc429 8
daisukekmr 6:1273e99a6058 9 #define DEMO_AP_SSID "nad11-10e168"
MACRUM 3:837766adc429 10 #define DEMO_AP_SECURITY_TYPE e_SEC_WPA2_AES
daisukekmr 6:1273e99a6058 11 #define DEMO_AP_SECUTIRY_KEY "18e36c5e791f9"
daisukekmr 7:bf74da76618b 12 #define WAIT 10.0
MACRUM 3:837766adc429 13
MACRUM 3:837766adc429 14 C_SNIC_WifiInterface wifi( p9, p10, NC, NC, p30 );
MACRUM 3:837766adc429 15
MACRUM 5:3dbedd084f79 16 #if defined(_DEBUG)
MACRUM 5:3dbedd084f79 17 Serial pc(USBTX, USBRX);
MACRUM 5:3dbedd084f79 18 #endif
MACRUM 5:3dbedd084f79 19
daisukekmr 7:bf74da76618b 20 DigitalIn PIR(p8);
daisukekmr 7:bf74da76618b 21 I2C temphum(p28, p27);
donatien 1:d263603373ac 22 HTTPClient http;
donatien 1:d263603373ac 23 char str[512];
donatien 1:d263603373ac 24
donatien 0:0e0debc29569 25 int main()
donatien 0:0e0debc29569 26 {
MACRUM 3:837766adc429 27 #if defined(TARGET_LPC1768)
MACRUM 3:837766adc429 28 PHY_PowerDown();
MACRUM 3:837766adc429 29 #endif
MACRUM 3:837766adc429 30
MACRUM 3:837766adc429 31 wifi.init(); //Use DHCP
donatien 0:0e0debc29569 32
MACRUM 3:837766adc429 33 wait(0.5);
MACRUM 3:837766adc429 34 int s = wifi.disconnect();
MACRUM 3:837766adc429 35 if( s != 0 ) {
MACRUM 3:837766adc429 36 return -1;
MACRUM 3:837766adc429 37 }
MACRUM 3:837766adc429 38
MACRUM 3:837766adc429 39 wait(0.3);
daisukekmr 7:bf74da76618b 40
daisukekmr 7:bf74da76618b 41 // Connect AP
MACRUM 3:837766adc429 42 wifi.connect( DEMO_AP_SSID
daisukekmr 7:bf74da76618b 43 , strlen(DEMO_AP_SSID)
daisukekmr 7:bf74da76618b 44 , DEMO_AP_SECURITY_TYPE
daisukekmr 7:bf74da76618b 45 , DEMO_AP_SECUTIRY_KEY
daisukekmr 7:bf74da76618b 46 , strlen(DEMO_AP_SECUTIRY_KEY) );
MACRUM 3:837766adc429 47 wait(0.5);
daisukekmr 8:846dfefd3110 48 wifi.setIPConfig( true );
daisukekmr 8:846dfefd3110 49 wait(0.5);
MACRUM 3:837766adc429 50 printf("IP Address is %s\n", wifi.getIPAddress());
donatien 0:0e0debc29569 51
daisukekmr 7:bf74da76618b 52 //define var
daisukekmr 8:846dfefd3110 53 double value;
daisukekmr 7:bf74da76618b 54 char* sensortype;
daisukekmr 7:bf74da76618b 55
daisukekmr 7:bf74da76618b 56 while(1)
donatien 0:0e0debc29569 57 {
daisukekmr 7:bf74da76618b 58 //for PIR sensor
daisukekmr 7:bf74da76618b 59 //GET value from PIR sensor
daisukekmr 7:bf74da76618b 60 sensortype = "PIR";
daisukekmr 7:bf74da76618b 61 rightvalue = PIR;
daisukekmr 7:bf74da76618b 62 //GET data
daisukekmr 7:bf74da76618b 63 printf("\nTrying to fetch page...\n");
daisukekmr 7:bf74da76618b 64 char buf[128];
daisukekmr 8:846dfefd3110 65 sprintf(buf, "http://192.168.179.7/put?type=%s&value=%lf",sensortype, value);
daisukekmr 7:bf74da76618b 66 int ret = http.get(buf, str, 128);
daisukekmr 7:bf74da76618b 67 if (!ret)
daisukekmr 7:bf74da76618b 68 {
daisukekmr 7:bf74da76618b 69 printf("Page fetched successfully - read %d characters\n", strlen(str));
daisukekmr 7:bf74da76618b 70 printf("Result: %s\n", str);
daisukekmr 7:bf74da76618b 71 }
daisukekmr 7:bf74da76618b 72 else
daisukekmr 7:bf74da76618b 73 {
daisukekmr 7:bf74da76618b 74 printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode());
daisukekmr 7:bf74da76618b 75 }
daisukekmr 7:bf74da76618b 76 wait(WAIT);
daisukekmr 7:bf74da76618b 77 /*
daisukekmr 7:bf74da76618b 78 //for tempsensor
daisukekmr 7:bf74da76618b 79 //GET value from PIR sensor
daisukekmr 7:bf74da76618b 80 sensortype = "Temp";
daisukekmr 7:bf74da76618b 81 value = Temp;
daisukekmr 7:bf74da76618b 82 //GET data
daisukekmr 7:bf74da76618b 83 printf("\nTrying to fetch page...\n");
daisukekmr 7:bf74da76618b 84 char buf[128];
daisukekmr 8:846dfefd3110 85 sprintf(buf, "http://192.168.179.7/put?type=%s&value=%lf",sensortype, value);
daisukekmr 7:bf74da76618b 86 int ret = http.get(buf, str, 128);
daisukekmr 7:bf74da76618b 87 if (!ret)
daisukekmr 7:bf74da76618b 88 {
daisukekmr 7:bf74da76618b 89 printf("Page fetched successfully - read %d characters\n", strlen(str));
daisukekmr 7:bf74da76618b 90 printf("Result: %s\n", str);
daisukekmr 7:bf74da76618b 91 }
daisukekmr 7:bf74da76618b 92 else
daisukekmr 7:bf74da76618b 93 {
daisukekmr 7:bf74da76618b 94 printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode());
daisukekmr 7:bf74da76618b 95 }
daisukekmr 7:bf74da76618b 96 wait(WAIT);
daisukekmr 7:bf74da76618b 97 */
donatien 0:0e0debc29569 98 }
daisukekmr 7:bf74da76618b 99
daisukekmr 7:bf74da76618b 100 wifi.disconnect();
donatien 1:d263603373ac 101
donatien 0:0e0debc29569 102 }