Please explain how I can use case statements inside conditions!

To be honest, I do not even believe in "110a000f00551001" beeing the actual payload from the device, but []byte{0x11, 0x0a, 0x00, 0x0f, 0x00, 0x55, 0x10, 0x01} ([]byte{17, 10, 0, 15, 0, 85, 16, 1}).

Thats why I am insisting on seeing real payload.

As long as you do not understand how your payload will look like in go, we won’t be able to tell you anything but wild guesses.

But from my experience, no sensor or device will “prettify” its raw data for you, as this does cost additional power and power for such a device is time.

1 Like

@kync thanks I’ll check that out.

1 Like

@kync @NobbZ. I restructured the code for the updated version of the sensor.

package main
import (
// “bytes”
“encoding/hex”
“fmt”
)
type decoded struct{
payload, debug byte
port int
packetTtype, firmwareVersion string
occupied bool
}

func main() {
payload := “0000000099020206029600000017030200”
port := 3
payloadstr, err := hex.DecodeString(payload)
if err != nil {
panic(err)
}
fmt.Printf(“%#v\n”, payloadstr)
fmt.Printf(“%#v\n”, port)

if port == 3{
25> decoded.packetType = “Startup”
// bytes are for debug info
27> decoded.debug = payloadstr[0:12]
//bytes 12-14 are firmware version
29> decoded.firmawareVersion = payloadstr[12]+ ‘.’+payloadstr[13]+‘.’+payloadstr[14]
}
31> decoded.occupied = false
if (payloadstr[16]&1 ==1){
33> decoded.occupied = true
}
35> return decoded
}

This time the hardcoded payload is as received in the network server.
And i’m getting the following error.

go:25:9: decoded.packetType undefined (type decoded has no method packetType)
go:27:9: decoded.debug undefined (type decoded has no method debug)
go:29:9: decoded.firmawareVersion undefined (type decoded has no method firmawareVersion)
go:31:8: decoded.occupied undefined (type decoded has no method occupied)
go:33:9: decoded.occupied undefined (type decoded has no method occupied)
go:35:1: type decoded is not an expression
go:35:1: too many arguments to return

1 Like