Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

panic on missing pressureunit #6

Closed
theHausdorffMetric opened this issue Nov 6, 2020 · 9 comments
Closed

panic on missing pressureunit #6

theHausdorffMetric opened this issue Nov 6, 2020 · 9 comments

Comments

@theHausdorffMetric
Copy link

Thx for the nice work. On example get_station_data I get

Finished dev [unoptimized + debuginfo] target(s) in 0.07s
Running target/debug/examples/get_station_data
thread 'main' panicked at 'Failed to get station data: Error { inner: Error("missing field pressureunit", line: 1, column: 1393)

failed to deserialize JSON }', examples/get_station_data.rs:36:10
note: run with RUST_BACKTRACE=1 environment variable to display a backtrace

Looking into it (however rust newbie)

@lukaspustina
Copy link
Owner

Hi @theHausdorffMetric, thanks for using my create.

I haven't looked into it yet, before I do, just one questions: Do the other examples work for you? If not, it might be due to authorization. If yes, it might be that Netatmo changed the response or something else broke in my parser.

@lukaspustina
Copy link
Owner

I've just added logging right before the location I suspect your panic to occur. Can please rerun your example from the current master and prepend RUST_LOG=netatmo_rs=trace to your command. This should show us the result that we receive from the API -- please be aware that the log output will contain sensitive authentication information; so make sure to omit that from sharing.

@theHausdorffMetric
Copy link
Author

Hi @lukaspustina,
thx - I can auth ok and get some data but it panics on deserialisation where the pressureunit is missing. I will try to investigate the api response with the browser first.

Below is the current ouput (I DELETED some confidential stuff as you suggested)

Finished dev [unoptimized + debuginfo] target(s) in 0.07s
Running target/debug/examples/get_station_data
[2020-11-08T08:53:29Z TRACE netatmo_rs::client] Sucessful (200) repsone: '{"access_token":"DELETED":"DELETED","scope":["read_station"],"expires_in":10800,"expire_in":10800}'
[2020-11-08T08:53:29Z TRACE netatmo_rs::client] Sucessful (200) repsone: '{"body":{"devices":[{"_id":"DELETED","station_name":"FamilyProbst NetAtmo","date_setup":1359763200,"last_setup":1359763200,"type":"NAMain","last_status_store":1604825349,"module_name":"Indoor1","firmware":177,"last_upgrade":1439971768,"wifi_status":68,"reachable":true,"co2_calibrating":false,"data_type":["Temperature","CO2","Humidity","Noise","Pressure"],"place":{"altitude":803,"city":"Menzingen","country":"CH","timezone":"Europe/Zurich","location":[8.5909,47.17796]},"home_id":"DELETED","home_name":"FamilyProbst NetAtmo","dashboard_data":{"time_utc":1604825336,"Temperature":23.2,"CO2":1049,"Humidity":44,"Noise":44,"Pressure":1024.9,"AbsolutePressure":931,"min_temp":22.6,"max_temp":23.5,"date_max_temp":1604790274,"date_min_temp":1604804783,"temp_trend":"stable","pressure_trend":"stable"},"modules":[{"_id":"02:00:00:2e:ee:e0","type":"NAModule1","module_name":"Outdoor2017","last_setup":1513417244,"data_type":["Temperature","Humidity"],"battery_percent":80,"reachable":true,"firmware":50,"last_message":1604825342,"last_seen":1604825330,"rf_status":77,"battery_vp":5524,"dashboard_data":{"time_utc":1604825330,"Temperature":10,"Humidity":76,"min_temp":5.6,"max_temp":10,"date_max_temp":1604825330,"date_min_temp":1604799903,"temp_trend":"up"}}]}],"user":{"mail":"DELETED","administrative":{"country":"CH","feel_like_algo":0,"lang":"en","reg_locale":"en-GB","unit":0,"windunit":0}}},"status":"ok","time_exec":0.05339217185974121,"time_server":1604825609}'
thread 'main' panicked at 'Failed to get station data: Error { inner: Error("missing field pressureunit", line: 1, column: 1433)

failed to deserialize JSON }', examples/get_station_data.rs:38:10
note: run with RUST_BACKTRACE=1 environment variable to display a backtrace

@lukaspustina
Copy link
Owner

So it seems your device is sending slightly different Administrative information compared to mine. The crate so far expects this:

#[derive(Debug, Serialize, Deserialize)]
pub struct Administrative {
    pub feel_like_algo: u64,
    pub lang: String,
    pub pressureunit: u64,
    pub reg_locale: String,
    pub unit: u64,
    pub windunit: u64,
}

I don't see a reason to force these information. I will make country (as in your response) and pressureunit (as in my response) optional. Let's see how far this will get us.

The only concern I have here is that this is going to break the API and other users might get affected. But I will need to push a new create version anyway, so I'll make a minor increment. Please give a few days to change the code.

@lukaspustina
Copy link
Owner

@theHausdorffMetric Please check my changes on master. If it works, can you check all other examples too? Maybe we can surface other misplaced requirements, too.

@theHausdorffMetric
Copy link
Author

can now confirm that get_measure and get_station_data work as intended.
Thx a lot
(now i'm just waiting for my new rapi 0 and e-ink hat to make a temperature display)

@lukaspustina
Copy link
Owner

Great. I'll push a new crate version later.

@lukaspustina
Copy link
Owner

Please see https://crates.io/crates/netatmo-rs/0.5.0.

If this works for you, please close the issue.

@theHausdorffMetric
Copy link
Author

Thx for the support.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants