ESP-01 + DHT22: Send data to influxdb

My first ESP-01 "system" is running now. It measures temperature and humidity using a DHT22 every 20 seconds and send the data to an influxdb database.

The influxdb is then used by a Grafana instance where I define a panel for the temperature and humidity. Here are the first measurements:

Looks like there where a glitch at about 12:30 - I will have a look how often this happen.
And here is the corresponding ESP code:


First Steps with ESP-01 on OS X El Capitan - Part 2

In part 1 I described how I setup my my environment. In this part I will show my first lua programming steps with the ESP8266 using the Lua based NodeMCU firmware.

First I create an init script (init.lua). This will be loaded by the firmware after each boot/restart.
As last step in the boot/restart process the firmware loads and executes the script init.lua (you can see a corresponding error message in the last screenshot in part 1).
It is recommended to provide an opportunity to interrupt the execution of init.lua to be able to change anything. Otherwise it may happen e.g. if your code contains a fatal error which cause a reboot that you are unable to deactivate/fix the code - and finally have to reflash the firmware to be break the loop.

I'm looking around an found a post about Methods of Interrupting init.lua during boot. My init.lua code based mainly on the ideas described there. But here it is:
  1. it calls firmwareInfo() to output information about the firmware. For the moment it just inform if it is a FLOAT or INTEGER version
  2. after a delay of BootTimeout ms (to give the NodeMCU some time to initialize it self) init() is called
  3. in init() the serial port is initialized and configured to watch for a transmitted ENTER key
  4. if an ENTER is received the function abort() is called, which set the abortFlag to true.
  5. After AbortTimeoutms startup() is called. There the abortFlag is checked and the startup is canceled or executed by trying to load and execute 'user.lua'
The output of such a run without interrupt is shown below:

Next step was to wrote a script to read out a DHT22 sensor. The user_dht22.lua script shown below reads temperature and humidity every 2 sec and prints both values. Depending on the used firmware the output is generated using different format and in case of integer also further values.

Output running the script


First Steps with ESP-01 on OS X El Capitan

Environment: MacBook Pro Mid 2010, OS X El Capitan 10.11.4
ESP-01 Module + Simple DIY Dev Board (based on this)

  1. Install esptool to backup/change/update ESP8266 firmware
    1. Clone git repository https://github.com/themadinventor/esptool
      $ git clone https://github.com/themadinventor/esptool.git
      Cloning into 'esptool'...
    2. cd esptool
    3. run install routine
      $ sudo python setup.py install
      running install
      Installing esptool.py script to /usr/local/bin
  2. Connect ESP8266 ESP-01 Board via CH340G Converter to MBP
    1. Install CH340G driver (WCH provides a signed driver)
    2. Identify the tty port
      $ ls /dev/tty.w*
    3. activate ESP boot loader (needs to be repeat before each esptool command) by reset ESP and pull GPIO 0 to GND meanwhile.
    4. Check communication
      $ esptool.py --port /dev/tty.wchusbserial410 --baud 115200 flash_id
      Manufacturer: c8
      Device: 4013
      $ esptool.py --port /dev/tty.wchusbserial410 --baud 115200 chip_id
      Chip ID: 0x009b82bc
  3. (optional) make a backup of the original firmware - takes about 48sec
    $ time esptool.py --port /dev/tty.wchusbserial410 --baud 115200 
    read_flash 0x000 524288 fw_backup.bin
    Please wait...
    real 0m47.721s
    user 0m0.762s
    sys 0m0.344s
    (Note: ESP12-E has a bigger flash - 4MB = 4194304)
  4. Flash alternative firmware - I want to give NodeMCU firmware a try
    1. Use standard NodeMCU firmware (download from github) or
    2. Config your own customized NodeMCU firmware 
    3. Get the download links (integer and float version) about 2min later (you can also use the preconfigured
    4. Flash it to the ESP-01 (I start with the integer version)
      $ time esptool.py --port /dev/tty.wchusbserial410 --baud 115200 
      write_flash 0x00000 nodemcu-master-9-modules-2016-03-29-19-22-38-integer.bin
      Erasing flash...
      Took 1.22s to erase flash block
      Wrote 403456 bytes at 0x00000000 in 48.2 seconds (66.9 kbit/s)...
      real 0m50.195s
      user 0m0.383s
      sys 0m0.126s
  5. Connect to ESP. I use SerialTools (AppStore Link) - Note: Baud Rate is 76800