@krixen1 ,
OK, perhaps a bit of a reset then. I understand you want mesh functionality. For that, you will need to use the branch that @jgskarda made of the Particle RH LoRA library. We have not been successful in getting Particle to agree to merge the branch so this may be a new library someday - we will see.
Take a look at this simplified code - it should work and let you test mesh functionality before adding all the complexity that comes with an actual functional solution.
Edit your pin assignments based on your implementation.
A minimal mesh node sketch
/*
* Project Simple-LoRA-Mesh-Node
* Description: Simple code to test mesh functionality
* Author: Chip McClelland based on example code in the RF9X-RK library
* Date:2/15/23
*/
// Mesh has much greater memory requirements, and you may need to limit the
// max message length to prevent wierd crashes
#define RH_MESH_MAX_MESSAGE_LEN 50
#include "Particle.h"
#include <RHMesh.h>
#include <RH_RF95.h>
SerialLogHandler logHandler(LOG_LEVEL_INFO); // Easier to see the program flow
// In this small artifical network of 4 nodes,
#define CLIENT_ADDRESS 1
#define SERVER1_ADDRESS 2
#define SERVER2_ADDRESS 3
#define SERVER3_ADDRESS 4
// Edit the RHRouter.cpp file to test different mesh topologies
// Prototypes and System Mode calls
SYSTEM_THREAD(ENABLED); // Means my code will not be held up by Particle processes.
SYSTEM_MODE(MANUAL);
// #define RF95_FREQ 915.0
#define RF95_FREQ 926.84
//Define pins for the RFM9x on the Feather Exapander board - this is not the same as on the carrier board
const pin_t RFM95_CS = D5; // Carrier Board setting
const pin_t RFM95_RST = D6; // Carrier Board Setting
// const pin_t RFM95_CS = D6; // Featherwing Setting
// const pin_t RFM95_RST = A5; // Featherwing Setting
const pin_t RFM95_INT = D2; // Interrupt from radio
const pin_t BLUE_LED = D7;
// Singleton instance of the radio driver
// RH_RF95 driver(D6, D2);
RH_RF95 driver(RFM95_CS, RFM95_INT);
// Class to manage message delivery and receipt, using the driver declared above
RHMesh manager(driver, CLIENT_ADDRESS);
void setup()
{
pinMode(BLUE_LED,OUTPUT);
digitalWrite(BLUE_LED,HIGH);
waitFor(Serial.isConnected, 10000); // Wait for serial connection
if (!manager.init()) Log.info("init failed"); // Defaults after init are 434.0MHz, 0.05MHz AFC pull-in, modulation FSK_Rb2_4Fd36
driver.setFrequency(RF95_FREQ); // Frequency is typically 868.0 or 915.0 in the Americas, or 433.0 in the EU
driver.setTxPower(23, false); // you can set transmitter powers from 5 to 23 dBm:
digitalWrite(BLUE_LED,LOW);
}
uint8_t data[] = "Hello World!";
uint8_t buf[RH_MESH_MAX_MESSAGE_LEN]; // Dont put this on the stack:
void loop()
{
Log.info("Sending to manager_mesh_server1");
// Send a message to manager_server
// A route to the destination will be automatically discovered.
digitalWrite(BLUE_LED,HIGH);
if (manager.sendtoWait(data, sizeof(data), SERVER1_ADDRESS) == RH_ROUTER_ERROR_NONE) {
// It has been reliably delivered to the next node.
// Now wait for a reply from the ultimate server
uint8_t len = sizeof(buf);
uint8_t from;
uint8_t hops;
if (manager.recvfromAckTimeout(buf, &len, 3000, &from)){
buf[len] = 0;
Serial.printlnf("got reply from 0x%02x rssi=%d %s and %d hops", from, driver.lastRssi(), (char *) buf, hops);
}
else {
Log.info("No reply, is rf95_mesh_server1, rf95_mesh_server2 and rf95_mesh_server3 running?");
}
}
else Log.info("sendtoWait failed. Are the intermediate mesh servers running?");
digitalWrite(BLUE_LED,LOW);
delay(3000);
}
A minimal Mesh Gateway sketch
/*
* Project Simple-LoRA-Mesh-Server
* Description: Simple implementation based on RH9X-RK example code
* Author: Chip McClelland
* Date: 2/15/23
*/
// Mesh has much greater memory requirements, and you may need to limit the
// max message length to prevent wierd crashes
#define RH_MESH_MAX_MESSAGE_LEN 50
#include "Particle.h"
#include <RHMesh.h>
#include <RH_RF95.h>
SerialLogHandler logHandler(LOG_LEVEL_INFO); // Easier to see the program flow
// In this small artifical network of 4 nodes,
#define CLIENT_ADDRESS 1
#define SERVER1_ADDRESS 2
#define SERVER2_ADDRESS 3
#define SERVER3_ADDRESS 4
// Prototypes and System Mode calls
SYSTEM_THREAD(ENABLED); // Means my code will not be held up by Particle processes.
SYSTEM_MODE(MANUAL);
// #define RF95_FREQ 915.0
#define RF95_FREQ 926.84
//Define pins for the RFM9x on the Feather Exapander board - this is not the same as on the carrier board
const pin_t RFM95_CS = D5; // SPI Chip select pin - Standard SPI pins otherwise was A5
const pin_t RFM95_RST = D6; // Radio module reset was D3
// const pin_t RFM95_CS = D6; // SPI Chip select pin - Standard SPI pins otherwise was A5
// const pin_t RFM95_RST = A5; // Radio module reset was D3
const pin_t RFM95_INT = D2; // Interrupt from radio
const pin_t BLUE_LED = D7;
// Singleton instance of the radio driver
// RH_RF95 driver(D6, D2);
RH_RF95 driver(RFM95_CS, RFM95_INT);
// Class to manage message delivery and receipt, using the driver declared above
RHMesh manager(driver, SERVER1_ADDRESS);
void setup()
{
pinMode(BLUE_LED,OUTPUT);
digitalWrite(BLUE_LED,HIGH);
waitFor(Serial.isConnected, 10000); // Wait for serial connection
Log.info("Starting the Simple LoRA Server");
if (!manager.init()) Log.info("init failed"); // Defaults after init are 434.0MHz, 0.05MHz AFC pull-in, modulation FSK_Rb2_4Fd36
driver.setFrequency(RF95_FREQ); // Frequency is typically 868.0 or 915.0 in the Americas, or 433.0 in the EU
driver.setTxPower(23, false); // you can set transmitter powers from 5 to 23 dBm:
digitalWrite(BLUE_LED,LOW);
}
uint8_t data[] = "And hello back to you from server1";
uint8_t buf[RH_MESH_MAX_MESSAGE_LEN]; // Dont put this on the stack:
void loop()
{
uint8_t len = sizeof(buf);
uint8_t from;
uint8_t hops;
if (manager.recvfromAck(buf, &len, &from, &hops))
{
digitalWrite(BLUE_LED,HIGH);
buf[len] = 0;
Serial.printlnf("got request from : 0x%02x rssi=%d %s and %d hops", from, driver.lastRssi(), (char *) buf, hops);
// Send a reply back to the originator client
if (manager.sendtoWait(data, sizeof(data), from) != RH_ROUTER_ERROR_NONE)
Log.info("sendtoWait failed");
digitalWrite(BLUE_LED,LOW);
}
}
You can test the mesh network by editing the RHRouter.cpp file so you can keep all your gear on your desktop and monitor the serial messages.
Hope this helps,
Chip