Skip to content

Commit

Permalink
Merge pull request #2 from CK1-CK/First-Alarm-Loop
Browse files Browse the repository at this point in the history
Alarm-Loop-Check
  • Loading branch information
CK1-CK authored Sep 22, 2022
2 parents fc8b6b9 + 118f4fa commit a3f9e14
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 17 deletions.
Binary file not shown.
Binary file added Documentation/Documentation_IBM_LMiC-v1.5.pdf
Binary file not shown.
2 changes: 1 addition & 1 deletion include/settings.h
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#define LORA_TX_INTERVAL 900 //KeepAlive-WatchDog Signal every n Secondes
#define LORA_TX_INTERVAL 1200 //KeepAlive-WatchDog Signal every n Secondes
#define LMIC_LORA_SF DR_SF7 // LORA Data rate
9 changes: 5 additions & 4 deletions src/global.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#include "global.h"
#include "io_pins.h"

volatile uint8_t door_state = 0; // DOOR-Status open/closed
volatile uint8_t watchdog = 1; // Watchdog, Differentiation between watchdog and real alarm. 1=WatchDogSignal 0=Real DoorAlarm
volatile uint8_t AlarmMode_Enabled = 0; // Alarmmode 1=Enabled
volatile unsigned long oldTime=0, minSendIntervall=300000;
volatile uint8_t door_state = 0; // DOOR-Status open/closed
volatile uint8_t watchdog = 1; // Watchdog, Differentiation between watchdog and real alarm. 1=WatchDogSignal 0=Real DoorAlarm
volatile uint8_t AlarmMode_Enabled = 0; // Alarmmode 1=Enabled
volatile unsigned long oldTime = 0;
volatile unsigned long minSendIntervall = 60000; // Intervall to Send Alarm Pakages in ms 60000=1min
5 changes: 4 additions & 1 deletion src/lorawan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ void LoRaWANDo_send(osjob_t *j)
if (LMIC.opmode & OP_TXRXPEND)
{
Serial.println(F("OP_TXRXPEND, not sending"));
Serial.println(F("DEAD END")); //#todo vielleicht hier Reset wenn zb. 10000 aufrufe
}
else
{
Expand Down Expand Up @@ -160,9 +159,13 @@ void onEvent(ev_t ev)
Serial.print(LMIC.dataLen);
Serial.println(F(" bytes of payload"));
}

os_clearCallback(&sendjob); //Clear the SendQueue

// Schedule next transmission
os_setTimedCallback(&sendjob, os_getTime() + sec2osticks(TX_INTERVAL), LoRaWANDo_send);
// GO_DEEP_SLEEP = true; // if Deep_Sleep is activated, no Interrupts will work.
Serial.println("Next Package is scheduled.");

break;
case EV_LOST_TSYNC:
Expand Down
32 changes: 21 additions & 11 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ void resetToDefaultValues()
{
watchdog = 1; // Reset Watchdog
door_state = digitalRead(PIN_DOOR_SWITCH); // Reset Doorstate

// Serial.println("resetToDefaultValues");
}

void CheckAlarm_SendAlarmLoraPackage()
Expand All @@ -24,29 +22,37 @@ void CheckAlarm_SendAlarmLoraPackage()
{
if (watchdog == 0) // Real Alarm?
{
// Queue Lora Package
LoRaWANDo_send(&sendjob); // Send Alarm Message
LoRaWANDo(); // Run os_runloop_once() for LMIC OS

if (!os_queryTimeCriticalJobs(ms2osticks(500)))
{
// Queue Lora Package
LoRaWANDo_send(&sendjob); // Send Alarm Message

// Debug
Serial.println("Alarm Package queued!!");
// Debug
Serial.println("Alarm Package queued!!");

oldTime = millis(); // Remember last run time.
minSendIntervall = 600000; // Intervall to Send Alarm Pakages in ms 600000=10min - From here on, an alarm message is only sent every x ms.
}
}
oldTime = millis(); // Remember last run time.
}
}

void CheckDoorStateForAlarm()
{
if (digitalRead(PIN_DOOR_SWITCH) == 0)
if (digitalRead(PIN_DOOR_SWITCH) == 0 && AlarmMode_Enabled)
{
door_counter++; // Doorswitch is zero --> Debouncing
}
else // Door is closed
{
door_counter = -1;
door_state = 1;
minSendIntervall = 180000; // Intervall to Send Alarm Pakages in ms 180000=3min -> If door is closed reset to fast SendIntervall
}

if (door_counter >= 40000) // Door must opened for some time --> Debouncing
if (door_counter >= 50000) // Door must opened for some time --> Debouncing
{
door_state = 0; // Door open
watchdog = 0; // Real Alarm
Expand All @@ -69,17 +75,21 @@ void setup()
Setup_Pins();
door_state = digitalRead(PIN_DOOR_SWITCH);
Blink_Info_LED(50, 15); // LED blink (The LED can only be used once at the beginning due to SPI PIN/collision)
delay(3000);

PrintResetReason();
LoRaWANVersion();
delay(3000);
PowerDownSetupWatchdog();
LoRaWANSetup();
disableDeepSleep(); // DeepSleep Disable
}

void loop() // Infinity Loop
{
CheckDoorStateForAlarm();
if (!os_queryTimeCriticalJobs(ms2osticks(500)))
{
CheckDoorStateForAlarm();
}
LoRaWANDo();
os_getTime(); //probably not needed.
}

0 comments on commit a3f9e14

Please sign in to comment.