LoRa If Message Contains - Then

I am very new at this but slowly learning.

I have a LoRa remote transmitter (MKR1310) that I made to monitor water levels. It sends a daily message 'LowWater' if more water is needed. 'OkWater' of water is ok. That part is working fine.

I also have a MKR1310 that is receiving those transmissions just fine but I want to make a conditional 'If transmission contains 'LowWater' then turn on something'. I have been trying to figure this out for days and Im stuck.

I was using a Heltec LoRa and found an example that worked but I want to use the 1310 now instead and it appears to use different syntax and libraries that are not compatible.

The Heltec code section that works (keep in mind I have very little understanding of HOW it works.. just it made my LED light up as designed :slight_smile: )

if(strncmp(Readback, "LowWater", strlen(Readback)) == 0) {
	digitalWrite(LED, HIGH); 
        Serial.print("Low Water Level '");
 }

What would I need to do to get that same/similar result here?:

#include <SPI.h>
#include <LoRa.h>

void setup() {
  Serial.begin(9600);
 // while (!Serial);

  Serial.println("LoRa Receiver");

  if (!LoRa.begin(915E6)) {
    Serial.println("Starting LoRa failed!");
    while (1);
  }
}

void loop() {
  // try to parse packet
  int packetSize = LoRa.parsePacket();
  if (packetSize) {
    // received a packet
    Serial.print("Received packet '");

    // read packet
    while (LoRa.available()) {
      Serial.print((char)LoRa.read());
    }

    // print RSSI of packet
    Serial.print("' with RSSI ");
    Serial.println(LoRa.packetRssi());
  }
}

Thank you VERY much in advance!!!

What would I need to do to get that same/similar result here?:

You can declare a char array where you you will accumulate the received characters.Make the array size one longer than the longest message expected so that you can add a terminating NULL. Read the received characters into that array.

Once you have the received message in a null terminated character array, you can use the strncmp() function as you currently do.

#include <SPI.h>
#include <LoRa.h>
char Readback[10] = "";//Size this for max message
byte index = 0;

void setup() {
  Serial.begin(9600);
  Serial.println("LoRa Receiver");

  if (!LoRa.begin(915E6)) {
    Serial.println("Starting LoRa failed!");
    while (1);
  }
}

void loop() {
  // try to parse packet
  int packetSize = LoRa.parsePacket();
  if (packetSize) {
    // received a packet
    Serial.print("Received packet '");
    index = 0;//reset index

    // read packet
    while (LoRa.available()) {
      Readback[index] = (char)LoRa.read();
      index++;
      Readback[index] = '\0';//NULL terminate next position
      //Serial.print((char)LoRa.read());
    }
    Serial.println(Readback);
    if (strncmp(Readback, "LowWater", strlen(Readback)) == 0) {
      digitalWrite(LED, HIGH);
      Serial.print("Low Water Level '");
    }

    // print RSSI of packet
    Serial.print("' with RSSI ");
    Serial.println(LoRa.packetRssi());
  }
}

Thank you SO MUCH! Worked perfectly!

Thanks again!