Sunday, September 29, 2019

IoT House Monitor


In the fall of 2018 I developed an initial prototype of an IoT House Monitor using Particle boards, the Particle platform and ThingSpeak.  The goal was to prototype a device that would monitor temperature and humidity and publish the data for remote monitoring.

See Adventures in IOT - Particle Photon for more information on the Particle Photon and Particle Platform.


Hardware

The prototype was built using a Particle Argon so that if the house to be monitored didn’t have Internet connectivity a Particle Boron could be swapped for the Argon and the setup would be able to communicate using cellular rather than wifi.

A BME280 sensor was used for temperature and humidity, information was locally displayed using a 0.96" I2C IIC SPI Serial 128X64 OLED LCD Display and for local input a 1 x 4 membrane keypad was added.  A lipo battery was added so that the device could operate for a time without external power.

Software

The Particle platform along with excellent libraries from Adafruit for the BME280 and the OLED display made it extremely easy to integrate the individual components into a working prototype.  In addition to the Adafruit libraries I included the clickButton library.

The code for the prototype is on Github.

Cloud Services

Once the data has been transmitted into the Particle Cloud I used a webhook to send the data over to Thingspeak.  Thingspeak has a nice clean simple to use interface and a free tier for small non-commercial projects that allows messages every 15 seconds which was more than enough for my prototype.

On the Particle end the webhook integration was configured as shown below:


Then on the Thingspeak end widgets were configured to create the following Then on the Thingspeak end widgets were configured to create the following:

ThingSpeak

After creating a ThingSpeak account you start by setting up a channel.  For this channel I used the following:


You then customize the resulting web page by editing the charts, removing charts or by adding visualizations.  Below are the settings for the Temperature chart.



At this point you should have a pretty nice dashboard to monitor the temperature and humidity.

Friday, April 12, 2019

What I Have Been Up To

Over the past several years I have not been good about posting about the projects I have been working on.  This post is a high level overview of what I have been up to.

Home Automation (September 2016)

In September 2016 I setup a Raspberry PI 3 B+ running Domoticz with a Aeon Labs Z-Stick Series 2 USB device to support Home Automation.  My setup is very simple. 

I have four Ecolink Z-Wave Motion Sensors, three Leviton Z-Wave Smart Plug-In Dimmers, one GE Z-Wave 3 Way Dimmer Switch, one GE Z-Wave In-Wall Smart Switch and an Everspring Siren.  The system is setup to turn lights on and off at certain times and act as an alarm system when we are not home.

Domoticz was easy to setup, simple to use and very reliable.  In the two and a half years I have been using it the system has no hung or crashed.

When I started Domoticz I used the built in timers for the lights and LUA scripting for the security system.  Since the original installation I have upgraded Domoticz which added Python scripting which I am using for some of the newer automation.

I would highly recommend Domoticz for anyone looking for reliable and easy to use home automation.

Home Server Upgrade (September 2017)

Back in March of 2015 I shared setting up a home server using a pcDuino3 Nano and OpenMediaVault.  In September 2017 after successfully running that home server for two and a half years I migrated to an ODROID-HC1 running OpenMediaVault.  This setup has performed admirably since then.  Based on my experience I would recommend both the ODROID-HC1 and OpenMediaVault for use as a home server.

Home Music Center Upgrade (December 2017)

In December 2015 I shared setting up a Raspberry PI Music Player.  In December 2017 I migrated from my Raspberry PI running the Rune Audio Player to a Raspberry PI running MPD controlled by MPD clients on our cell phones.  This setup allows everyone in the house to control the music and has worked quite well.  I had to build a web based interface using lirc to control power and volume on the stereo receiver that powers speakers throughout the house.  The new setup has worked quite well.

Internet Bandwidth Monitor (October 2018)

Many years ago when I migrated from Comcast to Verizon Fios one of the things that I lost was the ability to monitor Internet utilization at my home. 

My Comcast cable modem supported SNMP and I had setup a script that ran every five minutes that queried the appropriate MIBs and then graphed the data using MRTG.  The Fios router doesn’t support SNMP so the way I was monitoring the bandwidth couldn’t be setup the same way.  I eventually found that I could telnet into the Fios router and pull down utilization data.  However, some where along the way a router upgrade broke that feature.

Late in the summer of 2018 I started looking at browser automation and discovered the ability to script a headless instance of a browser to scrape data off web pages  I started out using PhantomJS which I found was easy to use but also found out that development had been suspended in March.  I ended up using Headless Chrome and Selenium with a Python script to scrape the utilization data off the Fios router.

I had started this project on a Raspberry PI 3 B+ but found that the process didn’t run well on that platform and I ultimately had to move it to my much more powerful Windows desktop.  Once the data is scraped off the web page I store it in an InfluxDB from which I drive dashboards using Grafana.

The InfluxDB and Grafana are running on my ODROID-HC1 / OpenMediaVault home server as Docker containers using the OpenMediaVault Docker Plugin.

The whole setup has been running quite well for the past six month and I am once again able to see how much bandwidth is being consumed on my Internet connection.

House Temperature Monitor Prototype (November 2018 - March 2019)

Back in May of 2016 I shared my initial experiences with the Particle Photon.  I was very impressed with the photon and Particles platform.  So when they announced in their Particle Mesh devices for pre-order in February 2018 I decided to an Argon and four Xenons. 

Flash forward to the fall of 2018 and the Paticle Mesh boards arrive and I decide to build a simple monitoring device that would upload the temperature to a service which would allow it to be monitored from a remote location.  The beauty of using the Particle devices was that the device could be prototyped using an Argon and connect over wifi but could be deployed using the Boron and connect over LTE.  This would allow it to support monitoring where there wasn’t wifi.

The resulting prototype consisted of an Argon, an I2C VME280 temperature sensor, an I2C 128x64 OLED display and a Lipo battery in a plastic case with four buttons.  Using the firmware on the Argon uploads the temperature every five minutes to the Particle Cloud which creates a webhook to ThingSpeak where the temperature and humidity are presented in both graph and gauge form.

The prototype device has been sitting on my desk uploading data ThingSpeak consistently for the past two months.

I have a number of ideas that I hope to incorporate in a subsequent prototype and hope to document in more detail some of the useful lessons I learned along the way.

Tuesday, November 28, 2017

IOT- Mongoose OS

In preparing for another IoT project I came across Mongoose OS.  Mongoose OS describes itself as “an operating system for connected products” and is a product of Cesanta. It is open source and dual-licensed under the GPLv2 licenses and a Commercial License which removes the GPLv2 and functionality restrictions.

It supports the ESP32, ESP8266, CC3220, and CC3200.  I have been mostly using it with a nodemcu board but also have gotten several simple examples running on an Olimex mod-wifi-esp822-dev board

I have been working with it off and on for a few weeks and so far am impressed. 

I have put a couple of my examples on github in the hope that they will help others.

More to follow…

Saturday, February 4, 2017

Another Adventure with IOT - CallerID Project

Over the past year or so I have been looking for an IoT project.  Last summer I came up with one which was to capture caller id information and display it on our multiple computers around the house so we can see who is calling with out getting up and checking the phone.

image

For the project I used the opensource Mosquitto MQTT Broker running on a Raspberry PI configured with self signed certificates.  I used TLS connections with usernames and password to secure communications between the nodes.

I captured the caller id using an old US Robotics Sportster modem connected to an original Raspberry PI Model B using a serial to USB adapter.  I started the project with the goal of working with Node.js but but had problems getting the node.js serial module running on the old Raspberry PI.  I switched over to a simple C program to capture the caller id information from the modem and publish it to the MQTT Broker.

So far I have built a Windows client which displays the caller id information using a notification from a tray icon.

The project took me a couple of months to get up and working.  This was in part due to having limited time to work on it and partly as I spent a good bit of time getting familiar with node.js.  I found Mosquitto very easy to use.  The documentation for Mosquitto and the Mosquitto API very good.

The setup has been running for several weeks now.  Both my wife and my computers have the CallerID Subscriber installed on them and we get notifications with caller id when calls come in.

One tool that I used extensively during the development process was mqtt-spy which I would recommend to anyone working with MQTT.

Friday, December 23, 2016

New Setup Guide Posted - lirc on Raspberry PI 3

A setup guide for setting up lirc on the Raspberry Pi 3 has been posted.

Setup guides are reference documents that I create for installing hardware, software and entire systems. They consist of the steps I followed for the build. They are mostly meant for my future reference but they might be able to help someone so I post them online. They are posted in the digitalhack GitHub repository under SetupGuides

Sunday, May 22, 2016

Adventures in IOT - Particle Photon

Last summer I came across the Particle Photon and decided to pick up two of them and give them a try. Fast forward a number of months and I decided on a simple project combining a DHT22 temperature and humidity sensor with the Particle Photon in a simple IOT project.

Introduction

The Photon is a nice development platform in the style of the Arduino.  The Photon consists of a STM32 ARM Cortex M3 microcontroller paired with a Broadcom WICED wifi chip.  This allows easy access from the board to the Internet.

Development with the Photon can be done a couple of different ways.  There is a web based IDE paired with an online compiler known as Particle Build.  There is an IDE that can be installed on your computer which also uses the online compiler known as Particle Dev.  The online compiler can be accessed using a node.js based command line environment which allows you to use a iDE of your choice.  Finally you can roll your own development environment with the ide of your choice, ARM gcc and the DFU boot loader.  The flash process can be done over wifi or usb.

The development environment is styled after the popular Arduino development environment with good documentation and core and user contributed libraries  I have a good bit of experience with that Arduino and It’s IDE and found that there was a very minimal learning curve.

The most complex part of developing on the Photon is activating your Photon so that it can be flashed via wifi over the Internet.  There are a number of methods for doing this.  I used the Android App and the process went very smoothly.

To get started there is excellent documentation on the Particle website and a very good guide at Sparkfun.
image image image image

image

My plan was to read the DHT22 with the photon and upload temperature and humidity data over the Internet to an IOT analytics service.

Hardware Setup

Minimal hardware is required for this project.  I used a mini breadboard, s photon, a DHT22, 10 K resistor and some hook up wire.

The DHT22 has four pins on it.  With the DHT22 facing you so you are looking at the vents the pins are numbered 1 – 4 left to right.
  1. VCC 3V to 5.5V: connects to 3.3V on Photon with a 10K resistor to pin 2.
  2. Data: connects to D3 on the Photon.
  3. N/A: is not used
  4. Ground: connect to GND on the Photon.

Software

Using Particle Build, Particle Dev or the command line development environment a program is written the same way as an Arduino sketch with a setup routine that is executed once and a loop routine that is executed continuously after setup completes.

My simple example was made considerably easier thanks to the user contributed library for the DNT22 sensor.  The PietteTech_DHT library can be found in the list of user contributed libraries in Particle Build or as a GitHub repository

To build this example I used the command line.  When using the command line environment you put your library files, in this caswe PietteTech_DHT.cpp, PietteTech_DHT.h, and your Photon program in the same directory.  When you compile or flash you specify the directory as the source.

The example below reads the sensor and then publishes the temperature, humidity and status to the
Particle website.

#include <cstdio>
#include "PietteTech_DHT.h"

#define DHTTYPE  DHT22       // Sensor type for PietteTech_DHT
#define DHTPIN   3           // Digital pin for PietteTech_DHT

// Must be declared before PietteTech_DHT 
void dht_wrapper();

// Library instantiation
PietteTech_DHT DHT(DHTPIN, DHTTYPE, dht_wrapper);

float temp;
float humidity;
float status;

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

// Must be setup like this for PietteTech_DHT to work
void dht_wrapper() {
  DHT.isrCallback();
}

void loop() {
  int result = DHT.acquireAndWait();
  
  if (result == DHTLIB_OK) {
    temp = DHT.getFahrenheit();
    humidity = DHT.getHumidity();
  } else {
    temp = 0;
    humidity = 0;
  }
  
  char buf[80];
  
  int n = snprintf(buf, 80, 
    "{ \"temp\": \"%5.2f\", \"humidity\": "
    "\"%5.2f\", \"status\": \"%d\" }",
    temp, humidity, result);

  Particle.publish("THEvent", buf, 60, PRIVATE);
  
  delay(60000);
}

In a command window at the command line compile using the command below where THPublish is a subdirectdory that contains the ino file and library files.

image

To flash your code to the photon is done using the command below again THPublish is a subdirectory that contains the ino file and library files.  Also, photon2 is the name of the photon you are flashing.

image

The photon led will flash blue/red and then green and back to blue.
If everything is successful you can go to the Particle log and see you events and event data.  Starting
at the main Particle web page select  image from the upper right corner.  Then on the left side of the screen select the log icon imageand see your events and event data in the log.  The way that logging works it will start logging when you show the log which means you will need to wait for your event to occur before it will be shown.
image

Thoughts

The folks at Particle has put together a very nice device and a comprehensive development environment.  The price of the device and the ease of use has greatly lowered the cost of entry in the IOT space.  Beyond traditional IOT the Particle Photon can be used to allow easy interaction with a microcontroller based project over wifi.

The Particle Photon can be purchased for $19 from Particle, Sparkfun or Adafruit making it an attractive option for your next project.

Saturday, December 26, 2015

It Worked For Me (Sort Of) - Raspberry PI and D-Link DWA-171A1

I recently purchased a D-Link DWA-171A1 Wireless AC Dual Band USB Adapter to use with a Raspberry PI 2 B after seeing a posting that stated that it worked out of the box.  Well…

It didn’t work out of the box but I was able to get it to work by compiling the driver.  I used this code from GitHub on the Raspbian Jessie image dated 11/21/2015

  1. Loaded the Raspbian Jessie image from here: https://www.raspberrypi.org/downloads/raspbian/ Linux raspberrypi (4.1.13-v7+)  to my SD Card.
  2. Added the following packages using apt-get: apt-get install dkms build-essential bc
  3. Downloaded and unzip the driver from abperiasamy/rtl8812AU_8821AU_linux GitHub repository:  https://github.com/abperiasamy/rtl8812AU_8821AU_linux/archive/master.zip
  4. Download the appropriate kernel headers for your version of Raspbian.  I found the ones I needed here: https://www.niksula.hut.fi/~mhiienka/Rpi/linux-headers-rpi/.
  5. Install the headers using sudo dpkg –i <package name>.deb.
  6. cd to the directory you unziped the driver into.
  7. Using nano or some other editor update the Makefile:
  8. CONFIG_PLATFORM_I386_PC = n
    CONFIG_PLATFORM_ARM_RPI = y
  9. The using the following commands build and install the driver.
  10. # sudo make clean
    # sudo make
    # sudo make install
    # sudo modprobe -a 8812au
You should now see the DWA-171 as a wireless interface and should be able to configure it.
I tried the same procedure using a Raspberry Pi B running Arch Linux with a 3.12.26-1-ARCH kernel and wasn’t able to get the driver to compile.
Thanks to all those who made resources available to help me along this journey.