file write test
This commit is contained in:
parent
f0f0e9f27e
commit
fb0ad6b1dc
@ -1,5 +1,6 @@
|
|||||||
nvs, data, nvs, 0x9000, 0x4000,
|
nvs, data, nvs, , 16k,
|
||||||
otadata, data, ota, 0xd000, 0x2000,
|
otadata, data, ota, , 8k,
|
||||||
phy_init, data, phy, 0xf000, 0x1000,
|
phy_init, data, phy, , 4k,
|
||||||
ota_0, app, ota_0, 0x10000, 0x180000,
|
factory, app, ota_0, , 1792K,
|
||||||
ota_1, app, ota_1, 0x190000, 0x180000,
|
ota_1, app, ota_1, , 1792K,
|
||||||
|
storage, data, spiffs, , 400K,
|
|
@ -1,20 +1,25 @@
|
|||||||
use std::{fs::File, io::Write};
|
use std::{
|
||||||
|
ffi::CString,
|
||||||
|
fs::File,
|
||||||
|
io::{Read, Write},
|
||||||
|
str::from_utf8,
|
||||||
|
};
|
||||||
|
|
||||||
use chrono::{Datelike, Timelike, NaiveDateTime};
|
use chrono::{Datelike, NaiveDateTime, Timelike};
|
||||||
|
|
||||||
|
use anyhow::{Context, Result};
|
||||||
use chrono_tz::Europe::Berlin;
|
use chrono_tz::Europe::Berlin;
|
||||||
use esp_idf_hal::delay::Delay;
|
use esp_idf_hal::delay::Delay;
|
||||||
use esp_idf_svc::http::server::EspHttpServer;
|
use esp_idf_svc::http::server::EspHttpServer;
|
||||||
use plant_hal::{PlantCtrlBoardInteraction, PlantHal, CreatePlantHal, PLANT_COUNT};
|
use plant_hal::{CreatePlantHal, PlantCtrlBoardInteraction, PlantHal, PLANT_COUNT};
|
||||||
use anyhow::{Context, Result};
|
|
||||||
use webserver::webserver::httpd;
|
use webserver::webserver::httpd;
|
||||||
pub mod plant_hal;
|
|
||||||
mod config;
|
mod config;
|
||||||
|
pub mod plant_hal;
|
||||||
mod webserver {
|
mod webserver {
|
||||||
pub mod webserver;
|
pub mod webserver;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() -> Result<()>{
|
fn main() -> Result<()> {
|
||||||
// It is necessary to call this function once. Otherwise some patches to the runtime
|
// 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
|
// implemented by esp-idf-sys might not link properly. See https://github.com/esp-rs/esp-idf-template/issues/71
|
||||||
esp_idf_svc::sys::link_patches();
|
esp_idf_svc::sys::link_patches();
|
||||||
@ -69,7 +74,7 @@ fn main() -> Result<()>{
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
// let proceed = config.unwrap();
|
// let proceed = config.unwrap();
|
||||||
|
|
||||||
//check if we have a config file
|
//check if we have a config file
|
||||||
// if not found or parsing error -> error very fast blink general fault
|
// if not found or parsing error -> error very fast blink general fault
|
||||||
@ -109,19 +114,43 @@ fn main() -> Result<()>{
|
|||||||
initial_measurements_p[plant] = board.measure_moisture_hz(plant, plant_hal::Sensor::PUMP)?;
|
initial_measurements_p[plant] = board.measure_moisture_hz(plant, plant_hal::Sensor::PUMP)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
match board.wifi("C3MA", Some("chaosimquadrat"), 10000) {
|
//match board.wifi("C3MA", Some("chaosimquadrat"), 10000) {
|
||||||
Ok(_) => println!("online mode"),
|
// Ok(_) => println!("online mode"),
|
||||||
Err(_) => {
|
// Err(_) => {
|
||||||
|
|
||||||
println!("Offline mode");
|
// println!("Offline mode");
|
||||||
},
|
//},
|
||||||
}
|
//}
|
||||||
//try connect wifi and do mqtt roundtrip
|
//try connect wifi and do mqtt roundtrip
|
||||||
// if no wifi, set general fault persistent
|
// if no wifi, set general fault persistent
|
||||||
//if no mqtt, set general fault persistent
|
//if no mqtt, set general fault persistent
|
||||||
|
|
||||||
|
unsafe {
|
||||||
|
let base_path = CString::new("/spiffs").unwrap();
|
||||||
|
let storage = CString::new("storage").unwrap();
|
||||||
|
|
||||||
match board.sntp(1000*120) {
|
let conf = esp_idf_sys::esp_vfs_spiffs_conf_t {
|
||||||
|
base_path: base_path.as_ptr(),
|
||||||
|
partition_label: storage.as_ptr(),
|
||||||
|
max_files: 5,
|
||||||
|
format_if_mount_failed: true,
|
||||||
|
};
|
||||||
|
|
||||||
|
let mount = esp_idf_sys::esp_vfs_spiffs_register(&conf);
|
||||||
|
println!("Mount returned {}", mount);
|
||||||
|
}
|
||||||
|
println!("writing");
|
||||||
|
let mut config_file = File::create("/spiffs/config.cfg")?;
|
||||||
|
config_file.write_all("test stuff".as_bytes())?;
|
||||||
|
config_file.flush()?;
|
||||||
|
println!("Reading");
|
||||||
|
let mut cfg = File::open("/spiffs/config.cfg")?;
|
||||||
|
let mut data: [u8; 512] = [0; 512];
|
||||||
|
let read = cfg.read(&mut data)?;
|
||||||
|
println!("Read file {}", from_utf8(&data[0..read])?);
|
||||||
|
|
||||||
|
/*
|
||||||
|
match board.sntp(1000 * 120) {
|
||||||
Ok(new_time) => cur = new_time,
|
Ok(new_time) => cur = new_time,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
println!("sntp error: {}", err);
|
println!("sntp error: {}", err);
|
||||||
@ -131,8 +160,6 @@ fn main() -> Result<()>{
|
|||||||
let europe_time = cur.with_timezone(&Berlin);
|
let europe_time = cur.with_timezone(&Berlin);
|
||||||
println!("Running logic at europe/berlin {}", europe_time);
|
println!("Running logic at europe/berlin {}", europe_time);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//if config battery mode
|
//if config battery mode
|
||||||
//read battery level
|
//read battery level
|
||||||
//if not possible set general fault persistent, but do continue
|
//if not possible set general fault persistent, but do continue
|
||||||
@ -163,7 +190,6 @@ fn main() -> Result<()>{
|
|||||||
// state += notworking
|
// state += notworking
|
||||||
//set consecutive pumps+=1
|
//set consecutive pumps+=1
|
||||||
|
|
||||||
|
|
||||||
//check if during light time
|
//check if during light time
|
||||||
//lightstate += out of worktime
|
//lightstate += out of worktime
|
||||||
//check battery level
|
//check battery level
|
||||||
@ -173,7 +199,6 @@ fn main() -> Result<()>{
|
|||||||
//if no preventing lightstate, enable light
|
//if no preventing lightstate, enable light
|
||||||
//lightstate = active
|
//lightstate = active
|
||||||
|
|
||||||
|
|
||||||
//keep webserver in scope
|
//keep webserver in scope
|
||||||
let webserver = httpd(true);
|
let webserver = httpd(true);
|
||||||
let delay = Delay::new_default();
|
let delay = Delay::new_default();
|
||||||
@ -181,9 +206,8 @@ fn main() -> Result<()>{
|
|||||||
//let freertos do shit
|
//let freertos do shit
|
||||||
delay.delay_ms(1001);
|
delay.delay_ms(1001);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
return Ok(())
|
return Ok(());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//error codes
|
//error codes
|
||||||
|
Loading…
Reference in New Issue
Block a user