phpoc_man
Published © GPL3+

Arduino - Monitoring Door Open via Facebook Messenger

If door is opened, Arduino sends a message to your Facebook Messenger.

BeginnerFull instructions provided1 hour11,560
Arduino - Monitoring Door Open via Facebook Messenger

Things used in this project

Hardware components

Arduino UNO & Genuino UNO
Arduino UNO & Genuino UNO
×1
PHPoC WiFi Shield for Arduino
PHPoC WiFi Shield for Arduino
×1
Adafruit Magnetic Contact Switch
×1

Software apps and online services

Maker service
IFTTT Maker service

Story

Read more

Schematics

Wiring

Code

MonotorDoorMessenger

Arduino
// Tutorial for the example is available here:
// https://forum.phpoc.com/articles/tutorials/1241-arduino-ssl-web-client

#include <Phpoc.h>

String IFTTT_WEBHOOKS_KEY = "xxxxxxxxxxxxxxxxxxxxxx"; // change your webhooks key here
char server_name[] = "maker.ifttt.com";

PhpocClient client;

void sendNotification()
{
	// connect to web server on port 443:
	if(client.connectSSL(server_name, 443)) {
		// if connected:
		Serial.println("Connected to server");

		// make a HTTP request:
		client.println("GET /trigger/door_open/with/key/" + IFTTT_WEBHOOKS_KEY + " HTTP/1.1");
		client.println("Host: maker.ifttt.com");
		client.println("Connection: close");
		client.println();
	}

	while(client.connected()) {
		if(client.available()) {
			char c = client.read();
			Serial.write(c);
		}
	}

	Serial.println();
	Serial.println("disconnecting from server.");
	client.stop();
}

void setup() {
	Serial.begin(9600);

	// initialize PHPoC [WiFi] Shield:
	Phpoc.begin(PF_LOG_SPI | PF_LOG_NET);

	pinMode(A0, INPUT_PULLUP);
}

int previous_status = 1;

void loop() {
	int current_status = digitalRead(A0);

	if(previous_status == 0 && current_status == 1) { // if door is opened...
		Serial.println("door is opened");
		sendNotification();
		delay(100);
	} else if(previous_status == 1 && current_status == 0) { // if door is closed...
		Serial.println("door is closed");
	}

	previous_status = current_status;
}

Credits

phpoc_man

phpoc_man

53 projects • 271 followers

Comments