Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: ESP8266_eduvance_shield mbed
Fork of PIR_Sensor_wifi by
Diff: main.cpp
- Revision:
- 1:6c0345c34efb
- Parent:
- 0:bab4cf7cdda8
--- a/main.cpp Thu May 14 17:09:07 2015 +0000
+++ b/main.cpp Sat May 14 08:00:46 2016 +0000
@@ -9,14 +9,15 @@
#include "mbed.h"
#include "ESP8266.h"
-#define APIKEY 7X2TD78DKY4459M0
+
+#define APIKEY YTDILMQL53ASDCJ4
Serial pc(USBTX,USBRX);
DigitalOut Buzzer(D10); // output
PwmOut LED(D13); // flashing the led
DigitalIn inputPin(D2); // pir senor input
DigitalOut redled(LED1);
-ESP8266 wifi(PTC17, PTC16, 115200); // baud rate for wifi
+ESP8266 wifi(PTE0, PTE1, 115200); // baud rate for wifi
char snd[255],rcv[1000];
#define IP "184.106.153.149" // thingspeak.com IP Address
@@ -32,13 +33,13 @@
int main () {
-pc.baud(115200);
+pc.baud(9600);
pc.printf("SET mode to AP\r\n");
wifi.SetMode(1); // set ESP mode to 1
wifi.RcvReply(rcv, 1000); //receive a response from ESP
pc.printf("%s",rcv); //Print the response onscreen
pc.printf("Conneting to AP\r\n");
-wifi.Join("Network", "Password"); // Your wifi username & Password
+wifi.Join("VESCAMPUS", "1234@abcd"); // Your wifi username & Password
wifi.RcvReply(rcv, 1000); //receive a response from ESP
pc.printf("%s", rcv); //Print the response onscreen
wait(8); //waits for response from ESP
@@ -59,7 +60,7 @@
cnt++;
pc.printf(" The Sensor is ON And I Detected = %i Till NOW\r\n",cnt);
pc.printf("PLEASE STAY AWAY\r\n");
- pc.printf("Sending WiFi information");
+ pc.printf("Sending WiFi information\n\r");
wifi_send();
redled=1; // when the motion detected turn of the on board red led
LED.period(2.0f); // 2 seconds period
@@ -82,35 +83,42 @@
void wifi_send(void){
+ strcpy(snd,"AT+CIPMODE=0");//Setting WiFi into MultiChannel mode
+ wifi.SendCMD(snd);
+ pc.printf(snd);
+ wifi.RcvReply(rcv, 3000);
+ pc.printf("%s", rcv);
+
//WIFI updates the Status to Thingspeak servers//
strcpy(snd,"AT+CIPMUX=1");//Setting WiFi into MultiChannel mode
wifi.SendCMD(snd);
pc.printf(snd);
- wait(2.0);
- wifi.RcvReply(rcv, 1000);
+ wifi.RcvReply(rcv, 3000);
pc.printf("%s", rcv);
- wait(2);
+
+
sprintf(snd,"AT+CIPSTART=4,\"TCP\",\"%s\",80",IP); //Initiate connection with THINGSPEAK server
+ wifi.SendCMD(snd);
pc.printf(snd);
- wait(3.0);
- wifi.RcvReply(rcv, 1000);
+ wifi.RcvReply(rcv, 3000);
pc.printf("%s", rcv);
- wait(2);
+
strcpy(snd,"AT+CIPSEND=4,47"); //Send Number of open connections,Characters to send
wifi.SendCMD(snd);
pc.printf(snd);
- wait(2.0);
- wifi.RcvReply(rcv, 1000);
+ wifi.RcvReply(rcv, 3000);
pc.printf("%s", rcv);
- wait(2);
- sprintf(snd,"GET /update?key=7X2TD78DKY4459M0&field1=%2.2f\r\n",1.0); //Post values to thingspeak
+
+
+ sprintf(snd,"GET /update?key=YTDILMQL53ASDCJ4&field1=%2.2f\r\n",1.0); //Post values to thingspeak
pc.printf("%s",snd);
wifi.SendCMD(snd);
- wait(3.0f);
- wifi.RcvReply(rcv, 1000);
+
+ wifi.RcvReply(rcv, 3000);
pc.printf("%s", rcv);
+
wifi.SendCMD("AT+CIPCLOSE"); //Close the connection to server
- wifi.RcvReply(rcv, 1000);
+ wifi.RcvReply(rcv, 3000);
pc.printf("%s", rcv);
}
