Close
0%
0%

Linux-ESPNOW

An attempt at implementing a direct link between a linux station and an ESP module using ESPNOW protocol for real time robot control

Public Chat
Similar projects worth following
For a robotic application, I would like to use a direct wireless link between a control computer and a distant robot. With minimum latency, and delay.

Expressif proposed ESPNOW, a way to link two ESP8266 or ESP32 using vendor specific action frame of 802.11. This is way faster than UDP on regular WIFI. My first test show less than 300us to transmit 200Bytes of data !

A solution is to use two of this module, but then we need to use another link between the computer and one of the modules. We don't want to use USB because of the possible jitter and delay it introduces.

Since some wireless card support monitoring and injection of raw packets, it should be possible to use directly the WiFi card of the control PC !! But how??

This project will keep track of my investigation, and any advise is warmly welcome.

Ideally, at the end, we could have a ESP-NOW driver for linux that allow to efficiently connect our favorite ESP chip to a control PC.

Some ressources to be update on the go

ESP NOW protocol:

https://docs.espressif.com/projects/esp-idf/en/latest/api-reference/wifi/esp_now.html

http://wiki.ai-thinker.com/_media/esp8266/docs/30c_esp-now_user_guide_en.pdf

Linux Wireless Networking:

https://www.linux.com/blog/linux-wireless-networking-short-walk

https://stackoverflow.com/questions/48271119/how-to-send-both-802-11-management-frames-and-data-frames-using-raw-sockets-in-l

After swimming in a lot of information, I think I found the perfect starting point to send and receive raw 802.11 packet !

https://warmcat.com/git/packetspammer

Update 12/14/2018: Here is an other lib to send and receive raw wifi packet, It even has a python binding...To be tested soon..

https://github.com/kismetwireless/lorcon

  • How ESP-NOW really works ?

    Thomas Flayols10/18/2018 at 13:29 0 comments

    To implement the ESP-NOW Protocol, we first need to understand how it works in details.

    The datasheet doesn't say much on the really low level, especially on the acknowledgment behavior.

    To understand what ESP-NOW does, I use Wireshark with my PC Wifi card in monitoring mode:

    > sudo ifconfig wlan0 down
    > sudo iwconfig wlan0 mode monitor
    > sudo ifconfig wlan0 up
    > sudo wireshark

    With one ESP8266 sending ESP-NOW to a non existing MAC adress, I got the following packets:

    The same packet is sent multiple times, with a decreasing datarate :

    • 2 tries at 6Mb/s
    • 2 tries at 2Mb/s
    • 7 tries at 1Mb/s (maybe this last number of tries depends on a timeout...)

    First bad news: ESP-NOW continues to send the packet again and again for 20ms !

    I hope their is a way to disable this resend behavior... Indeed, for a robotic control, we prefer to wait for the next up-to-date packet than getting an outdated one, and jamming the channel...

    Let's look at the packet itself:

    0000   00 00 12 00 2e 48 00 00 10 0c 6c 09 c0 00 d5 03   .....H....l.À.Õ.
    0010   00 00 d0 00 3c 00 84 f3 eb 73 55 0d 86 f3 eb 73   ..Ð.<..óësU..óës
    0020   ca 61 84 f3 eb 73 55 0d a0 09 7f 18 fe 34 17 71   Êa.óësU. ...þ4.q
    0030   47 8c dd ff 18 fe 34 04 01 62 12 12 12 12 12 12   G.Ýÿ.þ4..b......
    0040   12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12   ................
    0050   12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12   ................
    0060   12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12   ................
    0070   12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12   ................
    0080   12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12   ................
    0090   12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12   ................
    00a0   12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12   ................
    00b0   12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12   ................
    00c0   12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12   ................
    00d0   12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12   ................
    00e0   12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12   ................
    00f0   12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12   ................
    0100   12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12   ................
    0110   12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12   ................
    0120   12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12   ................
    0130   12 12 12 1d 2c ba 98                              ....,º.
    

     The payload is "0x04 0x12 0x12 ... 0x12" (on my test I choose to begin with a packet counter to distinguish different packets.)

    The frame format seems to follow the documentation from expressif, and the header should be easy to generate:

    https://docs.espressif.com/projects/esp-idf/en/latest/api-reference/wifi/esp_now.html

    Now, if I turn on the destination ESP8266, the packets are sent only once, and a quick acknowledgement frame is sent back in (about 60us):

    I guess this acknowledgment frame will be generated by the low level MAC layer, so we shouldn't take care of managing it... 

    The next test is then to send ESP-NOW packets to my laptop MAC address, and check that ACK are sent automatically even in monitoring mode... 

    Hum... After a quick test, when I Sending a packet to my laptop's MAC address, it does't send an ACK back. Maybe the monitor mode disable this in the MAC layer ?

View project log

Enjoy this project?

Share

Discussions

Similar Projects

Does this project spark your interest?

Become a member to follow this project and never miss any updates