ESP-NOW

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
FanOfHue
Normal user
Posts: 96
Joined: 06 Oct 2018, 10:08

ESP-NOW

#1 Post by FanOfHue » 09 Oct 2019, 13:20

Who has experience with ESP-NOW, combined with ESPEasy at the same time?
I've read that it cannot be combined with normal Wifi operation so that could complicate things a bit.

How to do OTA upgrade when the device can't use normal Wifi/Webserver and at the same time being a ESP-NOW sensor?
I guess we need some smart way to switch between normal Wifi and ESP-NOW, but a reboot is required in between.

FanOfHue
Normal user
Posts: 96
Joined: 06 Oct 2018, 10:08

Re: ESP-NOW

#2 Post by FanOfHue » 11 Oct 2019, 14:41

I decided to dive in deep myself, but it took a while to find a good sample on how to setup ESP-NOW with two STATION mode units and make use of encryption and peering.
This supprised me a bit, but majority of samples skip encryption options and sometimes also use mac broadcast messages.
That looks like a similar security by obscurity as with the Wifi probe mac hack solution. That was fun to play with but i don't think i'll be using it in real production.
And it only allowed for 5 bytes of data where ESP-NOW can send plain text messages, as needed within the Smartnoderules concept.

I'm totally new on ESP-NOW, so ready to make stupid mistakes, but i think that i've implemented it into SmartNodeRules the way that uses best options that the official API provides.
Using custom encryption keys and verifying peer nodes against the configed peer list should avoid sniffing data and protect against attacks with mac spoofing.
(i'm no expert on this and have to rely on how espressif build their stuff inside ESP-NOW magic)

New rule engine commands:

* ESPNowConfig <kok>,<key>,<mac>,<mode>
* ESPNowAddPeer <key>,<mac>,<role>
* ESPNowSend <msg>

Using it now on a battery operated doorsensor as sender node. Normal ESP as receiver.
Alive time is now a lot shorter than with standard Wifi and it will surely extend battery life.
It also speeds up reaction time quite a lot.

Sample rules to configure two SmartNodeRules:

Receiver:

Code: Select all

on espnow do
  ESPNowConfig 1234567890abcdef,1234567890abcdef,02:01:02:03:04:30,Receiver
  ESPNowAddPeer 1234567890abcdef,02:01:02:03:04:01,1
endon
Sensor:

Code: Select all

on espnow do
  ESPNowConfig 1234567890abcdef,1234567890abcdef,02:01:02:03:04:01,Sender
  ESPNowAddPeer 1234567890abcdef,02:01:02:03:04:30,0
  ESPNowSend Hello There!
endon
It seems that the peering is limited to 10 stations. May not be enough for some, but you could always add another receiver for 10 more.
Maybe ESP32 can do more, but i have not checked this.

happytm
Normal user
Posts: 107
Joined: 15 Aug 2016, 17:53

Re: ESP-NOW

#3 Post by happytm » 11 Oct 2019, 23:00

Please keep us informed about time it consume to send data over ESPNow protocol.

Thanks.

FanOfHue
Normal user
Posts: 96
Joined: 06 Oct 2018, 10:08

Re: ESP-NOW

#4 Post by FanOfHue » 12 Oct 2019, 10:05

happytm wrote: 11 Oct 2019, 23:00 Please keep us informed about time it consume to send data over ESPNow protocol.

Thanks.
Using millis() as counter, current dev version takes 300 mSec to get the message out. I estimate that approx. 100 mSec is spend on communication to the MCU on 9600 baud. I tried to skip some parts like getting the device string and version, but then it starts to behave differently.
And the device also needs some time to powerup, maybe settle time for the step-up converter (?)

But it's a huge improvement from the 5 seconds that it took with standard Wifi connection.
The stock firmware version was not really suitable for things like switching a light on, because you would have to wait for 5 seconds in the dark.
Now it's < 1 second.

I also flashed the firmware on the PIR sensor and it works the same way now.

happytm
Normal user
Posts: 107
Joined: 15 Aug 2016, 17:53

Re: ESP-NOW

#5 Post by happytm » 12 Oct 2019, 10:08

I think anything below 1 second is great improvement for battery powered device.Looks promising.

Thanks

FanOfHue
Normal user
Posts: 96
Joined: 06 Oct 2018, 10:08

Re: ESP-NOW

#6 Post by FanOfHue » 12 Oct 2019, 12:24

Have to do some cleanup, but code is nearing completion for production use.
Some minor changes reduced the send-delay from 300 -> 240 mSeconds
SmartNodeRules Tuya plugin now properly checks the MCU responses and creates events for the rule engine and it also creates a debug event to send internal reponse status replies.

When rules are setup to use ESPNOW:
In normal situation it sends the switch state and powers off as fast as possible
When the build-in 'setup' button is pressed for 5 seconds, the device will start in normal mode and connect to the configured Wifi network.
This ways it's really easy to do OTA firmware updates and no need for a custom sketch. :P

To merge ESPNOW into normal SmartNodeRules network, you need a dedicated ESP to act as ESPNOW to Serial gateway.
This needs to be connected to another SmartNodeRule ESP that connects to the gateway using serial port.

This gateway also uses standard firmware, just configure the rules for it.
(i hate maintaining multiple sketches so all features must be handled by the same firmware :geek: )

You can still configure the rules that is does not use ESPNOW protocal at all, but it will be a lot slower.
Advantage for normal Wifi mode is that you do not need an 'ESPNOW to serial gateway'

tim
Normal user
Posts: 52
Joined: 05 Dec 2015, 11:24

Re: ESP-NOW

#7 Post by tim » 13 Oct 2019, 16:55

Is this about the LSC doorsensor? I also asked in the other topic about the status for ESP Easy. This looks great but can i use it with ESP Easy?

Post Reply

Who is online

Users browsing this forum: No registered users and 32 guests