Raspberry Pi and GSM network- sending SMS, connecting to the Internet (IoT)

This time I’m going to connect to our Raspberry Pi a GSM module. Why? Internet of Things, in short IoT, as it was noted at Krakow’s PLNOG17  by Marcin Aronowski involves and depends on the network which should be easily accessible, and the very essence of IoT is the energy efficiency. Perhaps, he said, 3G will go away but 2G but will still remain. And we do not huge pipes – just enough bandwidth. 2G connection is still the cheapest in the implementation (also due to the cost of the module and a SIM card).

Therefore, I will try to show you how easy it is to connect very cheap GSM module Neoway M590 . It is a simple device that is a GSM modem (2G).

We will learn how to send an SMS and how to connect to the Internet.



  • software: picocom, gammu, ppp (accessible via standard Raspbian’s repository)
  • turning off the console redirection to serial port on Raspberry Pi


  • Raspberry Pi – 1B, 1A, 2B, 3B, Zero – any model with installed Raspbian (mini version is enough)
  • Neoway M590 GSM module – preferably without extra letters at the end – get a version with everything soldered and 2×7 pins
  • Multimer for voltage and power supply check for GSM module
  • Optional: DC-DC step down converter – at least rated 2A, usually allows using 5-24V on input and keeping stable 3,9V at output – used to power the GSM module

    DC-DC step down module
    DC-DC step down module

Let’s begin!

I chose the Neoway M590 GSM modem module, because it is a bit underestimated – and one of the most important things is to have proper and stable power supply. Module is not as popular as SIM800/SIM900, but – it’s very, very cheap, and after few months of trails on two modules I can say it’s stable.

Please remember, in most cases the correct voltage is 3,7-3,9V, and power rating needs to be minimum 2A.

Connecting to Raspberry Pi

Neoway GSM module has a serial port – this is the standard way to talk – via connections TX, RX. However, the default serial port on Raspberry Pi is occupied by the system console – so if you connect our module to Raspberry’s serial port you will get overflow of text data. Edit the Raspberry Pi file /boot/cmdline.txt and remove the part console=/dev/ttyAMA0,115000. Yo can us it after reboot.
Connect the DC-DC step down power converter – you can also use a battery from an unused smartphone or battery type 18650 – provided that it has a rating of 3.7V – Li Poly or Li Ion battery. If you use are using smilar DC-DC converter as on the picture – with adjustable resistor – use a screwdriver when powered with no load, connect a multimeter and turn as long as the voltage suddenly begin to fall – the set 3,9V. Now connect the GSM module and verify the voltage – sometimes cheap module does not provide stable power supply under load – as a result we have a voltage drop that must be corrected. Do the final adjustment VERY carefully – do not damage the GSM module. Here is the power scheme and the connection to the Raspberry Pi. Diagram shows the version with 2×7 pin connector plates on Neoway M590 facing the SIM card:

Schema: RPI - Neoway M590
Schema: RPI connected to Neoway M590 GSM module
Neoway M590 connection
Neoway M590 connection

As you can see this is not hard to wire, please remember the GND connections. Neoway M590 needs GND connected to BOOT to start, hence the “extra” connection to the GND of the system. Again the connections from the view of the SIM card slot:
After inserting the SIM card powering the module – the first LED should lit red, and the second should bling to indicate the GSM network connections. Here’s the final view:

The Raspberry Pi with GSM M590 module
The Raspberry Pi with GSM M590 module

Sending first SMS

To get to now the module – you will need to install this:

sudo apt-get install picocom

then issue on the console:

pi@rpi ~ $ picocom --baud 115200 /dev/ttyAMA0
picocom v1.7

port is        : /dev/ttyAMA0
flowcontrol    : none
baudrate is    : 115200
parity is      : none
databits are   : 8
escape is      : C-a
local echo is  : no
noinit is      : no
noreset is     : no
nolock is      : no
send_cmd is    : sz -vv
receive_cmd is : rz -vv
imap is        :
omap is        :
emap is        : crcrlf,delbs,

Terminal ready

You can exit picocom by CTR+A then Q.
At the very end, in line 21, I’ve entered the command “AT” and M590 answered “OK”. This means that we have properly (proper TX and RX) connected console. The AT commands with parameters are the natural language of modems – the old “analog” and the new GSM modems. If you’re getting “weird” characters – it’s the bad speed, and if we see what you write – it means that you haven’t deactivated the system console redirection to a serial port yet (in that case – please see above). Let’s see those commands in detail..

Let’s send the first SMS, first by picocom, and later “automatically” via gammu:

pi@rpi ~ $ picocom --baud 115200 /dev/ttyAMA0
picocom v1.7

port is        : /dev/ttyAMA0
flowcontrol    : none
baudrate is    : 115200
parity is      : none
databits are   : 8
escape is      : C-a
local echo is  : no
noinit is      : no
noreset is     : no
nolock is      : no
send_cmd is    : sz -vv
receive_cmd is : rz -vv
imap is        :
omap is        :
emap is        : crcrlf,delbs,

Terminal ready
+CSMS: 1,1,1

> "To is TESTING. A SMS that is!"
+CMGS: 46


What happened here ? First we setup the modem to send SMS via GSM, then you need to change the “601xxx555” to a proper number for the recipient of the SMS. Next we will get the > sign – this is where you enter your SMS. To send it – press CTRL+Z. After 3-4 seconds you should get: “+CMGS: 46” and “OK’. Check your phone!

To use it with other software and use it wisely – we can use the gammu, that allows single line SMS:

sudo apt-get install gammu

Then edit the gammu’s config:

sudo pico /etc/gammurc

insert just this:

device = /dev/ttyAMA0
connection = at115200

And now send your SMS like that:

pi@rpi ~ $ gammu sendsms TEXT 601xxx555 -text "To is TESTING. A SMS that is!"

Easy, ain’t it ?

Connecting to the Internet

Our module enables data transmission in GPRS mode. Combining that with the fact that we are @ 115kbps serial link, allows us to use the GPRS. Don’t forget – this is suited the task of running IoT solution, and not to use the browser in graphics mode (yet lynx, links or elinks do work without problem)
Let’s install the program to connect to the Internet. The ‘ppp’ will negotiate connection using a GSM modem, set ppp0 and append DNS entries, as well as the default route:

sudo apt-get install ppp

Create a file:

sudo pico /etc/ppp/peers/m590-gsm-internet


# the script - standard to use
connect "/usr/sbin/chat -v -f /etc/chatscripts/gprs -T ****"
 # Our serial port
# The speed of the serial port.
# Get the IP address from ISP.
# Also get DNS entries
# Set the route as default to the Internet
# pppd will reconnect after disconnection
# Don't auth the remote site
# No need to check hardware flow on serial port
# No need to send control lines for modem

Checkout the gprs file from chatscripts – it should be exactly like this:

# You can use this script unmodified to connect to cellular networks.
# The APN is specified in the peers file as the argument of the -T command
# line option of chat(8).

# For details about the AT commands involved please consult the relevant
# standard: 3GPP TS 27.007 - AT command set for User Equipment (UE).
# (http://www.3gpp.org/ftp/Specs/html-info/27007.htm)

ABORT           BUSY
ABORT           VOICE
ABORT           "NO CARRIER"
ABORT           "NO DIAL TONE"
ABORT           "NO ANSWER"
ABORT           "DELAYED"
ABORT           "ERROR"

# cease if the modem is not attached to the network yet
ABORT           "+CGATT: 0"

""              AT
TIMEOUT         12
OK              ATH
OK              ATE1

# +CPIN provides the SIM card PIN
#OK             "AT+CPIN=1234"

# +CFUN may allow to configure the handset to limit operations to
# GPRS/EDGE/UMTS/etc to save power, but the arguments are not standard
# except for 1 which means "full functionality".
#OK             AT+CFUN=1

OK              AT+CGDCONT=1,"IP","\T","",0,0
OK              ATD*99#
TIMEOUT         22
CONNECT         ""

That’s it. Connect to the internet using:

sudo pon m590-gsm-internet

Check the logs in separate console (i.e.: tail -f /var/log/syslog)

Oct  8 23:23:13 rpi pppd[17390]: Connect: ppp0  /dev/ttyAMA0
Oct  8 23:23:13 rpi ifplugd(ppp0)[17403]: ifplugd 0.28 initializing.
Oct  8 23:23:13 rpi ifplugd(ppp0)[17403]: Using interface ppp0/00:00:00:00:00:00
Oct  8 23:23:13 rpi ifplugd(ppp0)[17403]: Using detection mode: IFF_RUNNING
Oct  8 23:23:13 rpi ifplugd(ppp0)[17403]: Initialization complete, link beat detected.
Oct  8 23:23:14 rpi ifplugd(ppp0)[17403]: Executing '/etc/ifplugd/ifplugd.action ppp0 up'.
Oct  8 23:23:14 rpi ifplugd(ppp0)[17403]: client: Ignoring unknown interface ppp0=ppp0.
Oct  8 23:23:14 rpi ifplugd(ppp0)[17403]: Program executed successfully.
Oct  8 23:23:14 rpi kernel: [701282.272157] PPP BSD Compression module registered
Oct  8 23:23:14 rpi kernel: [701282.284205] PPP Deflate Compression module registered
Oct  8 23:23:16 rpi pppd[17390]: local  IP address
Oct  8 23:23:16 rpi pppd[17390]: remote IP address
Oct  8 23:23:16 rpi pppd[17390]: primary   DNS address
Oct  8 23:23:16 rpi pppd[17390]: secondary DNS address
Oct  8 23:23:17 rpi ntpd[779]: Listen normally on 11 ppp0 UDP 123
Oct  8 23:23:17 rpi ntpd[779]: peers refreshed
Oct  8 23:23:18 rpi dnsmasq[6117]: reading /var/run/dnsmasq/resolv.conf
Oct  8 23:23:18 rpi dnsmasq[6117]: using name server
Oct  8 23:23:18 rpi dnsmasq[6117]: using name server
Oct  8 23:23:18 rpi dnsmasq[6117]: using name server
Oct  8 23:23:18 rpi dnsmasq[6117]: using name server

It works Check the ifconfig output:

ppp0      Link encap:Point-to-Point Protocol
          inet addr:  P-t-P:  Mask:
          RX packets:8 errors:0 dropped:0 overruns:0 frame:0
          TX packets:9 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:3
          RX bytes:116 (116.0 B)  TX bytes:191 (191.0 B)

Turning off is also easy:

sudo poff m590-gsm-internet

Logs will show:

Oct  8 23:26:40 rpi avahi-daemon[539]: Withdrawing workstation service for ppp0.
Oct  8 23:26:41 rpi ntpd[779]: Deleting interface #11 ppp0,, interface stats: received=0, sent=0, dropped=0, active_time=204
Oct  8 23:26:41 rpi ntpd[779]: peers refreshed

That’s it – please remember that data plan can be costly. Check your data plan!

Domoticz part 6: Water/Rain/Snow/ sensor FC-37 using ESPEasy (digital)

Rain/Snow/Water detection system
Rain/Snow/Water detection system

We return today to the simple and quick solutions! The weather station or irrigation/sprinkler system – can’t operate without proper detection of rain, water or even snow. Let’s use the FC-37 sensor (also know as YL-38 or MH-RD, or just similar to the picture)

What will you need?

  • rain sensor type FC-37/MH-RD (rain drop/snow sensor) – must come with D0 pin, price around $0.50 to $1.50
  • ESPEasy working on ESP8266 from the previous entries

Installation and configuration

The sensor must be connected to the power supply + 3.3V (3V) and GND of the ESP8266 running ESPEasy. Next we connectthe D0 pin to the selected pin our ESPEasy – which is going to notify Domoticz using IP. Let’s use free GPIO-12 (pin D6 on the NodeMCU v2 board). This sensor also has an analog output – which allows for more advanced detection of rain, and we will deal with in the future.
Finally – we connect the rain sensor plate with  the sensor module that is connected to ESP8266:

New virtual switch
New virtual switch – for the rain or no rain information in domoticz

Check in the Devices section the IDX number – it’s 543 in this example:

Device IDX for rain sensor
Device IDX for rain sensor

Next – let’s configure via WWW interface our ESPEasy software – selecting the “Switch Input”, entering correct IDX and setting some options  – please do mind the “Inversed”, and of courser the correct value of IDX:

Config and setup
Config and setup

Let’s test our sensor! For this purpose you should set the sensor using Philips screwdriver just so that the green LED still does not glow when we apply only dry finger plate (blue cube with white “screw”):

Rain drop sensor

Rain drop sensor setupIf the sensor is correctly adjusted we should get the green LED to glow right after dropping some water on the sensor plate:

Of course, when the device is installed outside, the seonsor is protected – we need to re-set it so as not to react not to dew, but the rain or snow.
Domoticz should show us this swithc in the following way:
When there is no rain:

Rain stopped
Rain stopped

And when it rains:

It is raining
It is raining

That is it!

Domoticz part 3.1: ESP Easy on ESP8266 – remote and local OLED display with temperature, humidity, light – weather station

Previously we played around the SSD1306 OLED display as side display for Raspberry Pi. The author of ESP Easy – Richard ten Klooster (https://github.com/ESP8266nu/ESPEasy) – recently updated his project to include new sensors, so today we will update our DHT22 enabled remote sensor for Domoticz with display and light metering. Our weather station will get a remote display.

I’ve created such bundle of sensors to allow both temperature and humidity measurement small shack for chopped wood but also to light the way to it after dark via LED lamp. Also I was interested in stability of ESPEasy with DHT22, BH 1750 and OLED I2C display.

What will you need?

Software & Hardware

Let’s do it!

Connecting the display is very easy – event if you didn’t the previous example for Raspberry Pi. After logging in to ESP – ESPEasy – we choose the PINs that will work as I2C bus. This example uses the default: GPIO 4 & 5. Let’s connect our display to +3,3V, GND, and SDL & SCL to GPIO 4 & 5. The configuration is as follows:

ESP Easy - SSD1306
ESP Easy – SSD1306

Pay attention – this is how the sensor was called and the values that we defined – we need to enter them again just the same for the display for ESPEasy to get data and to display them correctly:

ESPEasy DHT22 - config
ESPEasy DHT22 – config

The first value is the address on the I2C bus – to find out if we have correct one go to Tools->I2C Scan, which gives you the address – and notice that example shows another – connected to the I2C bus sensor – Lux – BH1750.:

ESP Easy - Scan i2c
ESP Easy – Scan i2c

Out address is (hexadecimal): 0x3c!
If all is correct – we should see “ESPEasy” on the screen (upside down is still fine).

Next – we move to display configuration – direction, which line are used for displaying – but first let’s try to display some data from external source:

Remote and local display

ESPEasy allows you to display both local sensor dana or any other data via unprotected method – using just http URL.
What is possible – first we can turn on/off the display. In this example the IP address of ESP8266 running ESPEasy is We can turn off the display (i.e. it’s too bright in the night),off

Then to turn in on:,on

Clearing the display:,clear

Now, to us it in our project – we should use the curl to send data from Raspberry Pi:


An example:


Finally, we will use this function to display data from other sensor that our Raspberry Pi has data of – the opposite of what we usually use the ESP for!

But first – we should get the data from our already connected DHT22 and lux sensor. Let’s type the name of our sensor in Line 1. The Line 2 could hold the info about uptime – and time – we know that device is working and has proper communications with NTP.

Where to set NTP ? Go to NTP in Tools and choose your favourite NTP server – i.e. pool.ntp.org.
We got time & uptime – that’s easy. Displaying variable takes more effort – we need to use the percentage as brackets (%). Take a peek at Wiki page for examples.
We’re ready to display the data from DHT22. It’s time to check what was it’s name in the configuration:

ESPEasy DHT22 - config
ESPEasy DHT22 – config

– and here it’s name is: AmicaTempHum. It’s a bit different we need “[ ]”, and the variables (we have two of them when talking to DHT 22) are separated by (#): [AmicaTempHum#Humidity]. This time the “%” is used to tell you that humidity is in % – so it’s supposed to be displayed.

The same approach should be used for temperature. Since by default we set 300 seconds of update time – we should get on the screen, after a while:

ESP8622 with SSD1306 (OLED) display working on ESPEasy
ESP8622 with SSD1306 (OLED) display working on ESPEasy

OPTIONAL: Since we can have quite a lot devices on I2C bus – let’s connect in paralel lux meter – BH1750. Meaning: VCC 3,3V to VCC, SDA & SCL to SDA & SCL finnaly GND to GND. Just like DHT22 it needs tiny amounts of power so the Amica NodeMCU can handle it safely. If we connected it properly we should get this info:

ESP8622 with SSD1306 (OLED) display, DHT22, BH1750 under ESPEasy
ESP8622 with SSD1306 (OLED) display, DHT22, BH1750 under ESPEasy

So, next photo show how much light I’m using here:

ESP8622 with SSD1306 (OLED) display, DHT22, BH1750 under ESPEasy

Beware – if you’re getting values like 54612 lux – the sensor is NOT working properly (check connections).

This is it – domoticz needs to be updated with new virtual Lux sensor (the virtuals for DHT22 have been added last time). So what to do with light intensity sensor ? Using the same approach as with the script for opening garage – we can turn on some LED lamps if it gets dark enough. Or use ‘Events’ in domoticzu if you like GUI approach.

But wait! People commenting this brought up interesting idea:

Displaying other values FROM domoticz on remote sensor

Looking at our example we see that Line 7 is empty. Originally I wanted to add the baraometer, but the shop canceled the order. I have other one on RPi – so why not use this data – atmospheric pressure cannot be that different, right? The BMP180 gives me temperature and pressure in hPa. I don’t care about the temperature, but the pressure is interesting. Since we already brought up the garage exampe  you might remember that a LUA script w domoticz can give you data and allows you to use it:

  • we need to get the pressure data
  • cut it (remove extra info)
  • display it on SSD1306 attached to ESP8266

The LUA script will use the round function – single digit, and will be launched every minute (or smarter – at any change then if with devicechanged) – so let’s use the time option.
In my system this sensor is named ‘TemperaturaCisnienie’ so remember the name of the script has to match it:


IP address needs to mathc you network and script goes to /home/pi/domoticz/scripts/lua:

function round(num, idp)
 local mult = 10^(idp or 0)
 return math.floor(num * mult + 0.5) / mult
commandArray = {}
commandArray['OpenURL']=',7,1,Baro:'..hektopaskale..'hPa '
return commandArray

NOTE: Newer version of ESP Easy (inscluding ESP Easy Mega), use “oled” instead of “oledcmd”, as it was noted by one of the commentators.

So after a while you will get pressure on the screen.

Another example from comments discussion:
I you have the termometer from previous example about attaching termometers to domoticz – corresponding script is here (remember about the name!)

local NazwaCzujnika="ZKominka"
commandArray = {}

if devicechanged[NazwaCzujnika] then
return commandArray

This time we only update on temperature CHANGE.

BME280 in Domoticz – updating the sensor data via Python

[Update: 30.07.2017 – as of now – latest stable domoticz version supports BME280, so this is now obsolete! The Hardware menu has now I2C Sensors and BME280 is present in submenu]
This is a modification of: https://bitbucket.org/MattHawkinsUK/rpispy-misc/raw/master/python/bme280.py, which after you change the IP address and port of Domoticz in ip_domoticz, and creating dummy sensor in Domoticz – “Temp+Humi+Baro” – and then changing the IDX to it’s value in: idx_dummy_bme280 – will update the sensor with the same data as you can see while running the program. This program will update Domoticz via JSON.
Continue reading BME280 in Domoticz – updating the sensor data via Python

Domoticz part 4: connecting the DS18b20 thermometer

Temperature readout is one of the first sensor we add to domoticz. It’s a very simple task and allows to connect multiple thermometers via the 1-wire bus. 1-wire means that thermometer has a single data wire, on top of VCC and GND. This wire is used to send back data to 1-wire controller and then it gets verified.

Termometr DS18b20
Thermometr DS18b20

What will you need?


  • thermometer DS18B20 (Dallas) – comes in variety of housings – usually it’s a chip with 3 pins. It’s good to measure from -55 degrees Celsius and up to +125, but it’s accurate till about +95 – +100.
  • 4,7kOhm resistor – used to pull up to VCC the data pin
  • Raspberry Pi (any model – A, B, B+, 2, 3 or new Zero)


  • domoticz – the same we installed in part one

Let’s do it!

This thermometer is able to perform very well on a long cable, being powered just by RPi using the PIN +3,3V. It’s OK to get 20 meters of calbe with 5 such thermometers, to check on recuperator and chimney. Recuperator has 2 inputs and two outputs – this allows to use the ‘custom’ mode of drawing the temp graphs to check on it’s performance.
Now first thing is to change the way our Wheezy or Jessie Raspbian starts. Add to /boot/config.txt this line:


Now reboot RPi and connect the thermometer – add the 4,7kOhm resistor between the (red) data pin and the +3,3V (white) – just like on the first picture. This will make the signal crisp & clear on the 1-wire bus. The GND is using (blue) cable. All set? Connect to Raspberry Pi in this way:

Connecting Dallas DS18b20 to Raspberry Pi
Connecting Dallas DS18b20 to Raspberry Pi

Pin +3,3V to +3,3V, Pin Data (the middle on the thermometer) to GPIO#4 on RPi, and GND to GND of RPi (blue). If you have more (i.e. 5) connect them in parallel.
Now – let’s use console to find out if RPi can see the thermometer on the 1-wire bus:

cat /sys/bus/w1/devices/28-*/w1_slave

Now you should get RAW readout of the temperature – this example shows the real system with 5 thermometers:

3d 01 4b 46 7f ff 0c 10 75 : crc=75 YES
3d 01 4b 46 7f ff 0c 10 75 t=19812
3b 01 4b 46 7f ff 0c 10 e6 : crc=e6 YES
3b 01 4b 46 7f ff 0c 10 e6 t=19687
39 01 4b 46 7f ff 0c 0c 5e : crc=5e YES
39 01 4b 46 7f ff 0c 0c 5e t=19562
35 01 4b 46 7f ff 0c 10 5f : crc=5f YES
35 01 4b 46 7f ff 0c 10 5f t=19312
26 02 4b 46 7f ff 0c 0c b7 : crc=b7 YES
26 02 4b 46 7f ff 0c 0c b7 t=34375

You should expect just one entry for single thermometer. The part crc=xx YES – tells you that we have good readout.
All that’s left is to add the 1-wire to domoticz, using: Settings->Hardware:

Adding 1-wire to Domoticz
Adding 1-wire to Domoticz

Our themometer(s) will be at once visible via Settings->Devices:

Dallas tehrmometers DS18b20 in Domoticz (1-wire)
Dallas tehrmometers DS18b20 in Domoticz (1-wire)

This is really all – add them to make’em visible in Temperature tab!

Domoticz part 3: ESP Easy – quick and easy sensor for weather station using ESP8266

ESP8266 has become so popular that a beginner can choose from multitude of projects/firmwares and then – just start using them. Advanced IoT adopters will praise it’s quick implementation and stability. Today we will check out the Richard Ten Klooster’s project ESPEasy – https://github.com/ESP8266nu/ESPEasy. Basically ESPEasy is a firmware that can be flashed onto ESP8266 – preferably ESP-12E or ESP-12F and right after boot – we can join it’s WiFi access point (AP) to configure it via web interface. No console needed. Then, it is as easy as adding sensors (can be multiple) and ESPEasy starts to upload the data to Domoticz. The WiFi networks to connect to is named ESP_01XYZW, we should use “configesp” as WPA password and point our browser to

TL DR; If you ever wanted to use ESP8266 but it was too complicated – ESPEasy is the right tool for you and great remote sensor for weather station

What will you need ?

ESPEasy requires at least ESP8266, best if it’s the ESP-12E or ESP-12F version. To make it even more easy – take a look at ready prototype boards with ESP8266, they have gold pins, own power supply that uses 5V/micro USB. This allows you to re-use old phone charger or powerbank with USB output. Let’s choose for this project a very nice and precise sensor – DHT22, that gives you temperature and humidity. Advanced users can simply get a ESP-12E, solder cables and use classic VCC of 3,3V.
Putting the software is also very easy – flash a */bin file, but I will get you through (optionally) full compilation & build phase. This might come in handy for testing newer version of EasyESP. YOu will need to download and install Arduino Studio, libraries and ESP Easy source, build it and flash it.


  • I choose the NodeMCU (2.0) with ESP-12E V2 (search for: Amica NodeMCU in your favorite online shop)
  • DHT22 sensor

    ESP8266 na NodeMCU Amica Board z czujnikiem DHT22
    ESP8266 na NodeMCU Amica Board z czujnikiem DHT22
  • jumper cables
  • one 4,7k up 10k Ohm resistor
  • OPTION: Raspberry Pi – used to flash, debug – also for console


  • the easy path: ready ESPEasy firmware (*.bin file)
  • the optional, interesting path: Arduino Studio – exactly 1.6.5 version
  • sources from ESP Easy

OPTIONAL: Building the ESPEasy firmware

Let’s look at our ESP8266 board – we can now flash it with firmware that we can build from sources or flash the bin. As our polish commenter noticed (huczas) – we can use the 078 (or 120) version, that has three distinct versions for different size of the flash in tour ESP8266. Since we have NodeMCU – we use the “biggest” file. In case this doesn’t work for you – use the installed Arduino IDE in specific version – 1.6.5. This is a IDE software that is capable  (but of course not limited to) of compiling – building firmware for ESP ESP8266. Let’s install (MS Windows, Linux) exactly this version 1.6.5: https://www.arduino.cc/en/Main/OldSoftwareReleases#previous.
But why 1.6.5 ? IT’s suited to support our board and will work with this tutorial.

Arduino IDE
Arduino IDE

So let’s download now the board description for the IDE to understand what we will be building for: enter in preferences the Additional Boards Manager URLs:

Arduino IDE - preferencje
Arduino IDE – preferences and the field to enter URL

Type into “Additional Boards Manager URLs:” address: http://arduino.esp8266.com/stable/package_esp8266com_index.json that holds the ESPEasy 2.0.0 definition – Then go to Tools -> Boards Manager:

Arduino IDE - Boards Manager - instalacja płytki ESP8266
Arduino IDE – Boards Manager – instalacja płytki ESP8266

Install the esp8266 2.1.0-rc2 (or newer). Again go to Tools – and choose the right board:

Wybór płytki ESP
Wybór płytki ESP

Now to get the sources (I was using here version 048), today (January 2017) we have stable version 120: http://www.letscontrolit.com/

After downloading – unpack the file into ESPEasy folder in Arduino IDE, copy the libraries – from folder Libraries to folder in Arduino IDE – libraries.

Open the ESPEasy.ino file via Arduino IDE and choose Export compiled binary

Eksport firmware ESP8266
Export (compile & build) – firmware ESP8266

you should see the progress bar

Kompilacja w toku...
Compilation in progress

and then it should finish like this:

Ukończona kompilacja ESPEasy
Finished ESPEasy compilation

Look into the ESPEasy folder for file: ESPEasy.cpp.thing.bin

Flashing  ESPEasy firmware

Connect your  NodeMCU board to RPi, just like last time and choose either current version downloaded (078 4M) or the above 4M file: ESPEasy.cpp.thing.bin. Check the current firmware on the unit either:


or this command will work:


Since a lot of cheap UART converters on MS Windows has issues with the chip and drivers (IP problem) – we are using here RaspberryPi. Put the file to the folder with already used esptool.py and let’s flash as before with some extra commands (SPI flash 4M): https://blog.jokielowie.com/2015/10/domoticz-cz-2-termometr-wifi-z-precyzja-do-dwoch-miejsc-po-przecinku-czyli-esp8266-dla-poczatkujach-w-praktyce/:

python esptool.py -p /dev/ttyAMA0 write_flash 0x0 ESPEasy.cpp.thing.bin -fs 32m -fm dio -ff 40m

Flashing finished ? Now you got the ESPEasy installed! Reboot to run it, but first:

Connecting the DHT22 and Domoticz integration

As you probably noticed on the first photo – I did not connect the DHT22 using a pull-up resistor. You should – connect the middle  DATA pin to VCC pin via ~10k resistor. It’s only my good luck that it works stable.


The NodeMCU has the interesting pins right above the WiFi logo:

ESP8266 na NodeMCU Amica Board z czujnikiem DHT22 - podłączenie z boku
ESP8266 on NodeMCU Amica Board with DHT22 – side view
  • +3,3V -> first pin on the left on DHT22 (looking en-face at DHT22, where you see the markings, serial number etc.)
  • GND pin -> last, fourth pin from left DHT22
  • D4 -> second pin from left  DHT22, donlt forget to put also 10k resistor from D4 to +3,3V


The NodeMCU v 1.0/2.0 requires +5V with microUSB cable – the same as RaspberryPi, and it could be an old 300-500mA phone charger (it could be also even 2A). After turing on the board – look on your PC/Tablet for new WiFi network (password “configesp”) in format of ESP_01WXYZ (last six characters are from the MAC address of the WiFi interface on ESP8266). Connect to this WIFi via browser: and you will get this nice looking configuration menu:

ESPEasy - Main Screen
ESPEasy – Main Screen

In this example we have already preconfigured the device so lets move to the Config tab, and enter our normal home netwokr WiFi details:

ESPEasy - konfiguracja sieciowa
ESPEasy – network config

OK, so let’s give our device a friendly name, and access password to protect the Web interface (you can reset it via console – reset.). Next – the WiFi details – we expect that device can reach Domoticz  via this network. Use if you can DHCP. The WP Ap Mode Key should be left with default value, but change the protocol to Domoticz HTTP, enter IP address of Domoticz and port. The important Sensor Delay parameter will determine the interval of the reporting the values – 300 seconds – we will update the data from DHT22 every 5 minutes!

Next – let’s tell ESPEasy that we have DHT22 connected – via the Hardware tab:


The key here is to use the pin on the NodeMCU – D4 is GPIO2 which is not THE BEST solution, and IDX – the virtual sensor index that we create in Domoticz. What’s that ? Just like here: https://blog.jokielowie.com/2015/07/przekazniki-kontaktrony-wake-on-lan-oraz-z-wave-czyli-domoticz-w-sluzbie-domu/ we need to create a “virtual’ sensor – which tells Domoticz that it’s not going to be linked to it’s hardware but rather it’s going to be updated via network, using for example JSON. So this time let’s create “Temp+Humidity” sensor!

Dodawanie wirtualnego czujnika temperatury i wilgotności
WIlg is Humi in Polish

So move to Domoticz – Settings -> Devices, find our newly created sensor and remember the IDX value – copy it to IDX / Var in  ESPEasy. And… that’s it!

After couple of days you will get this nice graph:

Wykres z czujnika ESPEasy
ESPEasy gathered data – drawn by Domoticz

Right now the sensor is using mains charger, but after the overal temperature goes up (it’s outside the house) I’ll move to solar power.