@@ -138,6 +138,7 @@ int err; // Error value returned by IridiumSBD.begin
138
138
bool firstTime = true ; // Flag to indicate if this is the first time around the loop (so we go right round the loop and not just check the PHT)
139
139
int delayCount; // General-purpose delay count used by non-blocking delays
140
140
bool alarmState = false ; // Use this to keep track of whether we are in an alarm state
141
+ uint8_t alarmType = 0 ; // Field to save which alarm has been set off
141
142
bool dynamicModelSet = false ; // Flag to indicate if the ZOE-M8Q dynamic model has been set
142
143
bool geofencesSet = false ; // Flag to indicate if the ZOE-M8Q geofences been set
143
144
@@ -420,57 +421,58 @@ void loop()
420
421
}
421
422
422
423
alarmState = false ; // Clear the alarm state
424
+ alarmType = 0 ; // Clear the alarm type
423
425
424
426
// Check if a PHT alarm has occurred
425
- if (( myTrackerSettings.FLAGS1 & FLAGS1_HIPRESS) == FLAGS1_HIPRESS) // If the HIPRESS alarm is enabled
427
+ if (myTrackerSettings.PRESS . the_data > myTrackerSettings. HIPRESS . the_data ) // Check if HIPRESS has been exceeded
426
428
{
427
- // Check if HIPRESS has been exceeded
428
- if (myTrackerSettings.PRESS . the_data > myTrackerSettings. HIPRESS . the_data )
429
+ alarmType |= ALARM_HIPRESS;
430
+ if (( myTrackerSettings.FLAGS1 & FLAGS1_HIPRESS) == FLAGS1_HIPRESS) // If the HIPRESS alarm is enabled
429
431
{
430
432
alarmState = true ;
431
433
Serial.println (F (" *** HIPRESS Alarm! ***" ));
432
434
}
433
435
}
434
- if (( myTrackerSettings.FLAGS1 & FLAGS1_LOPRESS) == FLAGS1_LOPRESS) // If the LOPRESS alarm is enabled
436
+ if (myTrackerSettings.PRESS . the_data < myTrackerSettings. LOPRESS . the_data ) // Check if LOPRESS has been exceeded
435
437
{
436
- // Check if LOPRESS has been exceeded
437
- if (myTrackerSettings.PRESS . the_data < myTrackerSettings. LOPRESS . the_data )
438
+ alarmType |= ALARM_LOPRESS;
439
+ if (( myTrackerSettings.FLAGS1 & FLAGS1_LOPRESS) == FLAGS1_LOPRESS) // If the LOPRESS alarm is enabled
438
440
{
439
441
alarmState = true ;
440
442
Serial.println (F (" *** LOPRESS Alarm! ***" ));
441
443
}
442
444
}
443
- if (( myTrackerSettings.FLAGS1 & FLAGS1_HITEMP) == FLAGS1_HITEMP) // If the HITEMP alarm is enabled
445
+ if (myTrackerSettings.TEMP . the_data > myTrackerSettings. HITEMP . the_data ) // Check if HITEMP has been exceeded
444
446
{
445
- // Check if HITEMP has been exceeded
446
- if (myTrackerSettings.TEMP . the_data > myTrackerSettings. HITEMP . the_data )
447
+ alarmType |= ALARM_HITEMP;
448
+ if (( myTrackerSettings.FLAGS1 & FLAGS1_HITEMP) == FLAGS1_HITEMP) // If the HITEMP alarm is enabled
447
449
{
448
450
alarmState = true ;
449
451
Serial.println (F (" *** HITEMP Alarm! ***" ));
450
452
}
451
453
}
452
- if (( myTrackerSettings.FLAGS1 & FLAGS1_LOTEMP) == FLAGS1_LOTEMP) // If the LOTEMP alarm is enabled
454
+ if (myTrackerSettings.TEMP . the_data < myTrackerSettings. LOTEMP . the_data ) // Check if LOTEMP has been exceeded
453
455
{
454
- // Check if LOTEMP has been exceeded
455
- if (myTrackerSettings.TEMP . the_data < myTrackerSettings. LOTEMP . the_data )
456
+ alarmType |= ALARM_LOTEMP;
457
+ if (( myTrackerSettings.FLAGS1 & FLAGS1_LOTEMP) == FLAGS1_LOTEMP) // If the LOTEMP alarm is enabled
456
458
{
457
459
alarmState = true ;
458
460
Serial.println (F (" *** LOTEMP Alarm! ***" ));
459
461
}
460
462
}
461
- if (( myTrackerSettings.FLAGS1 & FLAGS1_HIHUMID) == FLAGS1_HIHUMID) // If the HIHUMID alarm is enabled
463
+ if (myTrackerSettings.HUMID . the_data > myTrackerSettings. HIHUMID . the_data ) // Check if HIHUMID has been exceeded
462
464
{
463
- // Check if HIHUMID has been exceeded
464
- if (myTrackerSettings.HUMID . the_data > myTrackerSettings. HIHUMID . the_data )
465
+ alarmType |= ALARM_HIHUMID;
466
+ if (( myTrackerSettings.FLAGS1 & FLAGS1_HIHUMID) == FLAGS1_HIHUMID) // If the HIHUMID alarm is enabled
465
467
{
466
468
alarmState = true ;
467
469
Serial.println (F (" *** HIHUMID Alarm! ***" ));
468
470
}
469
471
}
470
- if (( myTrackerSettings.FLAGS1 & FLAGS1_LOHUMID) == FLAGS1_LOHUMID) // If the LOHUMID alarm is enabled
472
+ if (myTrackerSettings.HUMID . the_data < myTrackerSettings. LOHUMID . the_data ) // Check if LOHUMID has been exceeded
471
473
{
472
- // Check if LOHUMID has been exceeded
473
- if (myTrackerSettings.HUMID . the_data < myTrackerSettings. LOHUMID . the_data )
474
+ alarmType |= ALARM_LOHUMID;
475
+ if (( myTrackerSettings.FLAGS1 & FLAGS1_LOHUMID) == FLAGS1_LOHUMID) // If the LOHUMID alarm is enabled
474
476
{
475
477
alarmState = true ;
476
478
Serial.println (F (" *** LOHUMID Alarm! ***" ));
@@ -480,6 +482,7 @@ void loop()
480
482
// If voltage is lower than LOWBATT, send an alarm message
481
483
get_vbat (); // Get the battery (bus) voltage
482
484
if (myTrackerSettings.BATTV .the_data < myTrackerSettings.LOWBATT .the_data ) {
485
+ alarmType |= ALARM_LOBATT;
483
486
Serial.print (F (" *** LOWBATT: " ));
484
487
Serial.print ((((float )myTrackerSettings.BATTV .the_data )/100.0 ),2 );
485
488
Serial.println (F (" V ***" ));
@@ -489,6 +492,10 @@ void loop()
489
492
Serial.println (F (" *** LOWBATT Alarm! ***" ));
490
493
}
491
494
}
495
+ // If an alarm has fired, execute alarm user function
496
+ if (alarmType) {
497
+ ALARM_FUNC (alarmType); // Execute alarm user function
498
+ }
492
499
493
500
loop_step = start_GPS; // Get ready to move on and start the GPS
494
501
0 commit comments