Category Archives: IoT

[UPDATED 03-02-2018] SMOG sensor – 2,5 and 10 micro meter particles

[Last changes]:
07-11-2017: Additional data from richer stations, Open-Smog Integration
20-12-2017: USB power control on Raspberry Pi 3, thanks to reader
02-03-2018: New API from GIOŚ Poland

SMOG is common nowadays in big cities. Let’s put together a working, precise own SMOG sensor, first for the 2,5 and 10 μm size particles. There is one issue – the choices are many, but only few are reliable, precise and have affordable price. Finally – after a log searching, I’ve chosen Nova Fitness SDS011:

  • precision is OK
  • fan included
  • ability to mount a small tube to access external air
  • very realiable
  • UART with USB converter included
  • Low Total cost: around $40 (with Orange Pi Zero) up to $60 (with Raspberry Pi)

Continue reading [UPDATED 03-02-2018] SMOG sensor – 2,5 and 10 micro meter particles

ESP8266 and SMOG part four: Sleep mode for SDS011 in ESPEasy MEGA 2.0

The SMOG sensor project became a bit complex – along with the addition of relay. In the mean time thanks to Gijs Noorlander and yours- since you build, ask and use the sensor – we got updated version of ESPEasy MEGA 2.0 for ESP8266.

Why the new blog entry? That’s because Gijs added the included in SDS011 function that when sent over serial connections allows to put SDS011 to sleep. Simple, elegant solution to extend the life and quality of the measurements of the SDS011 – better than relay approach.

ESP8266 ESP Easy MEGA 2.0
ESP8266 ESP Easy MEGA 2.0

Now, just by means of connecting extra jumper cable we can go back to a simpler version of the sensor – a union of first version with addition of the temperature and humidity sensor form the second one.
Continue reading ESP8266 and SMOG part four: Sleep mode for SDS011 in ESPEasy MEGA 2.0

Measuring air quality using Bosch BME680 and AMS CCS811 – IAQ, TVOC, eCO2

BME680 on Raspberry Pi 3

Measurement of basic environmental data in our apartment – temperature and humidity is one of the most popular applications of commonly available sensors for Raspberry Pi (RPi), Orange Pi (OPi) and ESP8266.

Then we added ability to measure the SMOG otuside and inside and today we will deal with two new and very interesting air quality sensors.
Continue reading Measuring air quality using Bosch BME680 and AMS CCS811 – IAQ, TVOC, eCO2

ESP8266 and SMOG part three: sensor protection, cloud upload

Last time we updated our simple SMOG sensor with display (OLED) and added BME 280 to verify the SMOG measurements – the environmental sensor – as we know that humidity over 70% can add up to the SMOG.
It’s time now to protect our sensor.
Continue reading ESP8266 and SMOG part three: sensor protection, cloud upload

ESP8266 and SMOG part two: OLED display, measuring conditions

Last time we build a simple SMOG sensor, it’s time to add display (OLED) and to verify the SMOG measurements – the environmental sensor – as we know that humidity over 70% can add up to the SMOG.
Continue reading ESP8266 and SMOG part two: OLED display, measuring conditions

ESP8266 and SMOG: Quick and snappy SMOG sensor with WiFi interface – first, basic version

Recently, we built a smog sensor which measures PM2.5 and PM10 ppm particles common in SMOG. This time let’s focus on something easy to do, without deliberations on extending life of the sensor. The Nova Fitness SDS011 (also versions 018 or 015) has proven to be quite accurate, with a good life expectancy, even with nearly theoretical unsupported air humidity above 70%. Today I will try to show you the mobile version of the sensor, using the cheapest elements, and then expand it with a temperature and humidity sensor, display – up to the cloud version. To start with – let’s build the basic version.

NOTICE: The ESPEasy MEGA 2.0 software that we use here – has been updated in January 2018 with much better SDS011 support. When finished with this version check out the updated one (fourth version)

Najmniejszy system weryfikacji smogu
Smallest SMOG measurment system

This is a very easy project that can be completed withinin 10 minutes.
Flash the software,  connect 3 cables and read the result via WWW. Something that can be shown at school (or as a school project) or at the local community – as an effective SMOG meter.
Continue reading ESP8266 and SMOG: Quick and snappy SMOG sensor with WiFi interface – first, basic version

PLNOG: The 18th, 19th and 22nd Polish editions – with presentations, both SildeShare and YouTube (Polish language only)

PLNOG 18 Warszawa - Domoticz i DIY
PLNOG 18 Warszawa – Domoticz i DIY

PLNOG is a conference held in Warsaw and Krakow twice a year. This is the place where IT and telco people meet. Last time I spoke about some of my experiences in building small devices, listen if want to (Polish only):

During next PLNOG 19 I’m going to talk about SMOG sensor:

PLNOG 19 - SMOG w Krakowie
SMOG w Krakowie

Big Thank You to all who were present – hope you liked it!

Presentation:

PLNOG 22, thanks for attendence and comments!

SMOG - PLNOG 19 w Krakowie
SMOG – PLNOG 19 w Krakowie




Power supply for Raspberry Pi, Orange Pi, ESP8266 – XBOX 360 PSU modification

Proper supply of power is a very important part of our SBC (Small Board Computers) projects. Power supplies with too low current efficiency, instability and lack of filtration – often lead to accidental resets, lack of sensor readings or simply unstable behavior of SBCs. One of the solution is to modify the power supply from Microsoft console – XBOX 360.
WARNING: We will work with high currents and high voltage, which requires basic knowledge of electrical engineering. The author is not responsible for accidents and everything you do – you do at your own risk.
Continue reading Power supply for Raspberry Pi, Orange Pi, ESP8266 – XBOX 360 PSU modification

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.

Required

Software:

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

Hardware:

  • 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
AT
OK

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
AT+CMGF=1
OK
AT+CSMS=1
+CSMS: 1,1,1

OK
AT+CSCS="GSM"
OK
AT+CMGS="601xxx555"
> "To is TESTING. A SMS that is!"
>
+CMGS: 46

OK

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:

[gammu]
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

with:

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

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 DIALTONE"
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 10.75.12.27
Oct  8 23:23:16 rpi pppd[17390]: remote IP address 10.75.12.27
Oct  8 23:23:16 rpi pppd[17390]: primary   DNS address 89.108.202.21
Oct  8 23:23:16 rpi pppd[17390]: secondary DNS address 89.108.195.21
Oct  8 23:23:17 rpi ntpd[779]: Listen normally on 11 ppp0 10.75.52.17 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 8.8.4.4#53
Oct  8 23:23:18 rpi dnsmasq[6117]: using name server  8.8.8.8#53
Oct  8 23:23:18 rpi dnsmasq[6117]: using name server  89.108.202.21#53
Oct  8 23:23:18 rpi dnsmasq[6117]: using name server  89.108.195.21#53

It works Check the ifconfig output:

ppp0      Link encap:Point-to-Point Protocol
          inet addr:10.75.12.27  P-t-P:10.75.12.27  Mask:255.255.255.255
          UP POINTOPOINT RUNNING NOARP MULTICAST  MTU:1500  Metric:1
          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, 10.75.12.37#123, interface stats: received=0, sent=0, dropped=0, active_time=204
 secs
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!