alext-mkrs / edison-weather-station

Wireless weather station project based on Edison and Arduino/Genuino 101

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

General

This repo contains code and assets for a wireless weather station project based on Intel(r) Edison (Base module) and Arduino/Genuino 101 (wireless Sensor modules).

The project was done (see Instructables post for assemby instructions), with the end-goal of having the following features supported:

Base module (Edison)

  • Getting data from sensor modules through BLE
  • Displaying sensor data through a user interface (web) - for short-term analysis and observation
  • Cloud upload for long-term preservation and analytics (ThingSpeak)
  • Displaying weather forecast from the Internet aside the sensor data - dropped this one as it turned out I don't need it.
  • Getting data from locally-attached sensors
    • Barometric pressure + temperature sensor (BMP180)
    • Humidity + temperature sensor (HTU21D)

Making AM2302 work with Edison on Arduino expansion board was not possible/easy, so I resorted to a pair of I2C sensors to cover necessary measurements.

Sensor module (Arduino/Genuino 101)

  • Temperature sensor (DHT-22/AM2302)
  • Humidity sensor (DHT-22/AM2302)
  • Battery-powered - per my measurements it's not feasible to run all my modules off of the battery, but I'll do that with at least one, which is located in a place without wall socket nearby
  • Exposing data through Bluetooth LE
  • Configurability through Bluetooth LE - I decided to drop this as well, as it turned out I don't really need such a feature. Pull requests are welcome 😃

KISS and DRY principles were the guiding light all the time as well 😃

While I started it just for myself to create a network of sensors at home, I believe this is a nice example demonstrating various features and aspects of both Edison and Arduino/Genuino 101, so I'm sharing it with a wider audience.

How it all works

There are two main code pieces: for Base and Sensor modules.

The latter is a usual Ardunio sketch, which uses only one additional library - DHT. Its main role is to expose data acquired from the AM2303/DHT-22 sensor through standard BLE Environmental Sensing service.

It's important to mention that the code does not try to acquire data unless there's a BLE connection. This is done to consume less energy - if there's no connection, no one is going to see the data anyway.

The Base module code is a JavaScript/Node.js application, which includes several components:

  1. Module for data acquisition from Sensor modules through BLE. Upon start it runs a BLE scan and tries to find namely our Sensor modules (based on advertised name and BLE services present, see code for details). When a module is found, we subscribe for data change notifications (so no polling is done). After initial discovery it runs a scan every 30 seconds for 5 seconds to pick up any module set changes. Module disconnects or reconnects are handled automatically. The module uses great Noble library for BLE functionality;
  2. Module for data acquisition from local sensors, which is implemented using standard polling technique - every 10 seconds we acquire data from sensors. This module uses awesome UPM and mraa libraries for sensor interaction, which makes it very easy to acquire data even though the underlying sensor protocols are not that simple at all;
  3. Both BLE and local sensor code modules expose the acquired data through a method each, and for convenience both are wrapped into a single sensor data acquisition module;
  4. Then there's a web UI based on a standard Node.js Express module and a template app it generates. The UI is kept very simple and generic and uses AJAX approach with client-side code using Chart.js and jQuery libraries for data display. Upon loading into a browser, AJAX code starts polling our web server for data every 5 seconds and displays current sensor data items in a text form and as animated charts (one per sensor). Charts/text items are automatically added/deleted if a sensor module connects/disconnects. I initially wanted to create a dedicated Android app for this, but then it turned out in Chrome/Firefox the data is perfectly readable, so I ditched this;
  5. Finally there's a cloud data upload module (I used ThingSpeak, see my blog post for reasoning) and a config file. I don't use any additional ThingSpeak connection libraries (there's one in NPM), but as we just upload data to pre-configured channels on ThingSpeak, plain Express is good enough (remember KISS?). In a nutshell - create one ThingSpeak channel per sensor module and one field per sensor data item. Naming and ordering must be the same as the one you see in web interface. See Step 5 of my Instructables post for more details.

Running Base module code

Base module code is written in JavaScript and is intended to be run on Node.js on Edison. package.json file contains all dependency data, so just run npm install in the ws-base-module directory and then start the data acquisition process and web interface by running node main.js. I haven't tested the very latest versions of all dependencies, but at least Edison image from Release 2.1 + mraa 0.9.0 + UPM 0.4.1 + Noble 1.2.0 work fine.

Note that if you've upgraded your Node.js to a non-default one (e.g. 0.12.7 from my package repo), you'll need to manually build UPM modules for sensors. NPM will handle rebuilding of the mraa one, but UPM does not yet have this capability. Ask in their bugtracker (or me) if in doubt.

By default the web interface will be available at http://<IP of your Edison>:3000

ws-base-module dir also contains a working Systemd service description file, edison-weather-station.service, to start weather station process automatically.

Copy it to /lib/systemd/system and then run systemctl enable edison-weather-station. The file assumes that you'll put the clone of this git repo to /home/root/edison-weather-station on your board, correct paths inside if that's not the case.

To enable debug output, set NODE_ENV environment variable to development before starting main.js.

Note that more than three sensor modules would force you to switch to 5GHz Wi-Fi for the base module. At least that was the case for me. With four modules Wi-Fi was breaking every now and then (both incoming and outgoing connections). My guess is interference between BT and 2.4GHz Wi-Fi, maybe due to the fact that both use the same band and standard built-in interference avoidance techniques do not work well with more than three modules connected.

Running Sensor module code

This is a standard Arduino sketch, which is uploaded using standard Arduino IDE. Make sure to install "Intel Curie" board package through Board manager before doing that.

You'll need to install one of the two DHT sensor libraries and set the module name, see header of the sketch for details.

To enable debug mode, set DEBUG define to 1.

Bill of materials

  • Intel(r) Edison with a Kit for Arduino (Base module) - 1 pc
    • Generally speaking, a mini-breakout board would work too, but you need to take care of I2C voltage level translations for directly attached sensors.
  • Arduino/Genuino 101 (Sensor module) - 1 or more (depending on your needs)
  • DHT-22/AM2302 sensor - 1 per sensor module
  • BMP180 sensor (I used generic GY-68 module) - 1 pc (attached to Base module)
  • HTU21D sensor (I used SparkFun module) - 1 pc (attached to Base module)
  • Enclosures for both Sensor and Base modules

About

Wireless weather station project based on Edison and Arduino/Genuino 101

License:Other


Languages

Language:JavaScript 85.0%Language:Arduino 12.9%Language:HTML 1.7%Language:CSS 0.3%