Friday, December 23, 2016

Sonoff special offer on banggood for WiFi Sonoff relay

Tthere is a special offer on SONOFF module on Banggood from today until 10th of January. You can buy the module for under $6, $5.99 ( 5.79 if you order it from mobile application).

The SONOFF module is produced by and can be used with their mobile app eWeLink or you can write your own software.

The core of the module is the ESP8266 and is connected to a 5V relay capable of 10A ( I will not bet on that)

I already ordered few of them and I am planning to put my own software so in the end I can :

-on/off the relay from my mobile app
-give a vocal command to trigger it on/off with Amazons echo dot 2 help
-set cron task for relay.

The promotion will end in January so if you are reading this post after this date it may be outdated ,but you can check the site.

Monday, December 19, 2016

Amazon's Echo DOT 2 controls ESP8266

Since Amazon's Echo Dot 2 can control the Belkin's WeMos why not emulate it with this Esp8266 .

ESP after is connected to the WiFi network will start an UDP server on address port 1900 and an HTTP server on its own IP address and port 80. Alexa on "Alexa, discover my devices " will send UDP on multicast address/port and the ESP will reply with its configuration (IP/PORT). 

Echo Dot 2 will get the setup.xml from ESP on provided IP and Port.

From now on the Echo cand send SendBinaryState command that will end up in trigger a GPIO.

SSDP protocol is used in the discovery part.

And a video controlling 2 GPIOs with on one ESP8266.

Original code is here:

Thursday, December 1, 2016

BMP280 and ESP8266

The BMP280 is the next generation sensor from Bosch and follows its predecessors BMP085 - BMP180.

Key parameters

  •  Pressure range 300 … 1100 hPa (equiv. to +9000…-500 m above/below sea level)
  •  Package 8-pin LGA metal-lid
  • Footprint : 2.0 × 2.5 mm², height: 0.95 mm
  •  Relative accuracy ±0.12 hPa, equiv. to ±1 m
  •  (950 … 1050hPa @25°C)
  •  Absolute accuracy typ. ±1 hPa  (950 ...1050 hPa, 0 ...+40 °C)
  •  Temperature coefficient offset 1.5 Pa/K, equiv. to 12.6 cm/K  (25 ... 40°C @900hPa)
  •  Digital interfaces I²C (up to 3.4 MHz) SPI (3 and 4 wire, up to 10 MHz)
  •  Current consumption 2.7µA @ 1 Hz sampling rate
  •  Temperature range -40 … +85 °C

Typical applications

  • Enhancement of GPS navigation
  •  (e.g. time-to-first-fix improvement, dead-reckoning, slope detection)
  •  Indoor navigation (floor detection, elevator detection)
  •  Outdoor navigation, leisure and sports applications
  •  Weather forecast
  •  Health care applications (e.g. spirometry)
  •  Vertical velocity indication (e.g. rise/sink speed)

For connecting the BMP280 to ESP8266 the following pins need to be connected: 

NodeMCU / WeMos D1 mini
Other ESP8266




The BMP280 supports the I²C and SPI digital interfaces; it acts as a slave for both protocols. 

The I²C interface supports the Standard, Fast and High Speed modes. 

The SPI interface supports both SPI mode ‘00’ (CPOL = CPHA = ‘0’) and mode ‘11’ (CPOL = CPHA = ‘1’) in 4- wire and 3-wire configuration. The following transactions are supported: Single byte write  multiple byte write (using pairs of register addresses and register data) single byte read multiple byte read (using a single register address which is auto-incremented) 

Connect the CSB pin to GND to have SPI and to VCC(3V3) for I2C.

The 7-bit device address is 111011x. The 6 MSB bits are fixed. The last bit is changeable by SDO value and can be changed during operation. 

Connecting SDO to GND results in slave address 1110110 (0x76), connecting it to VCC results in slave address 1110111 (0x77), which is the same as BMP180’s I²C address. 

The SDO pin cannot be left floating, if left floating, the I²C address will be undefined.

In my setup I've connected CSB and SDO to VCC to have I2C and 0x77 as address.

To run a quick test I've installed the Adafruit Sensor library and Adafruit BMP280 library .

The code to test the BMP280 is the example code from library.

This code assume that the SDA and SCL are connected on GPIO 4 and GPIO 5. If you need to assign new pins to your BMP280 use the Wire.begin(2,0) where the GPIO 2 is connected to SDA and GPIO 0 is connected to  SCL.

Now its time to add some code to read the temperature and pressure, post them to the and also update the temperature gauge on this blog.

 * Catalin Batrinu 
 * Read temperature and pressure from BMP280
 * and send it to

#include <Wire.h>
#include <SPI.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BMP280.h>
#include <ESP8266WiFi.h>

#define BMP_SCK 13
#define BMP_MISO 12
#define BMP_MOSI 11 
#define BMP_CS 10

Adafruit_BMP280 bme; // I2C
// replace with your channel’s thingspeak API key,
String apiKey = "YOUR-API-KEY";
const char* ssid = "YOUR-SSID";
const char* password = "YOUR-ROUTER-PASSWORD";
const char* server = "";
WiFiClient client;

 *   S E T U P
void setup() {
  Serial.println(F("BMP280 test"));
  if (!bme.begin()) {  
    Serial.println("Could not find a valid BMP280 sensor, check wiring!");
    while (1);
  WiFi.begin(ssid, password);
  Serial.print("Connecting to ");
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) 
  Serial.println("WiFi connected");  

 *  L O O P
void loop() {
    Serial.print(" *C");
    Serial.print(" P=");
    Serial.print(" Pa");

    Serial.print(" A= ");
    Serial.print(bme.readAltitude(1013.25)); // this should be adjusted to your local forcase
    Serial.println(" m");

    if (client.connect(server,80))  // "" or
        String postStr = apiKey;
        postStr +="&field1=";
        postStr += String(bme.readTemperature());
        postStr +="&field2=";
        postStr += String(bme.readPressure());
        postStr += "\r\n\r\n";
        client.print("POST /update HTTP/1.1\n");
        client.print("Connection: close\n");
        client.print("X-THINGSPEAKAPIKEY: "+apiKey+"\n");
        client.print("Content-Type: application/x-www-form-urlencoded\n");
        client.print("Content-Length: ");
    //every 20 sec   

Temperature logging

Sunday, November 20, 2016

ESP8266 adapter module fits LoRa Dorji module

Soldering the Dorji LoRa module is not so easy if you don't have soldering skills. But you can borrow this adapter board ($2.60 per 10pcs) from ESP8266 and its fits very well. Same pads distance, just few modification ( remove components) and a short on the back where the AMS1117 should be and that's it, we have a more practical module to work with. Don't forget to add a curly antenna.

Don't forget to relabel the edges with the Dorji's module values, since the labels will not be visible anymore.

Dorji's LoRa module on ESP8266 adapter plate

ESP8266 adapter plate
Back of ESP8266 adapter plate 

Monday, November 14, 2016

ESP8266-ESP201 Step-by-step Guide

This is a step-by-step guide to ESP8266-ESP201.

1.       Buy ESP8266-ESP201 with its hardware development kit from eBay, click here:

The development board is shown in photo below as well. You have a relay, buzzer, switches, LEDs, etc. to play with and test your code and to learn input/output functions of ESP8266:

2.       Connect the USB cable between your computer and the development board.
3.       Push the power button to check if power led is working and the board shows sign of life.
4.       Complete schematic of the development board is as follows:

5.       On the PCB near the DIP switch these are the values:
·         R - should be the RED led from the RGB connected to the IO15 pin. Putting the R DIP to ON will light RED if the GPIO15 is HIGH.
·         G - GREEN led from RGB led is connected to IO13. Putting the G DIP to ON will light GREEN if the GPIO13 is HIGH.
·         B - BLUE led from RGB led is connected to IO12. Putting the B DIP to ON will light BLUE if the GPIO12 is HIGH.
·         W - WHITE led located almost under RGB led is connected to the IO14 pin. Putting HIGH on GPIO14 and DIP switch ON will light the WHITE led.
·         J - relay pin connected to IO16 (which is always HIGH - I have no idea why. This behavior and the RED led that is not working can be because I have a bad board or the design for all the boards is wrong. Connecting the IO16 to GND (not recommended) will stop the relay, otherwise it will be ON all the time the J DIP pin is ON.
·         B - BUZZER connected to IO5 pin through B DIP switch. Having GPIO5 HIGH and B on DIP switch ON will prove that the buzzer is working.
·         K1 - I assume is connected to S2.
·         K2 - I assume is connected to S3.

6.       A schematic on a napkin will look like this one:

7.       ESP8266 comes with pre-installed AT commands, so you can check these to see if you get any response. The list of AT commands can be found here:

To test the AT commands, you need to have a program like “Hyper Terminal”. The easiest and recommended way is to install Arduino from here which has a built-in serial monitor through which you can send and receive data.

Once you have downloaded and installed Arduino, you can now run it and it will look like this:

Now click File menu and then select Preferences. It will look like this:

Now add the link below in the “Additional Boards Manager URLs” because ESP8266 board is not included in Arduino by default.

Click OK button.

Now click Tools menu and select Board. Our board in this case will Generic ESP8266 Module. Your screen should look like this:

Now click Tools menu again and select Port from the list of available ports. Your screen should look like this:

Now if you have set everything corrected (i.e. (a) USB connection between ESP8266 development board and computer, (b) Settings in Arduino software) then you are ready to type AT and send AT commands to your ESP8266 and be excited to see “OK” response from your chip. When you send AT to your ESP8266, it will respond you with OK.

Click Tools menu and select Serial Monitor or press on your keyboard Ctrl+Shift+M to open serial monitor where you can send and receive AT commands from serial interface. Make sure you select (a) “both NL and CR” for both new line and carriage return, (b) correct baud rate (e.g. 115200 baud). Your screen should look like this when you ready to send AT commands:

8.       If you have been successful so far, you can be sure that your ESP8266 and its development board and communication between your computer and development board – all is working fine!
9.       Now you want to know how to control GPIO pins by yourself. For that, click File menu, select Examples, select ESP8266WiFi, and then select WiFi WebServer. Your screen should look like this:


A new window with WiFi webserver example will open (as shown above in left screenshot). Now edit this file by typing in your WiFi SSID and password. Save the example with another filename and then press upload button to start code compilation and upload to the ESP8266. This will fail. To be successful you need to perform a few more steps.

10.   Turn the board off; Ground the IO0 pin; Set K2 to Ground (ON); Power on the board; and Set K2 to OFF.
11.   Now press Ctrl+Shift+M to open Serial Monitor and then click upload button again, if it fails or shows error close Arduino and open Arduino again and press upload button. It will upload successfully – at least it did it for me! J
12.   Now you will see in Serial Monitor window that your ESP8266 is now connected to your WiFi network and shows an IP address from where you can control IO2 to be 1 or 0.
13.   Connect LED to IO2 and Ground. Go to the given IP address in Serial Monitor (say, and turn on/off LED like this:

14.    The pinouts of ESP8266-ESP201 look like this:

Helpful resources:



Guest post by: Ahmed Hussain