@@ -167,8 +167,9 @@ void API::init() {
167
167
evse->subscribe_powermeter ([this , var_powermeter, &session_info](types::powermeter::Powermeter powermeter) {
168
168
json powermeter_json = powermeter;
169
169
this ->mqtt .publish (var_powermeter, powermeter_json.dump ());
170
- session_info->set_latest_energy_wh (powermeter_json.at (" energy_Wh_import" ).at (" total" ));
171
- session_info->set_latest_total_w (powermeter_json.at (" power_W" ).at (" total" ));
170
+ session_info->set_latest_energy_wh (powermeter.energy_Wh_import .total );
171
+ if (powermeter.power_W .has_value ())
172
+ session_info->set_latest_total_w (powermeter.power_W .value ().total );
172
173
});
173
174
174
175
std::string var_limits = var_base + " limits" ;
@@ -270,17 +271,16 @@ void API::init() {
270
271
});
271
272
}
272
273
273
- this ->api_threads .push_back (
274
- std::thread ([this , var_connectors, connectors]() {
275
- auto next_tick = std::chrono::steady_clock::now ();
276
- while (this ->running ) {
277
- json connectors_array = connectors;
278
- this ->mqtt .publish (var_connectors, connectors_array.dump ());
274
+ this ->api_threads .push_back (std::thread ([this , var_connectors, connectors]() {
275
+ auto next_tick = std::chrono::steady_clock::now ();
276
+ while (this ->running ) {
277
+ json connectors_array = connectors;
278
+ this ->mqtt .publish (var_connectors, connectors_array.dump ());
279
279
280
- next_tick += NOTIFICATION_PERIOD;
281
- std::this_thread::sleep_until (next_tick);
282
- }
283
- }));
280
+ next_tick += NOTIFICATION_PERIOD;
281
+ std::this_thread::sleep_until (next_tick);
282
+ }
283
+ }));
284
284
}
285
285
286
286
void API::ready () {
0 commit comments