fix bug with outsideGreenzone Logic
This commit is contained in:
parent
2d93042fff
commit
c9f0610cc0
|
|
@ -67,14 +67,15 @@ func Convert2Hex(payload_raw string) (string, error) {
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func IsOutsideGreenzone(deveui string, lon float64, lat float64) bool {
|
// 0: inside greenzone, 1: outside greenzone, 2: no GPS
|
||||||
res := false
|
func IsOutsideGreenzone(deveui string, lon float64, lat float64) int {
|
||||||
if lon < 1 {
|
if lon < 1 {
|
||||||
return res
|
return 2
|
||||||
}
|
}
|
||||||
if lat < 1 {
|
if lat < 1 {
|
||||||
return res
|
return 2
|
||||||
}
|
}
|
||||||
|
res := false
|
||||||
greenzone := getDevGreenzone(deveui)
|
greenzone := getDevGreenzone(deveui)
|
||||||
if greenzone != "" {
|
if greenzone != "" {
|
||||||
coords := strings.Split(greenzone, ",")
|
coords := strings.Split(greenzone, ",")
|
||||||
|
|
@ -88,7 +89,11 @@ func IsOutsideGreenzone(deveui string, lon float64, lat float64) bool {
|
||||||
log.Printf("greenzone does not have right format: %s!", greenzone)
|
log.Printf("greenzone does not have right format: %s!", greenzone)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return res
|
if res {
|
||||||
|
return 1
|
||||||
|
} else {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func DecodePayload(s string, deveui string) {
|
func DecodePayload(s string, deveui string) {
|
||||||
|
|
@ -121,7 +126,7 @@ func DecodePayload(s string, deveui string) {
|
||||||
alarm := (pl.AlarmBat & 0x4000) == 0x4000 // Alarm Bit
|
alarm := (pl.AlarmBat & 0x4000) == 0x4000 // Alarm Bit
|
||||||
outsideGreenzone := IsOutsideGreenzone(deveui, float64(pl.Longitude)/1000000.0, float64(pl.Latitude)/1000000.0)
|
outsideGreenzone := IsOutsideGreenzone(deveui, float64(pl.Longitude)/1000000.0, float64(pl.Latitude)/1000000.0)
|
||||||
flags := 0
|
flags := 0
|
||||||
if outsideGreenzone {
|
if outsideGreenzone == 1 {
|
||||||
flags += 2
|
flags += 2
|
||||||
}
|
}
|
||||||
if alarm {
|
if alarm {
|
||||||
|
|
@ -129,7 +134,7 @@ func DecodePayload(s string, deveui string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Printf("AlarmBit: %v", alarm)
|
log.Printf("AlarmBit: %v", alarm)
|
||||||
log.Printf("outsideGreenzone: %v", outsideGreenzone)
|
log.Printf("outsideGreenzone: %d", outsideGreenzone)
|
||||||
|
|
||||||
mystring := fmt.Sprintf("measurement,deveui=%s lat=%.5f,lon=%.5f,vbat=%d,fw=%d,flags=%d %d\n", deveui, float32(pl.Latitude)/1000000.0, float32(pl.Longitude)/1000000.0, vbat, fw, flags, (time.Now().Unix() * 1000 * 1000 * 1000))
|
mystring := fmt.Sprintf("measurement,deveui=%s lat=%.5f,lon=%.5f,vbat=%d,fw=%d,flags=%d %d\n", deveui, float32(pl.Latitude)/1000000.0, float32(pl.Longitude)/1000000.0, vbat, fw, flags, (time.Now().Unix() * 1000 * 1000 * 1000))
|
||||||
|
|
||||||
|
|
@ -139,10 +144,10 @@ func DecodePayload(s string, deveui string) {
|
||||||
log.Printf("DispatchAlert (button pressed) for %s\n", deveui)
|
log.Printf("DispatchAlert (button pressed) for %s\n", deveui)
|
||||||
DispatchAlert(deveui, "alert_button")
|
DispatchAlert(deveui, "alert_button")
|
||||||
}
|
}
|
||||||
if outsideGreenzone {
|
if outsideGreenzone == 1 {
|
||||||
log.Printf("DispatchAlert (outside greenzone) for %s\n", deveui)
|
log.Printf("DispatchAlert (outside greenzone) for %s\n", deveui)
|
||||||
DispatchAlert(deveui, "alert_greenzone")
|
DispatchAlert(deveui, "alert_greenzone")
|
||||||
} else {
|
} else if outsideGreenzone == 0 {
|
||||||
// we reset the alert, when we are again withing the greenzone
|
// we reset the alert, when we are again withing the greenzone
|
||||||
if AlertAlreadySentRecently(deveui, "alert_greenzone") {
|
if AlertAlreadySentRecently(deveui, "alert_greenzone") {
|
||||||
fmt.Printf("Info: we are again in Greenzone for Deveui %s, clear alert!", deveui)
|
fmt.Printf("Info: we are again in Greenzone for Deveui %s, clear alert!", deveui)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue