From f3eb5dcc4e3db1c2e45f5903c714f63c88094751 Mon Sep 17 00:00:00 2001 From: Joerg Lehmann Date: Fri, 30 Apr 2021 15:42:23 +0200 Subject: [PATCH] ignore short payloads (i.e. join messages) --- main.go | 570 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 287 insertions(+), 283 deletions(-) diff --git a/main.go b/main.go index a8659f0..e4dd924 100644 --- a/main.go +++ b/main.go @@ -213,294 +213,298 @@ func DecodePayload(s string, deveui string, devaddr string, lrrlat float32, lrrl pl_130 = payload_130{} br := bytes.NewReader(ba) fmt.Printf("Payload String: %s\n", s) - if s[0:2] == "01" { - err := binary.Read(br, binary.LittleEndian, &pl_1) - if err != nil { - fmt.Println(err) + if len(s) > 2 { + if s[0:2] == "01" { + err := binary.Read(br, binary.LittleEndian, &pl_1) + 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" { - err := binary.Read(br, binary.LittleEndian, &pl_2) - if err != nil { - fmt.Println(err) + 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) + 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" { - err := binary.Read(br, binary.LittleEndian, &pl_128) - if err != nil { - fmt.Println(err) + // Send alert if necessary + if val, ok := alertMap[deveui]; ok { + sendAlert(deveui, val) + delete(alertMap, deveui) + // alte Werte loeschen + deleteValues(deveui) } - } 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) + if val2, ok2 := alertLogMap[deveui]; ok2 { + WriteStringToFile(val2, deveui, false) + delete(alertLogMap, deveui) } } else { - fmt.Printf("Payload String is unknown: %s\n", s) - } - 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) - 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) - } - } - // 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) + fmt.Printf("Payload String is not longer that 2 chars, ignore it\n") } }