WiFi Logger OneWire

Since May 2015 a 30 pin Dual-Inline (2.54 mm spacing) module named NodeMCU (Version 0.9, later 1.0) appeared on the market, which carries an ESP-12 module (with ESP8266 chip) and a Serial to USB converter with micro USB socket. The pinout and schematic can be found at Links #5. The firmware API description you can find at Links #6. This module is similar to the Arduino Nano 3 module.

I liked to use it as a temperature logging device. This is already done, see instructables.com together with thingspeak.com for data visualization.

In my case I want to use volkszaehler.org server software on a Raspberry Pi computer for data visualization via web browser. In this case the warm water temperature of the heating system should be controlled.

In the following text I describe, how to program such a nice System on Chip (SoC), containing a lot of debug assistance and HowTo about the software routines.

SSID and password of the WiFi router are stored in EEPROM. If on a fresh setup NodeMCU no SSID exists in the EEPROM, it is switched to Access Point mode, and you must connect with a web browser to hotspot http://esp_ap.local and enter SSID and password. With tap on Connect/Disconnect your data are stored in EEPROM. After a NodeMCU restart you should have a connect to your WiFi router.

/!\ I made all programming with the Arduino IDE version 1.6.6/7. The ESP plug-in software is found here, I use the git version.

/!\ In any case the NodeMCU can be connected with their hostname, no IP address is needed.

/!\ The WiFi password length must be >= 8 characters.

/!\ A big Thank You for all the genius programmers, who created the examples and libraries.

Click on the pictures to enlarge them.

attachment:WiFi_Logger_DSC06319.jpg

Temperature Sensor, LED

As the temperature sensor a Dallas DS18B20 (One Wire Interface) was selected. The connection to the NodeMCU is:

NodeMCU -> DS18B20
Arduino pin 2 = NodeMCU pin D4 = ESP8266 GPIO2 
        -> DQ - One Wire bus on DS18B20, 
           connect a resistor 4k7 to VDD, see the picture
GND     -> Ground
3V3     -> VDD

Those pin's are adjacent on the module, so it is easy to find a 3 pin (2.54 mm spacing) connector. You can also use a cheaper ESP-01 module, but need an extra Serial to USB converter, with must have a supply voltage of 3.3 V.

A blue LED is soldered on the NodeMCU board, and connected to GPIO16. A LOW on this output will let the LED shine. The same GPIO15 pin is also available on the ESP-01 module (RST).

attachment:WiFiLoggerOneWire_config.png

WiFi Connection

The WiFi router credentials SSID and password are stored in the NodeMCU EEPROM.

But at the first program start, or after changing the WiFi router, there are no or wrong credentials stored in the EEPROM. In this case no connect could be made to the WiFi router, and the program will setup an WiFi Access Point with URL esp_ap.local .

With a smartphone connect to hotspot esp_ap (password 12345678) and connect the web browser to the URL http://esp_ap.local and enter in a dialog the credentials, please see the screen shot on the right. With tap on the button Connect the credentials are stored in EEPROM, and you must reset the NodeMCU to connect now to the WiFi router.

/!\ In Station Access mode (Infrastructure mode) the NodeMCU hostname is logger_one_wire. The IP address is fetched via DHCP from the WiFi router.

/!\ A Telnet client can be connect via URL http://logger_one_wire.local .

With the Arduino plug-in examples and the help of the ESP8266 community I managed it to rewrite and extend the software to an Temperature Measurement Device, with TCP data link to a volkszaehler server.

Program WiFiLoggerOneWire.ino

Let me describe the program from top to bottom. The following example programs are used partially:

The ESP8266 Arduino Core Reference API is described in Links #17.

For sending the application data to the volkszaehler server there are two methods possible (GET, POST), which are explained in the next chapter. The method must be selected via a define statement. The default is the GET method.

WiFi SSID and password according to your WiFi router must be entered first.

Please adopt the Raspberry Pi hostname volkszaehler and UUID of the temperature channel.

Show/Download on click on WiFiLoggerOneWire.c, after download please rename the extension from .c to .ino for the Arduino IDE. I had to rename it to .c, in order to get the lexer of this wiki to work (color printing).

In order to make the program more modular, large parts are extracted to other files, which must take place in the same Arduino folder WiFiLoggerOneWire as the main program:

attachment:WiFiLoggerOneWireVZ.png

Volkszaehler.org

Please see the screen shot of the volkszaehler frontend, on the right. The red vertical line is the mouse cursor, showing top left the data value.

Volkszaehler is a web server application to mainly collect the data of an electric power meter in a house, store it in a data base and visualize the data for web access, see the screen shot on the right. Alongside, similar data could be managed, for example Temperature in my case. To make it easy to setup such a web server application an SD-card image is provided for a Raspberry Pi computer. For installation of the software have a look here.

The hostname of the Raspberry Pi must be set to volkszaehler. The handling is:

$ sudo raspi-config # ENTER

8 Advanced Options  # ENTER
A2 Hostname         # ENTER
# ENTER
Please enter a hostname
volkszaehler        # ENTER
<Finish>            # ENTER
Would you like to reboot now?
<Yes>               # ENTER

For sending the application data to the volkszaehler server there are two methods possible:

The GET method is easier to implement in the program, and you need no Internet access for a NTP server.

attachment:WiFiLogger_screenshot2.png

Warm Water Measurement

It should be checked, if the warm water of the heating system heats up once in a week to a higher temperature, in order to fight the possible Legionella.

As you can see in the diagram on the right, the temperature is rised once in a week to 70 degree Celsius.

Raspberry Pi maintenance

SSH-connect via Terminal

In case you have to power down your volkszaehler (Raspberry Pi) you have to conecct via SSH to it in a terminal. On Linux and Mac OS X you type:

# connect via SSH
$ ssh pi@volkszaehler

# First time you are asked, if you allow the connection
The authenticity of host 'volkszaehler (192.168.178.77)' can't be established.
RSA key fingerprint is 35:f7:35:a6:f5:44:ed:a0:cc:a5:e4:78:f2:3c:3e:e1.
Are you sure you want to continue connecting (yes/no)?
# answer with "yes"
Warning: Permanently added 'volkszaehler' (RSA) to the list of known hosts.

# shutdown the Raspberry Pi, to avoid data loss
$ sudo shutdown now
# when all signal LED's are off, just the power LED lits, cut off the power (+5V)

# exit the SSH connection
$ exit

On Windows, please download and install the freeware program PuTTY for terminal use.

If you change the software on your Raspberry Pi, or the host name, SSH will no longer allow the access to that SSH server. In that case edit in your home directory (Linux and Mac OS X) the file .ssh/known_hosts, and delete the line with the old IP address. Then you can connect again. Because you can not see the dot-folder in the Finder you have to click on menu GoTo/GoTo folder and enter ~/.ssh (~ you get with the keys alt-gr + N). Then you see the file known_hosts.

Backup the SD-card

In regular times (month, depends on how much data you are willing to loose in worst case) you should backup your SD-card with the collected volkszaehler data. The procedure in the terminal is on Mac OS X:

# shutdown the Raspberry Pi
# take the SD-card and insert it in a SD-card reader.

# find out the device name:
$ diskutil list
# ususally it will be disk1

# copy to an image on harddisk ("rdisk" and "bs=1m" for faster copying), e.g.:
$ dd if=/dev/rdisk1 of=volkszaehler2015-12.img bs=1m

For a more detailed description please see here.

Assembly

The NodeMCU module is screwed with 4 pieces screws M2 x 20 mm to a PCB plate 70 x 70 mm. Then I soldered a 15 pin connector (spacing 2.54 mm) on a raster board for the possible connection of up to 5 sensors. The pins of the 5 individual sensor connections are soldered together, and connected to the NodeMCU. Add a 4k7 resistor between VDD and DQ of the DS18B20 connection. To hold the box on a steel metal case, a Neodym magnet is glued inside of a thin transparent box. Please see the picture for the mechanical layout.

attachment:WiFiLogger_DSC06322.jpg

Debug Help

It happens often, that after a new program upload, the WiFi router is not found. In this case just push the Reset Button on the NodeMCU.

In order to have some debugging informations, I have listed following a sample print of the Arduino Serial Monitor from the first program cycle.

Program Version: 1.2
Chip ID: 0x67214
MAC address Station: 5C:CF:7F:06:72:14
Recovered credentials:
FRITZ-7170R
********
Connect to Router requested
Connecting as wifi client to SSID: FRITZ-7170R
...............
signal strength (RSSI):-67 dBm
WiFi connected; IP address: 192.168.17.231
WiFi mode: WIFI_STA
Status: WL_CONNECTED
ROM = 10 B 88 E3 1 8 0 EA
  Chip = DS18S20
Now start Telnet client
Free Heap[B]: 43920
mDNS responder started
<----- cycle starts from here ----->
New Telnet client
555        <-- Input from Telnet client
21.5 °C 
GET /middleware.php/data/e1131330-a27e-11e5-94d4-ed7230fae87c.json?operation=add&value=21.5 HTTP/1.1
Host:volkszaehler
Content-Type: application/json
Connection: keep-alive
Accept: */*
<------ answer from volkzaehler server ----->
HTTP/1.0 200 OK
Date: Thu, 17 Dec 2015 10:12:39 GMT
Server: Apache/2.4.10 (Raspbian)
Cache-Control: no-cache
Access-Control-Allow-Origin: *
Connection: close
Content-Type: application/json

{"version":"0.3","rows":1} <--- volkszaehler middleware answer (JSON format)

Program Version: 1.2
Chip ID: 0x67214
MAC address Station: 5C:CF:7F:06:72:14
Recovered credentials:
FRITZ-7170R
********
Connect to Router requested
Connecting as wifi client to SSID: FRITZ-7170R
...............
signal strength (RSSI):-76 dBm
WiFi connected; IP address: 192.168.17.231
WiFi mode: WIFI_STA
Status: WL_CONNECTED
Starting UDP
Local port: 2390
.sending NTP packet...
packet received, length=48
Seconds since Jan 1 1900 = 3659197748
Unix time = 1450208948
The UTC time is 19:49:08

ROM = 10 B 88 E3 1 8 0 EA
  Chip = DS18S20
Now start Telnet client
Free Heap[B]: 43416
mDNS responder started
<----- cycle starts from here ----->
Unix timestamp: 1450209007
The UTC time is 19:50:07
21.6 °C 
POST /middleware.php/data/e1131330-a27e-11e5-94d4-ed7230fae87c.json?ts=1450209009000&value=21.6 HTTP/1.1
Host:volkszaehler
Content-Type: application/json
Connection: keep-alive
Accept: */*
<------ answer from volkzaehler server ----->
HTTP/1.0 200 OK
Date: Tue, 15 Dec 2015 19:50:10 GMT
Server: Apache/2.4.10 (Raspbian)
Cache-Control: no-cache
Access-Control-Allow-Origin: *
Connection: close
Content-Type: application/json

{"version":"0.3","rows":1} <--- volkszaehler middleware answer (JSON format)

The Access Point mode print looks like:

Sync,Sync,Sync,Sync,Sync

Program Version: 1.2
Chip ID: 0x67214
MAC address Station: 5C:CF:7F:06:72:14
Recovered credentials:
FRITZ-7170R
********
Connect to Router requested

WiFi connect failed, try Access Point mode for configuration
Configuring as access point, SSID: esp_ap
AP IP address: 192.168.4.1
Status: WL_DISCONNECTED
HTTP server started
ROM = 10 18 B4 DC 1 8 0 9F
  Chip = DS18S20
Now start Telnet client
Free Heap[B]: 35272
Error setting up MDNS responder!
Request redirected to captive portalscan start
scan done
<-------  input SSID and password, tap on button Connect -------->
wifi save
scan start
scan done

The Telnet Client print (for debug only) looks like:

$ telnet logger_one_wire.local
Trying 192.168.17.231...
Connected to logger_one_wire.local.
Escape character is '^]'.
555    <---- typed via keyboard
20.8 °C, sec.: 15731
Free Heap[B]: 37040
20.8 °C, sec.: 15791
Free Heap[B]: 37040
......

Thingspeak Visualization

An alternative to volkszaehler.org server is the web site http://thingspeak.com. For non commercial use you have nothing to pay for this service. This is very good for a quick test, without own server. For a setup tutorial please see IoT Datalogger with ESP8266 WiFi Module and Arduino WiFi 101 ThingSpeak Data Uploader.

The data handling is very similar to the volkszaehler use. Therefore I will just show the data telegram part of the program, and a screen-shot of the web site with my temperature data visualized.

   1 // replace with your channel's thingspeak API key, 
   2 String APIKey = "Y4IHTB9MEOA2....";
   3 const char* server = "api.thingspeak.com";
   4 WiFiClient client;
   5 
   6 void loop() {
   7   .........
   8       readTemp();
   9       strCelsius = String(celsius, 1); // 1 decimal place only
  10       Serial.print(strCelsius);
  11       Serial.println(" °C ");
  12       // send to ThingsPeak.com
  13       if (client.connect(server,80)) {  // "184.106.153.149" or api.thingspeak.com
  14         String postStr = "field1=";
  15                postStr += String(strCelsius);
  16                postStr += "\r\n\r\n";
  17                
  18         String cmd = "POST /update HTTP/1.1\n";
  19         cmd += "Host: api.thingspeak.com\n"; 
  20         cmd += "Connection: close\n"; 
  21         cmd += "X-THINGSPEAKAPIKEY: " + APIKey + "\n";
  22         cmd += "Content-Type: application/x-www-form-urlencoded\n"; 
  23         cmd += "Content-Length: "; 
  24         cmd += postStr.length(); 
  25         cmd += "\n\n"; 
  26         cmd += postStr;   
  27         client.print(cmd);
  28         Serial.print(cmd);
  29       } else Serial.println("Connect to thingspeak.com failed");
  30       // Print Update Response to Serial Monitor
  31       if (client.available()) {
  32         char c = client.read();
  33         Serial.println(c);
  34       }
  35       client.stop();
  36   .........
  37 }

attachment:Thingspeak_WarmWasser.png

  1. 2WD L293D WiFi RC Smart Car with NodeMCU + Shield for ESP-12E based on ESP8266

  2. wikipedia.de - ESP8266 (German)

  3. www.mikrocontroller.net - ESP8266 Info (German)

  4. wikipedia.org - ESP8266 modules

  5. NodeMCU, pinout, schematic

  6. NodeMCU firmware API 0.95

  7. Motor Shield Board (L293DD) for NodeMCU from ESP8266 ESP-12E

  8. Shenzhen Doctors of Intelligence & Technology

  9. Doit WiFi car manual

  10. ESP-12E module documentation

  11. Adafruit.com, ESP-12E specification

  12. NodeMCU manual (ESP-12E)

  13. wikipedia.com, NodeMCU

  14. ESP-12E motor shield, user manual

  15. WiFi-Car control with smart phone orientation

  16. AJAX programming

  17. Arduino ESP8266 plugin package

  18. ESP8266 Arduino Core Reference API

  19. Mozilla Developer Network, DeviceMotionEvent.acceleration

  20. W3C, DeviceOrientation Event Specification

  21. html5rocks.com, This End Up: Using Device Orientation

  22. ESP8266 Community Forum and wiki

  23. hackaday.io ESP8266 WiFi Module Library

  24. 2. Get ESP8266 source code

  25. ESP8266 Documents, Firmware

  26. Forum of company espressif for ESP8266

  27. ESP8266 WiFi Module Quick Start Guide

  28. electrodragon, ESP8266 wiki, ESP8266 IC pinout

  29. ESP8266 flashing LUA firmware

  30. LUA nodemcu ESP8266 firmware

  31. Wlan2Serial Modul für 5 euro (German Forum

  32. msxfaq.de, many Links for NodeMCU and LUA (German)

List of pages in this category:

-- RudolfReuter 2015-12-06 21:20:11


Go back to CategoryAVR or StartSeite ; KontaktEmail (ContactEmail)

WiFiLoggerOneWire (last edited 2016-10-11 13:57:40 by RudolfReuter)