Errors unmarshalling device info
When querying an RLC-820A on the latest firmware the response from the camera is that the wifi is 0 and not a boolean false
I have written a fairly ugly function to manage this here - https://github.com/parkervcp/reolinkapigo/blob/update_deviceinfo/internal/pkg/models/system.go#L53
I am not saying it's "the" fix to use but it is "a" fix that works right now. It handles both the int and bool values and errors on any other value.
example data from my camera
{
"B485" : 0,
"IOInputNum" : 0,
"IOOutputNum" : 0,
"audioNum" : 1,
"buildDay" : "build 21073001",
"cfgVer" : "v3.0.0.0",
"channelNum" : 1,
"detail" : "IPC_523128M8MPS18E1W01100000001",
"diskNum" : 1,
"firmVer" : "v3.0.0.494_21073001",
"frameworkVer" : 1,
"hardVer" : "IPC_523128M8MP",
"model" : "RLC-820A",
"name" : "Camera1",
"pakSuffix" : "pak,paks",
"serial" : "00000000HEIGSDH",
"type" : "IPC",
"wifi" : 0
}
example code:
cam, err := reolink.NewCamera("admin", "", "192.168.10.106")
if err != nil {
log.Errorln(err)
}
_, err = cam.Login()(cam.RestHandler)
if err != nil {
log.Errorln(err)
}
camInfo, err := cam.GetDeviceInformation()(cam.RestHandler)
if err != nil {
log.Errorln(err)
}
log.Printf("%v", camInfo.Name)
error:
2021/11/06 23:20:33 token data unmarshalled &{60d05f1bfa4516b 3600}
2021/11/06 23:20:34 token data unmarshalled &{b1ab49e8c6d468c 3600}
ERRO[0000] json: cannot unmarshal number into Go struct field DeviceInformation.wifi of type bool
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x90 pc=0x6432f9]
goroutine 1 [running]:
main.main()
/home/nvr/test/vnCT5zWjiz/test.go:48 +0x179
Hi @parkervcp
Sorry for taking so long to get back to you!
So this error has only appeared recently? Before the update the command worked?
If it did not work, then maybe my interpretation of the JSON response was incorrect and an easy fix would just be to change the Response type to be an int.
From what I can see, the example response taken from a test camera seems to be an int, as shown here.
Thus, I believe the easiest course of action is to just change the type in the struct from a bool to an int here.
I apologize for not getting back sooner as I see you have already submitted a PR to address this issue, and I thank you for your hard work :bowing_man:
@Benehiko In my PR I was trying to be flexible as I only have one camera and am not sure about the consistency of that value across them all.
My PR allows for both a bool and and int value to be returned.