yellowhat
yellowhat

Reputation: 529

go-coap get current status

I would like to connect to my air purifier (Philips AC3033) via COAP to get current statistics/status.

The following go code:

package main

import (
    "context"
    "log"
    "time"

    "github.com/plgd-dev/go-coap/v3/udp"
)

func main() {
    co, err := udp.Dial("192.168.0.12:5683")
    if err != nil {
        log.Fatalf("Error dialing: %v", err)
    }

    ctx, cancel := context.WithTimeout(context.Background(), 2 * time.Second)
    defer cancel()

    resp, err := co.Get(ctx, "/sys/dev/info")
    if err != nil {
        log.Fatalf("Error sending request: %v", err)
    }
    log.Printf("Response payload: %+v", resp)
}

returns information of the device like:

{
    "product_id": "<id>",
    "device_id": "<id>",
    "name": "Living Room",
    "type": "AC3033",
    "modelid":"AC3033/14",
    "swversion":"Ms3411",
    "option":"1"
}

To get more statistics I could use /sys/dev/status:

package main

import (
    "context"
    "log"
    "time"

    "github.com/plgd-dev/go-coap/v3/udp"
)

func main() {
    co, err := udp.Dial("192.168.0.12:5683")
    if err != nil {
        log.Fatalf("Error dialing: %v", err)
    }

    ctx, cancel := context.WithTimeout(context.Background(), 2 * time.Second)
    defer cancel()

    resp, err := co.Get(ctx, "/sys/dev/status")
    if err != nil {
        log.Fatalf("Error sending request: %v", err)
    }
    log.Printf("Response payload: %+v", resp)
}

But it hangs for 2 secs and then errors with:

2024/12/07 22:20:36 Error sending request: cannot write request: cannot write request: context deadline exceeded

If I run:

pip install aioairctrl
aioairctrl --host 192.168.0.12 status --json

it hangs but if I press a button on the device it prints the current statistics/status.

Are there any options to get the current statistics without having to interact physically with the device?

Thanks

Upvotes: 2

Views: 125

Answers (0)

Related Questions