diff --git a/lorahandler.go b/lorahandler.go index a9d219e..0c3ab17 100644 --- a/lorahandler.go +++ b/lorahandler.go @@ -231,7 +231,7 @@ func DecodePayload(s string, deveui string, devaddr string, lrrlat float32, lrrl multiply_by_2 = true } w32 = int32(((float64(pl_128.W1-w1_0_real) / float64(pl_128.W1_C)) + (float64(pl_128.W2-w2_0_real) / float64(pl_128.W2_C))) / 5.0) - if (multiply_by_2) { + if multiply_by_2 { w32 = w32 * 2 } if w32 < 0 { @@ -278,6 +278,11 @@ func DecodePayload(s string, deveui string, devaddr string, lrrlat float32, lrrl } } +func IsDayTime() bool { + hours, _, _ := time.Now().Clock() + return ((hours >= 6) && (hours <= 22)) +} + func WriteDatapoint(mytime int64, deveui string, devaddr string, v uint8, h uint8, p uint8, w uint16, w1 int32, w2 int32, t int16, lrrlat float32, lrrlon float32, fw_version int32, w1_0 int32, w2_0 int32, w1_c float32, w2_c float32) { // wir nehmen humidity als Referenz, wenn diese > 0 ist, dann ist es // eine gueltige Messung @@ -307,7 +312,7 @@ func WriteDatapoint(mytime int64, deveui string, devaddr string, v uint8, h uint w_gram := uint32(w) * 5 addValue(deveui, w_gram) w_loss := getMaxValue(deveui) - w_gram - if w_loss > 500 { + if w_loss > 750 && IsDayTime() { // Schwarmalarm! alertLogMap[deveui] = fmt.Sprintf("alert,deveui=%s reason=\"swarmalarm\",w=%di,w_loss=%di %d\n", deveui, w_gram, w_loss, mytime*60*1000*1000*1000) location, _ := time.LoadLocation("Europe/Zurich")