Edge IoT with Rust on ESP: NTP

This page summarizes the projects mentioned and recommended in the original post on dev.to

Our great sponsors
  • InfluxDB - Power Real-Time Data Analytics at Scale
  • WorkOS - The modern identity platform for B2B SaaS
  • SaaSHub - Software Alternatives and Reviews
  • esp-idf-template

    A "Hello, world!" template of a Rust binary crate for the ESP-IDF framework. (by esp-rs)

  • use anyhow; use chrono::{DateTime, Utc}; use embedded_svc::wifi::{AuthMethod, ClientConfiguration, Configuration}; use esp_idf_hal::delay::FreeRtos; use esp_idf_hal::peripherals::Peripherals; use esp_idf_svc::eventloop::EspSystemEventLoop; use esp_idf_svc::nvs::EspDefaultNvsPartition; use esp_idf_svc::sntp::{EspSntp, SyncStatus}; use esp_idf_svc::wifi::{BlockingWifi, EspWifi}; use std::time::SystemTime; fn main() -> anyhow::Result<()> { // It is necessary to call this function once. Otherwise some patches to the runtime // implemented by esp-idf-sys might not link properly. See https://github.com/esp-rs/esp-idf-template/issues/71 esp_idf_sys::link_patches(); let peripherals = Peripherals::take().unwrap(); let sysloop = EspSystemEventLoop::take()?; let nvs = EspDefaultNvsPartition::take()?; let mut wifi = BlockingWifi::wrap( EspWifi::new(peripherals.modem, sysloop.clone(), Some(nvs))?, sysloop, )?; wifi.set_configuration(&Configuration::Client(ClientConfiguration { ssid: "Wokwi-GUEST".into(), bssid: None, auth_method: AuthMethod::None, password: "".into(), channel: None, }))?; // Start Wifi wifi.start()?; // Connect Wifi wifi.connect()?; // Wait until the network interface is up wifi.wait_netif_up()?; // Print Out Wifi Connection Configuration while !wifi.is_connected().unwrap() { // Get and print connection configuration let config = wifi.get_configuration().unwrap(); println!("Waiting for station {:?}", config); } println!("Wifi Connected"); // Create Handle and Configure SNTP let ntp = EspSntp::new_default().unwrap(); // Synchronize NTP println!("Synchronizing with NTP Server"); while ntp.get_sync_status() != SyncStatus::Completed {} println!("Time Sync Completed"); loop { // Obtain System Time let st_now = SystemTime::now(); // Convert to UTC Time let dt_now_utc: DateTime = st_now.clone().into(); // Format Time String let formatted = format!("{}", dt_now_utc.format("%d/%m/%Y %H:%M:%S")); // Print Time println!("{}", formatted); // Delay FreeRtos::delay_ms(1000); } }

  • InfluxDB

    Power Real-Time Data Analytics at Scale. Get real-time insights from all types of time series data with InfluxDB. Ingest, query, and analyze billions of data points in real-time with unbounded cardinality.

    InfluxDB logo
NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts