Why I Picked the MUCH Slower Wi-Fi Over ESPNow for My Contact Sensor

by MrDIYLab in Circuits > Sensors

885 Views, 0 Favorites, 0 Comments

Why I Picked the MUCH Slower Wi-Fi Over ESPNow for My Contact Sensor

maxresdefault.jpg
Screen Shot 2022-10-12 at 8.59.27 AM.png

This is an overview article of my hubless contact sensor.

New to ESP8266? Watch my Introduction to ESP8266 video.

Why I picked the MUCH slower Wi-Fi over ESPNow: a Hub-less option for the contact sensor

The video walks through the changes in the design to go Hub-less. Feel free to add your questions in the comment section of the YouTube video if you need any further assistance.

Trade-offs

Screen Shot 2022-10-12 at 8.56.33 AM.png

Previously I mentioned how the contact sensor doesn't necessarily need a hub to function, so let's explore it now. I covered the contact sensor in great detail previously (click here to read more).

The trade-off of using Wi-Fi is the longer wake up time. However, that is not always so bad. As you know, Wi-Fi requires a connection to be established before updates are sent and that takes multiple seconds. For comparison, here is the same exact sensor sending data over ESPNow to the hub (140ms) vs sending directly to the router over Wi-Fi (3200ms).

Well, you might be wondering why even bother with the Wi-Fi variant when the hub route is better all around: (1) flexibility and (2) not every scenario requires extreme speeds and optimal power consumption.

This is explained easier using examples, so here are some.

Examples

Screen Shot 2022-10-12 at 8.57.37 AM.png
Screen Shot 2022-10-12 at 8.57.48 AM.png

Example 1:

When used on the garage door opener. The door itself takes around 10 seconds to open so instant reaction is not really needed. My home automation system gets the update in time from the sensor and turns on the light way before the garage door is fully opened. I also have aWifi access point in the garage so I don't have to worry about the ESPNow hub range.

Example 2:

The doorbell. When someone rings my door, I get a notification on my phone within seconds which is more than adequate in this scenario.

Another advantage of the Wifi variant is having direct access to local or Wifi services. For example, I can bypass my home automation entirely and send notifications directly to my phone using a third party service like telegram. Literally anything that can be coded can be performed: sending emails, logging the action, publishing to MQTT or consuming an API.

Code

Screen Shot 2022-10-12 at 8.59.05 AM.png

Implementing this in the sensor itself is pretty simple. It all starts with this skeleton code.

When the sensor wakes up, it connects to Wi-Fi, performs whatever it needs to do, then at the end, it puts itself in deep sleep using this line. This signals the LDO to shutdown.

The block in the middle is what changes from one application to another. In the garage door: I published to an MQTT topic. In the doorbell: I used the telegram API.

And that is really all it takes to use the contact or temperature sensor directly with Wi-Fi, bypassing the hub.

Another side effect or not using a hub is minimizing it as a single point of failure. If my hub goes down, it might take me a while to realize that. But when my Wi-Fi goes down, I almost notice immediately.

PCBs

Screen Shot 2022-10-12 at 9.12.35 AM.png

A shoutout to PCBWay for providing these PCBs for my project. I have been using their service for over 3 years and had nothing but great experience and quality. If you are a hobbyist and in the market for PCBs, I highly encourage you to give them a visit. Get 10 PCBs for $5 USD at https://www.pcbway.com

Conclusion

Screen Shot 2022-10-12 at 9.01.52 AM.png

As you can see there are many scenarios where using Wi-Fi directly, over ESPNow, makes sense and it never hurts to have options.

If you are interested in getting my sensor, it is available in my store.

Links:

ESP8266 I use for prototyping (affiliate links):

If you found this useful, maybe consider visiting my YouTube channel and say hello. Thank you for reading.