Servers by jDrones

Simple ESP Telemetry Serial Bridges

Due to the low cost and high flexibility of Espressif development boards, it’s very attractive to use them for a telemetry link, among many other things. There is some existing software for ESP-based MAVLink telemetry, but I found it somewhat frustrating.

I have had very little success with DroneBridge, even after following the documentation closely. I also tried Tridge’s fork of mavesp8266 with little success.

I think Tridge’s mavesp8266 fork is quite promising, and I do not intend to replace or supplant it in any way, I’m just offering my own (likely somewhat “caveman”) solution to the problem at hand.

DroneBridge, on the other hand, seems a bit bloated for the intended purpose and offers no way to operate in station mode, but only as an access point, which does not fit my use case. My apologies if my criticism is taken negatively by its developers. In fairness, I forked the project, made an attempt at bending it to my will…and failed, mostly due to my unfamiliarity with the build environment.

Because of my success relaying MAVLink messages using ser2net on a Raspberry Pi, which simply repeats serial traffic over a network connection without regard for message content, I thought it should be possible to use an ESP board to do similar. Both DroneBridge and mavesp8266 parse MAVLink messages prior to forwarding them, which seems an unnecessary processing and memory burden.

Testing shows that an ESP32 clocked at 240MHz can process a simple serial repeater loop in less than 3μs, which means that even at 921600 baud, the loop will complete in less time than it takes for an 8-N-1 byte to be transmitted, meaning that the ESP32 can process a serial message byte-by-byte without loss, if necessary.

ESP WiFi Serial Bridge
In any case, I was motivated to attempt my own solution set, and I first achieved success with an ESP32 and this serial bridge code, forked from another example. Testing the bridge with an ESP8266 proved unreliable, perhaps because of the way its UARTs are configured in hardware, so I recommend using an ESP32. It simply creates an access point or connects to an existing network and relays serial traffic on a TCP port.

You’ll need to modify config.h to suit your application and then compile, build, and upload using the Arduino IDE. While I’m sure the Espressif IDE is more capable, I find the Arduino IDE more friendly for small projects like this, and I’ve been frustrated more than once when using the Espressif one.

Moving Forward with ESP-Now
I was dissatisfied with the range using the built-in antenna, and before I started cutting traces or ordering hardware for an external antenna modification, I stumbled on Espressif’s ESP-Now feature for ESP32 and ESP8266 platforms. If you are unfamiliar, ESP-Now is a peer-to-peer 2.4GHz protocol allowing Espressif WiFi boards to communicate directly with one another at a fairly low power state and at longer ranges than the usual WiFi connection (without as much overhead).

ESP-Now is somewhat weakly documented, and the online examples are sometimes a bit dated, as the libraries have changed since some of the example code was written. I found this bi-directional example which seemed most up to date and worked from there. The author of that example, Rui Santos, posted this video describing ESP-Now.

I arrived at this sketch, which shows zero packet loss at short range, and has offered ~25m range with brick walls obstructing the signal. Outdoor testing showed a reliable range of ~115m with direct line of sight, though ANY minor obstruction causes signal loss when using the built-in antennas beyond ~50m. A range test with these external antennas got ~50m through brick/obstacles and 430m outdoors in direct line-of-sight (and farther is probably achievable, since I couldn’t really get much farther away than that and maintain direct line-of-sight where I was testing). All testing was done at 57600 baud, though it should be possible to use much faster serial transmission rates.

OF NOTE: There is a 250 byte limit for ESP-Now packet transmission, where MAVLink defines a maximum packet size of 263 bytes. In practice, most MAVLink messages are much shorter than that, and I have not discovered a case where information is lost under the latest Rover 4.2.0-dev firmware. I have not yet done the homework to determine which MAVLink messages exceed 250 bytes (I suspect few to none). I think it’s important to realize, though, that this ESP-Now bridge may result in data loss when large packets are transmitted, and it should likely not be considered for critical applications.

I did not include the libraries/definitions for ESP8266 compatibility in the ESP-Now code, though it would likely be trivial to do so if one were so motivated.

I modified an ESP-based WiFi serial bridge you can use for MAVLink..
and then
I wrote an ESP-Now serial bridge for increased range at the expense of using another ESP board.

Post Script
If you’re interested in adding an external antenna to your ESP development board, the following should get you pointed in the right direction. There are MANY variations of these boards, so use caution when cutting traces and soldering components based on these pictures alone - your board may differ significantly. There are some boards with antenna connectors already present if you don’t want to go to this trouble and/or potentially ruin your board.

The onboard antenna is located here, and the portion of it we are going to modify is under the tweezers - the two traces leading away from the exposed dots just left of the tweezer tips.

Cut the traces as shown, scoring somewhat deeply with a razor blade to ensure the circuit is permanently broken. You want to cut the two short sections that are vertically oriented in this picture.

Carefully use a razor blade to scrape the solder mask away, exposing the bare copper traces here. It doesn’t take much pressure, and you could easily damage the traces, so go easy.

Tin the traces and component leads, and carefully solder the connector like this. Note, in this orientation, the bottom trace is ground, and the top trace is signal (center pin). You could also solder a length of small coaxial cable or a different style connector in a similar fashion. These SMA connectors have appropriate pin spacing for the job.

You don’t want to rely on the thin copper traces and solder joint as the only mechanical support for the connector, so add some hot glue or dielectric epoxy to provide some additional strength/strain relief. Use care when screwing an antenna onto the board - hold the entire connector rather than relying on the solder joint and glue.


Hi @Yuri_Rage,

Thanks for the great idea to transmit MAVLink packages via ESP-Now. My very first tests on the bench show way better results than I ever was able to achieve with mavesp8266 or BT-dongles.
Very promising!!!
Maybe others busy with swarming experiments will love this too.

Thanks for sharing.

1 Like

Handling Databurst-Type Messages > 250 bytes

Through my testing of RTCM3 injection on Rover-4.1.0-rc1, I found a need for a slightly different version of the ESP-Now bridge discussed above.

MAVLink messages generally fit within ESP-Now’s 250 byte limit, so any ESP-Now message could be assumed a fully formed packet ready for further transmission and processing. RTCM3 messages, on the other hand, can be as large as 1023 bytes, generally hovering in the 400-600 byte range.

The original sketch’s serial polling simply waited for a delay just long enough (in μs) to ensure that any given serial message had been fully collected in a buffer before sending it forward. The receiver simply dumped that message to the serial port immediately upon receipt.

That same serial polling routine works for the sender even when dealing with larger databurst-type transmissions like RTCM3, but the receiver must also do some work to collect things up before passing a message forward. In the case of 1Hz RTCM3 messaging, I found that a 50ms delay between ESP-Now messages is more than adequate to have reasonable certainty that a fully formed packet has been received before writing the entire thing to the serial port (just like @ktrussell uses in his Serial_to_LoRa logic) .

I arrived at the sketch linked below, which was tested up to 460800 baud using external 2.4GHz antennas and resulted in complete coverage of a 2 acre property (where I run my Rover mower) at ranges of up to ~75m, with some elevation changes and obstacles like buildings and trees with virtually no data loss.

I’m so encouraged by the results that I plan to use this method for RTCM3 injection on Zed-F9P modules as a permanent solution for my mower.

A minor footnote: I still recommend the original ESP-Now-Serial-Bridge linked above for MAVLink - it’s faster and likely more reliable for smaller message sizes.

Servers by jDrones