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 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.
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.