Versions Compared

Key

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

Status
colourYellow
titlePending
Arduino Library (AT): https://github.com/OpenDevice/ESP8266AT
DRAFT

Table of Contents

Introduction

...

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.

Note, if you do not have this sensor in hand, you can continue this tutorial by simply skipping or commenting on the parts where it is used.

Prerequisites

Image Modified

DHT22

NodeMCU DEVKIT 1.0.jpgImage Modified

NodeMCU

Wiring

...

dht22_esp8266_wiring.pngImage Removed

...

Image Added

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 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.

Code / Firmware

The OpenDevice for Arduino software greatly simplifies application development, managing devices and communicating with the server in a completely transparent way, so you can really focus on your project.

The library uses a set of build techniques to customize the firmware. According to the platform used and the imported libraries, OpenDevice enables certain features.

Basically when importing the libraries below, we are activating the WiFi communication and the MQTT protocol.

Code Block
#include <ESP8266WiFi.h>  // Enable ESP8266 / WiFi
#include <PubSubClient.h> // enable MQTT
#include <ArduinoOTA.h>   // Remote Updates
XXXXXXXXXXXX DHT
#include <OpenDevice.h>  // Must be included after

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

Code Block
#define ODEV_API_KEY "-----"
#define ODEV_MODULE_NAME "ODevESP8266-1"

app code:

Code Block
const char* ssid = "--";
const char* password = "--";

void setup() {
  ODev.enableDebug();
  ODev.name(ODEV_MODULE_NAME);
  ODev.apiKey(ODEV_API_KEY);
  ODev.server("192.168.3.106"); // Change Server !

  ODev.addDevice("LED", 2, Device::DIGITAL);
   -- XXXXXXXXXXXX DHT
  WiFi.mode(WIFI_AP_STA);
  WiFi.begin(ssid, password);
  ODev.begin();
}

void loop() {
  ODev.loop();
}


Next, upload code to the board and open up your serial monitor, you should see the data:

IMAGEM DA SERIALLLLLLLLLLLLLLLLLLLLLLLLLL

Sending data to the cloud

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

The OpenDevice server already has a mqtt broker and an embedded database, this makes it much easier =].

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

IMAGEMXXXXXXXXXXXXXXXXXXXXXXXXXXXX - devices

IMAGEMXXXXXXXXXXXXXXXXXXXXXXXXXXXX - interna dos devices

Create custom visualizations using Dashboards

You can create multiple dashboards in OpenDevice that let you analyze device data in both real-time and historical data. You can also apply functions to the data such as average and standard deviation.

First create the dashboard

IMAGEM

Then add Widgets

Vamos criar o  gráfico de linha para exibir as informações da temparatura nas útimas 4 horas

IMAGEM

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

Vamos agora adicionar uma gauge que mostre o valor da temperatura em tempo real:

IMAGEM

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(GUIDE) in Losant to send yourself a text message whenever the humidity gets too high. 


See examples:
https://github.com/OpenDevice/opendevice-lib-arduino/tree/master/examples/ESP8266WiFi_ATDevice Code (Firmware)

The application that is running on ESP8266 is written using Arduino SDK which is quite simple and easy to understand.

Features:

  • AT Firmware and Stand-alone mode
  • Auto-Discovery
  • Remote wifi config
  • Remote Update

Recommended Resources:

...