-
Notifications
You must be signed in to change notification settings - Fork 0
/
TetraedreMBUS.go
executable file
·105 lines (85 loc) · 3.56 KB
/
TetraedreMBUS.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package main
import (
"time"
)
type TetraedreMBUSData struct {
Time time.Time
MeterReading float64
ErrorStatus string
}
type decodedtetraedrembusdata struct {
DeviceEui string `json:"deviceEui"`
Seqno uint32 `json:"seqno"`
Port uint8 `json:"port"`
AppEui string `json:"appEui"`
Time string `json:"time"`
DeviceTx devicetx `json:"deviceTx,omitempty"`
GatewayRx []gatewayrx `json:"gatewayRx,omitempty"`
Data []TetraedreMBUSData `json:"data,omitempty"`
}
/*
"payload": {"applicationID": "20","applicationName": "TalkpoolOY","deviceName": "OY1100","devEUI": "20-56-31-55-54-33-57-14","rxInfo": [{"mac": "C0-EE-40-FF-FF-29-3D-F8","rssi": -33,"loRaSNR": 7.2,"name": "GW name","latitude": "","longitude": "","altitude": ""}],"txInfo": {"frequency": "X","dataRate": {"modulation": "LORA","bandwidth": "X","spreadFactor": "X"},"adr": true,"codeRate": "X"},"fCnt": 25,"fPort": 1,"data": [{"time": 1547008071054,"temp": 23.7,"hum": 62.1},{"time": 1547005891054,"temp": 23.7,"hum": 62},{"time": 1547010251054,"temp": 23.6,"hum": 60.8}]}
*/
// func parseTetraedreMBUSDataData(receivedtime time.Time, port uint8, receiveddata string) []TetraedreMBUSData {
// //Input Validation
// //Length should be a multiple of 6
// databytes, _ := base64.StdEncoding.DecodeString(receiveddata)
// fmt.Println("databytes", databytes)
// dst := ByteToHex(databytes)
// fmt.Println("Hex=", dst)
// first := dst[24:26]
// first1 := dst[26:28]
// first2 := dst[28:30]
// first3 := dst[30:32]
// first4 := dst[32:34]
// first5 := dst[34:36]
// fmt.Println("first=", first)
// fmt.Println("first1=", first1)
// fmt.Println("first2=", first2)
// fmt.Println("first3=", first3)
// fmt.Println("first4=", first4)
// str := first5 + first4 + first3 + first2 + first1 + first
// str1, err := strconv.ParseInt(str, 10, 64)
// if err == nil {
// fmt.Println(str1)
// }
// //fmt.Println("str=",str)
// var parsedvalues []TetraedreMBUSData
// fmt.Println("len(databytes):", len(databytes))
// if len(databytes)%18 == 0 {
// // return nil
// //databytes = databytes[1:]
// capacity := len(databytes) / 18
// parsedvalues = make([]TetraedreMBUSData, capacity)
// for index := 0; index < capacity; index++ {
// parsedvalues[index].MeterReading = float64(str1) / 10000.0
// parsedvalues[index].ErrorStatus = "0000"
// parsedvalues[index].Time = receivedtime.Add(time.Duration((-15)*index) * time.Minute)
// }
// }
// fmt.Println("parsedvalues: ", parsedvalues)
// return parsedvalues
// }
// func publishTetraedreMBUSData(dev device, entry loradata, parsedvalues []TetraedreMBUSData) {
// loradatabytes, err := json.Marshal(entry)
// if err != nil {
// fmt.Println("Failed to encode message", err)
// return
// }
// if !dev.RawData {
// var decodeddata decodedtetraedrembusdata
// if err := json.Unmarshal([]byte(loradatabytes), &decodeddata); err != nil {
// fmt.Println("Failed to encode message", err) //This error is ok as the format of data is different
// }
// decodeddata.Data = append(decodeddata.Data, parsedvalues...)
// loradecodeddatabytes, err := json.Marshal(decodeddata)
// if err != nil {
// fmt.Println("Failed to encode message", err)
// return
// }
// fmt.Println("Data sent: ", string(loradecodeddatabytes))
// transferDatatoEndPoint(loradecodeddatabytes, dev)
// } else {
// transferDatatoEndPoint(loradatabytes, dev)
// }
// }