Smart Doorbell using Raspberry Pi

About a year ago, I had to do a project titled Smart Home Automation using a Raspberry Pi and Arduino, part of the project  incorporated a doorbell but not just any doorbell but a Smart doorbell.

Why do I call it a Smart Doorbell?

A classic doorbell can be defined as a signalling device typically placed near an entry door to a building. When a visitor presses a button the bell rings inside the building, alerting the occupant to the presence of the visitor.

The smart doorbell, works in that manner however when a visitor presses the doorbell button it notifies the occupant with an images of the visitor and also sends an email, sms and push notification (to an smart device) to the occupant in case they are not able to hear the bell ringing.

If the button is pressed a pre-recorded voice notification is played for the occupant to check the door as there might be someone, this happens concurrently with an sms notification while a picture of the visitor is captured and sent to both email and push notification. Initially there was a feature to enable 2-way real-time video communication but due to network latency and high resource usage the feature was deprecated.

Click For A Demo

Comment if you need the code

See code snippets(Initial Revision): https://mmphego.wordpress.com/2015/01/11/smart-doorbell-using-rpi-with-voice-and-email-notification/

Setting up an MQTT server on Debian Jessie

Jolabs Tech Blog

Intro

Today we`re going to be setting up our own home automation server in a dedicated linux server. It’s gonna host our platform using the the Node.Js environment. The different devices around the house are going to be speaking MQTT to this server. I’ve chosen MQTT because of it’s robustness and lightweightness allowing for easy deployment on my favourite controllers: ESP8266. The esp-01, still the cheapest to this date,only sports 4mb of flash, has no trouble at all controlling a couple of relay’s for now. In the future the newer/bigger boards can be used to get more IO and function, but for now I’m going to be using the esp-01’s extensively around the house flexibly (it’s wireless…).

Requirements

The idea is to have the server online 24/7, so consider a computer thats not to power-hungry; like a Raspberry Pi or a small embedded box computer. Alternatively you can boot up…

View original post 340 more words

Node-Red Dashboard running on Nginx port 80

After finishing my Node-Red dashboard app, and boy, it’s awesome. Everything works great, but I wanted to bind it to port 80 on my nginx server.

Nginx

A more popular approach is to set up Nginx as a reverse proxy by having it bind to the desired port, forwarding all incoming traffic to my node red dashboard.

Nginx is a high performance, open source web server (similar to Apache) that is widely-used.

The main benefit of Nginx is the fact that it takes care of transport optimization.

Installing Nginx

sudo apt-get install nginx
 

Configuring Nginx

Next, we’ll need to configure Nginx so that it forwards traffic to my dashboard. Let’s start off by removing the default configuration file:

sudo rm /etc/nginx/sites-enabled/default
 

Next, create a new file in /etc/nginx/sites-available/ called node and open it with nano:

sudo nano /etc/nginx/sites-available/node
 

Paste the following code in the file and make sure to change example.com to your domain (or IP), and 1880 to your Node-Red Dashboard port:

server {
    listen 80;
    server_name example.com;

    location /ui {
        proxy_set_header   X-Forwarded-For $remote_addr;
        proxy_set_header   Host $http_host;
        proxy_pass         "http://127.0.0.1:1880";
    }
}

The proxy_pass declaration configures Nginx to act as a reverse proxy by forwarding all incoming requests on port 80 to Node-Red dashboard on port 1880, on behalf of the client.

Next, we need to symlink our configuration to sites-enabled for it to be used by Nginx, since it’s currently in sites-available:

sudo ln -s /etc/nginx/sites-available/node /etc/nginx/sites-enabled/node

Applying the Configuration

Let’s restart Nginx so that it loads our configuration:

sudo service nginx restart

run

sudo service nginx status

and you should see something like:

* nginx.service - A high performance web server and a reverse proxy server
   Loaded: loaded (/lib/systemd/system/nginx.service; enabled)
   Active: active (running) since Sat 2017-02-11 14:14:14 UTC; 306ms ago
  Process: 3103 ExecStop=/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /run/nginx.pid (code=exited, status=0/SUCCESS)
  Process: 3111 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
  Process: 3108 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
 Main PID: 3113 (nginx)
   CGroup: /system.slice/nginx.service
           |-3113 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
           |-3114 nginx: worker process
           |-3115 nginx: worker process
           |-3116 nginx: worker process
           `-3119 nginx: worker process

Feb 11 14:14:14 alexapi nginx[3108]: nginx: [warn] server name "127.0.0.1:1880/ui" has suspicious symbols in /etc/nginx/sites-enabled/node:3
Feb 11 14:14:14 alexapi nginx[3111]: nginx: [warn] server name "127.0.0.1:1880/ui" has suspicious symbols in /etc/nginx/sites-enabled/node:3
Feb 11 14:14:14 alexapi systemd[1]: Started A high performance web server and a reverse proxy server.

All set! Nginx will now forward all incoming requests to your app and even survive a server crash, since it automatically starts up with your machine.

Screenshot_2017-02-11_16-18-49.png

also see: https://www.digitalocean.com/community/tutorials/how-to-connect-your-internet-of-things-with-node-red-on-ubuntu-16-04

Raspberry Pi – Stuck in boot after installing upstart

I  installed upstart so I could run a script at startup [native /etc/init/*.conf]  with sudo apt-get install upstart and I then rebooted my RPi.

Afterwards my RPi running Debian-Jessie was pretty much unresponsive via the network. Right after connecting it to my monitor I then realised that it was stuck on boot.

CODE:

[   17.777252] init: samba-ad-dc main process (513) terminated with status 1
[  133.770712] init: failsafe main process (364_ killed by TERM signal
[info] Using makefile-style concurrent boot in runlevel S
...
[info] Loading kernel module fuse.

Only at that moment, I started realising that I should have probably backed up my SD Card before, but then it was already too late. It then struck me – So I will have to redo it all over again with a new and fresh raspbian installation. That was not something I was looking forward to do ,especially not after I have invested my time to this project I have undertaken myself on[apts, pips and nodes].

And then it hit me, A while ago – I had more or less the same issue on my Xubuntu 12.04 install and managed to get away with it via chroot which then worked, then started researching as to if it is possible to chroot my ARM Raspbian install from an Wbuntu system. To my revelation it was…And below is how I managed to rollback to Systemd-sysv without having to burn a new raspbian image to my sd card.

First, install two packages on your Ubuntu system: qemu-user, and proot.

sudo apt-get install -y qemu-user proot

After you mount the Raspbian SD card, you can do the equivalent of a ‘chroot‘ with:

 sudo proot -q qemu-arm  -r /mnt/raspbian_sd_card

I was then able to chroot/proot to my raspbian install and removed upstart:

sudo apt-get -y purge --auto-remove upstart

This command will also automatically re-install systemd-sysv

System V init script(start-stop-daemon)

I’ve been looking for efficient ways to start at boot my NodeJS dependent applications, with inspiration from https://gist.github.com/alobato/1968852, I modified it to my own needs.

Link might interest you as well:
http://big-elephants.com/2013-01/writing-your-own-init-scripts/
https://www.cyberciti.biz/tips/linux-write-sys-v-init-script-to-start-stop-service.html

Copy template to /etc/init.d and rename it to something meaningful. Then edit the script and enter that name after Provides:(between ### BEGIN INIT INFO and ### END INIT INFO).

#!/bin/bash
# Inspired by https://gist.github.com/alobato/1968852
# Needs Provides, Descriptions

### BEGIN INIT INFO
# Provides:
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description:
# Description:
### END INIT INFO

set -e
NAME=""
PIDFILE="/run/$NAME/$NAME.pid"
# Application one wants to upstart
DAEMON=""
DAEMON_OPTS=""
# Run as user
RUN_USER=""
RUN_GROUP=""
function daemon_run {
	mkdir -p /run/$NAME
	chown $RUN_USER:$RUN_GROUP /run/$NAME
	start-stop-daemon --start --background --quiet --chuid $RUN_USER:$RUN_GROUP --chdir /run/$NAME --pidfile $PIDFILE --make-pidfile --exec $DAEMON $DAEMON_OPTS
}
exec > /var/log/$NAME.log 2>&1

case "$1" in
start)
	echo -n "Starting $NAME ... "
	daemon_run
	echo "done."
;;

silent)
	echo -n "Starting $NAME in silent mode ... "
	daemon_run
	echo "done."
;;

stop)
	echo -n "Stopping $NAME ... "
	start-stop-daemon --stop --quiet --oknodo --pidfile $PIDFILE --remove-pidfile
	echo "done."
;;
restart|force-reload)
	echo -n "Restarting $NAME ... "
	start-stop-daemon --stop --quiet --oknodo --retry 30 --pidfile $PIDFILE --remove-pidfile
	alexa_run
	echo "done."
;;
*)
	echo "Usage: $0 {start|stop|restart}"
exit 1
esac
exit 0

When done,

sudo systemctl enable 'name_of_filename'
reboot

Mpho

Installing latest Node.js on Raspberry Pi B+

So, I’ve been battling with updating my node.js via apt-get, for some apparent reason seems like they’ve discontinued updates or maybe I’ve been doing it wrong all along – who knows.

But I found a way to bypass apt-get and go back to the basics.
Note: This assumes that the latest release is node-v7.4.0, else you can go to https://nodejs.org/dist/latest and get the required build.

This assumes the Raspberry Pi is running Rasbian – Jessie

# Download Node.js source Raspberry Pi Model A, B, B+ and Compute Module

wget -qO- https://nodejs.org/dist/latest/node-v7.4.0-linux-armv6l.tar.gz | tar xvz
cd node-v7.4.0*

# Raspberry Pi 2 Model B

wget https://nodejs.org/dist/latest/node-v7.4.0-linux-armv7l.tar.gz | tar xzv
cd node-v7.4.0-linux-armv7l

# and lastly
sudo cp -Rv * /usr/local/

# That's it! To check Node.js is properly installed and you have the right version, run the command:

node -v

Mpho

Bachelor’s project demo

So after completing my diploma, and it becoming redundant in the working industry. I had to set my eyes on a Bachelor’s degree.
Trust me it was not easy, in the sense of being a part-time student, full-time employee, a father, a fiance and being stuck on some island for 15 months then when you come back you’re residing in Cape Town and the university in Pretoria.
I think I can write a book with my life’s story.

Long story short, I managed to complete my degree within 3.5 years instead of 2 – which was a bonus, And now I have set my eyes on a Master’s degree just to challenge myself one thing for sure, one doesn’t need to be stagnant in life.
I believe in continuous improvement of oneself.

Let me stop yapping and show you a demo of my Bachelor’s project

If you like give thumbs up.