|
|
|
@ -11,6 +11,7 @@ import (
|
|
|
|
"log"
|
|
|
|
"log"
|
|
|
|
"net/http"
|
|
|
|
"net/http"
|
|
|
|
"os"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"strconv"
|
|
|
|
"strings"
|
|
|
|
"strings"
|
|
|
|
"time"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
@ -19,7 +20,7 @@ const (
|
|
|
|
MyDB = "beieliscaledb"
|
|
|
|
MyDB = "beieliscaledb"
|
|
|
|
username = "beieli"
|
|
|
|
username = "beieli"
|
|
|
|
password = "beieli4president"
|
|
|
|
password = "beieli4president"
|
|
|
|
outputfile = "/home/beieli/mini-beieli-lorahandler/mini-beieli-lorahandler.log"
|
|
|
|
outputfile = "/data/mini-beieli-lorahandler.log"
|
|
|
|
NOT_PLAUSIBLE_16 = 65535
|
|
|
|
NOT_PLAUSIBLE_16 = 65535
|
|
|
|
NOT_PLAUSIBLE_32 = 2147483647
|
|
|
|
NOT_PLAUSIBLE_32 = 2147483647
|
|
|
|
)
|
|
|
|
)
|
|
|
|
@ -213,270 +214,298 @@ func DecodePayload(s string, deveui string, devaddr string, lrrlat float32, lrrl
|
|
|
|
pl_130 = payload_130{}
|
|
|
|
pl_130 = payload_130{}
|
|
|
|
br := bytes.NewReader(ba)
|
|
|
|
br := bytes.NewReader(ba)
|
|
|
|
fmt.Printf("Payload String: %s\n", s)
|
|
|
|
fmt.Printf("Payload String: %s\n", s)
|
|
|
|
if s[0:2] == "01" {
|
|
|
|
if len(s) > 2 {
|
|
|
|
err := binary.Read(br, binary.LittleEndian, &pl_1)
|
|
|
|
if s[0:2] == "01" {
|
|
|
|
if err != nil {
|
|
|
|
err := binary.Read(br, binary.LittleEndian, &pl_1)
|
|
|
|
fmt.Println(err)
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
fmt.Println(err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if s[0:2] == "02" {
|
|
|
|
|
|
|
|
err := binary.Read(br, binary.LittleEndian, &pl_2)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
fmt.Println(err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if s[0:2] == "80" {
|
|
|
|
|
|
|
|
err := binary.Read(br, binary.LittleEndian, &pl_128)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
fmt.Println(err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if s[0:2] == "81" {
|
|
|
|
|
|
|
|
err := binary.Read(br, binary.LittleEndian, &pl_129)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
fmt.Println(err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if s[0:2] == "82" {
|
|
|
|
|
|
|
|
err := binary.Read(br, binary.LittleEndian, &pl_130)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
fmt.Println(err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
fmt.Printf("Payload String is unknown: %s\n", s)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if s[0:2] == "02" {
|
|
|
|
if s[0:2] == "01" {
|
|
|
|
err := binary.Read(br, binary.LittleEndian, &pl_2)
|
|
|
|
fmt.Printf("{\n")
|
|
|
|
if err != nil {
|
|
|
|
fmt.Printf(" version: %d,\n", pl_1.Version)
|
|
|
|
fmt.Println(err)
|
|
|
|
fmt.Printf(" vbat: %d,\n", pl_1.Vbat)
|
|
|
|
|
|
|
|
fmt.Printf(" offset: %d\n", pl_1.O)
|
|
|
|
|
|
|
|
fmt.Printf(" humidity: [%d,%d,%d,%d,%d,%d,%d,%d],\n", pl_1.H1, pl_1.H2, pl_1.H3, pl_1.H4, pl_1.H5, pl_1.H6, pl_1.H7, pl_1.H8)
|
|
|
|
|
|
|
|
fmt.Printf(" pressure: [%d,%d,%d,%d,%d,%d,%d,%d],\n", pl_1.P1, pl_1.P2, pl_1.P3, pl_1.P4, pl_1.P5, pl_1.P6, pl_1.P7, pl_1.P8)
|
|
|
|
|
|
|
|
fmt.Printf(" weight: [%d,%d,%d,%d,%d,%d,%d,%d],\n", pl_1.W1, pl_1.W2, pl_1.W3, pl_1.W4, pl_1.W5, pl_1.W6, pl_1.W7, pl_1.W8)
|
|
|
|
|
|
|
|
fmt.Printf(" temp: %d,\n", pl_1.T)
|
|
|
|
|
|
|
|
fmt.Printf(" temp_change: [%d,%d,%d,%d,%d,%d,%d],\n", pl_1.TC1, pl_1.TC2, pl_1.TC3, pl_1.TC4, pl_1.TC5, pl_1.TC6, pl_1.TC7)
|
|
|
|
|
|
|
|
fmt.Printf("}\n")
|
|
|
|
|
|
|
|
if write2file {
|
|
|
|
|
|
|
|
// Time of first Packet
|
|
|
|
|
|
|
|
var tfp = (time.Now().Unix() / 60) - int64(pl_1.O)
|
|
|
|
|
|
|
|
humidity_values := []uint8{pl_1.H1, pl_1.H2, pl_1.H3, pl_1.H4, pl_1.H5, pl_1.H6, pl_1.H7, pl_1.H8}
|
|
|
|
|
|
|
|
valid_measurements := 0
|
|
|
|
|
|
|
|
for _, v := range humidity_values {
|
|
|
|
|
|
|
|
if v > 0 {
|
|
|
|
|
|
|
|
valid_measurements = valid_measurements + 1
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Printf("Valid Measurements: %d,\n", valid_measurements)
|
|
|
|
|
|
|
|
var step int64
|
|
|
|
|
|
|
|
if valid_measurements > 1 {
|
|
|
|
|
|
|
|
step = int64(int(pl_1.O) / (valid_measurements - 1))
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// the first temperature is usually too high (maybe becaus of lorawan send, so we take
|
|
|
|
|
|
|
|
// the second measurement as first..., the same for humidity, which is usually too low...
|
|
|
|
|
|
|
|
t := pl_1.T
|
|
|
|
|
|
|
|
t = t + int16(pl_1.TC1)
|
|
|
|
|
|
|
|
if valid_measurements > 0 {
|
|
|
|
|
|
|
|
WriteDatapoint(tfp, deveui, devaddr, pl_1.Vbat, pl_1.H1, pl_1.P1, pl_1.W1, 0, 0, t, lrrlat, lrrlon, 0, 0, 0, 0, 0)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//t = t + int16(pl_1.TC1)
|
|
|
|
|
|
|
|
if valid_measurements > 1 {
|
|
|
|
|
|
|
|
WriteDatapoint(tfp+(step), deveui, devaddr, 0, pl_1.H2, pl_1.P2, pl_1.W2, 0, 0, t, lrrlat, lrrlon, 0, 0, 0, 0, 0)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
t = t + int16(pl_1.TC2)
|
|
|
|
|
|
|
|
if valid_measurements > 2 {
|
|
|
|
|
|
|
|
WriteDatapoint(tfp+(2*step), deveui, devaddr, 0, pl_1.H3, pl_1.P3, pl_1.W3, 0, 0, t, lrrlat, lrrlon, 0, 0, 0, 0, 0)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
t = t + int16(pl_1.TC3)
|
|
|
|
|
|
|
|
if valid_measurements > 3 {
|
|
|
|
|
|
|
|
WriteDatapoint(tfp+(3*step), deveui, devaddr, 0, pl_1.H4, pl_1.P4, pl_1.W4, 0, 0, t, lrrlat, lrrlon, 0, 0, 0, 0, 0)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
t = t + int16(pl_1.TC4)
|
|
|
|
|
|
|
|
if valid_measurements > 4 {
|
|
|
|
|
|
|
|
WriteDatapoint(tfp+(4*step), deveui, devaddr, 0, pl_1.H5, pl_1.P5, pl_1.W5, 0, 0, t, lrrlat, lrrlon, 0, 0, 0, 0, 0)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
t = t + int16(pl_1.TC5)
|
|
|
|
|
|
|
|
if valid_measurements > 5 {
|
|
|
|
|
|
|
|
WriteDatapoint(tfp+(5*step), deveui, devaddr, 0, pl_1.H6, pl_1.P6, pl_1.W6, 0, 0, t, lrrlat, lrrlon, 0, 0, 0, 0, 0)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
t = t + int16(pl_1.TC6)
|
|
|
|
|
|
|
|
if valid_measurements > 6 {
|
|
|
|
|
|
|
|
WriteDatapoint(tfp+(6*step), deveui, devaddr, 0, pl_1.H7, pl_1.P7, pl_1.W7, 0, 0, t, lrrlat, lrrlon, 0, 0, 0, 0, 0)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
t = t + int16(pl_1.TC7)
|
|
|
|
|
|
|
|
if valid_measurements > 7 {
|
|
|
|
|
|
|
|
WriteDatapoint(tfp+(7*step), deveui, devaddr, 0, pl_1.H8, pl_1.P8, pl_1.W8, 0, 0, t, lrrlat, lrrlon, 0, 0, 0, 0, 0)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if s[0:2] == "02" {
|
|
|
|
|
|
|
|
fmt.Printf("{\n")
|
|
|
|
|
|
|
|
fmt.Printf(" version: %d,\n", pl_2.Version)
|
|
|
|
|
|
|
|
fmt.Printf(" vbat: %d,\n", pl_2.Vbat)
|
|
|
|
|
|
|
|
fmt.Printf(" offset: %d\n", pl_2.O)
|
|
|
|
|
|
|
|
fmt.Printf(" weight: [%d,%d,%d,%d,%d,%d,%d,%d],\n", pl_2.W1, pl_2.WC1, pl_2.WC2, pl_2.WC3, pl_2.WC4, pl_2.WC5, pl_2.WC6, pl_2.W8)
|
|
|
|
|
|
|
|
fmt.Printf(" temp: %d,\n", pl_2.T)
|
|
|
|
|
|
|
|
fmt.Printf(" temp_change: [%d,%d,%d,%d,%d,%d,%d],\n", pl_2.TC1, pl_2.TC2, pl_2.TC3, pl_2.TC4, pl_2.TC5, pl_2.TC6, pl_2.TC7)
|
|
|
|
|
|
|
|
fmt.Printf(" humidity: %d\n", pl_2.H)
|
|
|
|
|
|
|
|
fmt.Printf(" pressure: %d\n", pl_2.P)
|
|
|
|
|
|
|
|
fmt.Printf("}\n")
|
|
|
|
|
|
|
|
if write2file {
|
|
|
|
|
|
|
|
// Time of first Packet
|
|
|
|
|
|
|
|
var tfp = (time.Now().Unix() / 60) - int64(pl_2.O)
|
|
|
|
|
|
|
|
temp_change_values := []int8{pl_2.TC1, pl_2.TC2, pl_2.TC3, pl_2.TC4, pl_2.TC5, pl_2.TC6, pl_2.TC7}
|
|
|
|
|
|
|
|
valid_measurements := 1
|
|
|
|
|
|
|
|
for _, v := range temp_change_values {
|
|
|
|
|
|
|
|
if v < 127 {
|
|
|
|
|
|
|
|
valid_measurements = valid_measurements + 1
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Printf("Valid Measurements: %d,\n", valid_measurements)
|
|
|
|
|
|
|
|
var step int64
|
|
|
|
|
|
|
|
if valid_measurements > 1 {
|
|
|
|
|
|
|
|
step = int64(int(pl_2.O) / (valid_measurements - 1))
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// the first temperature is usually too high (maybe becaus of lorawan send, so we take
|
|
|
|
|
|
|
|
// the second measurement as first...
|
|
|
|
|
|
|
|
t := pl_2.T
|
|
|
|
|
|
|
|
w := pl_2.W1
|
|
|
|
|
|
|
|
t = t + int16(pl_2.TC1)
|
|
|
|
|
|
|
|
if valid_measurements > 0 {
|
|
|
|
|
|
|
|
WriteDatapoint(tfp, deveui, devaddr, pl_2.Vbat, pl_2.H, pl_2.P, w, 0, 0, t, lrrlat, lrrlon, 0, 0, 0, 0, 0)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//t = t + int16(pl_2.TC1)
|
|
|
|
|
|
|
|
if valid_measurements == 2 {
|
|
|
|
|
|
|
|
w = pl_2.W8
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
w = w + uint16(pl_2.WC1)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if valid_measurements > 1 {
|
|
|
|
|
|
|
|
WriteDatapoint(tfp+(step), deveui, devaddr, 0, 1, 0, w, 0, 0, t, lrrlat, lrrlon, 0, 0, 0, 0, 0)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
t = t + int16(pl_2.TC2)
|
|
|
|
|
|
|
|
if valid_measurements == 3 {
|
|
|
|
|
|
|
|
w = pl_2.W8
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
w = w + uint16(pl_2.WC2)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if valid_measurements > 2 {
|
|
|
|
|
|
|
|
WriteDatapoint(tfp+(2*step), deveui, devaddr, 0, 1, 0, w, 0, 0, t, lrrlat, lrrlon, 0, 0, 0, 0, 0)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
t = t + int16(pl_2.TC3)
|
|
|
|
|
|
|
|
if valid_measurements == 4 {
|
|
|
|
|
|
|
|
w = pl_2.W8
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
w = w + uint16(pl_2.WC3)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if valid_measurements > 3 {
|
|
|
|
|
|
|
|
WriteDatapoint(tfp+(3*step), deveui, devaddr, 0, 1, 0, w, 0, 0, t, lrrlat, lrrlon, 0, 0, 0, 0, 0)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
t = t + int16(pl_2.TC4)
|
|
|
|
|
|
|
|
if valid_measurements == 5 {
|
|
|
|
|
|
|
|
w = pl_2.W8
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
w = w + uint16(pl_2.WC4)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if valid_measurements > 4 {
|
|
|
|
|
|
|
|
WriteDatapoint(tfp+(4*step), deveui, devaddr, 0, 1, 0, w, 0, 0, t, lrrlat, lrrlon, 0, 0, 0, 0, 0)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
t = t + int16(pl_2.TC5)
|
|
|
|
|
|
|
|
if valid_measurements == 6 {
|
|
|
|
|
|
|
|
w = pl_2.W8
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
w = w + uint16(pl_2.WC5)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if valid_measurements > 5 {
|
|
|
|
|
|
|
|
WriteDatapoint(tfp+(5*step), deveui, devaddr, 0, 1, 0, w, 0, 0, t, lrrlat, lrrlon, 0, 0, 0, 0, 0)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
t = t + int16(pl_2.TC6)
|
|
|
|
|
|
|
|
if valid_measurements == 7 {
|
|
|
|
|
|
|
|
w = pl_2.W8
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
w = w + uint16(pl_2.WC6)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if valid_measurements > 6 {
|
|
|
|
|
|
|
|
WriteDatapoint(tfp+(6*step), deveui, devaddr, 0, 1, 0, w, 0, 0, t, lrrlat, lrrlon, 0, 0, 0, 0, 0)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
t = t + int16(pl_2.TC7)
|
|
|
|
|
|
|
|
w = pl_2.W8
|
|
|
|
|
|
|
|
if valid_measurements > 7 {
|
|
|
|
|
|
|
|
WriteDatapoint(tfp+(7*step), deveui, devaddr, 0, 1, 0, w, 0, 0, t, lrrlat, lrrlon, 0, 0, 0, 0, 0)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if s[0:2] == "80" {
|
|
|
|
|
|
|
|
fmt.Printf("{\n")
|
|
|
|
|
|
|
|
fmt.Printf(" version: %d,\n", pl_128.Version)
|
|
|
|
|
|
|
|
fmt.Printf(" fw_version: %d,\n", pl_128.Fw_version)
|
|
|
|
|
|
|
|
fmt.Printf(" vbat: %d,\n", pl_128.Vbat)
|
|
|
|
|
|
|
|
fmt.Printf(" humidity: %d\n", pl_128.H)
|
|
|
|
|
|
|
|
fmt.Printf(" pressure: %d\n", pl_128.P)
|
|
|
|
|
|
|
|
fmt.Printf(" weight1: %d\n", pl_128.W1)
|
|
|
|
|
|
|
|
fmt.Printf(" weight2: %d\n", pl_128.W2)
|
|
|
|
|
|
|
|
fmt.Printf(" cal_1_0: %d\n", pl_128.W1_0)
|
|
|
|
|
|
|
|
fmt.Printf(" cal_2_0: %d\n", pl_128.W2_0)
|
|
|
|
|
|
|
|
fmt.Printf(" cal_1_C: %f\n", pl_128.W1_C)
|
|
|
|
|
|
|
|
fmt.Printf(" cal_2_C: %f\n", pl_128.W2_C)
|
|
|
|
|
|
|
|
fmt.Printf(" temp: %d\n", pl_128.T)
|
|
|
|
|
|
|
|
fmt.Printf("}\n")
|
|
|
|
|
|
|
|
if write2file {
|
|
|
|
|
|
|
|
// Time of Packet received
|
|
|
|
|
|
|
|
var tfp = (time.Now().Unix() / 60)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// we calculate the weight...
|
|
|
|
|
|
|
|
var w32 int32
|
|
|
|
|
|
|
|
var w uint16
|
|
|
|
|
|
|
|
w1_0_real := pl_128.W1_0
|
|
|
|
|
|
|
|
w2_0_real := pl_128.W2_0
|
|
|
|
|
|
|
|
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 w32 < 0 {
|
|
|
|
|
|
|
|
w = 0
|
|
|
|
|
|
|
|
} else if w32 > 65535 {
|
|
|
|
|
|
|
|
// this is not realistic (>320 kg), we set this to 0 as well...
|
|
|
|
|
|
|
|
w = 0
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
w = uint16(w32)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
WriteDatapoint(tfp, deveui, devaddr, pl_128.Vbat, pl_128.H, pl_128.P, w, pl_128.W1, pl_128.W2, pl_128.T, lrrlat, lrrlon, pl_128.Fw_version, pl_128.W1_0, pl_128.W2_0, pl_128.W1_C, pl_128.W2_C)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
ProcessInitPacket(deveui, pl_128.W1_0, pl_128.W2_0, pl_128.W1_C, pl_128.W2_C, pl_128.W1, pl_128.W2)
|
|
|
|
|
|
|
|
} else if s[0:2] == "81" {
|
|
|
|
|
|
|
|
fmt.Printf("{\n")
|
|
|
|
|
|
|
|
fmt.Printf(" version: %d,\n", pl_129.Version)
|
|
|
|
|
|
|
|
fmt.Printf(" fw_version: %d,\n", pl_129.Fw_version)
|
|
|
|
|
|
|
|
fmt.Printf(" vbat: %d,\n", pl_129.Vbat)
|
|
|
|
|
|
|
|
fmt.Printf(" humidity: %d\n", pl_129.H)
|
|
|
|
|
|
|
|
fmt.Printf(" pressure: %d\n", pl_129.P)
|
|
|
|
|
|
|
|
fmt.Printf(" weight1: %d\n", pl_129.W1)
|
|
|
|
|
|
|
|
fmt.Printf(" weight2: %d\n", pl_129.W2)
|
|
|
|
|
|
|
|
fmt.Printf(" weight: %d\n", pl_129.W)
|
|
|
|
|
|
|
|
fmt.Printf(" temp: %d\n", pl_129.T)
|
|
|
|
|
|
|
|
fmt.Printf("}\n")
|
|
|
|
|
|
|
|
if write2file {
|
|
|
|
|
|
|
|
// Time of Packet received
|
|
|
|
|
|
|
|
var tfp = (time.Now().Unix() / 60)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
WriteDatapoint(tfp, deveui, devaddr, pl_129.Vbat, pl_129.H, pl_129.P, pl_129.W, pl_129.W1, pl_129.W2, pl_129.T, lrrlat, lrrlon, pl_129.Fw_version, 0, 0, 0, 0)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if s[0:2] == "82" {
|
|
|
|
|
|
|
|
fmt.Printf("{\n")
|
|
|
|
|
|
|
|
fmt.Printf(" version: %d,\n", pl_130.Version)
|
|
|
|
|
|
|
|
fmt.Printf(" fw_version: %d,\n", pl_130.Fw_version)
|
|
|
|
|
|
|
|
fmt.Printf(" vbat: %d,\n", pl_130.Vbat)
|
|
|
|
|
|
|
|
fmt.Printf(" weight1: %d\n", pl_130.W1)
|
|
|
|
|
|
|
|
fmt.Printf(" weight2: %d\n", pl_130.W2)
|
|
|
|
|
|
|
|
fmt.Printf(" cal_1_0: %d\n", pl_130.W1_0)
|
|
|
|
|
|
|
|
fmt.Printf(" cal_2_0: %d\n", pl_130.W2_0)
|
|
|
|
|
|
|
|
fmt.Printf(" cal_1_C: %f\n", pl_130.W1_C)
|
|
|
|
|
|
|
|
fmt.Printf(" cal_2_C: %f\n", pl_130.W2_C)
|
|
|
|
|
|
|
|
fmt.Printf(" temp: %d\n", pl_130.T)
|
|
|
|
|
|
|
|
fmt.Printf(" humidity: %d\n", pl_130.H)
|
|
|
|
|
|
|
|
fmt.Printf(" pressure: %d\n", pl_130.P)
|
|
|
|
|
|
|
|
fmt.Printf("}\n")
|
|
|
|
|
|
|
|
if write2file {
|
|
|
|
|
|
|
|
// Time of Packet received
|
|
|
|
|
|
|
|
var tfp = (time.Now().Unix() / 60)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// we calculate the weight...
|
|
|
|
|
|
|
|
var w32 int32
|
|
|
|
|
|
|
|
var w uint16
|
|
|
|
|
|
|
|
w1_0_real := pl_130.W1_0
|
|
|
|
|
|
|
|
w2_0_real := pl_130.W2_0
|
|
|
|
|
|
|
|
w32 = int32(((float64(pl_130.W1-w1_0_real) / float64(pl_130.W1_C)) + (float64(pl_130.W2-w2_0_real) / float64(pl_130.W2_C))) / 5.0)
|
|
|
|
|
|
|
|
if w32 < 0 {
|
|
|
|
|
|
|
|
w = 0
|
|
|
|
|
|
|
|
} else if w32 > 65535 {
|
|
|
|
|
|
|
|
// this is not realistic (>320 kg), we set this to 0 as well...
|
|
|
|
|
|
|
|
w = 0
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
w = uint16(w32)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
WriteDatapoint(tfp, deveui, devaddr, pl_130.Vbat, pl_130.H, pl_130.P, w, pl_130.W1, pl_130.W2, pl_130.T, lrrlat, lrrlon, pl_130.Fw_version, pl_130.W1_0, pl_130.W2_0, pl_130.W1_C, pl_130.W2_C)
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if s[0:2] == "80" {
|
|
|
|
// Send alert if necessary
|
|
|
|
err := binary.Read(br, binary.LittleEndian, &pl_128)
|
|
|
|
if val, ok := alertMap[deveui]; ok {
|
|
|
|
if err != nil {
|
|
|
|
sendAlert(deveui, val)
|
|
|
|
fmt.Println(err)
|
|
|
|
delete(alertMap, deveui)
|
|
|
|
|
|
|
|
// alte Werte loeschen
|
|
|
|
|
|
|
|
deleteValues(deveui)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if s[0:2] == "81" {
|
|
|
|
if val2, ok2 := alertLogMap[deveui]; ok2 {
|
|
|
|
err := binary.Read(br, binary.LittleEndian, &pl_129)
|
|
|
|
WriteStringToFile(val2, deveui, false)
|
|
|
|
if err != nil {
|
|
|
|
delete(alertLogMap, deveui)
|
|
|
|
fmt.Println(err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if s[0:2] == "82" {
|
|
|
|
|
|
|
|
err := binary.Read(br, binary.LittleEndian, &pl_130)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
fmt.Println(err)
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
fmt.Printf("Payload String is unknown: %s\n", s)
|
|
|
|
fmt.Printf("Payload String is not longer that 2 chars, ignore it\n")
|
|
|
|
}
|
|
|
|
|
|
|
|
if s[0:2] == "01" {
|
|
|
|
|
|
|
|
fmt.Printf("{\n")
|
|
|
|
|
|
|
|
fmt.Printf(" version: %d,\n", pl_1.Version)
|
|
|
|
|
|
|
|
fmt.Printf(" vbat: %d,\n", pl_1.Vbat)
|
|
|
|
|
|
|
|
fmt.Printf(" offset: %d\n", pl_1.O)
|
|
|
|
|
|
|
|
fmt.Printf(" humidity: [%d,%d,%d,%d,%d,%d,%d,%d],\n", pl_1.H1, pl_1.H2, pl_1.H3, pl_1.H4, pl_1.H5, pl_1.H6, pl_1.H7, pl_1.H8)
|
|
|
|
|
|
|
|
fmt.Printf(" pressure: [%d,%d,%d,%d,%d,%d,%d,%d],\n", pl_1.P1, pl_1.P2, pl_1.P3, pl_1.P4, pl_1.P5, pl_1.P6, pl_1.P7, pl_1.P8)
|
|
|
|
|
|
|
|
fmt.Printf(" weight: [%d,%d,%d,%d,%d,%d,%d,%d],\n", pl_1.W1, pl_1.W2, pl_1.W3, pl_1.W4, pl_1.W5, pl_1.W6, pl_1.W7, pl_1.W8)
|
|
|
|
|
|
|
|
fmt.Printf(" temp: %d,\n", pl_1.T)
|
|
|
|
|
|
|
|
fmt.Printf(" temp_change: [%d,%d,%d,%d,%d,%d,%d],\n", pl_1.TC1, pl_1.TC2, pl_1.TC3, pl_1.TC4, pl_1.TC5, pl_1.TC6, pl_1.TC7)
|
|
|
|
|
|
|
|
fmt.Printf("}\n")
|
|
|
|
|
|
|
|
if write2file {
|
|
|
|
|
|
|
|
// Time of first Packet
|
|
|
|
|
|
|
|
var tfp = (time.Now().Unix() / 60) - int64(pl_1.O)
|
|
|
|
|
|
|
|
humidity_values := []uint8{pl_1.H1, pl_1.H2, pl_1.H3, pl_1.H4, pl_1.H5, pl_1.H6, pl_1.H7, pl_1.H8}
|
|
|
|
|
|
|
|
valid_measurements := 0
|
|
|
|
|
|
|
|
for _, v := range humidity_values {
|
|
|
|
|
|
|
|
if v > 0 {
|
|
|
|
|
|
|
|
valid_measurements = valid_measurements + 1
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Printf("Valid Measurements: %d,\n", valid_measurements)
|
|
|
|
|
|
|
|
var step int64
|
|
|
|
|
|
|
|
if valid_measurements > 1 {
|
|
|
|
|
|
|
|
step = int64(int(pl_1.O) / (valid_measurements - 1))
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// the first temperature is usually too high (maybe becaus of lorawan send, so we take
|
|
|
|
|
|
|
|
// the second measurement as first..., the same for humidity, which is usually too low...
|
|
|
|
|
|
|
|
t := pl_1.T
|
|
|
|
|
|
|
|
t = t + int16(pl_1.TC1)
|
|
|
|
|
|
|
|
if valid_measurements > 0 {
|
|
|
|
|
|
|
|
WriteDatapoint(tfp, deveui, devaddr, pl_1.Vbat, pl_1.H1, pl_1.P1, pl_1.W1, 0, 0, t, lrrlat, lrrlon, 0, 0, 0, 0, 0)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//t = t + int16(pl_1.TC1)
|
|
|
|
|
|
|
|
if valid_measurements > 1 {
|
|
|
|
|
|
|
|
WriteDatapoint(tfp+(step), deveui, devaddr, 0, pl_1.H2, pl_1.P2, pl_1.W2, 0, 0, t, lrrlat, lrrlon, 0, 0, 0, 0, 0)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
t = t + int16(pl_1.TC2)
|
|
|
|
|
|
|
|
if valid_measurements > 2 {
|
|
|
|
|
|
|
|
WriteDatapoint(tfp+(2*step), deveui, devaddr, 0, pl_1.H3, pl_1.P3, pl_1.W3, 0, 0, t, lrrlat, lrrlon, 0, 0, 0, 0, 0)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
t = t + int16(pl_1.TC3)
|
|
|
|
|
|
|
|
if valid_measurements > 3 {
|
|
|
|
|
|
|
|
WriteDatapoint(tfp+(3*step), deveui, devaddr, 0, pl_1.H4, pl_1.P4, pl_1.W4, 0, 0, t, lrrlat, lrrlon, 0, 0, 0, 0, 0)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
t = t + int16(pl_1.TC4)
|
|
|
|
|
|
|
|
if valid_measurements > 4 {
|
|
|
|
|
|
|
|
WriteDatapoint(tfp+(4*step), deveui, devaddr, 0, pl_1.H5, pl_1.P5, pl_1.W5, 0, 0, t, lrrlat, lrrlon, 0, 0, 0, 0, 0)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
t = t + int16(pl_1.TC5)
|
|
|
|
|
|
|
|
if valid_measurements > 5 {
|
|
|
|
|
|
|
|
WriteDatapoint(tfp+(5*step), deveui, devaddr, 0, pl_1.H6, pl_1.P6, pl_1.W6, 0, 0, t, lrrlat, lrrlon, 0, 0, 0, 0, 0)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
t = t + int16(pl_1.TC6)
|
|
|
|
|
|
|
|
if valid_measurements > 6 {
|
|
|
|
|
|
|
|
WriteDatapoint(tfp+(6*step), deveui, devaddr, 0, pl_1.H7, pl_1.P7, pl_1.W7, 0, 0, t, lrrlat, lrrlon, 0, 0, 0, 0, 0)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
t = t + int16(pl_1.TC7)
|
|
|
|
|
|
|
|
if valid_measurements > 7 {
|
|
|
|
|
|
|
|
WriteDatapoint(tfp+(7*step), deveui, devaddr, 0, pl_1.H8, pl_1.P8, pl_1.W8, 0, 0, t, lrrlat, lrrlon, 0, 0, 0, 0, 0)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if s[0:2] == "02" {
|
|
|
|
|
|
|
|
fmt.Printf("{\n")
|
|
|
|
|
|
|
|
fmt.Printf(" version: %d,\n", pl_2.Version)
|
|
|
|
|
|
|
|
fmt.Printf(" vbat: %d,\n", pl_2.Vbat)
|
|
|
|
|
|
|
|
fmt.Printf(" offset: %d\n", pl_2.O)
|
|
|
|
|
|
|
|
fmt.Printf(" weight: [%d,%d,%d,%d,%d,%d,%d,%d],\n", pl_2.W1, pl_2.WC1, pl_2.WC2, pl_2.WC3, pl_2.WC4, pl_2.WC5, pl_2.WC6, pl_2.W8)
|
|
|
|
|
|
|
|
fmt.Printf(" temp: %d,\n", pl_2.T)
|
|
|
|
|
|
|
|
fmt.Printf(" temp_change: [%d,%d,%d,%d,%d,%d,%d],\n", pl_2.TC1, pl_2.TC2, pl_2.TC3, pl_2.TC4, pl_2.TC5, pl_2.TC6, pl_2.TC7)
|
|
|
|
|
|
|
|
fmt.Printf(" humidity: %d\n", pl_2.H)
|
|
|
|
|
|
|
|
fmt.Printf(" pressure: %d\n", pl_2.P)
|
|
|
|
|
|
|
|
fmt.Printf("}\n")
|
|
|
|
|
|
|
|
if write2file {
|
|
|
|
|
|
|
|
// Time of first Packet
|
|
|
|
|
|
|
|
var tfp = (time.Now().Unix() / 60) - int64(pl_2.O)
|
|
|
|
|
|
|
|
temp_change_values := []int8{pl_2.TC1, pl_2.TC2, pl_2.TC3, pl_2.TC4, pl_2.TC5, pl_2.TC6, pl_2.TC7}
|
|
|
|
|
|
|
|
valid_measurements := 1
|
|
|
|
|
|
|
|
for _, v := range temp_change_values {
|
|
|
|
|
|
|
|
if v < 127 {
|
|
|
|
|
|
|
|
valid_measurements = valid_measurements + 1
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Printf("Valid Measurements: %d,\n", valid_measurements)
|
|
|
|
|
|
|
|
var step int64
|
|
|
|
|
|
|
|
if valid_measurements > 1 {
|
|
|
|
|
|
|
|
step = int64(int(pl_2.O) / (valid_measurements - 1))
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// the first temperature is usually too high (maybe becaus of lorawan send, so we take
|
|
|
|
|
|
|
|
// the second measurement as first...
|
|
|
|
|
|
|
|
t := pl_2.T
|
|
|
|
|
|
|
|
w := pl_2.W1
|
|
|
|
|
|
|
|
t = t + int16(pl_2.TC1)
|
|
|
|
|
|
|
|
if valid_measurements > 0 {
|
|
|
|
|
|
|
|
WriteDatapoint(tfp, deveui, devaddr, pl_2.Vbat, pl_2.H, pl_2.P, w, 0, 0, t, lrrlat, lrrlon, 0, 0, 0, 0, 0)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//t = t + int16(pl_2.TC1)
|
|
|
|
|
|
|
|
w = w + uint16(pl_2.WC1)
|
|
|
|
|
|
|
|
if valid_measurements > 1 {
|
|
|
|
|
|
|
|
WriteDatapoint(tfp+(step), deveui, devaddr, 0, 1, 0, w, 0, 0, t, lrrlat, lrrlon, 0, 0, 0, 0, 0)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
t = t + int16(pl_2.TC2)
|
|
|
|
|
|
|
|
w = w + uint16(pl_2.WC2)
|
|
|
|
|
|
|
|
if valid_measurements > 2 {
|
|
|
|
|
|
|
|
WriteDatapoint(tfp+(2*step), deveui, devaddr, 0, 1, 0, w, 0, 0, t, lrrlat, lrrlon, 0, 0, 0, 0, 0)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
t = t + int16(pl_2.TC3)
|
|
|
|
|
|
|
|
w = w + uint16(pl_2.WC3)
|
|
|
|
|
|
|
|
if valid_measurements > 3 {
|
|
|
|
|
|
|
|
WriteDatapoint(tfp+(3*step), deveui, devaddr, 0, 1, 0, w, 0, 0, t, lrrlat, lrrlon, 0, 0, 0, 0, 0)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
t = t + int16(pl_2.TC4)
|
|
|
|
|
|
|
|
w = w + uint16(pl_2.WC4)
|
|
|
|
|
|
|
|
if valid_measurements > 4 {
|
|
|
|
|
|
|
|
WriteDatapoint(tfp+(4*step), deveui, devaddr, 0, 1, 0, w, 0, 0, t, lrrlat, lrrlon, 0, 0, 0, 0, 0)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
t = t + int16(pl_2.TC5)
|
|
|
|
|
|
|
|
w = w + uint16(pl_2.WC5)
|
|
|
|
|
|
|
|
if valid_measurements > 5 {
|
|
|
|
|
|
|
|
WriteDatapoint(tfp+(5*step), deveui, devaddr, 0, 1, 0, w, 0, 0, t, lrrlat, lrrlon, 0, 0, 0, 0, 0)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
t = t + int16(pl_2.TC6)
|
|
|
|
|
|
|
|
w = w + uint16(pl_2.WC6)
|
|
|
|
|
|
|
|
if valid_measurements > 6 {
|
|
|
|
|
|
|
|
WriteDatapoint(tfp+(6*step), deveui, devaddr, 0, 1, 0, w, 0, 0, t, lrrlat, lrrlon, 0, 0, 0, 0, 0)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
t = t + int16(pl_2.TC7)
|
|
|
|
|
|
|
|
w = pl_2.W8
|
|
|
|
|
|
|
|
if valid_measurements > 7 {
|
|
|
|
|
|
|
|
WriteDatapoint(tfp+(7*step), deveui, devaddr, 0, 1, 0, w, 0, 0, t, lrrlat, lrrlon, 0, 0, 0, 0, 0)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if s[0:2] == "80" {
|
|
|
|
|
|
|
|
fmt.Printf("{\n")
|
|
|
|
|
|
|
|
fmt.Printf(" version: %d,\n", pl_128.Version)
|
|
|
|
|
|
|
|
fmt.Printf(" fw_version: %d,\n", pl_128.Fw_version)
|
|
|
|
|
|
|
|
fmt.Printf(" vbat: %d,\n", pl_128.Vbat)
|
|
|
|
|
|
|
|
fmt.Printf(" humidity: %d\n", pl_128.H)
|
|
|
|
|
|
|
|
fmt.Printf(" pressure: %d\n", pl_128.P)
|
|
|
|
|
|
|
|
fmt.Printf(" weight1: %d\n", pl_128.W1)
|
|
|
|
|
|
|
|
fmt.Printf(" weight2: %d\n", pl_128.W2)
|
|
|
|
|
|
|
|
fmt.Printf(" cal_1_0: %d\n", pl_128.W1_0)
|
|
|
|
|
|
|
|
fmt.Printf(" cal_2_0: %d\n", pl_128.W2_0)
|
|
|
|
|
|
|
|
fmt.Printf(" cal_1_C: %f\n", pl_128.W1_C)
|
|
|
|
|
|
|
|
fmt.Printf(" cal_2_C: %f\n", pl_128.W2_C)
|
|
|
|
|
|
|
|
fmt.Printf(" temp: %d\n", pl_128.T)
|
|
|
|
|
|
|
|
fmt.Printf("}\n")
|
|
|
|
|
|
|
|
if write2file {
|
|
|
|
|
|
|
|
// Time of Packet received
|
|
|
|
|
|
|
|
var tfp = (time.Now().Unix() / 60)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// we calculate the weight...
|
|
|
|
|
|
|
|
var w32 int32
|
|
|
|
|
|
|
|
var w uint16
|
|
|
|
|
|
|
|
w1_0_real := pl_128.W1_0
|
|
|
|
|
|
|
|
w2_0_real := pl_128.W2_0
|
|
|
|
|
|
|
|
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 w32 < 0 {
|
|
|
|
|
|
|
|
w = 0
|
|
|
|
|
|
|
|
} else if w32 > 65535 {
|
|
|
|
|
|
|
|
// this is not realistic (>320 kg), we set this to 0 as well...
|
|
|
|
|
|
|
|
w = 0
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
w = uint16(w32)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
WriteDatapoint(tfp, deveui, devaddr, pl_128.Vbat, pl_128.H, pl_128.P, w, pl_128.W1, pl_128.W2, pl_128.T, lrrlat, lrrlon, pl_128.Fw_version, pl_128.W1_0, pl_128.W2_0, pl_128.W1_C, pl_128.W2_C)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
ProcessInitPacket(deveui, pl_128.W1_0, pl_128.W2_0, pl_128.W1_C, pl_128.W2_C, pl_128.W1, pl_128.W2)
|
|
|
|
|
|
|
|
} else if s[0:2] == "81" {
|
|
|
|
|
|
|
|
fmt.Printf("{\n")
|
|
|
|
|
|
|
|
fmt.Printf(" version: %d,\n", pl_129.Version)
|
|
|
|
|
|
|
|
fmt.Printf(" fw_version: %d,\n", pl_129.Fw_version)
|
|
|
|
|
|
|
|
fmt.Printf(" vbat: %d,\n", pl_129.Vbat)
|
|
|
|
|
|
|
|
fmt.Printf(" humidity: %d\n", pl_129.H)
|
|
|
|
|
|
|
|
fmt.Printf(" pressure: %d\n", pl_129.P)
|
|
|
|
|
|
|
|
fmt.Printf(" weight1: %d\n", pl_129.W1)
|
|
|
|
|
|
|
|
fmt.Printf(" weight2: %d\n", pl_129.W2)
|
|
|
|
|
|
|
|
fmt.Printf(" weight: %d\n", pl_129.W)
|
|
|
|
|
|
|
|
fmt.Printf(" temp: %d\n", pl_129.T)
|
|
|
|
|
|
|
|
fmt.Printf("}\n")
|
|
|
|
|
|
|
|
if write2file {
|
|
|
|
|
|
|
|
// Time of Packet received
|
|
|
|
|
|
|
|
var tfp = (time.Now().Unix() / 60)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
WriteDatapoint(tfp, deveui, devaddr, pl_129.Vbat, pl_129.H, pl_129.P, pl_129.W, pl_129.W1, pl_129.W2, pl_129.T, lrrlat, lrrlon, pl_129.Fw_version, 0, 0, 0, 0)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if s[0:2] == "82" {
|
|
|
|
|
|
|
|
fmt.Printf("{\n")
|
|
|
|
|
|
|
|
fmt.Printf(" version: %d,\n", pl_130.Version)
|
|
|
|
|
|
|
|
fmt.Printf(" fw_version: %d,\n", pl_130.Fw_version)
|
|
|
|
|
|
|
|
fmt.Printf(" vbat: %d,\n", pl_130.Vbat)
|
|
|
|
|
|
|
|
fmt.Printf(" weight1: %d\n", pl_130.W1)
|
|
|
|
|
|
|
|
fmt.Printf(" weight2: %d\n", pl_130.W2)
|
|
|
|
|
|
|
|
fmt.Printf(" cal_1_0: %d\n", pl_130.W1_0)
|
|
|
|
|
|
|
|
fmt.Printf(" cal_2_0: %d\n", pl_130.W2_0)
|
|
|
|
|
|
|
|
fmt.Printf(" cal_1_C: %f\n", pl_130.W1_C)
|
|
|
|
|
|
|
|
fmt.Printf(" cal_2_C: %f\n", pl_130.W2_C)
|
|
|
|
|
|
|
|
fmt.Printf(" temp: %d\n", pl_130.T)
|
|
|
|
|
|
|
|
fmt.Printf(" humidity: %d\n", pl_130.H)
|
|
|
|
|
|
|
|
fmt.Printf(" pressure: %d\n", pl_130.P)
|
|
|
|
|
|
|
|
fmt.Printf("}\n")
|
|
|
|
|
|
|
|
if write2file {
|
|
|
|
|
|
|
|
// Time of Packet received
|
|
|
|
|
|
|
|
var tfp = (time.Now().Unix() / 60)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// we calculate the weight...
|
|
|
|
|
|
|
|
var w32 int32
|
|
|
|
|
|
|
|
var w uint16
|
|
|
|
|
|
|
|
w1_0_real := pl_130.W1_0
|
|
|
|
|
|
|
|
w2_0_real := pl_130.W2_0
|
|
|
|
|
|
|
|
w32 = int32(((float64(pl_130.W1-w1_0_real) / float64(pl_130.W1_C)) + (float64(pl_130.W2-w2_0_real) / float64(pl_130.W2_C))) / 5.0)
|
|
|
|
|
|
|
|
if w32 < 0 {
|
|
|
|
|
|
|
|
w = 0
|
|
|
|
|
|
|
|
} else if w32 > 65535 {
|
|
|
|
|
|
|
|
// this is not realistic (>320 kg), we set this to 0 as well...
|
|
|
|
|
|
|
|
w = 0
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
w = uint16(w32)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
WriteDatapoint(tfp, deveui, devaddr, pl_130.Vbat, pl_130.H, pl_130.P, w, pl_130.W1, pl_130.W2, pl_130.T, lrrlat, lrrlon, pl_130.Fw_version, pl_130.W1_0, pl_130.W2_0, pl_130.W1_C, pl_130.W2_C)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Send alert if necessary
|
|
|
|
|
|
|
|
if val, ok := alertMap[deveui]; ok {
|
|
|
|
|
|
|
|
sendAlert(deveui, val)
|
|
|
|
|
|
|
|
delete(alertMap, deveui)
|
|
|
|
|
|
|
|
// alte Werte loeschen
|
|
|
|
|
|
|
|
deleteValues(deveui)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if val2, ok2 := alertLogMap[deveui]; ok2 {
|
|
|
|
|
|
|
|
WriteStringToFile(val2, deveui, false)
|
|
|
|
|
|
|
|
delete(alertLogMap, deveui)
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -516,7 +545,7 @@ func WriteDatapoint(mytime int64, deveui string, devaddr string, v uint8, h uint
|
|
|
|
s = fmt.Sprintf("measurement,deveui=%s devaddr=\"%s\",%sh=%di,p=%di,w=%di,t=%.1f,lrrlat=%f,lrrlon=%f%s %d\n", deveui, devaddr, sv, h, int32(p)+825, uint32(w)*5, float32(t)/10, lrrlat, lrrlon, sfw, mytime*60*1000*1000*1000)
|
|
|
|
s = fmt.Sprintf("measurement,deveui=%s devaddr=\"%s\",%sh=%di,p=%di,w=%di,t=%.1f,lrrlat=%f,lrrlon=%f%s %d\n", deveui, devaddr, sv, h, int32(p)+825, uint32(w)*5, float32(t)/10, lrrlat, lrrlon, sfw, mytime*60*1000*1000*1000)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
implausible = (w1 == NOT_PLAUSIBLE_32) || (w2 == NOT_PLAUSIBLE_32) || (w == NOT_PLAUSIBLE_16)
|
|
|
|
implausible = (w1 == NOT_PLAUSIBLE_32) || (w2 == NOT_PLAUSIBLE_32) || (w == NOT_PLAUSIBLE_16) || (w == 0)
|
|
|
|
|
|
|
|
|
|
|
|
WriteStringToFile(s, deveui, implausible)
|
|
|
|
WriteStringToFile(s, deveui, implausible)
|
|
|
|
|
|
|
|
|
|
|
|
@ -530,6 +559,38 @@ func WriteDatapoint(mytime int64, deveui string, devaddr string, v uint8, h uint
|
|
|
|
location, _ := time.LoadLocation("Europe/Zurich")
|
|
|
|
location, _ := time.LoadLocation("Europe/Zurich")
|
|
|
|
alertMap[deveui] = fmt.Sprintf("*** Schwarmalarm ***\n%s\n%s\nGewichtsverlust: %d g", getDevAlias(deveui), time.Unix(mytime*60, 0).In(location).Format("02.01.2006 15:04"), w_loss)
|
|
|
|
alertMap[deveui] = fmt.Sprintf("*** Schwarmalarm ***\n%s\n%s\nGewichtsverlust: %d g", getDevAlias(deveui), time.Unix(mytime*60, 0).In(location).Format("02.01.2006 15:04"), w_loss)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// minmax Alert
|
|
|
|
|
|
|
|
fmt.Println("debug minmax alert")
|
|
|
|
|
|
|
|
minmax := getDevMinmax(deveui)
|
|
|
|
|
|
|
|
fmt.Printf("debug getDevMinmax: minmax = %s\n", minmax)
|
|
|
|
|
|
|
|
if minmax != "0,0" {
|
|
|
|
|
|
|
|
tokens := strings.Split(minmax, ",")
|
|
|
|
|
|
|
|
if len(tokens) == 2 {
|
|
|
|
|
|
|
|
min, _ := strconv.ParseInt(tokens[0], 10, 32)
|
|
|
|
|
|
|
|
max, _ := strconv.ParseInt(tokens[1], 10, 32)
|
|
|
|
|
|
|
|
fmt.Printf("debug min: %d, max: %d\n", min, max)
|
|
|
|
|
|
|
|
minmaxstatus := GetMinMaxStatus(deveui)
|
|
|
|
|
|
|
|
fmt.Printf("debug minmaxstatus: %s\n", minmaxstatus)
|
|
|
|
|
|
|
|
if (w_gram < uint32(min)) && (minmaxstatus != "MINALERT") {
|
|
|
|
|
|
|
|
fmt.Printf("debug minalert\n")
|
|
|
|
|
|
|
|
SetMinMaxStatus(deveui, "MINALERT")
|
|
|
|
|
|
|
|
alertLogMap[deveui] = fmt.Sprintf("alert,deveui=%s reason=\"minmaxlarm\",w=%di,w_min=%di %d\n", deveui, w_gram, min, mytime*60*1000*1000*1000)
|
|
|
|
|
|
|
|
location, _ := time.LoadLocation("Europe/Zurich")
|
|
|
|
|
|
|
|
alertMap[deveui] = fmt.Sprintf("*** Min/Max-Alarm ***\n%s\n%s\nUnterschreiten des Minimalgewichts: %d g (Minimal: %d g)", getDevAlias(deveui), time.Unix(mytime*60, 0).In(location).Format("02.01.2006 15:04"), w_gram, min)
|
|
|
|
|
|
|
|
} else if (w_gram > uint32(max)) && (minmaxstatus != "MAXALERT") {
|
|
|
|
|
|
|
|
fmt.Printf("debug maxalert\n")
|
|
|
|
|
|
|
|
SetMinMaxStatus(deveui, "MAXALERT")
|
|
|
|
|
|
|
|
alertLogMap[deveui] = fmt.Sprintf("alert,deveui=%s reason=\"minmaxlarm\",w=%di,w_max=%di %d\n", deveui, w_gram, max, mytime*60*1000*1000*1000)
|
|
|
|
|
|
|
|
location, _ := time.LoadLocation("Europe/Zurich")
|
|
|
|
|
|
|
|
alertMap[deveui] = fmt.Sprintf("*** Min/Max-Alarm ***\n%s\n%s\nUeberschreiten des Maximalgewichts: %d g (Maximal: %d g)", getDevAlias(deveui), time.Unix(mytime*60, 0).In(location).Format("02.01.2006 15:04"), w_gram, max)
|
|
|
|
|
|
|
|
} else if (w_gram > uint32(min+100)) && (w_gram < uint32(max-100)) {
|
|
|
|
|
|
|
|
fmt.Printf("debug resettonormal\n")
|
|
|
|
|
|
|
|
SetMinMaxStatus(deveui, "NORMAL")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -549,9 +610,9 @@ func WriteStringToFile(s string, deveui string, implausible bool) {
|
|
|
|
|
|
|
|
|
|
|
|
// Also write to individual files
|
|
|
|
// Also write to individual files
|
|
|
|
datestr := time.Now().Format("2006-01")
|
|
|
|
datestr := time.Now().Format("2006-01")
|
|
|
|
individual_file := "/home/beieli/mini-beieli-lorahandler/logs/" + deveui + "-" + datestr + ".log"
|
|
|
|
individual_file := "/data/logs/" + deveui + "-" + datestr + ".log"
|
|
|
|
if implausible {
|
|
|
|
if implausible {
|
|
|
|
individual_file = "/home/beieli/mini-beieli-lorahandler/logs/" + "implausible" + "-" + datestr + ".log"
|
|
|
|
individual_file = "/data/logs/" + "implausible" + "-" + datestr + ".log"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fi, err := os.OpenFile(individual_file, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0644)
|
|
|
|
fi, err := os.OpenFile(individual_file, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0644)
|
|
|
|
|