I have written about the ESP8266 before in my post about the magic button. For the button I am using the nodeMCU firmware which let’s you run lua script on the ESP. But recently the people over at esp8266.com created an Arduino IDE version which is compatible with the ESP8266. I was already using an ESP connected to an Arduino to log the output of my solar panels so I decided to try and run this code natively on the ESP. And it worked, so although this is not automation or virtualization related, here are some more details about my ESP8266 PV Logger.
The logger connects to my Mastervolt Soladin 600. This inverter has an RS485 port but connecting it to a TTL serial port is easy. All you need is two resistors. For the schematic see the readme on github. I have been monitoring my PV panels for years using this library. That lib only works with software serial ports which are not supported by the ESP so I changed that to use the Stream class instead. Both Software Serial and Serial are inherited from Stream so now it should work with both on a normal arduino but I haven’t tested it with the software serial. I also changed the serial delay and timeout settings to get reliable communication between the ESP and the Soladin. You can find the updated lib here.
There are a couple places you could send your logging data to. Until today I was using data.sparkfun.com and that worked fine. But it’s lacking nice grapical presentation of you data. And I’m too lazy to build my own so I looked for something else. Now I am using thingspeak and that seems to work just a s well with the added bonus of nice graphs and google gauge visualisation. You can find my stats here.
The logger code is pretty easy. It tries to connect to the Soladin, if that succeeds it sends data to thingspeak. This is repeated every 15 seconds. If it can’t make a connection to the Soladin the loop slows down. You can find the whole code here on github. Don’t forget to compile it with arduino 1.6.1-esp8266-1 instead of the regular arduino IDE.
All you need to run this is a 3.3volt power supply, two resistors, a cable with an RJ11 connect and a ESP-01. Mince looks like this.
The best part? The whole thing costs about 5 bucks! That’s a lot cheaper than Mastervolt’s PC-Link cable.
On March 19th we used The Magic Button ( a.k.a “The What Does This Button Do Button”) in our demo’s at the Dutch VMUG UserCon. It magically made a CoreOS cluster appear out of nowhere, Launched our demo app and then it scaled it out so all people in the room could open the page. Of course you want to build your own now. Here is how.
The button itself is just a regular emergency stop button I got off e-bay (6$). Inside there is enough space for a battery holder with 2x AA batteries. These batteries power an ESP8266-01 board. The ESP8266 is a Wifi SoC, has a 80Mhz processor, wifi connection, 96KBytes of RAM, a couple of GPIOs, comes with SPI flash on the board, costs around 5$ and looks like this:
Here is how I connected the board:
- Connect the button between GPIO0 and Ground
- Connect the LED between GPIO2 and Ground. I used a 100Ohm resistor to limit the current through the LED
- Put a 1K pullup resistor between VCC and CH_PD
- Batteries are directly connected to VCC and GND. No Caps or regulators.
When everything is connected you can squeeze it all into the case. It actually doesn’t really fit. When I close the case the battery gets damaged a bit. But whatever, it works….
So How did I turn this wifi board into a magic button? The button simply does an HTTP POST to my webEye application. This application forwards the posted body to an AMQP bus where it get’s picked up by vRealize Orchestrator. vRO in turn runs a workflows which actually performs the magic. To enable your board to do the same, follow these steps:
- Setup webEye or another webhook receiver to test the button
- Flash this firmware on the chip: nodeMCU
- Use ESPlorer or another tool to load these two Lua files: https://github.com/vChrisR/TheMagicButton.
- Please edit the variable at the top of the files before copying to your ESP
- Emergency stop buttons are normally closed. So make sure the button is pressed (open) when you power up the ESP. If you don’t do that it will keep GPIO0 low which makes it boot into bootloader (flash) mode.
Now build a cool workflow which you can trigger with this button. Share your creations in the comments or find me on twitter.