PIR sensor 2

Fork of PIRSensorWithTwitter by ajeet prajapati

Revision:
4:460cb7603faf
Parent:
3:8d47f7e3f9d6
--- a/WizFi310Interface.cpp	Thu Sep 28 08:49:46 2017 +0000
+++ b/WizFi310Interface.cpp	Fri Nov 24 08:35:18 2017 +0000
@@ -23,9 +23,13 @@
  *  port to the Wiznet Module WizFi310
  */
 
+#include "WizFi310Interface.h"
+#define var i ;
+//DigitalIn PIR(D9);
+//DigitalOut myled(LED1);
+DigitalOut myled(LED2);
 
-#include "WizFi310Interface.h"
-
+    
 WizFi310Interface::WizFi310Interface(PinName tx, PinName rx, PinName cts, PinName rts, PinName reset, PinName alarm, int baud):
     WizFi310(tx, rx, cts, rts, reset, alarm, baud)
 {
@@ -65,7 +69,6 @@
 }
 
 
-
 char* WizFi310Interface::getMACAddress()
 {
     return _state.mac;
@@ -91,37 +94,87 @@
 //}
 
 
-int WizFi310Interface::test_twitter()
-{    Timer timer;
-     timer.start();
-	// TCPSocketConnection();
-   int errConnect;
+int WizFi310Interface::test_ThingSpeak(int data)
+{    //Timer timer;
+   //  timer.start();
+	TCPSocketConnection();
+  
     char http_cmd[1000] = "";
-    char buffer[2048] = "";
+   char buffer[2048] = "";
+    int i = 0;
+    //int PIR_sensor;
+ //   int CDS_data = 0;
+    //double CDS_vol = 0; 
+    
 	TCPSocketConnection TCPconnection;
 
-   char *p="arduino-tweet.appspot.com";
+
+   char *p="api.thingspeak.com";
    int a=TCPconnection.connect(p,80);
-  while (true) {
+  while(1){
         if(a!=0) {
-            printf("\r\ncould not connect to socket : error = %d\r\n", p);
+            printf("\r\n could not connect to socket : error = %d\r\n", p);
+            
             a = TCPconnection.connect(p, 80);
         } else {
             printf("socket connected\r\n");
-            break;
+                        break;
         }
-    }    
+     }  
      
-    sprintf((char *)http_cmd,"GET http://arduino-tweet.appspot.com/update?token=3301685856-5P62Kt6NhZtqhxsBkVbOYRMpGhalWQjOfZKEEKM&status=SomebodyEnteredYourHome%d\r\n",timer.read_ms());
-
-    TCPconnection.send_all(http_cmd, sizeof(http_cmd));
-    
+  printf("\r\n Now Reading the LDR sensor values\n\r");
+  printf("===========================================\n\r");
+      
+      /*while (i < 5) {*/
+        	        	
+     //   CDS_data = CDS.read()*1000;
+        //CDS_vol = CDS.read()*3.3;
+        
+        //CDS Seneor ADC Low Data
+        printf("CDS Data : %3d\r\n",data);
+        
+        printf("===========================================\n\r");
+        wait(2);
+            sprintf((char *)http_cmd,"GET https://api.thingspeak.com/update?api_key=1M68DA3MGRI6TGOO&field1=%d\r\n",data);               
+     
+     	// sprintf((char *)http_cmd,"GET https://api.thingspeak.com/update?api_key=H1S5TNVE9QZ4V86Q&field1=%d\r\n",CDS_data); 
+     	
+	if(TCPconnection.send_all(http_cmd, sizeof(http_cmd))!=-1)
+            {
+                printf("The sent URL is: %s\r\n",http_cmd);
+              //  printf("The sent Tweet is: %s",message);
+                printf("\r\nMessage sent successfully\r\n\r\n");
+            }
+            else
+            {
+                                printf("\r\n Message sending failed\r\n\r\n");
+            }
+	
+	//printf("now Read the PIR sensor values\n\r");
+	TCPconnection.send_all(http_cmd, sizeof(http_cmd));
     TCPconnection.receive_all(buffer, sizeof(buffer));
-    printf("%s",buffer);
-  
+    
+	 
+	 
+	 
+	 return 0;
+	}
+	
+	
+	
+	
 	
-		return 0;
-	}
-//char* getNetworkMask();
-
-
+/*        if(CDS_data < 600){
+            myled = 1;
+        }
+        Status is dark.
+       else {
+          myled = 0;
+      }
+        	        	
+          PIR_sensor = PIR;
+         printf("PIR Value : %d\r\n",PIR_sensor);
+       myled =! PIR_sensor;
+        wait(0.2f);      
+      sprintf((char *)http_cmd,"GET https://api.thingspeak.com/update?api_key=H1S5TNVE9QZ4V86Q&field1=%d\r\n",CDS_data); */      
+