[Project]

Monitoring Door-opening with PHPoC Shield for Arduino (Send Email when the door is opened.)


Click image for larger version

Name:	IMG_9087.jpg
Views:	1
Size:	64.9 KB
ID:	834



[Items]

1. Arduino Uno
2. PHPoC Shield for Arduino (P4S-348)
3. Magetic Sensor (Switch)

Click image for larger version

Name:	IMG_9105.JPG
Views:	1
Size:	68.5 KB
ID:	835

Click image for larger version

Name:	IMG_9088.JPG
Views:	1
Size:	71.0 KB
ID:	836


[How it works]

1. Connect PHPoC Shield for Arduino on your Arduino
2. Connect LAN cable to the shield for ethernet
3. Get notification on smart phone.


[Video]


[Library]

PHPoC library for Arduino
- https://github.com/phpoc/arduino


[Source Code]

Code:
#include "SPI.h"
#include "Phpoc.h"

PhpocEmail email;

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

  Phpoc.begin(PF_LOG_SPI | PF_LOG_NET | PF_LOG_APP);
  pinMode(A0, INPUT);
}

int previous_status = 1;


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

  if (previous_status == 1 && current_status == 0) {    // if door is opened...
    email.setOutgoingServer("smtp.gmail.com", 587);
    email.setOutgoingLogin("Google ID", "Google Password");

    email.setFrom("Gmail address ", "Sender Name");
    email.setTo("Receiver email address", "Receiver Name");

    email.setSubject("Door is opened. [#905]");  // Mail Subject

    // Mail Contents
    email.beginMessage();
    email.println("#905");
    email.println("");
    email.println("Door is opened.");
    email.endMessage();                

    if (email.send() > 0)  // Send Email
      Serial.println("Your Mail has been sent successfully");
    else
      Serial.println("Your Mail is not sent");


  }   else if (previous_status == 0 && current_status == 1) { // if door is closed...

        // Write codes in the same way

  }

  previous_status = current_status;
  delay(1500);

}