Raspberry PI Camera Module

Basic Installation

Warning: The installer will replace various files, so backup all your data.

Step 1: Install Raspbian on your RPi
Step 2: Attach camera to RPi and enable camera support (http://www.raspberrypi.org/camera)
Step 3: Update your RPi with the following commands:

sudo apt-get update
sudo apt-get dist-upgrade

Occasionally if camera core software updates have been done then a sudo rpi-update may be used to benefit from these before they become available as standard.

Step 4:

For Jessie Lite run sudo apt-get install git

Clone the code from github and enable and run the install script with the following commands:

git clone https://github.com/silvanmelchior/RPi_Cam_Web_Interface.git
cd RPi_Cam_Web_Interface
chmod u+x *.sh
./install.sh

after all finished, there will be a new folder called html under /var/www. Login that and further advanced camera settings will be available too.
By Ctrl | Alt | Del Posted in IoT

Setup Zabbix to send gmail for triggered actions

Create gmail login script

create “zabbix-alert-smtp.sh” under /var/lib/zabbix/alertscript/

#!/usr/bin/python
# -*- coding: utf-8 -*-
“””
Zabbix SMTP Alert script for gmail.
“””

import sys
import smtplib
from email.MIMEText import MIMEText
from email.Header import Header
from email.Utils import formatdate

# Mail Account
MAIL_ACCOUNT = ‘your.account@gmail.com’
MAIL_PASSWORD = ‘your mail password’

# Sender Name
SENDER_NAME = u’Zabbix Alert’

# Mail Server
SMTP_SERVER = ‘smtp.gmail.com’
SMTP_PORT = 587
# TLS
SMTP_TLS = True

def send_mail(recipient, subject, body, encoding=’utf-8′):
session = None
msg = MIMEText(body, ‘plain’, encoding)
msg[‘Subject’] = Header(subject, encoding)
msg[‘From’] = Header(SENDER_NAME, encoding)
msg[‘To’] = recipient
msg[‘Date’] = formatdate()
try:
session = smtplib.SMTP(SMTP_SERVER, SMTP_PORT)
if SMTP_TLS:
session.ehlo()
session.starttls()
session.ehlo()
session.login(MAIL_ACCOUNT, MAIL_PASSWORD)
session.sendmail(MAIL_ACCOUNT, recipient, msg.as_string())
except Exception as e:
raise e
finally:
# close session
if session:
session.quit()

if __name__ == ‘__main__’:
“””
recipient = sys.argv[1]
subject = sys.argv[2]
body = sys.argv[3]
“””
if len(sys.argv) == 4:
send_mail(
recipient=sys.argv[1],
subject=sys.argv[2],
body=sys.argv[3])
else:
print u”””requires 3 parameters (recipient, subject, body)
\t$ zabbix-gmail.sh recipient subject body
“””

Gmail and Zabbix setup

disable “secure app” feature in Gmail.

then go to zabbix and add media under admin tab. choose script and type name zabbix-alert-smtp.sh, add 3 parameters for 3.x: {ALERT.SENDTO},{ALERT.SUBJECT},{ALERT.MESSAGE}.

then create trigger with action loading condition and operations and tell it to send notice to which user. by this step, we’ve finished defining using which gmail account under what condition to send an email notice. However, as which receiver it’s gonna be we haven’t define yet, to do that we need to setup media for user who’s supposed to be notified under user account, with receiver’s email account.

By Ctrl | Alt | Del Posted in IoT

PI with Zabbix for monitoring and graphing

Install Zabbix

sudo apt-get install  mysql-server  php5 apache2 php5-gd php5-mysql  php5-ldap  snmpd  libiksemel3  libodbc1  libopenipmi0  fping   ttf-dejavu-core ttf-japanese-gothic

wget https://github.com/imkebe/zabbix3-rpi/archive/master.zip

unzip master.zip
cd zabbix3-rpi-master
sudo dpkg -i zabbix-server-mysql_3.0.*+jessie_armhf.deb
sudo dpkg -i zabbix-frontend-php_3.0.*+jessie_all.deb
sudo dpkg -i zabbix-agent_3.0.*+jessie_armhf.deb
sudo service apache2 reload

Create mysql zabbix database:

mysql -uroot -p123sqwert -e “create database zabbix character set utf8 collate utf8_bin;”
mysql -uroot -p123sqwert -e “grant all privileges on zabbix.* to zabbix@localhost identified by ‘123sqwert’;”
zcat /usr/share/doc/zabbix-server-mysql/create.sql.gz | mysql -uzabbix -p123sqwert zabbix

this will take long, just wait until all data injected.

change zabbix server config to use db password:

sudo vi /etc/zabbix/zabbix_server.conf, and modify DBPassword=.

change timezone for php:

sudo vi /etc/apache2/conf-enabled/zabbix.conf

php_value date.timezone America/Toronto

Using snmp to pull data:

change snmpd for access control to allow all access.

create gettemp.sh to pull data from sensor

#!/bin/bash
#
# Usage: gettemp.sh
# e.g. gettemp.sh 28-0215012018ff
SENSOR=$1
SLAVE=”/sys/devices/w1_bus_master1/$SENSOR/w1_slave”
OUTPUT=$(/bin/cat $SLAVE | /usr/bin/awk -F ‘t=’ ‘{ printf $2 }’)
echo $OUTPUT

“gettemp.sh 28-0215012018ff” will show you temperature output.

add “extend .1.3.6.1.3.1.1 temp1 /bin/bash /opt/scripts/gettemp.sh 28-021500ce50ff” at the end of snmpd.conf then run “snmpwalk -v 2c -c public 127.0.0.1 .1.3.6.1.3.1.1” will show your what snmp trap can get. and this will later be the input data for Zabbix to draw.

So now go to zabbix server, run through installation page and login with default account: admin/zabbix.

enable PI as a host and add snmp interface.

create an new item called “temp_28-0315909092ff”, use SNMPv2, choose snmp interface, give it a key name “temp.28-0315909092ff”(sth that unique), SNMP OID”.1.3.6.1.3.1.1.4.1.2.5.116.101.109.112.49.1″(one that you’d get from snmpwalk script, any of those with correct input will work), community “public”, type of info “float”, unit “‘C”(easier identifier for C degree), custom multiplier”0.001″(because output of temp is like 21437, so this make it easier to read), then save.

then go to graph to create a new look, add this new item and you can see the graph in monitoring tab now!

Monitoring by zabbix Agent

Another way to monitor this is simply by adding UserParameter option under zabbix-agentd.conf.

UserParameter=temp.room.0,/home/pi/gettemp.sh 28-0315909092ff

So in this way, a new KEY temp.room.0 will be added into zabbix database with a value of the output of “gettemp.sh 28-0315909092ff”.

you can also test with this key by “zabbix_agentd -t temp.room.0”

reboot zabbix-agent and load this new key under host items, along with other options to create a new graph.

By Ctrl | Alt | Del Posted in IoT