Battery Operated ESP (Button, Sensors, ...)

The goal is a battery-operated ESP device that can be used as a sensor. After searching, the best way to lengthen battery life is by using deep sleep, removing led indicators, and using a more direct route of the WiFi. I am leaving this post as a place holder to document if we find something that works. I was inspired by @luma HA SwitchPlate and other projects to try this format. So for now, the discussion will follow in the next post.

1 Like

For the first try, I would like to explore Andreas Spiess low powered ESP. I watch several videos. Here is a list with the last link looking like it might be the solution.

The ESP now episode looks to be the most promising.
Bottom line with ESP now, you do not have all the over head of connecting to the AP cumming out of deep sleep, which is basically a reboot., and all the overhead of TCP. The catch is you need a master/slave setup.

ESPNow looks like it supports 20 nodes.

Andreas added a link in the show notes, but this code https://github.com/HarringayMakerSpace/IoT/blob/8b078b4a5663dd31603e70df603ae2457d442018/ESP-Now/espnow-gateway/espnow-gateway.ino may be the key. This will connect to MQTT to publish the sensors’ messages.

Here is the github.com link https://github.com/HarringayMakerSpace/IoT/tree/master/ESP-Now according to the read.me he was having some issues. The last post was about 4 years ago, so it might be a rabbit hole. Here we go, Alice.

I have 3 ESP12F to play with. I have to travel the first part of this week, but I hope to have the wired up in a bread board fashion for some testing.

I have started the code repository at https://github.com/penright/WiFi2MQTT

I have created two ESP12. The first lesson learned is an ESP12 needed pull/down resistors. I had to hack some on to my first attempt. The second one was a little more polished. For now, it works and I can test the code.

Right now I am trying to get some techniques down. Pushing data using the ESP-Now, for speed, the gateway receives the message and sticks it in the queue. The ESP-Now receive is part of the WiFi, so you do not want to block that function too long.

Next, I want to publish it to an MQTT broker.

Again, lots to learn just starting.

For hardware I am using ESP-12. Size is not much bigger than a ESP-01 but more pins. I have 3 ESP-12 and forgot to order adapter boards. So I hack them to some perfboard. My first attempt I forgot the pull up/down resistors. So there are two versions. One where I hack the resistors on to the hacked ESP-12.

So then I used the lessons learned for the second board.

Also, my laptop where I do development at home has only one available USB. For now I am using the cheap powered hub. The serial monitor is acting weird and I am not sure if it has to do with the project or not enough power from the hub. It is a powered hub.

So the first try is my gateway and the second one will be the button node.
I got the MQTT working so when the gateway boots up, it sends a up status to a MQTT broker. When the button one boots, it sends a message to the gateway, which someday will send a MQTT message. Right now I am just printing to the serial monitor.

Last night I added a mosfet and switch to the button board. All I had was STO-23 packages, but it works.

So now when I push the button connected to the gate, the node wakes up and sends the message. The node is only powered for as long as I push the button. The amazing part, with the ESP-Now. The ESP powers on, boots, sends the message all in the time of what I consider a normal press of the button.

Right now I could put this in production as long as I was hacking the code for needed values. But it would only work as a single press button. I would like to emulate my Almond Click. The have press, 2 press, and long press. I am wondering if one of the ESP pins could be used to hold the gate of the mosfet for more pressing, then turn it’s self off. I could build some logic into the gate way and node. The gateway would track and if 2 presses in a certain amount of time, then count it as a double press. For the long press, the button node could send a second message if it has been running for a certain amount of time.
But for now I would like the node to handle the logic.

I posted a video on YouTube so you can see the response …
Here the video showing the time from when I press the button (on the node) till the gateway sees it and prints it to the serial monitor.

You don’t need to use the button for power. Put the device in deep sleep. Then attach the button to a wake up pin. Then the power won’t be lost during a double click.

This issue with that technique is the “wake pin” is the reset pin. So as soon as you press the button a second time, it will reset and start over. Kind of like the movie 50 First Dates. :slight_smile:

I am new to this so I could easily be mistaken.

Messed with the project some over the weekend. Before I get to lessons learned, I made a new button.


I added a header for programming and the two buttons off in the corners are for flash and reset.
The long button by the battery holder just applies power.

Lessons learned.

  1. For the gateway to publish MQTT I was using PubSubClient. I guess there are two versions, a legacy and “not legacy” (not sure what to call it. I am developing two different PC. A PC and laptop. As I was moving the code from the PC->github->laptop. When I tried to compile I had errors. The same code would compile on the PC. After noticing the “Legacy” when compiling, I delete the library and downloaded it again. Then I had the same errors on the PC. So I had to fix how some functions are called. It now compiles without issue but would not connect to MQTT. This is where I stopped. I am sure I have a mistake somewhere.

  2. ESP-Now only works on channel 1. When connecting to the home AP it was on channel 11. So the node (Button) would not connect. I had to lock one AP to channel 1. This means the real gateway may have to have two ESP. One locked to AP mode and channel 1. The other can connect to the AP and let them talk via serial connection. Right now I am thinking serial so ESP-01 would work.

  3. When I tried the button battery, I don’t think there was enough power. The led would flash for a split second but not long enough. Next week I am going to try a cap and see if that helps. When I get the parts I was going to try a A23 12V going through a voltage regulator. Thinking it can loose a lot of voltage but still power a 3.3v device. Now I wonder if it might help with the inrush current. I know just enough EE to hack but not design.

Here is my current gateway. Right now I am using ESP-01. The difference between the board is the gateway does not have a power switch and I socket the ESP. It can also double as a ESP-01 programmer.

Both headers will accept this cable. I can use it for power and programming. The button work when configured this way. Not this exact setup, but simular is what I used in the video.

Got it working kind of. Adding the cap did allow the button push, but if I hold it for a long press there is not enough to carry it through. If I power it off of the USB the code works.
This is while I am waiting for parts to do a soft switch.

Here is it working.

Hi, nice project, I loved it!
I would like to contribute by designing a printed circuit board if you want to.
I’ve done a couple of boards using ESP12F in the past



Please let me know your intentions!
Kind regards

Very nice! I’m not that savvy, but I’ll be watching this in case I can contribute. Cheers! (From Facebook)