I am trying to run a simple Meshtastic example code that sends a text message over the 4631’s Lora interface every few seconds. I have a LilyGo T-beam that I am using to check reception, and it doesn’t see any messages from my sample code running on the 4631. The 4631 has the Meshtastic 2.5.x firmware running and communicates fine with my phone’s Meshtastic app over BT and the Meshtastic web client on my Windows laptop over USB. For example, when I send a text from the web client, it shows up immediately on the T-Beam.
Here’s the code I am using:
#include <Arduino.h>
#include <Adafruit_TinyUSB.h>
#include <Meshtastic.h>
#include <mt_internals.h>
#include "sensor.pb.h" // Include your generated Protobuf header
// 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 115200
// Send a text message every this many seconds
#define SEND_PERIOD 5
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, const char* text) {
// Do your own thing here. This example just prints the message to the serial console.
Serial.print("Received a text message from ");
Serial.print(from);
Serial.print(": ");
Serial.println(text);
}
void setup() {
mt_debugging = true;
// 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 ");
Serial.print("serial");
mt_serial_init(SERIAL_RX_PIN, SERIAL_TX_PIN, BAUD_RATE);
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) {
// Initial connection to the Meshtastic device
bool rv = mt_request_node_report(connected_callback);
if (!rv) {
Serial.println("mt_request_node returned error!");
}
rv = mt_send_text("Hello from RAK4631");
if (!rv) {
Serial.println("mt_send_text returned error!");
}
next_send_time = now + SEND_PERIOD * 1000;
}
}
This is based on the SendReceiveClient example from meshtastic.org. I am using PlatformIo to upload the code to the device. The only messages I see on the log are:
12:36:51.535 -> Requesting node report with random ID 1035912239
12:36:51.535 -> Sending text message 'Hello from RAK4631' to 4294967295
FYI, here’s the code for mt_serial_init() in the Meshtastic library:
void mt_serial_init(int8_t rx_pin, int8_t tx_pin, uint32_t baud) {
#ifndef ARDUINO_ARCH_SAMD
serial = new SoftwareSerial(rx_pin, tx_pin);
serial->begin(baud);
#endif
mt_wifi_mode = false;
mt_serial_mode = true;
}
Here’s my platformio.ini:
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html
[env:wiscore_rak4631]
platform = nordicnrf52
board = wiscore_rak4631
framework = arduino
lib_deps =
meshtastic/Meshtastic@^0.0.5
nanopb/Nanopb@^0.4.9
https://github.com/micooke/SoftwareSerial
Any pointers would be greatly appreciated!