Skip to content
This repository was archived by the owner on Feb 4, 2022. It is now read-only.

Commit c073d46

Browse files
authored
Merge pull request #37 from a-schneider-fmi/main
Add user function to be executed when a PHT alarm is set off.
2 parents 8094e14 + 0771816 commit c073d46

File tree

3 files changed

+40
-18
lines changed

3 files changed

+40
-18
lines changed

Software/examples/Example16_GlobalTracker/Example16_GlobalTracker.ino

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ int err; // Error value returned by IridiumSBD.begin
138138
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)
139139
int delayCount; // General-purpose delay count used by non-blocking delays
140140
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
141142
bool dynamicModelSet = false; // Flag to indicate if the ZOE-M8Q dynamic model has been set
142143
bool geofencesSet = false; // Flag to indicate if the ZOE-M8Q geofences been set
143144

@@ -420,57 +421,58 @@ void loop()
420421
}
421422

422423
alarmState = false; // Clear the alarm state
424+
alarmType = 0; // Clear the alarm type
423425

424426
// 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
426428
{
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
429431
{
430432
alarmState = true;
431433
Serial.println(F("*** HIPRESS Alarm! ***"));
432434
}
433435
}
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
435437
{
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
438440
{
439441
alarmState = true;
440442
Serial.println(F("*** LOPRESS Alarm! ***"));
441443
}
442444
}
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
444446
{
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
447449
{
448450
alarmState = true;
449451
Serial.println(F("*** HITEMP Alarm! ***"));
450452
}
451453
}
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
453455
{
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
456458
{
457459
alarmState = true;
458460
Serial.println(F("*** LOTEMP Alarm! ***"));
459461
}
460462
}
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
462464
{
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
465467
{
466468
alarmState = true;
467469
Serial.println(F("*** HIHUMID Alarm! ***"));
468470
}
469471
}
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
471473
{
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
474476
{
475477
alarmState = true;
476478
Serial.println(F("*** LOHUMID Alarm! ***"));
@@ -480,6 +482,7 @@ void loop()
480482
// If voltage is lower than LOWBATT, send an alarm message
481483
get_vbat(); // Get the battery (bus) voltage
482484
if (myTrackerSettings.BATTV.the_data < myTrackerSettings.LOWBATT.the_data) {
485+
alarmType |= ALARM_LOBATT;
483486
Serial.print(F("*** LOWBATT: "));
484487
Serial.print((((float)myTrackerSettings.BATTV.the_data)/100.0),2);
485488
Serial.println(F("V ***"));
@@ -489,6 +492,10 @@ void loop()
489492
Serial.println(F("*** LOWBATT Alarm! ***"));
490493
}
491494
}
495+
// If an alarm has fired, execute alarm user function
496+
if (alarmType) {
497+
ALARM_FUNC(alarmType); // Execute alarm user function
498+
}
492499

493500
loop_step = start_GPS; // Get ready to move on and start the GPS
494501

Software/examples/Example16_GlobalTracker/Tracker_Message_Fields.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,15 @@
236236
#define MOFIELDS2_LOWBATT 0x00200000
237237
#define MOFIELDS2_DYNMODEL 0x00100000
238238

239+
// Define the bits for the alarm types
240+
#define ALARM_HIPRESS 0x01
241+
#define ALARM_LOPRESS 0x02
242+
#define ALARM_HITEMP 0x04
243+
#define ALARM_LOTEMP 0x08
244+
#define ALARM_HIHUMID 0x10
245+
#define ALARM_LOHUMID 0x20
246+
#define ALARM_LOBATT 0x40
247+
239248
#define MOLIM 340 // Length limit for a Mobile Originated message
240249
#define MTLIM 270 // Length limit for a Mobile Terminated message
241250

Software/examples/Example16_GlobalTracker/Tracker_User_Functions.ino

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,9 @@ float USER_VAL_8()
112112
retVal = 8.0E8; // Set retVal to 8.0E8 for testing - delete this line if you add your own code
113113
return (retVal);
114114
}
115+
116+
void ALARM_FUNC(uint8_t alarmType)
117+
{
118+
debugPrintln(F("Executing ALARM_FUNC ..."));
119+
// Add your own code to be executed when an alarm is set off.
120+
}

0 commit comments

Comments
 (0)