wip-3
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
use esp_idf_svc::{eventloop::{EspSubscription, EspSystemEventLoop, System}, hal::modem::Modem, netif::IpEvent, nvs::{EspNvsPartition, NvsDefault}, sntp::{EspSntp, SyncStatus}, wifi::{AuthMethod, ClientConfiguration, Configuration, EspWifi, WifiEvent}};
|
||||
|
||||
use crate::{events::{EventBus, System as SystemNS}, properties::Variant, task::Task, time::Periodically};
|
||||
use crate::{events::{EventBus, System as SystemNS}, properties::Variant, task::{Environment, Task}, time::Periodically};
|
||||
|
||||
use std::fmt::Debug;
|
||||
|
||||
@@ -83,22 +83,22 @@ impl Task for WifiTask {
|
||||
self.connect();
|
||||
}
|
||||
|
||||
fn on_tick(&mut self, bus: &mut EventBus) {
|
||||
fn on_tick(&mut self, env: &mut Environment) {
|
||||
if self.connection_check.tick() {
|
||||
if bus.properties().get(SystemNS::NetworkOnline).unwrap() == Variant::Boolean(true) {
|
||||
if env.get_property(SystemNS::NetworkOnline).unwrap() {
|
||||
match self.ntp.get_sync_status() {
|
||||
SyncStatus::Completed => bus.set_property(SystemNS::TimeSync, true),
|
||||
_ => bus.set_property(SystemNS::TimeSync, false)
|
||||
SyncStatus::Completed => env.set_property(SystemNS::TimeSync, true),
|
||||
_ => env.set_property(SystemNS::TimeSync, false)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn stop(&mut self, bus: &mut EventBus) {
|
||||
fn stop(&mut self, env: &mut Environment) {
|
||||
log::info!("Stopping wifi");
|
||||
self.wifi_sub.take().unwrap();
|
||||
self.ip_sub.take().unwrap();
|
||||
self.disconnect();
|
||||
bus.set_property(SystemNS::NetworkOnline, false);
|
||||
env.set_property(SystemNS::NetworkOnline, false);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user