norstar:
Thank you for taking the time to offer suggestions. I added mesh.disconnect() and mesh.off() but that did not change anything. Then I switched to using the RHreliabledatagram manager. Now the behavior is different - my Xenon gets stuck on the manager.sendtowait(data, sizeof(data), SERVER_ADDRESS) and never returns (not even once). Recall that prior to using RHreliabledatagram manager I was able to execute one send and then I would get stuck on the second send. The same code minus the mesh particular code on a Adafruit Mo works just fine. And I can run the code on an Argon without issue.
#include "Particle.h"
// Command below will prevent the device connecting to the mesh network.
// NOTE: In SYSTEM_MODE(MANUAL), the status LED with breathe white. This is normal.
SYSTEM_MODE(MANUAL);
// Insure the application loop is not interrupted by the system background processing and network management.
SYSTEM_THREAD(ENABLED);
const byte pinBuiltInLED = D7;
//////////////////////////////////////////////////////////////////////////////
// 10000 ms = 10 sec = 0.1 Hz
// 1000 ms = 1 sec = 1 Hz
// 100 ms = 0.1 sec = 10 Hz
// 10 ms = 0.01 sec = 100 Hz
unsigned long timerInterval = random(1000,5000);
unsigned long timerLast = 0; // timer
//////////////////////////////////////////////////////////////////////////////
// LoRa 900 MHz Radio
// RadioHead library for LoRa Radio
// install library: RF9X-RK
// https://github.com/rickkas7/RF9X-RK
#include <RHReliableDatagram.h>
#define SENDER_ADDRESS 1
#define RECEIVER_ADDRESS 2
#include <RH_RF95.h>
// Argon/Boron/Xenon: A=D6, B=D5, C=D4, D=D3, E=D2, F=D14
#define RFM95_INT D2 // Ds="E"
#define RFM95_CS D6 // D6="A"
#define RFM95_RST D14 // D14="F"
// Define frequency (set later)
#define RF95_FREQ 915.0
// Singleton instance of the radio driver
RH_RF95 rf95(RFM95_CS, RFM95_INT);
// Class to manage message delivery and receipt, using the rf95 declared above
RHReliableDatagram manager(rf95, SENDER_ADDRESS);
//////////////////////////////////////////////////////////////////////////////
byte cData[31]; // 16+1+13+1=31 "20200216T150644Z;++6.534755E+06"
byte buf[RH_RF95_MAX_MESSAGE_LEN]; // holds reply from receiver
unsigned long successCount = 0;
boolean bStopOnError = false;
//////////////////////////////////////////////////////////////////////////////
// AF 128x32 mono OLED
// The 128x32 monochrome OLED uses I2C (D0 & D1; 0x3C) D2,D3,D4
// https://github.com/rickkas7/oled-wing-adafruit
// Install Library: oled-wing-adafruit
#include "oled-wing-adafruit.h"
OledWingAdafruit display;
//////////////////////////////////////////////////////////////////////////////
void setup() {
pinMode(pinBuiltInLED, OUTPUT);
// Make sure the Xenon is not connected to the Mesh network
Mesh.disconnect();
Mesh.off();
/* START AF FeatherWing OLED 128x32 mono */
display.setup();
display.clearDisplay();
display.setTextColor(WHITE);
display.setTextWrap(false);
display.setTextSize(1);
display.setCursor(0,0);
display.print("Xenon + LoRa");
display.display();
pinMode(RFM95_RST, OUTPUT);
delay(10);
digitalWrite(RFM95_RST, HIGH);
delay(10);
// manual reset (pull low for 100 us)
digitalWrite(RFM95_RST, LOW);
delay(10);
digitalWrite(RFM95_RST, HIGH);
delay(10);
while (!manager.init()) {
while (1) blinkERR(pinBuiltInLED);
}
// Defaults after init are 434.0MHz, modulation GFSK_Rb250Fd250, +13dbM
// Defaults after init are 434.0MHz, 13dBm, Bw = 125 kHz, Cr = 4/5, Sf = 128chips/symbol, CRC on
if (!rf95.setFrequency(RF95_FREQ)) {
while (1) blinkERR(pinBuiltInLED);
}
// The default transmitter power is 13dBm, using PA_BOOST.
// If you are using RFM95/96/97/98 modules which uses the PA_BOOST transmitter pin, then
// you can set transmitter powers from 5 to 23 dBm:
rf95.setTxPower(23, false);
//////////////////////////////////////////////////////////////////////////////
} // setup()
// loop() runs over and over again, as quickly as it can execute.
void loop() {
// Send a message at a random interval between 500 and 5000 ms
//if (timerLast > millis()) timerLast = millis();
if ((millis() - timerLast) > timerInterval) {
blinkLED(pinBuiltInLED);
digitalWrite(pinBuiltInLED, HIGH);
// Create a message to send with random content.
// "20200216T150644Z;++6.534755E+06"
BuildSimulatedSerialSensorData(cData, sizeof(cData));
display.clearDisplay();
display.setTextSize(2);
display.setCursor(0,0);
display.print("Msg send");
display.setCursor(0,16);
successCount++;
display.print(successCount);
display.display();
if (manager.sendtoWait(cData, sizeof(cData), RECEIVER_ADDRESS)) {
display.clearDisplay();
display.setTextSize(2);
display.setCursor(0,0);
display.print("Msg sent..");
display.setCursor(0,16);
display.print(successCount);
display.display();
// Now wait for a reply from the server
uint8_t len = sizeof(buf);
uint8_t from;
if (manager.recvfromAckTimeout(buf, &len, 2000, &from)) {
digitalWrite(pinBuiltInLED, LOW);
// Compare the received data buff to the data sent arrToEncrypt
int matches = 0;
for(int i=0; i < sizeof(cData); i++){
if(buf[i]==cData[i]){
matches++;
}
}
if (matches == sizeof(cData)) {
successCount++;
digitalWrite(pinBuiltInLED, LOW);
} else {
// The receiver didn't send back the same message content as
// what was sent by this sender.
if (bStopOnError == true)
while (1) blinkERR(pinBuiltInLED);
}
}
} else {
display.clearDisplay();
display.setTextSize(2);
display.setCursor(0,0);
display.print("SEND ERR");
display.setCursor(0,16);
display.print(successCount);
display.display();
}