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

Domoticz part. 7: Heating your house with Z-Wave

We do know how to install domoticz. But how easy is to control heating in your house/flat? After full season of testing radiator control – I can recommend a very interesting and useful heating control system that you can setup in your home or apartment. All just by means of adding radiator thermostats with Z-Wave radio.

Z-Wave - termostat grzejnikowy Danfoss
Z-Wave – termostat grzejnikowy Danfoss

What will you need?

Software

  • Up to date Domoticz installed on PC

Continue reading Domoticz part. 7: Heating your house with Z-Wave

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

Tracking gliders, airplanes, helicopters and baloons, part 3 – FLARM

We already know how to track airplanes using DVB-T USB dongle and Orange Pi or Raspberry Pi. Let’s move on to a new system that allows tracking of light aircrafts:

  • gliders
  • helicopters
  • baloons
  • smaller airplanes
Sender/reciever for glider (photo by: Sebastian Lampart)
Sender/reciever for glider (photo by: Sebastian Lampart)

FLARM – is a collision avoidance system for light aircrafts, popularized and approved by EASA, gaining traction, used mainly on gliders in Poland and Europe. We’re not going to use it to avoid collision – but to receive position and track light aircrafts – so we can share them on the OGN procest’s map – OPEN GLIDER. There are few station in Poland – let’s build a more robust network, so that gliders can be safer and their records – recorded.

What will you need?

Hardware:

  • Orange Pi Zero or RPI Zero W” rel=”noopener” target=”_blank”>Raspberry Pi Zero W
  • DVB-T USB Dongle. Look for the upgraded version in blue chassis – AKA “DVB-T RTL2832U+R820T2” – it offeres better sensitivity in interesting frequency – and will give you extra range. The most important part in that equation is the new R820T2 (version ‘2’) and of course the included antenna
  • Micro SD – could a cheap 8G for $4, but better is to use Sandisk Extreme/Ultra – at least 4GB
  • Power supply – at least 1.5 to 2A @5V with micro USB (i.e.: old charger from cellphone)
  • Two small heatsinks (radiators) for CPU and controller – for Orange Pi Zero
  • ALTERNATIVE: Raspberry Pi 2 or 3 – they have enough of CPU power, but triple the price
  • Antenna 868MHz. The one you got with USB dongle is OK for start – gives me around 50km of range without any modification. You can cut it to the lenght of single segment

Software:

    li>Armbian for Orange Pi – the best at this point is to use the Xenial NIghtly, developer/beta version, with 4.9.x kernel from https://www.armbian.com/orange-pi-zero/
  • ogn-decode i ogn-rf – software to be downloaded – ARM CPU version
  • Free ports on the Orange Pi/Raspberry Pi – 8080 and 8081 – if there’s nothing else there installed – they should be free to use.
Cokpit with FLARM  (photo by: Sebastian Lampart)
Cokpit with FLARM  (photo by: Sebastian Lampart)

Installation

First – if not installed already – we need SDR and some system libraries as well as binaries from glidernet.org:

cd /home/pi
sudo apt-get update && sudo apt-get upgrade
sudo apt-get install rtl-sdr
sudo apt-get install libconfig-dev fftw3-dev libjpeg-dev libconfig9 libjpeg8

To allow usage of the raw feed from airplanes we need to turn off the automatic loading of the DVB-T:

nano /etc/modprobe.d/rtl-sdr-blacklist.conf

paste:

blacklist dvb_usb_rtl28xxu
blacklist e4000
blacklist rtl2832
blacklist r820t
blacklist rtl2830
blacklist dvb_usb_rtl28xxu
blacklist dvb_usb_rtl2832u

Reboot the Orange Pi/Raspberry Pi
Now, lets download from glidernet.org the correct file, unpack it:

wget http://download.glidernet.org/arm/rtlsdr-ogn-bin-ARM-latest.tgz
tar xvzf rtlsdr-ogn-bin-ARM-latest.tgz

Create a FIFO to allow communication between both parts of the OGN software:

cd rtlsdr-ogn
mkfifo ogn-rf.fifo

View from glider (photo by: Sebastian Lampart)
View from glider (photo by: Sebastian Lampart)

Next, calibration of the USB dongle – cheap DVB-T USB tuners are not always good at tuning with high precision to given frequency – we need to correct the skew. To do that use the gsm_scan, that will give the ppm and gain correction values:

cd rtlsdr-ogn
./gsm_scan --ppm 50 --gain 20

Change values so that the deviation is around 10ppm (check the best GSM frequency GSM) – write them down.
Create own configuration based on the example:

cp Template.conf EPXX_OGN.conf
nano EPXX_OGN.conf

The example file contents based on my tuner: enter CORRECT values for FreqCorr, GSM: CenterFreq Gain – based on gsm_scan:

RF:
{
  FreqCorr = +87.060;          # [ppm]      "big" R820T sticks have 40-80ppm correction factors, measure it with gsm_scan

  GSM:                     # for frequency calibration based on GSM signals
  { CenterFreq  = 938.4;   # [MHz] find the best GSM frequency with gsm_scan
    Gain        =  25.0;   # [dB]  RF input gain (beware that GSM signals are very strong !)
  } ;
} ;

Position:
{ Latitude   =   +51.1514; # [deg] Antenna coordinates
  Longitude  =   +18.4642; # [deg]
  Altitude   =        150; # [m]   Altitude above sea leavel
  GeoidSepar =         48; # [m]   Geoid separation: FLARM transmits GPS altitude, APRS uses means Sea level altitude
} ;

APRS:
{ Call = "EPXX1";     # APRS callsign (max. 9 characters)
                      # Please refer to http://wiki.glidernet.org/receiver-naming-convention
} ;

Finally – start in background two programs using very basic (or other by your choosing method) thanks to cron:
Create two files:

cd /home/pi
nano /home/pi/rtlsdr-ogn/run_ogn-rf

with:

#!/bin/bash
cd /home/pi/rtlsdr-ogn
/home/pi/rtlsdr-ogn/ogn-rf /home/pi/rtlsdr-ogn/EPXX_OGN.conf

Add rights to execute:

chmod 755 /home/pi/rtlsdr-ogn/run_ogn-rf

Second file:
nano /home/pi/rtlsdr-ogn/run_ogn-decode

with:

#!/bin/bash
cd /home/pi/rtlsdr-ogn
/home/pi/rtlsdr-ogn/ogn-decode /home/pi/rtlsdr-ogn/EPXX_OGN.conf

Rights to execute:

chmod 755 /home/pi/rtlsdr-ogn/run_ogn-decode

Now edit your crontab:

crontab -e

Wklejamy:

*/5 * * * * if [ `pgrep ogn-rf | tr '\n' ' '| awk '{print $1}'` ]; then echo "ogn-rf works"; else screen -dmS ognrf /home/pi/rtlsdr-ogn/run_ogn-rf; fi > /tmp/ognrf.log 2>&1
*/5 * * * * if [ `pgrep ogn-decode | tr '\n' ' '| awk '{print $1}'` ]; then echo "ogn-decode works"; else screen -dmS ogndecode /home/pi/rtlsdr-ogn/run_ogn-decode; fi > /tmp/ogndecode.log 2>&1

Of course in our example we’re using username “pi”.
Verify the operation by attaching screen: screecn -r XXX, or enter the URLs in we browsers: http://ADDRESS_OF_PI:8080/ oraz http://ADDRESS_OF_PI:8081/. Your station will be listed at: http://ognrange.onglide.com/, along with the range. Since FLARM changes – check every 6 months for new version.

That’s it!

Glider's tail (photo by: Sebastian Lampart)
Glider’s tail (photo by: Sebastian Lampart)

Tracking airplanes with ADS-B & MLAT revisted- building a better and cheaper reciever for Flightradar 24 and Flightaware

[Update 2017-08-22 – Sharing data with friendly radars]
A lot has changed since the last entry about tracking the aircraft using ADS-B messages. There are new options for data sharing, greatly simplified installation procedure and – optionally new equipment. This allows you to build a new receiver with an emphasis on simplicity, yet lower cost of purchase and maintenance with new feature (MLAT). Moreover, in addition to the aircraft you can now track other aircraft – i.e. meteorological balloons! I call that progress!

Malasian 747 @ RNAV
Malasian 747 @ RNAV – picture thanks to first run of FR24

What will you need?

Hardware:

  • Orange Pi Zero. It’s a competition to Raspberry Pi – board that gives a lot for $10 – four CPU cores, 256 or 512MB RAM. Onboard you will find Ethernet and WiFi along with single USB. There’are extension available – extra USB/IR/CVSB Out HAT or new USB2SATA HAT
  • DVB-T USB Dongle. Look for the upgraded version in blue chassis – AKA “DVB-T RTL2832U+R820T2” – it offeres better sensitivity in interesting frequency – and will give you extra range. The most important part in that equation is the new R820T2 (version ‘2’) and of course the included antenna
  • Micro SD – could a cheap 8G for $4, but better is to use Sandisk Extreme/Ultra – at least 4GB
  • Power supply – at least1.5 to 2A @5V with micro USB (i.e.: old charger from cellphone)
  • Two small heatsinks (radiators) for CPU and controller – for Orange Pi Zero
  • ALTERNATIVE: Raspberry Pi 2 or 3 – they have enough of CPU power, but triple the price
  • In summary: Our new reciever should be around 25-30$ in total!
Orange Pi Zero
Orange Pi Zero

Software:

  • Armbian for Orange Pi – the best at this point is to use the Ubuntu Xenial with legacy kernel, you can also try developer/beta version, with 4.9.x kernel. Go to https://www.armbian.com/orange-pi-zero/
  • piaware and fr24feed – software to recieve, decode and share the data about plane flyovers. Free ports on the Orange Pi – 8080 and 3000-30010 – if there’s nothing else there – they should be free to use.

MLAT – new functionality

MLAT is short for multilateration. Airships without ADS-B transponders do not advertise their latitude and longitude, so the Mode S they use is not useful for us. Thankfully those Mode S transponder messages can be used by means of multilateration – based on the delay of the received messages in at least 3 different receiving Mode S. A very precise clock synchronization is required – which means you have another oportunity to ask friends living so-so close by to start their own radars!

BAE 747
BEA 747 – fantastic visability at that day

Orange Pi Zero

As you noticed – we have been using mainly Raspberry Pi. The unprecedented success of this small computer spurred a number of “compatible” boards – Orange Pi Zero is very cheap, able, but the software is not yet quite there or stable. Well, it’s whatever $10 can buy!

The antenna

Start with the included antenna. Next use google to find out the optimal length – and cut it. From there to increase coverage – you will ned to dive into the wonderful world of pro antennas!
The roof top is the best place for antenna, but don’t forget that if you place your Orange Pi in the attic – it may get very hot!

Installation

Before first run of the Orange Pi Zero – please install the heatsink on the H2+ CPU, and on the chip next to it. With the heatsinks and no chassis the CPU works at 42-48C. Without it 60-65C – which can shorten the life of both Orange Pi and the micro SD card.

Let’s install – just as in the first blog entry about SDR – Armbian  with 4.9.x (Xenial) – using dd or win32diskimager.

On the first run Armbian allows you to login as root with the password “1234”, and immediately asks to change this default password, and create a user. Could be ‘pi’ user of course.

Let’s login now as pi and change the credentials to root:

sudo su -

Now – every commend we issue we do it as root, so be careful!

First: update and upgrade of the armbian system.:

apt update && apt upgrade

To allow usage of the raw feed from airplanes we need to turn off the automatic loading of the DVB-T:

nano /etc/modprobe.d/rtl-sdr-blacklist.conf

and paste:

blacklist dvb_usb_rtl28xxu
blacklist e4000
blacklist rtl2832
blacklist r820t
blacklist rtl2830
blacklist dvb_usb_rtl28xxu
blacklist dvb_usb_rtl2832u

Next comes the Flightaware – Pi Aware software – first part of our radar:

wget http://flightaware.com/adsb/piaware/files/packages/pool/piaware/p/piaware-support/piaware-repository_3.1.0_all.deb

Install it:

dpkg -i piaware-repository_3.1.0_all.deb
apt update
apt install piaware
apt install dump1090-fa

Add auto upgrade of the piaware itself:

piaware-config allow-auto-updates yes
piaware-config allow-auto-updates yes

Now let’s turn to Flightradar24:

sudo bash -c "$(wget -O - http://repo.feed.flightradar24.com/install_fr24_rpi.sh)"

As with the first blog entry – please enter your data, key. postion of the antena.
Let’s connect FR24 with Pi Aware:

nano /etc/fr24feed.ini

and paste:

receiver="avr-tcp"
fr24key="YourFr24Key"
path="/usr/bin/dump1090-fa"
bs="yes"
raw="yes"
logmode="2"
mlat="yes"
mlat-without-gps="yes"

Enable’em all!:

systemctl enable piaware
systemctl enable fr24feed

reboot:

reboot

After reboot – check out your new map!

http://ip_address_of_orange_pi:8080/

Example:

Prezentacja odebranych danych z mapą z dump1090-fa
Data presentation using dump1090-fa

Go ahead and check this US military airplane… Nice example why MLAT is usefull! Couple of minutes later I found out circling… AWACS

Status “fr24feed” i “piaware” can be seen here:

tail -f /var/log/fr24feed.log /var/log/piaware.log

Or

piaware-status

That is it!

Sharing data with friends

Together we are strong! There’s always someone who has resources, server and is able to recieve multiple radar data and present them on web. Usually, by sharing you will get the access to such service, also to the data that is based on MLAT. How to connect? You should get the IP address and port (socket) from the server provider to connect to – all you need to do is one line to redirect (copy actually) the traffic and data from your radar.
First let’s install socat

apt-get install socat

Now – test the connection:

/usr/bin/socat -d -T 90 TCP4:localhost:30005 TCP4:IP_ADDRESS_OF_SERVER_WITH:PORT

If that works fine – break the operation using CRL+C and set-up the permanent connection via crontab:

crontab -e

add line:

*/20 * * * * /root/bin/share_flight_data.bash

Now crate the file/root/bin/share_flight_data.bash:

mkdir -p /root/bin
touch /root/bin/share_flight_data.bash
chmod 755 /root/bin/share_flight_data.bash
pico /root/bin/share_flight_data.bash

Put in the file:

#!/bin/bash
if [ `/usr/bin/pgrep -f "friend_feed_port_30005" | /usr/bin/tr '\n' ' '| /usr/bin/awk '{print $1}'` ]; then echo "friendly_feed works"; else /usr/bin/screen -dmS friend_feed_port_30005 /usr/bin/socat -d -T 90 TCP4:localhost:30005 TCP4:IP_ADDRESS_OF_SERVER_WITH:PORT; echo "Starting  friend_feed_port_30005"; fi >> /tmp/share_data.log 2>&1

That’s it – every 20 minutes the system will check if the feed works.




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:

[email protected] ~ $ 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:

[email protected] ~ $ 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:

[email protected] ~ $ 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!

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 10.20.30.40. We can turn off the display (i.e. it’s too bright in the night)

http://10.20.30.40/control?cmd=oledcmd,off

Then to turn in on:

http://10.20.30.40/control?cmd=oledcmd,on

Clearing the display:

http://10.20.30.40/control?cmd=oledcmd,clear

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

curl http://10.20.30.40/control?cmd=oledcmd,row,column,our_text

An example:

curl http://10.20.30.40/control?cmd=oledcmd,1,1,My%20login:%20$LOGNAME

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:

script_time_TemperaturaCisnienie.lua

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
end
hektopaskale=round(otherdevices_barometer['TemperaturaCisnienie'],1)
commandArray = {}
commandArray['OpenURL']='10.20.30.40/control?cmd=oledcmd,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
    commandArray['OpenURL']='10.20.30.40/control?cmd=oledcmd,7,1,Temp:'..otherdevices_svalues[NazwaCzujnika]..'*C'
   end
return commandArray

This time we only update on temperature CHANGE.




Embedded devices: Linux on Raspberry Pi, ESP 8266 and others