ignore data without GPS location
This commit is contained in:
parent
a13ec1db85
commit
1c657e2943
|
|
@ -11,7 +11,6 @@ import (
|
|||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
|
|
@ -19,16 +18,6 @@ const (
|
|||
outputfile = "/home/appuser/wo-bisch-lorahandler/wo-bisch-lorahandler.log"
|
||||
)
|
||||
|
||||
type MetadataTTN struct {
|
||||
Time string `json:"time"`
|
||||
}
|
||||
|
||||
type MessageTTN struct {
|
||||
Hardware_serial string `json:"hardware_serial"`
|
||||
Metadata MetadataTTN `json:"metadata"`
|
||||
Payload_raw string `json:"payload_raw"`
|
||||
}
|
||||
|
||||
type MessageProperties struct {
|
||||
Time string `json:"Time"`
|
||||
Payload_hex string `json:"payload_hex"`
|
||||
|
|
@ -106,7 +95,11 @@ func DecodePayload(s string, deveui string) {
|
|||
|
||||
mystring := fmt.Sprintf("measurement,deveui=%s lat=%.5f,lon=%.5f,vbat=%d,fw=%d %d\n", deveui, float32(pl.Latitude)/1000000.0, float32(pl.Longitude)/1000000.0, vbat, fw, (time.Now().Unix() * 1000 * 1000 * 1000))
|
||||
|
||||
WriteStringToFile(mystring, deveui)
|
||||
if pl.Longitude == 0 {
|
||||
fmt.Printf("Meaurement without GPS Position: %s", mystring)
|
||||
} else {
|
||||
WriteStringToFile(mystring, deveui)
|
||||
}
|
||||
|
||||
} else {
|
||||
log.Printf("Payload is not >= 11 bytes (22 chars): %s", s)
|
||||
|
|
@ -125,7 +118,6 @@ func main() {
|
|||
|
||||
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
var message_swisscom Message
|
||||
var message_ttn MessageTTN
|
||||
if r.Body == nil {
|
||||
http.Error(w, "Please send a request body", 400)
|
||||
return
|
||||
|
|
@ -143,43 +135,18 @@ func main() {
|
|||
log.Printf("BODY: %s", rdr1)
|
||||
r.Body = rdr2
|
||||
|
||||
// We look for the text string "mini-beieli" in the buffer, then it is a TTN Packet,
|
||||
// otherwise it should be a Swisscom Packet...
|
||||
|
||||
fmt.Printf("Length of JSON Body: %d\n", len(buf))
|
||||
|
||||
if strings.Contains(string(buf), "mini-beieli") {
|
||||
fmt.Printf("Seems to be a TTN Packet...\n")
|
||||
// it is probably a TTN package...
|
||||
err := json.NewDecoder(r.Body).Decode(&message_ttn)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), 400)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("Time: " + message_ttn.Metadata.Time)
|
||||
fmt.Println("Payload Raw: " + message_ttn.Payload_raw)
|
||||
fmt.Println("DevEUI: " + message_ttn.Hardware_serial)
|
||||
payload_hex, err := Convert2Hex(message_ttn.Payload_raw)
|
||||
if err == nil {
|
||||
DecodePayload(payload_hex, message_ttn.Hardware_serial)
|
||||
} else {
|
||||
fmt.Println("Error: could not convert raw_package to hex: %s" + message_ttn.Payload_raw)
|
||||
}
|
||||
} else {
|
||||
fmt.Printf("Seems to be a Swisscom Packet...\n")
|
||||
// it is probably a Swisscom package...
|
||||
err := json.NewDecoder(r.Body).Decode(&message_swisscom)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), 400)
|
||||
return
|
||||
}
|
||||
fmt.Println("Time: " + message_swisscom.Prop.Time)
|
||||
fmt.Println("Payload Hex: " + message_swisscom.Prop.Payload_hex)
|
||||
fmt.Println("DevEUI: " + message_swisscom.Prop.DevEUI)
|
||||
fmt.Println("DevAddr: " + message_swisscom.Prop.DevAddr)
|
||||
DecodePayload(message_swisscom.Prop.Payload_hex, message_swisscom.Prop.DevEUI)
|
||||
err := json.NewDecoder(r.Body).Decode(&message_swisscom)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), 400)
|
||||
return
|
||||
}
|
||||
fmt.Println("Time: " + message_swisscom.Prop.Time)
|
||||
fmt.Println("Payload Hex: " + message_swisscom.Prop.Payload_hex)
|
||||
fmt.Println("DevEUI: " + message_swisscom.Prop.DevEUI)
|
||||
fmt.Println("DevAddr: " + message_swisscom.Prop.DevAddr)
|
||||
DecodePayload(message_swisscom.Prop.Payload_hex, message_swisscom.Prop.DevEUI)
|
||||
})
|
||||
log.Fatal(http.ListenAndServe(":8080", nil))
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue