Hey Bob,
Thanks very much, that worked a treat but I have not got a clue how the program flow works. Why is it comparing a zero?
Here is my working Rx'r code for future people if they want it. Its working on a LoRa Heltec ESP32 clone. Later I intend it to be connected to a float tube with hall sensors in it to detect the water level.
//Tank water level Rxr 433Mhz LoRa ESP32
/*-----( Declare Constants )-----*/
#include <SPI.h>
#include <LoRa.h>
// WIFI_LoRa_32 ports
// GPIO5 -- SX1278's SCK
// GPIO19 -- SX1278's MISO
// GPIO27 -- SX1278's MOSI
// GPIO18 -- SX1278's CS
// GPIO14 -- SX1278's RESET
// GPIO26 -- SX1278's IRQ(Interrupt Request)
#define SS 18
#define RST 14
#define DI0 26
#define BAND 433E6
/*-----( Declare Variables )-----*/
const byte numChars = 32;
char receivedChars[numChars]; //an array to store received data
boolean newData = false;
int relayPin = 16;
int relayState;
/*----( SETUP: RUNS ONCE )----*/
void setup() {
Serial.begin(115200);
pinMode(relayPin, OUTPUT); // sets the pin as output for relay
relayPin = relayState;
while (!Serial); //if just the the basic function, must connect to a computer
delay(1000);
SPI.begin(5,19,27,18);
LoRa.setPins(SS,RST,DI0);
Serial.println("LoRa Receiver");
if (!LoRa.begin(BAND)) {
Serial.println("Starting LoRa failed!");
while (1);
}
Serial.println("LoRa Initial OK!");
}
/*----( LOOP: RUNS CONSTANTLY )----*/
void loop() {
int packetSize = LoRa.parsePacket(); // try to parse packet
if (packetSize) {
Serial.print("Received packet :"); // received a packet
recvWithStartEndMarkers();
showNewData();
}
}
void recvWithStartEndMarkers() {
static boolean recvInProgress = false;
static byte ndx = 0;
char startMarker = '<';
char endMarker = '>';
char rc;
while (LoRa.available() > 0 && newData == false) {
rc = LoRa.read();
if (recvInProgress == true) {
if (rc != endMarker) {
receivedChars[ndx] = rc;
ndx++;
if (ndx >= numChars) {
ndx = numChars - 1;
}
}
else {
receivedChars[ndx] = '\0'; // terminate the string
recvInProgress = false;
ndx = 0;
newData = true;
}
}
else if (rc == startMarker) {
recvInProgress = true;
}
}
}
void showNewData() {
if (newData == true) {
//Serial.print("This just in ... ")
Serial.println(receivedChars);
newData = false;
}
if (strcmp(receivedChars, "empty") == 0) //If this code received then turn on pump
{
Serial.println("Pump ON");
digitalWrite(16,HIGH); //Pump relay ON
relayState = HIGH;
delay(100);
}
if (strcmp(receivedChars, "full") == 0) //If this code received then turn off pump
{
Serial.println("Tank Full - Pump OFF");
digitalWrite(16,LOW); //Pump relay OFF
relayState = LOW;
delay(100);
}
}