Skip to content

11. LoRa MESH

Hero Shot of the Week

Summary

So this if from week 18. But I feel like I should put it here.

Work Process

Here I am working with:

Introduction

LoRa Alliance

Hackster.io

Meshtastic with Seeed Xiao ESP32S3 and Wio SX1262

What is a LoRa Mesh Network?

Decoding LoRa Technology: Understanding the Differences Between LoRaWAN®, LoRa P2P, and LoRa Mesh

lora radio mesh communication

Know your frequencies

Not mush ont the FabAcademy repo:

LoRa MESH

SX1262

Meshtastic

Meshtastic + XIAO ESP32-S3 + Wio-SX1262

Intro

Home page of Meshtastic

So I am gonna start with reading this: Bootcamp 2025 xIAO-Lora

GitHub

So I started to read the Getting Started documentation.

Seeed Tutorial & Documentation

This is the final understanding:

LoRa Tree

Driver

I have no clue if I need to download any of the drivers mentioned.

Lets continue and see if I have an error later on.

So I had that error after the flash of the ESP. Checking the Installation doc

Serial Test

I might need to install them after all.

Flash ESP32 Devices

Lets flash the firmware.

Use chromium based browser, eg: Chrome

Flash

So...

Is this a success or a fail ?

Flash

Well

The LED on the Wio-SX1262 is blinking so I will assume that it worked.

Settings

Serial Connection

Use chromium based browser, eg: Chrome

Serial Connection

Wow.

The settings interface is so nice and user friendly.

So I managed to connect them together after selecting the right region.

Connected

Now I need to understand how to transfer my sensor data to another node.

USE THE RIGHT FREQUENCY FOR YOUR COUNTRY AND FOR YOUR ANTENNA

Code

So there is a PIO library for this.

Library

Example Code from Meshtastic

The issue is that this code is for Adafruit Feather M0 WiFi.

Example Code
/*
    Meshtastic send/receive client

    Connects to a Meshtastic node via WiFi or Serial (and maybe one day Bluetooth),
    and instructs it to send a text message every SEND_PERIOD milliseconds.
    The destination and channel to use can be specified.

    If the Meshtastic nodes receives a text message, it will call a callback function,
    which prints the message to the serial console.
*/

#include <Meshtastic.h>

// Pins to use for WiFi; these defaults are for an Adafruit Feather M0 WiFi.
#define WIFI_CS_PIN 8
#define WIFI_IRQ_PIN 7
#define WIFI_RESET_PIN 4
#define WIFI_ENABLE_PIN 2

// Pins to use for SoftwareSerial. Boards that don't use SoftwareSerial, and
// instead provide their own Serial1 connection through fixed pins
// will ignore these settings and use their own.
#define SERIAL_RX_PIN 13
#define SERIAL_TX_PIN 15
// A different baud rate to communicate with the Meshtastic device can be specified here
#define BAUD_RATE 9600

// Send a text message every this many seconds
#define SEND_PERIOD 3000

uint32_t next_send_time = 0;
bool not_yet_connected = true;

// This callback function will be called whenever the radio connects to a node
void connected_callback(mt_node_t *node, mt_nr_progress_t progress) {
if (not_yet_connected) 
    Serial.println("Connected to Meshtastic device!");
not_yet_connected = false;
}

// This callback function will be called whenever the radio receives a text message
void text_message_callback(uint32_t from, uint32_t to,  uint8_t channel, const char* text) {
// Do your own thing here. This example just prints the message to the serial console.
Serial.print("Received a text message on channel: ");
Serial.print(channel);
Serial.print(" from: ");
Serial.print(from);
Serial.print(" to: ");
Serial.print(to);
Serial.print(" message: ");
Serial.println(text);
if (to == 0xFFFFFFFF){
    Serial.println("This is a BROADCAST message.");
} else if (to == my_node_num){
    Serial.println("This is a DM to me!");
} else {
    Serial.println("This is a DM to someone else.");
}
}

void setup() {
// Try for up to five seconds to find a serial port; if not, the show must go on
Serial.begin(9600);
while(true) {
    if (Serial) break;
    if (millis() > 5000) {
    Serial.print("Couldn't find a serial port after 5 seconds, continuing anyway");
    break;
    }
}

Serial.print("Booted Meshtastic send/receive client in ");

// Change to 1 to use a WiFi connection
#if 0
#include "arduino_secrets.h"
Serial.print("wifi");
mt_wifi_init(WIFI_CS_PIN, WIFI_IRQ_PIN, WIFI_RESET_PIN, WIFI_ENABLE_PIN, WIFI_SSID, WIFI_PASS);
#else
Serial.print("serial");
mt_serial_init(SERIAL_RX_PIN, SERIAL_TX_PIN, BAUD_RATE);
#endif
Serial.println(" mode");

// Set to true if you want debug messages
mt_set_debug(false);

randomSeed(micros());

// Initial connection to the Meshtastic device
mt_request_node_report(connected_callback);

// Register a callback function to be called whenever a text message is received
set_text_message_callback(text_message_callback);
}

void loop() {
// Record the time that this loop began (in milliseconds since the device booted)
uint32_t now = millis();

// Run the Meshtastic loop, and see if it's able to send requests to the device yet
bool can_send = mt_loop(now);

// If we can send, and it's time to do so, send a text message and schedule the next one.
if (can_send && now >= next_send_time) {

    // Change this to a specific node number if you want to send to just one node
    uint32_t dest = BROADCAST_ADDR; 
    // Change this to another index if you want to send on a different channel
    uint8_t channel_index = 0; 

    mt_send_text("Hello, world!", dest, channel_index);

    next_send_time = now + SEND_PERIOD * 1000;
}
}

Well...
This shit is not just plug and play...

Now I can't upload any arduino code...

So I figured out something. It is not the upload the issue but the fact that my button was on D6 which is now converted to serial comm as it is the TX pin.

I am starting to feel like I need to modify the firmware and I cannot just use it like a library.

Well...
The library previously mentioned is only for interfacing with the nodes. Not to connect to the MESH itself...

Day 2

I can connect via MESH 2 ESPs and chat.

Comm

Now I need to figure out how to send data FROM the secondary controller.

Serial Config

Following this Tutorial

  1. Go to the web portal
  2. Config
  3. Module Config
  4. Serial
  5. Enable
  6. Set RX and TX pins (GPIO Numbers)
  7. Select Baud Band Width
  8. Mode: Textmsg (For other modes check the Serial Conf link bellow)

Serial Configuration

Conf Serial

Well...

Whenever I upload to the ESP connected to node 00, node 02 receives weird messages. But not the message that I am trying to send XD

Weird messaged

Chat GPT
#include <arduino.h>
int i;

void setup() {
Serial.begin(115200);
pinMode(LED_BUILTIN, OUTPUT);
i = 0;
}

void loop() {

i++;

Serial.println(String(i));
Serial.println("Hello World");

if((i % 2) == 0){
    digitalWrite(LED_BUILTIN, HIGH);
}
else{
    digitalWrite(LED_BUILTIN, LOW);
}

delay(2000);
}

This is the code that is uploaded to my ESP that is connected to node 0

Node 2 does not recieves any of the serial.prints but node 2 shows messages (not related to the code) when I upload a new code to the esp it is the following text:

ESP-ROM:esp32s3-20210327 Build:Mar 27 2021 rst:0x15 (USB_UART_CHIP_RESET),boot:0x2 (DOWNLOAD(USB/UART0)) Saved PC:0x4201f4fe waiting for download

78be1 SPIWP:0xee mode:DIO, clock div:1 load:0x3fce3808,len:0x4bc load:0x403c9700,len:0xbd8 load:0x403cc700,len:0x2a0c entry 0x403c98d0

any idea what is happening ?

Chat GPT - Answer

Yes — this is a common and subtle issue when trying to use Serial communication between your ESP32-S3 (running Arduino code) and a Meshtastic node on the same or a separate device.

Let’s break it down:


🔍 What You’re Observing

  • Your code prints serial data using Serial.println()
  • Node 2 is not receiving those prints
  • But when you upload code, Node 2 sees bootloader/debug output like:

ESP-ROM:esp32s3...
waiting for download
* That means Node 2 is receiving serial data, just not the data from your program


🎯 Root Cause

You're using:

Serial.begin(115200);

Which is USB Serial on the ESP32-S3.

But Meshtastic expects serial data on UART, typically Serial1, not the USB Serial interface.

In other words:

  • Serial (USB) goes to your computer
  • Serial1 (UART) goes to the LoRa Meshtastic node (via physical TX/RX pins)

Unless your ESP32-S3 is connected via UART (hardware TX/RX) to another Meshtastic node’s UART RX/TX, it won’t work.


✅ How to Fix It

🔧 Option 1: Use Serial1 for Meshtastic Connection

Update your code:

void setup() {
Serial.begin(115200);     // USB for debug
Serial1.begin(921600);    // UART for Meshtastic node
pinMode(LED_BUILTIN, OUTPUT);
i = 0;
}

void loop() {
i++;

Serial.println(String(i));                // USB debug
Serial.println("Hello World");

Serial1.print("Hello World from Node 0"); // UART to Node 2 (Meshtastic)

if ((i % 2) == 0){
    digitalWrite(LED_BUILTIN, HIGH);
} else {
    digitalWrite(LED_BUILTIN, LOW);
}

delay(2000);
}

📌 Important:

You must connect the hardware pins:

  • ESP TX (e.g. D6)Meshtastic RX
  • ESP RX (e.g. D7)Meshtastic TX
  • Ensure common GND

And you must tell Serial1.begin() which pins to use:

Serial1.begin(921600, SERIAL_8N1, RX_PIN, TX_PIN);

Replace RX_PIN and TX_PIN with the actual pins on your ESP32-S3 board you're using.


🧪 How to Verify

  1. Upload the modified code.
  2. Connect Node 0 (your ESP) to Node 2 via UART.
  3. Monitor Node 2's messages — it should now receive the Serial1.print() messages.

Bonus Tip

If you only have one ESP32-S3 and you're trying to act as both sensor and Meshtastic node, you’ll need to either:

  • Modify Meshtastic firmware (advanced)
  • Or use another ESP32 as the Meshtastic node, and let your ESP32-S3 just send sensor data via UART

Would you like help choosing the correct pins for Serial1 on your ESP32-S3 board or wiring it to your Wio-SX1262 module?

And now my code works...

Success !

Success2

An issue is that after some time the web interface freezes. I do not know if it is the whole MESH or just the web interface.

Now to figure out how to go from received data to a website.

More info on UART

So I managed to serial print data sent over the LoRa. In reality it is only half managed...

Serial Print

Now its good.

Serial Print

The codes can be found here:

Serial print to p5.js

Distance Measurement

So I continued with my testing. It seems that I can only achieve 20m of distance. I followed theses tutorials

I also installed the Meshtastic python CLI.
I had the issue that it said that meshtastic is not recognized so in the end my friend Alessandro helped out. He gave me the following code to use instead python -m meshtastic --port COM22 --info

Its funny how a whole day of work was resumed in just +-10 lines 🥲

So I thought. What if I have an inadequate antenna ?

Here is the answer

Antenna

Antenna *

So it should work up to 2km in open space. And I am far of being of open space and without any interference...

But to go from 1km to 20m ...

Lets try it in a straight line. In the corridor.

Distance at which I loose signal

Distance

and the data analysis gives +-10m.

Meshtastic + XIAO nRF52840

Meshtastic Doc

Well...

It is for the kit version Mine is not the kit version.

Arduino LoRa

GitHub

This library is for SX1276/77/78/79

But this tutorial says that it works with SX1262...

MeshCore

Home page of MeshCore

ripple

Home page of ripple


Learning Outcome