Skip to content

Commit

Permalink
Add SNTP
Browse files Browse the repository at this point in the history
  • Loading branch information
fangpenlin committed Jan 6, 2025
1 parent 808f23b commit 6e17fc2
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion partitions.csv
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
# Note: if you have increased the bootloader size, make sure to update the offsets to avoid overlap
nvs, data, nvs, 0x9000, 0x6000,
phy_init, data, phy, 0xf000, 0x1000,
factory, app, factory, 0x10000, 1400K,
factory, app, factory, 0x10000, 1500K,
storage, data, fat, , 1500K,
8 changes: 4 additions & 4 deletions src/api/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use serde::{Deserialize, Serialize};
use std::io::{Read, Seek};
use std::mem::MaybeUninit;
use std::time::SystemTime;
use time::serde::iso8601;
use time::serde::timestamp::milliseconds;
use time::OffsetDateTime;

#[derive(Debug, Serialize, Deserialize, Clone)]
Expand All @@ -23,9 +23,9 @@ pub enum Command {
pub struct File {
path: String,
size: u64,
#[serde(with = "iso8601")]
#[serde(with = "milliseconds")]
modified_at: OffsetDateTime,
#[serde(with = "iso8601")]
#[serde(with = "milliseconds")]
created_at: OffsetDateTime,
is_dir: bool,
}
Expand All @@ -34,7 +34,7 @@ pub struct File {
pub struct DeviceInfo {
pub version: String,
pub wifi_ip: String,
#[serde(with = "iso8601")]
#[serde(with = "milliseconds")]
pub local_time: OffsetDateTime,
pub disk_size: u64,
pub disk_usage: u64,
Expand Down
5 changes: 5 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use embedded_svc::wifi::AuthMethod;
use embedded_svc::ws::FrameType;
use esp_idf_svc::hal::gpio::{PinDriver, Pull};
use esp_idf_svc::hal::prelude::Peripherals;
use esp_idf_svc::sntp::EspSntp;
use futures::executor::{LocalPool, LocalSpawner};
use futures::task::LocalSpawnExt;
use std::rc::Rc;
Expand All @@ -32,6 +33,10 @@ async fn run_async(spawner: LocalSpawner) -> Result<(), anyhow::Error> {
wifi.connect().await?;
log::info!("Connected wifi: {:#?}", wifi.get_ip_info());

// Keep it around or else the SNTP service will stop
let _sntp = EspSntp::new_default()?;
log::info!("SNTP initialized, current time is {}", OffsetDateTime::now_utc());

let mut msc_device = MSCDevice::new("storage", "/disk");
msc_device.install()?;

Expand Down

0 comments on commit 6e17fc2

Please sign in to comment.