bemasher / rtlamr-collect

Data aggregation for rtlamr.
GNU Affero General Public License v3.0
171 stars 29 forks source link

SCM+: Cannot unmarshal number #17

Closed PlasmaEye closed 5 years ago

PlasmaEye commented 5 years ago

Getting the following error message:

02:40:51.960603 main.go:381: json unmarshal: json: cannot unmarshal number 95326987 into Go value of type uint8

An example of a message that probably generated this (made about 5 minutes prior to the error):

{
    "Time": "2019-01-30T02:35:51.496553495Z",
    "Offset": 0,
    "Length": 0,
    "Type": "SCM+",
    "Message": {
        "FrameSync": 5795,
        "ProtocolID": 30,
        "EndpointType": 156,
        "EndpointID": 95326987,
        "Consumption": 115796,
        "Tamper": 0,
        "PacketCRC": 51378
    }
}

Similar message that is not throwing this error:

{
    "Time": "2019-01-30T02:31:01.422505762Z",
    "Offset": 0,
    "Length": 0,
    "Type": "SCM",
    "Message": {
        "ID": 64633980,
        "Type": 4,
        "TamperPhy": 0,
        "TamperEnc": 1,
        "Consumption": 58882,
        "ChecksumVal": 34959
    }
}

SCM vs. SCM+ problem?

bemasher commented 5 years ago

I see the issue. The fields are the right types, but the field tags are swapped. I don't have access to my development system again until this weekend. In the meantime, the following patch would fix the issue if you want to apply it and try it yourself:

diff --git a/main.go b/main.go
index 9b9d239..3157d3e 100644
--- a/main.go
+++ b/main.go
@@ -149,8 +149,8 @@ func (scm SCM) AddPoints(msg LogMessage, bp client.BatchPoints) {

 // SCMPlus handles Standard Consumption Message Plus messages from rtlamr.
 type SCMPlus struct {
-   EndpointID   uint32 `json:"EndpointType"`
-   EndpointType uint8  `json:"EndpointID"`
+   EndpointID   uint32 `json:"EndpointID"`
+   EndpointType uint8  `json:"EndpointType"`
    Consumption  uint32 `json:"Consumption"`
 }
PlasmaEye commented 5 years ago

That works!