Alert notifications for Boat bilge

I’m working on a project to monitor my boats bilge. When the bilge fills to a certain level a float switch activates a pump that empties the bilge. My project will monitor this activity and notify me when:

  1. The water level exceeds the switch activation level indicating either a failure of the switch or the rate of ingress exceeds the pumps ability to clear the bilge. Either is bad and I’d like to know when this happens.
    a) as part of this notification I’d like to rate limit the notifications say to every X minutes.
    b) I’d like to also know when the levels have been restored to normal
  2. The pump has activated as part of a normal cycle.

I’m currently wrestling with #1. Here’s what I have so far;

  //Section for High Bilge Alarm
if (average > 3100) {  // # is when bilge level gets past where the pump should have activated
        Particle.publish("BilgeAlert", "High Bilge level Detected", 60, PRIVATE);
        //tone(buzzer, 1000);                     //activate buzzer
        bilgeAlarmState = TRUE;  //  Set alarm state to TRUE
    } 
    else if (average < 3100 && bilgeAlarmState != bilgeAlarmState) { // # is when bilge level gets below the activation point and state changes from FALSE(off) to TRUE(on)
        //noTone(buzzer);                     //turn off buzzer
        Particle.publish("BilgeAlert", "Bilge level Back to Normal", 60, PRIVATE);
        bilgeAlarmState = FALSE;  // return alarm state to false = OFF
    } 

At the moment the high alarm triggers but the “return to normal” notification doesn’t trigger.
Any suggestions on the best way to do this?

Hi, what is your intention with the above? If I replace mentally with a value (false!=false, or true!=true) it always results in false, meaning the else if branch will never execute.

I think what I was trying to do was only have the “return to normal” notification trigger if there was a change of state specifically from the alarm state to the not alarm state. I only want the “return to normal” notification once but want a regular update to a high bilge level - as long as it is high.
Does that help?

ah ok.

From exactly what you mention below, what's needed is a Finite State Machine (FSM):

The easy way out is to have a variable (maybe called) inAlarmState which will be false if not in alarm, and true if in alarm.
So your else if could look like this:

I would play with that idea.
Best,
Gustavo.

2 Likes

That did the trick! Thanks

//Section for High Bilge Alarm
if (average > 3100) {  // # is when bilge level gets past where the pump should have activated
        //tone(buzzer, 1000);                     //activate buzzer

        inAlarmState = TRUE;  //  Set alarm state to TRUE
    
    // test whether the publishing interval has elapsed
    if (currentTime - lastPublishTime >= publishInterval) {  //test whether the publish period has elapsed
    
      Particle.publish("BilgeAlert", "High Bilge level Detected", 60, PRIVATE);
      
      lastPublishTime = currentTime;  //reset publishing timer
    }
    } 
    else if (average < 3100 && inAlarmState) { // # is when bilge level gets below the activation point and state changes from TRUE(on) to FALSE(off)
        //noTone(buzzer);                     //turn off buzzer
        Particle.publish("BilgeAlert", "Bilge level Back to Normal", 60, PRIVATE);
        inAlarmState = FALSE;  // return alarm state to false = OFF
    }```
1 Like