How to configure a Wemos D1 Pro (ESP8266/NodeMCU) device and an AM2302 sensor to publish ambient temperature and humidity via MQTT. These are notes/steps, not a tutorial.
- Install Arduino development environment. I found esptool.py to be too difficult to reliably use with the D1P -- apparently the 16MB flash size is new, only recently supported, and flaky.
- Install ESPEasy firmware source into Arduino development environment.
- Connect D1P to PC using USB cable. Do a ls -ltr /dev to identify the devices created for the D1P. I see tty.SLAB_USBtoUART and cu.SLAB_USBtoUART. Use the cu device.
- In Arduino 'Tools', set board to 'WeMos D1 R2 & mini'. Also set serial device, serial speed to 115200, and flash size to '4M (3M SPIFFS)'.
- Build and flash the firmware.
- When the flash is complete, ESP_0 should appear as an access point.
- Connect to the D1P with a PC. The password for the AP is configesp.
- Once connected, browse to 192.168.4.1. Enter the SSID and password of the WiFi AP that you want the D1P to connect to. The d!P will hang up and attempt to connect to the AP just provided.
- Once the D1P is connected to the AP, it will display it's new IP address.
- Connect your PC to the AP provisioned into the D1P. Browse to the IP provided in the previous step. You'll be viewing the ESPEasy setup screen.
I had an old SparkFun ESP8266 Thing laying around and decided that I wanted to install espeasy on it. Why was I interested in espeasy? It's new to me, but it seemed to provide a lot of leverage to someone wanting to monitor and/or control remote sensors/devices. Specifically:
- OTA software updates!
- Builtin support for many common sensors, e.g., DHT11, DHT22, RFID readers, analog input, IR, switches, displays, etc., etc.
- Web-based device configuration after initial software install.
- Multiple sensors/controls on a single device.
- Works with Sonoff devices (look for 'switches'). These are fantastic!
- MQTT support
- Integrations with Domoticz, OpenHAB
espeasy doesn't explicitly say that it supports Home Assistant, but since both support MQTT, I assume that this is possible. I'm new to Home Assistant as well and am just exploring options at this point.
These are my installation notes.
I used a SparkFun ESP8266 Thing and a SparkFun FTDI Basic Breakout - 3.3V. I liked the Thing at the time, because it has support for LiPo power and charging. Though it costs around 2X of what a generic NodeMCU board goes for now, it was still cheap. The FTDI Breakout made it very easy to flash the 8266 without using jumpers.
Note that the Thing only has 512K of flash, which means that espeasy will not support OTA on it. That's OK with me for now, as I just want to get espeasy up an running to understand its basic capabilities and setup a POC. I'll get new devices when I want to explore OTA.
Obtain the firmware here. Note that there are images for various flash sizes. I use the 512K image in the command below.
I decided to use esptool.py to burn the image to flash because it's in python and it's supported by Espressif. I installed it with pip.
Here's the command that worked for me:
$ esptool.py -p /dev/cu.usbserial-AI03KZNK \ --baud 115200 write_flash 0x00000 \ ~/Downloads/ESPEasy_R120/ESPEasy_R120_512.bin
The actual device and image location may differ.
Once downloaded, the Thing will go into access point mode. It will have an SSID of ESP_0. Connect to the AP using a PC and provide the password 'configesp'. I did this on my desktop and it assigned my desktop the IP of 192.168.4.2. I assumed that the Thing must be 192.168.4.1, so I typed that in the address bar of my browser. I was presented with the initial setup page. So far so good. This was all a little muddy to me initially and I'm surprised that it isn't explained more clearly in the documentation.
In the setup page, enter the SSID and password for the WiFi access point you wish the Thing to connect to. Once this is done, the Thing will connect to the AP that was just provisioned. After letting the countdown in the setup page window expire, I clicked the Proceed to main config link and was taken to 10.0.1.11, which was the config page for espeasy on the Thing. Overall, it's a very slick experience.
I ran across an excellent note on using espeasy on Sonoff with Home Assistant.