How do I set up alarm on loss of connection between LoRa sender and receiver?

Hello, I'm trying to set up my LoRa receiver device to display an alarm integer value to blynk when connection is lost between LoRa sender and receiver.

Here is my code for the LoRa receiver.

#include <Adafruit_MCP9808.h>

#define BLYNK_TEMPLATE_ID ""
#define BLYNK_TEMPLATE_NAME ""
#define BLYNK_AUTH_TOKEN ""
#define BLYNK_PRINT Serial

#include <SPI.h>
#include <LoRa.h>
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>

char ssid[] = "";
char pass[] = "";

const int csPin = 18;
const int resetPin = 14;
const int irqPin = 3;

int LoRaData;

BlynkTimer timer;

void myTimerEvent() {

Blynk.virtualWrite(V1, LoRaData);

}

void setup() {
  Serial.begin(9600);
  while (!Serial);
  
  LoRa.setSpreadingFactor(12);
  LoRa.setPins(csPin, resetPin, irqPin);
  LoRa.setSignalBandwidth(62.5E3);
  LoRa.setCodingRate4(8);

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

Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
  timer.setInterval(10000L, myTimerEvent);

}
 
void loop() {
 
  int packetSize = LoRa.parsePacket();
  if (packetSize) {
 
    while (LoRa.available()) {

    LoRaData = LoRa.read();
    Serial.print(LoRaData);
    Serial.print(" ");

    }
 
    Serial.print("RSSI: ");
    Serial.println(LoRa.packetRssi());
  }



  Blynk.run();
  timer.run();

}```

There is no 'connection' as such with LoRa.

However if the transmitter sends a packet and on receipt of the packet the receiver send back an acknowledge, which the transmitter does not receive, then the transmitter knows there is a problem.

My biggest concern is losing power on the transmitter side. Could an alarm be set up if the receiver fails to receive a packet from the transmitter within a certain time?

1 Like

You could do that, check in loop() the time in mS since the last packet was received.

But you would still need to use a send and ack setup. RF comms is not 100% reliable, its entirely possible that a missed packet is the norm.

Maybe a better description of what you are actually trying to do would help the forum ......

I'm trying to monitor temperature of a well about 3/4 mile from my house. The LoRa transmitter is at the well and the receiver is near my house within wifi range. The LoRa transmitter sends a packet every 10 seconds so I was thinking an alarm after a minute or two of the receiver receiving no packets would be good.

yes, that's a sound approach. You would basically take the LoRa transmitter's packet as a heartbeat. If you stop hearing it for sometime, then you've a problem

Since you are not likely to power both devices at the same time, you need to allow for the initial conditions of not getting an acknowledgement and for not getting a message at the receiver. A simple Boolean set to false will allow your transmission test to be ignored for perhaps, 10 minutes, to allow you to get power to both devices.

Temperature of a well ????

Why do you need to know what it is every 10 seconds ?

Do you mean the pump, as in checking for overheating? The water temperature should not vary much, if at all.

It's more so for making sure the wellhouse temp doesn't drop too low in the winter.

10 seconds is probably a little excessive. The goal is to make sure wellhouse temp doesn't drop below freezing in winter.

The outside temperature is a pretty good guide as whether there could even possibly be a problem in the well house.

The wellhouse is insulated and heated in the winter but historically the heater has failed or a breaker has been tripped.

Indeed.

So if the wellhouse is insulated it might take many minutes or an hour or more for there to be a significant drop in temperature ?

For sure. I can definitely increase the time between packets to a more suitable number. The low number I have now is more so for testing.

So I think I found a solution. I added a timer that gets reset every time a packet is received. The timer goes off at 20 seconds and will set the LoRaData variable to an error number.

void loop() {
  static unsigned long Timer = millis();
  int packetSize = LoRa.parsePacket();

  if (packetSize) {
 
    while (LoRa.available()) {

    LoRaData = LoRa.read();
    Serial.print(LoRaData);
    Serial.print(" ");
    }
 
    Serial.print("RSSI: ");
    Serial.println(LoRa.packetRssi());
    Timer = millis();
  }

if (millis() - Timer > 20000) {
  LoRaData = 50;
  }

  Blynk.run();
  timer.run();

}
1 Like

The well house is not the problem. ALL wells must breathe! An extremely cold high pressure weather will force the frigid air into the well house and into the well, freezing the top of the water pipe in the well casing. Has happened to me several times and the previous owner had it happen while they were away for an expended period. That allows the pump to run for ever because the water cannot get to the pressure tank and regulating switch, etc. The pump motor eventually burned out and all had to be replaced in the frigid weather.

I really need to do something similar to my well, but are seldom away from home and can keep track of what is happening to the well and water system. We also have a space heater in the well house, the pipe to the storage tank in the garage also has heat tape and all is wrapped with several inches on insulation. The space heater has died several time.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.