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 hour18,966
Arduino - Monitoring Door Open via Facebook Messenger

Things used in this project

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>
#include <ezButton.h>

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

PhpocClient client;
ezButton button(A0);  // create Button object that attach to pin A0;

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);

	button.setDebounceTime(100); // set debounce time to 100 milliseconds
}

void loop() {
	button.loop(); // MUST call the loop() function first

	if(button.isPressed()) { // if door is opened...
		Serial.println("door is opened");
		sendNotification();
		delay(100);
	} else if (button.isReleased()) { // if door is closed...
		Serial.println("door is closed");
	}
}

Credits

phpoc_man

phpoc_man

62 projects • 405 followers

Comments