testing

Dependencies:   HTTPClient PowerControl SNICInterface_mod mbed-rtos mbed

Fork of Fx0Hackson by Daisuke Kimura

Revision:
9:9fc77f7685b7
Parent:
8:846dfefd3110
--- a/main.cpp	Sun Feb 15 01:08:28 2015 +0000
+++ b/main.cpp	Sun Feb 15 04:00:06 2015 +0000
@@ -6,11 +6,15 @@
 #include "PowerControl/EthernetPowerControl.h"
 #endif
 
+#include "adc.h"        //a+
+
 #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
 
+#define SAMPLE_RATE    150000   // a+
+
 C_SNIC_WifiInterface     wifi( p9, p10, NC, NC, p30 );
 
 #if defined(_DEBUG)
@@ -18,26 +22,33 @@
 #endif
 
 DigitalIn PIR(p8);
-I2C temphum(p28, p27);
+Serial STemp(p28, p27);
+//I2C temphum(p28, p27);
 HTTPClient http;
 char str[512];
 
+//Initialise ADC to maximum SAMPLE_RATE and cclk divide set to 1    // a+
+ADC adc(SAMPLE_RATE, 1);                                            // a+
+
 int main() 
 {
 #if defined(TARGET_LPC1768)
     PHY_PowerDown();
 #endif
 
-    wifi.init(); //Use DHCP
+//    wifi.init(); //Use DHCP
 
     wait(0.5);
+/*
     int s = wifi.disconnect();
     if( s != 0 ) {
         return -1;
     }
+*/
     
     wait(0.3);
     
+/*
         // Connect AP
     wifi.connect( DEMO_AP_SSID
                 , strlen(DEMO_AP_SSID)
@@ -48,6 +59,7 @@
     wifi.setIPConfig( true );
     wait(0.5);
     printf("IP Address is %s\n", wifi.getIPAddress());
+*/
     
     //define var
     double value;
@@ -55,10 +67,14 @@
     
     while(1)
     {
+
+        printf("\nTesting.\n");
+
+/*
         //for PIR sensor
         //GET value from PIR sensor
         sensortype = "PIR";
-        rightvalue = PIR;
+        value = PIR;
         //GET data
         printf("\nTrying to fetch page...\n");
         char buf[128];
@@ -73,7 +89,31 @@
         {
         printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode());
         }
+*/
+//        wait(WAIT);
+
+        printf("\nTesting..\n");
+
+        //for tempsensor
+        //GET value from Temp sensor
+        sensortype = "Temp";
+        value = STemp.getc();
+        //GET data
+        printf("\nTrying to fetch page...\n");
+       char buf[128];
+        sprintf(buf, "http://192.168.179.7/put?type=%s&value=%lf",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
@@ -95,8 +135,47 @@
         }
         wait(WAIT);
         */
-    }
+
+/*
+        //for light                     a+
+        //GET value from PIR sensor
+        sensortype = "Light";
+
+        // a+
+        //Set up ADC on pin 20
+        adc.setup(p20,1);
+        
+        //Measure pin 20
+        adc.select(p20);
+        //Start ADC conversion
+        adc.start();
+        //Wait for it to complete
+        while(!adc.done(p20));
+        printf("Measured value on pin 20 is %04u.\n", adc.read(p20));
+        wait(1);
+        // ---------------------
 
-    wifi.disconnect();
+        value = adc.read(p20);
+        //GET data
+        printf("\nTrying to fetch page...\n");
+//       char buf[128];
+        sprintf(buf, "http://192.168.179.7/put?type=%s&value=%lf",sensortype, value);
+        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);
+          wait(0.2);
+ 
+     }
+
+//    wifi.disconnect();
     
 }