Only the list of sensors are supported.You need not write any code separately for sensors.Just connect the Sensor and configure on Dash board. Display or control it from DOMOTICZ over HTTP or MQTT protocols.
Download the MEGA version of ESP EASY.
Under dist folder Flasher application is provided.Double click on that.
Select the COM port where Nodemcu is connected.
Before selecting a .bin firmware file click on the update button.
Latest .bin files will be downloaded from Github repository.
Select the relevant .bin file for your hardware.Here I’m selecting ESP8266 4MB version, as my hardware is NODEMCU with 4096 flash memory.
Test beta version supports Nextion display hardware.
Setting of WIFI & fixed IP can be done later. For now Flash ESP EASY.
It takes approx 2 minutes to upload.
Once uploaded , close the flasher and reset Nodemcu.
It starts in AP mode and the WI FI access point name is ESP_EASY.
Connect your PC to this AP using password configesp
When a fresh ESP Easy module boots up, it has no Wifi config and it will start as an Access Point.
Use a Wifi enabled device (Laptop, Smartphone,..) to search for Wifi access and try to find an access point with the name ESP_Easy.
Connect to this access point with default password:
configesp
Once connected , open your browser and type in ip address 192.168.4.1
You should get a welcome screen:
Select your SSID and provide password.Click on CONNECT .
Now your NodeMcu connects with your SSID.
If the connection succeeded, you will see a screen, listing it’s new local IP address.
You can now reconnect your laptop or other device back to your private Wifi network.
Then click the “proceed” link to contact the ESP module on it’s private IP address:
ESP EASY Nodemcu is offered an IP ADDRESS by your Router.
Use this address on a browser to access the DASHBOARD of ESP EASY.
Under MAIN tab is the SYSTEM INFO.
Click on CONFIG tab.
Here you can change the AP password from configesp , if you need.
At the bottom is the IP Settings.
You can provide an IP address to make it STATIC.
The IP Address must be in the range of your Gateway IP.
Gateway IP is the IP of your ROUTER.When any client connects with the Router , it provides an IP address by its DHCP method.This IP will be in range of Gateway IP , only the last octet changes.
Finally click SUBMIT to effect changes.
Next tab is CONTROLLERS tab.
Under this you select a PROTOCOL .
HTTP,MQTT,UDP all are supported.
In this demo we control an LED from browser commands.So select STANDALONE.
Under HARDWARE tab you can set any GPIO pin to be High or Low on Boot up.
It is not needed in this demo , so we move on to next tab DEVICES.
Click on ADD from the list of devices.
Select SWITCH INPUT – SWITCH from the drop down.
Provide a name , like LED and then click the ENABLED .
Under GPIO , select GPIO 12 (D6) where we’ve connected an LED.
Click on SUBMIT.
Now from your browser use this command to control LED.
Instead of GPIO you can use PWM to control brightness of LED.
In the previous post , we worked on a home automation project and Android mobile application & controlled devices locally .ie., over Local Area Network.
In this post we will see how to make the home automation project to control from anywhere in the world. IOT CLOUD Platform BLYNK is used for implementing this.BLYNK is the most popular IoT platform to connect your devices to the cloud,
BLYNK is a digital dashboard where you can build a graphic interface for your project by simply dragging and dropping widgets.It supports a wide range of Hardware including Arduino,Nodemcu,Raspberry PI & others.
First install BLYNK on your mobile phone by signing up with your EMAIL ID.
Open BLYNK application.Touch on NEW PROJECT.
Provide a name to the project & select hardware.Here Im using NODEMCU.
Connection type is WIFI .
Touch on CREATE button.
An authorized token ID will be sent to your registered EMAIL.
Now we shall see the WIDGET BOX to add some elements.Each element of WIDGET BOX has got an ENERGY LEVEL.
While starting up you will be provided a free energy level of 2000.According to the usage of widgets this energy level will be deducted.
For e.g , add a BUTTON to your project.
An energy level of 200 will be deducted.If you want you can BUY Energy level by touching on the ADD button.
Add 2 buttons as shown below.
To set the properties of first button , touch on that button.
Provide a name to the button 1.
Touch on PIN to select pin.As we control a dc fan through relay board which is connected to D2 of Nodemcu , select DIGITAL PIN D2.
There are also VIRTUAL PINS Upto 255 , which are specific to BLYNK firmware. These virtual pins are NOT Physical pins , but are handy to send data or message to them and then control physical pins from within code.
Slide the MODE setting to SWITCH which makes the button at as ON or OFF.
Similarly for the Button 2 set the PIN to digital D4 where we control an AC load through the relay board.
Now touch on the Back arrow to go to the start up page.
On touching the PLAY Icon , a message indication stating Not yet online is displayed.As we are yet to upload code on to Nodemcu , the setting is OFF line for now,
From your PC side , open the Arduino IDE.
For setting NODEMCU to Arduino core ,open File & under Preferences paste this json link
Then open Tools –> Boards Manager , search for ESP8266 & install.
Also from Sketch – > Manage Libraries –> Library
search fro BLYNK & install the library.
Once the library is installed you can see under Examples —> Blynk
Open the NodemCU Example code.
You need to replace with your Authorized token ID which you received in Email while creating the Blynk project.
Provide your WiFi credentials ,SSID & password of Router to which Nodemcu will be connected.
Also under setup() make the digital pins D2 & D4 HIGH.
This step is to make the loads connected to relays initially OFF.
As the relay board we are using is a LOW ENABLED , a LOW at input energizes the Relay and a HIGH makes it OFF.
We make use of MB102 PSU board on a MB102 bread board.This MB102 board has got jumper settings to make one rail as 5v & the other rail as 3.3v.
A jumper seen at he relay board can be removed.
Connect Vcc to 3.3v & JD-Vcc to 5v rail of bread board.
The loads can be connected as shown below.Always connect the power source on which the load operates to the POLE pin.Actual load is connected to Normally Open contact.
Connect NODEMCU to PC , from ARDUINO IDE select the board as NODEMCU & select the port allotted.For this you must have already installed driver for CP2102.
Upload the code & then disconnect USB cable.
Provide 12v 1amp or 9v 1amp adapter to MB102 PSU board.
Allow some time for NODEMCU to join the SSID mentioned in the code.
While using AC load ,take care not to touch the relay board and insulate properly the relay board inside a plastic box.
Now open the BLYNK Application and touch on the project you created.On top right corner touch on the PLAY Icon.
Once you see ONLINE indication , you can touch on the buttons created to control the loads.
upload the above code and open the serial monitor to note the IP address allotted to NodeMCU.
Note that all devices NODEMCU ,PC & mobile are connected to same Router.
The IP address allotted is DYNAMIC ,meaning , it may change on next power up.
To make it STATIC , you can set Address Reservation setting under Routers settings.
Once the IP is allotted , open up the WEB browser and type in IP/fanon
for e.g 192.168.1.107/fanon
Initially both the LEDs will be ON .As we will use a LOW enabled input Relay board, these LEDs are made ON indicating the devices are OFF initially.
On sending the string fanon from browser , the RED LED will go OFF.
On sending 192.168.1.107/lightoff , the Green LED will go off.
Similarly fanoff string will make Red LED ON , lightoff string will make Green LED ON.
Now the code is working perfectly, we shall replace the LEDs with actual devices to be controlled.
A 4 channel 5 volt Relay module is used to connect the actual devices .We use a DC FAN 5v at relay contact 1 and a CFL bulb AC at RELAY 4
For power source a MB102 PSU board is used on MB102 Bread board.This board can be easily plugged on to MB102 Breadboard and has jumpers.One jumper (top) is set to 5v and the bottom jumper set to 3.3v.
An external adapter of 9v 1amp is used .
Connect IN1 of relay board to D2 of NODEMCU
IN4 to D4, GND to GND.
While connecting Load to relay board, always connect the power to load at POLE.
Actual Load is connected to NO Normally Open pin of relay contact.
While handling AC loads, take precaution to insulate relay board within a plastic box and do not touch the relay board.
It is safer to connect Neutral to POLE and AC Phase to other end of Load.
Also remove the jumper on relay board.
Connect 3.3v to Vcc and 5v to JD-Vcc
This enables error free operation , as the NODEMCU is a 3.3v device.
Now let us develop our Android Mobile Application using on line MIT APP INVENTOR.
Click on Start a New project and provide a Project name. Space and Hyphen not alloed in name , but underscore allowed.
You will be presented with development screen which has 4 columns.
1st Column is Palette with all User Interfaces and components to build the App.
2nd Column is the actual Screen viewer.
3rd Column displays all the selected Components.
4th Column shows the Properties of the selected Components.
From LAYOUT drag and drop a HORIZONTAL ARRANGEMENT
Set the Height under properties to 10 percent , Width TO FILL PARENT
This is to provide space at top of screen.
Then drag and drop LABEL from User Interface
Set Width TO FILL PARENT , Text to Heading of App. , alignment center ,Fontsize to 25
and background color to yellow.
Next drag and drop TABLE ARRANGEMENT from LAYOUT.
Set properties , COLUMNS to 3 and ROWS to 2, Width to FILL PARENT, Height to Automatic.
2 Rows required for 2 device control.
3 columns for image , on button and off button.
Drag and drop an IMAGE component from User Interface.
Under Properties set the Height to 15 percent, Width to 30 percent.
Under Picture property click Upload File and select the image to upload.
Now drag and drop 2 buttons next to image 1.
Drag and drop another IMAGE component, below the first imge.
Set properties accordingly and upload the second image.
Drag and drop 2 more buttons as shown below.
Select the properties of Buttons
You need to change the Text and the background COLOR.
Next drag and drop a WEB component from CONNECTIVITY.
As this one is a Non Visible component , it will show up at the bottom of the screen.
Now click on the BLOCKS button at the right top corner.
Select Button1 from the left side Blocks.
You will see a list of options.
Select the When..Do ..Button..Click block.
Next click on WEB .
Select the set..web1..url..to block
Third block to select is under TEXT
Select an empty Text block for text.
Finally from WEB
select call..web..get block.
Following are the blocks we selected.
Assemble the blocks as shown.Just drag and fix at the connecting points.
IOT is Internet Of Things where devices are connected over internet and made SMART.
These devices can be controlled from any where in the World or collect data from devices to process.
In this 1st post of IOT series I will introduce the hardware required to start with and also the IOT platforms used.
Arduino boards are much popular among hobbyists and developers.But these Arduino boards (UNO,MEGA) lack Ethernet or WIFI capability which is essential for IOT.
For wired connection there is ETHERNET Shield which can be plugged on directly to UNO or Mega.
For internet access I’m using a Huawei make USB Dongle with a Data SIM inserted.This dongle
can be used in standalone mode , as it has got WIFI capability.But plugging this to a Router
like TP-LINK enhances its capability of WIFI Range, more Clients, Static IP setting,etc..
The Ethernet shield can be plugged on to Arduino and an Ethernet cable (straight type)
can be used to connect with the Router.
The Router will then allot an IP Address (local IP) to the ethernet shield which is now a client.
DHCP server of Router allots the IP on first come first basis.As this IP is DYNAMIC ,
the address may not be the same if powered off and connected again.’’
To make the IP address STATIC , the ROUTER has ADDRESS RESERVATION settings
under DHCP.
MAC address of the device is used to make the local IP STATIC.
Instead of wired Ethernet connection you can go for WIFI Devices. ESP8266 WIFI modules are
cheap and popular now.
ESP8266 WIFI modules , a wide range available.ESP8266-01 module is basic model .As it is not breadboard friendly , you can make use of a base board to plug on , as shown in picture below.
ESP8266-12E module has more GPIO pins and memory.
These modules can communicate with ARDUINO using AT COMMANDS for ESP.
To use ESP modules we need a controller like Arduino.
Easier option is to use NODEMCU Modules.These NODEMCU modules are built on ESP12E chip
and has USB to upload code.LUA is the official Firmware that comes with NODEMCU.
Using BOARDS MANAGER in Arduino IDE you can implement ARDUINO CORE on to NODEMCU
and start using NODEMCU individually.
You can check out my video on how to implement Arduino core on to NODEMCU.
Once Arduino core implemented , you can use Arduino IDE and libraries to develop code on NODEMCU.
Latest arrival is ESP32 which is much more powerful than NODEMCU with more Analog pins
and with BLUETOOTH,BLE and inbuilt sensors.
For IOT and HOME AUTOMATION projects RELAY BOARDS are helpful to connect wide
range of Loads or devices.
5V Relay boards are available with 1 channel , 2, 4,8 Upto 16 channels .
Each relay is driven by an opto coupler and a NPN transistor.The relay contacts are
provided as Terminal connectors.
Each Relay has a common POLE, a NC –Normally Connected contact and a
NO – Normally Open contact.
These 5V relay boards are LOW ENBLED, meaning , a LOW at input will energize the Relay.
A low at input will make the opto coupler conduct which drives the NPN Transistor.
This in turn will switch ON the relay.
Electronic solid state relay boards are also available which are called SSR.
12v Relay modules also are available.Here the relay is driven by a NPN transistor .12V Modules are HIGH ENABLED ,meaning, a HIGH at input drives the relay ON.
Any load ,DC or AC can be connected to the RELAY contacts, irrespective of the supply voltage to relay board.
The power supply to load is connected to POLE pin and the actual load is connected to the NO pin.
As the relay is energized the pole pin changes from NC to NO ,thus activating the Load.
While using AC load take precaution to insulate properly the wires as well as the Relay boar.Do not touch relay board with AC load.
You can control the devices over Local Area Network or through Cloud or internet.
While using LAN , make sure that the NODEMCU and your mobile , both are connected to the same Router SSID.
For control over internet you need to PORT FORWARD the local ip device port on the router settings.But nowadays a number of IOT PLATFORMS are available as CLOUD. Though you need a paid subscription , most of them offer free service for hobbyists with some limitations.
BLYNK, CAYENNE, THINGSBOARD are some popular IOT PLATFORMS.
Sign in to any of these platforms and start controlling the devices from anywhere in the world.
WemosD1 R1 board is now the most preferred IOT WIFI Board .As the hardware resembles Arduino , it is most sought out board for any IOT project , than NODEMCU.
To add a display I prefer to use the SERIAL LCD WITH I2C BACKPACK .
The serial LCD is built on PCF8574 & works on I2C Bus ,thus requires only 2 wires SCL & SDA apart from the power pins.
The LCD works on 5V & it can be sourced from D1 board itself.
For more detailed information on this Serial LCD you can read my previous blog here :
WEMOS D1 is a WIFI development board based on ESP8266 12E. The functioning is similar to that of NODEMCU , except that the hardware is built resembling Arduino UNO.
The D1 board can be configured to work on Arduino environment using BOARDS MANAGER.
So,its not necessary to use a separate Arduino board , the D1 itself can be programmed on Arduino IDE.This is handy in using with IOT projects. Further many Arduino SHIELDs are compatible with the D1 board.
Different versions of D1 boards are available in the market R1 , R2 , MINI
As the name implies D1 Mini is a smaller version
R1 , R2 boards look like Arduino UNO board ,but version is not printed on board. On some boards WEMOS D1is printed , as the ESP12 chip is manufactured by WEMOS.
In some other boards it is printed just D1 ,where the ESP12 chip is that of AI Thinker.
As the ESP12 chip has only one ANALOG pin , on board there is only A0 & other analog pins are dummy .
Use a MicroUSB cable to connect D1 with PC. Make sure that the cable is capable of handling both Data & power (some of the mobile cables can handle only power & not data) .
Open the DEVICE MANAGER & note the COM PORT allotted to the module.
As the serial chip used on D1 is CH340 , you need to install the corresponding drivers.
PIN CONFIGURATION
Following is the pin configuration of R2 typeD1 Module.Note the changes in GPIO Pin position.
Open the Arduino IDE & select this COM port.
From TOOLS —> BOARDS —> BOARDS MANAGER install the package for ESP8266.
Prior to this , you need to provide the link from where the Boards manager will look for the package.
Paste the link against the Additional Boards Manager URLs ,seen at the bottom of preferences screen & click OK.
Now open the TOOLS –> BOARDS –> BOARDS MANAGER
Search for ESP8266
Now you will find the package from ESP8266 Community.
Select the latest version from drop down & install it.
It takes a while & requires internet connection.
Once the package is installed ,you can see the list of boards under TOOLS –> BOARDS
Select the board as WEMOS D1 R1.
Select UPLOAD speed as 115200 &Programmer as USBASP
Now open the File –> Examples –> Basics –> BLINK sketch
No need to modify the sketch ,as we’re going to blink the built in LED (on the ESP chip , there is another LED on board which is mapped to pin14)
Click on UPLOAD
On some PCs you get a compile error ,stating that the file is being used by another process.
On some forums ,it is mentioned that the board is Duplicate .Its not the case, the reason is that some Antivirus program like McAfee does not allow the compilation process.
Open the Antivirus dashboard & TURN OFF the REAL TIME SCANNING for some time
You can also configure the Antivirus settings for an EXCEPTION to Arduino programs.
Now Upload the sketch.
Once the code is uploaded, you can see the built in LED blinking on the chip
Next code is a WIFI scanner which scans for nearby SSIDs & display the names of WIFInetworks with RSSI signal power &encryption mode.
For this we include the Header file ESP8266WiFi.h
This is installed along with the Boards Manager & is a very powerful library.
You can get more information on this library from here :
Many useful Functions are there for this WiFi library.
WiFi.mode (WIFI_STA);
The mode function of library is used to set the D1 board in STATION mode.
WiFi.scanNetworks();
scanNetworks function scans for nearby SSIDs & the result is an integer (number of surrounding WiFis) which is stored in a variable n
Then we print the SSID name,RSSI signal strength ( the lower the negative dB the stronger the signal), & Encryption mode (a * indicates SSID is password protected)
—————————————–
// D1 ESP8266 WiFi scanner
# include “ESP8266WiFi.h”
void setup () {
Serial . begin ( 9600 );
// set WiFi to station mode and disconnect from previous connection
WiFi.mode (WIFI_STA) ;
WiFi.disconnect ();
delay ( 100 );
}
void loop () {
Serial . println ( “Start Scanning ..” );
// scan for nearby WiFi SSIDs & save their number into n
int n = WiFi.scanNetworks ();
// in case no Network found , print info
if (n == 0 ) {
Serial . println ( “No SSIDs nearby seen…” );
}
else {
Serial . print (n);
Serial . println ( “WiFi network SSIDs nearby ….” );
// list all WiFi networks nearby
// name, signal strength and security method
for ( int i = 0 ; i <n; ++ i)
{
Serial . print (i + 1 );
Serial . print ( “:” );
Serial . print ( WiFi.SSID(i));
Serial . print ( “(” );
Serial .print ( WiFi.RSSI(i));
Serial . print ( “)” );
Serial . println (( WiFi.encryptionType (i) == ENC_TYPE_NONE)?”” : “*” );
delay ( 10 );
}
}
// Exit
Serial . println ( “” );
// pause for 15 seconds before new scan
delay ( 15000 );
}
Serial.println(“new client”);
while(!client.available())
{
delay(1);
}
String req = client.readStringUntil(‘\r’);
Serial.println(req);
client.flush();
if (req.indexOf(“/ledoff”) != -1)
{
status_led=0;
digitalWrite(LED,LOW);
Serial.println(“LED OFF”);
}
else if(req.indexOf(“/ledon”) != -1)
{
status_led=1;
digitalWrite(LED,HIGH);
Serial.println(“LED ON”);
}
String web = “HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n”;
web += “<html>\r\n”;
web += “<body>\r\n”;
web += “<h1>LED Status</h1>\r\n”;
web += “<p>\r\n”;
if(status_led==1)
web += “LED On\r\n”;
else
web += “LED Off\r\n”;
web += “</p>\r\n”;
web += “</p>\r\n”;
web += “<a href=\”/ledon\”>\r\n”;
web += “<button>LED On</button >\r\n”;
web += “</a>\r\n”;
web += “</p>\r\n”;
web += “<a href=\”/ledoff\”>\r\n”;
web += “<button>LED Off</button >\r\n”;
web += “</a>\r\n”;
web += “</body>\r\n”;
web += “</html>\r\n”;
client.print(web);
}
——————————————-
First of all, we include the ESP8266WiFi library, which will make available the functionality needed for the ESP8266 to connect to a WiFi network.Then we define the D2 pin as LED where an Led is connected.
#include <ESP8266WiFi.h>
#define LED D2
The SSID name & password are stored in char variables.
A WiFiserver object called “server “ is created & we pass the port 80 where the server will be listening ( 80 is the default port of HTTP)
WiFiServer server(80);
In the setup() function serial monitor is started at baud 115200 & the LED pin is declared as Output.
The begin() function of WiFi class is used with parameters ssid & password to start connection to WiFIi
WiFi.begin(ssid, password);
We wait till the WiFi.status() becomes WL_CONNECTED which indicates that connection is established .Until then we print a dot every 500msec.
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(“.”);
}
Once connection is established , an IP address is allotted to NodeMCU by your Router.We print the IP address using the localIP() function.
Serial.println(WiFi.localIP());
Inside the loop we create an object called client of class WiFiClient & assign the server.available() result (it returns true or false) to it.
WiFiClient client = server.available();
It waits for a client ( here a web browser is the client) to connect with.
Once a request is received , the client.readStringUntil (‘\r”) will read the request till it encounters a carriage return & assign it to a String variable req
String req = client.readStringUntil(‘\r’);
indexOf() function of String is used to find out ehether the request is ledoff or ledon.
if (req.indexOf(“/ledoff”) != -1)
The indexOf() function returns a –1 if no match found.
Accordingly the LED is made ON or OFF.
Now let us see how a HTML page is served to webbrowser when a client request is received
ode will be stored in strings that will be returned in the HTTP responses
we can declare it in a string and just return it when a HTTP request is performed on the desired URL.
String web = “HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n”;
web += “<html>\r\n”;
web += “<body>\r\n”;
web += “<h1>LED Status</h1>\r\n”;
First, we return the 200 HTTP code (OK code). Then, we need to make sure that we specify the return content as text/html, so the browser will know that it should be interpreted and rendered as such
Finally, we pass the string with the HTML/CSS code
The <html> element represents the root of an HTML document. All other elements must be descendants of this element .
The <body> tag specifies where the body of the document starts .
The <h1> tag specifies the Heading of Webpage
The <p> tag specifies a paragraph and thus we use it to indicate our description message.
web += “<a href=\”/ledon\”>\r\n”;
web += “<button>LED On</button >\r\n”;
The <a> tag allows us to create a hyperlink by specifying the URL of a page and the message of the hyperlink. So, in the href attribute we specify the URL we want the user to be redirected to, and between the two tags we specify the message of the hyperlink.
In this case, we are specifying a path in the current address, so we don’t need to put the IP and the port. So, when a user clicks the hyperlink, the browser knows it will need to redirect the user to
As we will see later, the paths we are specifying in the href will correspond to the paths where the NodeMcu will be programmed to return the corresponding code.
the <br> tag is just a simple line break between the hyperlinks.
One thing that is very important is that we are specifying the HTML code inside a string, and thus some details need to be taken in consideration.
First, in order to leave the code structured, we should split the declaration of the string in multiple lines. To do so, we need to put the double quotes in each line so the compiler will know that it should be considered as a single string. So, the outermost quotes of the previous code are not from the HTML but from the declaration of a string in multiple lines.
Finally, every quote that is part of the HTML code (for example, the quotes around the URLs in the <a> tag) needs to be escaped with the \ character. So, the \ characters we see before the quotes are also not part of the HTML code but rather the escaping mechanism.
The <button> tag allows for the definition of a clickable button. One of its functionalities allows us to specify a function that is executed when the button is clicked
web += “<button>LED Off</button >\r\n”;
Now upload the code & open the serial monitor
WiFi connection starts & displays IP if connection established.
Open your web browser & type in the IP you got from the serial monitor.
Once you click the Enter button , a CLIENT request is sent to NodeMCU.
Now the HTML page is served & buttons LED ON & LED OFF are displayed on the browser.
If you click LED ON button , the message string “ledon” is added to URL & sent to Nodemcu.
The string is read and accordingly the LED will be ON or OFF.
Here is another version of code where we use client.print() to serve the Webpage
———————————-
#include <ESP8266WiFi.h>
#define LED D2 // LED at GPIO4 D2