DIY Projects

Connecting an ESP8266 to Blynk on WiFi with Johnny-Five (Firmata WiFi)

level advanced

In the previous tutorial, we discovered the Johnny-Five framework that allows to create connected objects (and more) based on Arduino, Raspberry Pi (or Orange Pi) in Javascript. Johnny-Five is also a very good solution to replace the GPIO of an Orange Pi by an Arduino Nano v3. In the previous tutorials, we used an Arduino connected to a USB port. In this tutorial, we will use the WiFi Firmata (StandardFirmataWiFi) available from the Arduino IDE which allows you to communicate with an ESP8266 in Wi-Fi.

Why not use the Firmware Serial UDP project?

If you do an internet search with the ESP8266 Johnny-Five keywords, you will also find this Serial UDP firmware project. This firmware is available in the form of a binary which installs with of Espressif (read this article for more information). You will first need to install Python 2.7 on your computer. I have encountered difficulties connecting to an ESP8266. This is probably a configuration error. Since the source code is not offered on GitHub (or another platform), I advise you to use the firmwareWiFi that works very well. It is simpler to install and is fully configurable.

Install the StandardFirmataWiFi firmware on the ESP8266

The StandardFirmataWiFi firmware provides access to all Arduino features via a TCP serial link. It is compatible with Arduino shields, Shield 101, MKR1000 boards and all ESP8266. For example, you can add an ESP-01 to an Arduino Uno, which is much cheaper than a WiFi Shield.

Connect the ESP8266 to the computer and open the Arduino IDE. In the examples menu you will find a submenu named Firmata. Select the StandardFirmataWiFi firmware.

By default, debugging is disabled. Look for the line containing the string #define SERIAL_DEBUG and remove comments (//).

Then go to the wifiConfig.h file to configure the connection parameters

The configuration is complete. Upload the program, it’s over!

To verify that everything is correct, open the 9600 baud serial monitor. You can also retrieve the IP address of the ESP8266 if you have not set it.

Example: driving a led, reading a BMP180 in WiFi

Let’s go to the test now. We will take the previous example and adapt it to the new configuration.

Necessary material

Wemos D1 Mini
5V/3A micro-usb power supply
220Ω resistor
Jumper Dupont


The LED is connected to pin D3 (GPIO-0). On the Wemos D1 mini, the I2C bus (SDA – D2, SCL – D1).

Javascript code

To establish communication with the ESP8266 we will install the npm etherport-client package (package page)

sudo npm install firmata etherport-client

After the installation is complete, create a new

cd ../..
cd nodebot
nano j5ESPDemo.js

At the beginning of the script, we will initialize the object that you allow us to establish the serial connection with the ESP8266 in WiFi

var EtherPortClient = require("etherport-client").EtherPortClient;

To connect to the ESP8266, just create an EtherPortClient object. This object requires two parameters, the IP address of the ESP and the port.

var board = new five.Board({
  port: new EtherPortClient({
    host: "",  // IP ESP8266
    port: 3030                
  timeout: 10000,
  repl: false

For the rest, the programming is perfectly identical to the previous tutorials.

Why is the npm Firmata package not used?

On the internet, you will find many tutorials that establish communication through the Firmata package. This package allows you to control the GPIO of the Arduino in javascript. This is also the goal of the Johnny-Five framework. The complete API for managing the board is detailed here. In my opinion, it is therefore not necessary to add this “over-layer” to your projects. I did not encounter any difficulties communicating in I2C with the BMP180 and driving the GPIO from the Blynk application.

ESP8266 + Johnny-Five + Blynk

Let’s go one step further by integrating the ESP8266 into Blynk. Thanks to Johnny-Five you will not have any programming to do on the ESP8266. If you’re starting out with Blynk, start here. Here is a diagram showing the architecture of the system. Everything happens in WiFi:

Project Bl- ynk

Create a new project and add:

Javascript code

Paste the project code into a new script by changing the following parameters:

var Blynk = require('blynk-library');
var five = require("johnny-five");
var EventEmitter = require('events').EventEmitter;
var EtherPortClient = require("etherport-client").EtherPortClient;

var AUTH = 'b065eb0a6e36434da42367b3fa7c3340';  // Remplacer par votre Token Blynk - Replace by your Blynk Token

var event = new EventEmitter();                 // Evenements javascript - Javascript Events
var DEBUG = true; //false;                      // Active les messages de mise au point - Activate debug message

// Setup Blynk
var blynk = new Blynk.Blynk(AUTH, options = {
  // Connecteur au serveur Blynk local - Local Blynk server connector
  connector : new Blynk.TcpClient( options = { addr:"IP_SERVEUR_BLYNK", port:8442 } )

var V0 = new blynk.VirtualPin(0);  // Temperature
var V1 = new blynk.VirtualPin(1);  // Barometer
var V2 = new blynk.VirtualPin(2);  // On/Off led
var temp, pa;

blynk.on('connect', function() { console.log("Blynk ready."); });
blynk.on('disconnect', function() { console.log("DISCONNECT"); });

// update host to the IP address for your ESP board
var board = new five.Board({
  port: new EtherPortClient({
    host: "",
    port: 3030
  timeout: 10000,
  repl: true,
  debug: true

board.on("ready", function() {
  var led = new five.Led(0);

  var bmp180 = new five.Multi({
    controller: "BMP180",
    freq: 5000

  bmp180.on("change", function() {
    console.log("Temperature BMP180   ", this.thermometer.celsius, "°C");
    console.log("Atm. Pressure BMP180 ", this.barometer.pressure * 10 , "hPa");
    temp = this.thermometer.celsius;
    pa = this.barometer.pressure * 10;

  board.on("exit", function(){
  event.on('V2', function(param){
    if ( param == 1 || param == true ) {
      if ( DEBUG ) { console.log("Start strobe led"); }
    } else {
      if ( DEBUG ) { console.log("Stop strobe Led"); }


setInterval(function() {
  if ( temp != undefined ) {
    if ( DEBUG ) { console.log('Temperature:', temp + ' C'); }
  if ( pa != undefined ) {
    if ( DEBUG ) { console.log('Humidity:   ', pa    + ' hPa'); }
}, 5000);

V2.on('write', function(param){
  if ( DEBUG ) { console.log("V2 ", param); }

Save with CTRL + X then Y and then run the script  node j5ESPDemo.js

node j5ESPBlink.js 
Connecting to TCP: 8442
1491226899573 SerialPort Connecting to host:port:  
1491226899605 Connected Connecting to host:port:  
Blynk ready.
1491226905821 Repl Initialized  
Temperature BMP180    20.9 °C
Atm. Pressure BMP180  983.7 hPa
V0  [ '1' ]
Start strobe led
Temperature BMP180    20.9 °C
Atm. Pressure BMP180  983.67 hPa
V0  [ '0' ]
Stop strobe Led
Temperature BMP180    20.9 °C
Atm. Pressure BMP180  983.63 hPa

As you can see in this photograph, the Wemos works on battery (1100 mAh). This is not an ideal situation because you can not take advantage of the ESP8266 standby. This is a good example of architecture that could be set up to develop a remote control.

Here, by installing the StandardFirmataWiFi firmware we cut the cord between the computer (or the mini PC Raspberry Pi …) and the ESP8266. In a few lines of code, it is very simple to drive or recover measurements from an ESP8266 in WiFi.

Click to rate this post!
[Total: 0 Average: 0]
Exit mobile version