Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Status
colourYellow
titleDRAFT

...

This guide will show you how to connect (WiFi) devices in the OpenDevice server and send data to save in storage and further visualization in dashboards, all in real time. server to store and then use this data to perform analysis using the dashboards.

We will use the DHT22 sensor connected to the WiFi ESP8266 module to collect temperature and humidity, and send the server using the MQTT protocol.

...

DHT22

NodeMCU DEVKIT 1.0.jpg

NodeMCU

Wiring


The most basic DHT humidity and temperature sensor comes in two variants with different levels of accuracy.


DHT-11DHT-22
Humidity range20%-80%RH (±5%RH)0%-100%RH (±2%RH)
Temperature range0-50°C (±2°C)-40-80°C (±0.5°C)
Measurement time1s per sample2s per sample

Setup

To program the NodeMCU, we are going to use Arduino's IDE. It's the easiest way to get up and running with the DHT22.

First, you'll have to set up your machine : (Device Setup Instructions). These instructions take you through installing the IDE, ESP8266 and the proper required libraries.

In addition to this, you'll have to install DHT sensor library to read the sensor, we are going to use Adafruit's DHT22 library., and Adafruit Unified Sensor Driver

Install Adafruit's DHT22 library using Library Manager:

Image Added

Next, install Adafruit Unified Sensor Driver

Image Added

Code / Firmware

...

Next we need to configure the device name (you choose) and the api key (see this guide).

App Code (full example)

...

You do not have to do much, just make sure you are looking at the console, if the WiFi connection and the server MQTT was successfully performed.

...

Start the OpenDevice (guide), access (http://localhost:8181), and verify that your devices have been registered correctly.

In the Boards page, you should see your device/module already.:

Our module has two linked devices:

On this page we already have a series of tools and visualizations that we can analyze how the device is behaving.

But we have a better tool to do the analyzes that are the Dashboards

Create custom visualizations using Dashboards

...

You can also add more then on device on the chart:

You have the freedom to edit and position and enlarge the graph as you wish

Let's now add a gauge that shows the temperature value in real time:

You have the freedom to edit and position and enlarge the graph as you wish

After organizing our charts, dragging and expanding, we get the result:

Update firmware over WiFi (OTA)

Now after the device is working and online, we can upgrade via OTA. In the Arduino IDE, the device should appear as if it were a Port:


Image Added

WHAT'S NEXT? 

At this point, you are collecting and visualizing data. But, what about reacting to it? The next step is to build a Rule(/wiki/spaces/DOC/pages/99352732) in Losant   to send yourself a text message whenever the humidity gets too highlow



See examples:
https://github.com/OpenDevice/opendevice-lib-arduino/tree/master/examples

...