Keith Mitchell
Published © GPL3+

Connected Security System

Reinventing the home security system with the IoT method using sensors connected to a Node.JS server.

AdvancedFull instructions provided4 hours9,515
Connected Security System

Things used in this project

Story

Read more

Custom parts and enclosures

F360 Hexiwear + Edison dock case

F360 - Hexiwear Wall Mount

A sleek hexagonal holder that screws to the walls and allows a Hexiwear to slide into the top

Code

Particle Photon Code

C/C++
Code for turning the Photon into a sensor. Use at build.particle.io. Requires you to import the HttpClient library via the Particle Online IDE.
// This #include statement was automatically added by the Particle IDE.
#include "HttpClient/HttpClient.h"

#define ADDRESS "192.168.0.27" /* Change this to the IP of the device running the server! */
#define PORT 3000

int pin = D0;

int led = D7;

HttpClient http;

http_request_t request;
http_response_t response;

void setup() {
    pinMode(pin, INPUT_PULLDOWN);
    pinMode(led, OUTPUT);
    
    Serial.begin(9600);
    
}

bool sentOn = false;
bool sentOff = true;

void loop() {
    if(digitalRead(pin) == HIGH){
        if(!sentOn){
            digitalWrite(led, HIGH);
            Serial.println("HIGH");
            send("true");
            sentOn = true;
            sentOff = false;
        }
    }
    
    if(digitalRead(pin) == LOW){
        digitalWrite(led, LOW);
        sentOn = false;
        if(!sentOff){
            Serial.println("LOW");
            send("false");
            digitalWrite(led, HIGH);
            sentOff = true;
        }
    }
}

void send(String on){
    Serial.println("sending...");
    request.hostname = ADDRESS;
    request.port = PORT;
    request.path = "/alarm/"+on;
    Serial.println(request.path);
    
    http.get(request, response, NULL);
    
    Serial.println(response.status);
    Serial.println(response.body);
    Serial.println("sent!");
}

Arduino Sensor Code

C/C++
The code for the MKR1000 to turn it into a sensor
#include <SPI.h>
#include <WiFi101.h>

char ssid[] = "ssid";
char pass[] = "password";

int status = WL_IDLE_STATUS;

char server[] = "192.168.0.27"; /* ip of the device running the nodejs server  */

int sensorPin = 6;

WiFiClient client;

bool sentHigh = false;

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

  pinMode(sensorPin, INPUT);
  
  while (status != WL_CONNECTED) {
    Serial.print("Attempting to connect to SSID: ");
    Serial.println(ssid);

    status = WiFi.begin(ssid, pass);

    // wait 10 seconds for connection:
    delay(10000);
  }
  Serial.println("Connected to wifi");
}

void loop() {
  if(digitalRead(sensorPin) == HIGH){
    if(!sentHigh){
        sentHigh = true;
        sendStatus("true");
      }
  }else{
    sentHigh = false;
  }
}

void sendStatus (char* status){
  Serial.println("\nStarting connection to server...");
  if (client.connect(server, 3000)) {
    Serial.println("connected to server");
    // Make a HTTP request:
    client.println(String("GET /alarm/") +status+" HTTP/1.1");
    client.println(String("Host: ") + server);
    client.println("Connection: close");
    client.println();
    client.stop();
    Serial.println(String("sent alarm status! ") + status);
  }
}

mbed repository with the Hexiwear code

The mbed repository with all the code for programming the Hexiwear via the online mbed IDE/Compiler - Link to the mbed repo is in the Gist

Intel Edison Node.JS Server

Upload to the Edsion. npm install && node.

Credits

Keith Mitchell

Keith Mitchell

10 projects • 41 followers
16 year old Canadian Professional Programmer and technology enthusiast

Comments

Add projectSign up / Login