-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[RSDK-9226] - fix time of day not setting when starting offline #352
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,8 @@ use crate::proto::{ | |
}, | ||
}; | ||
use bytes::{BufMut, Bytes, BytesMut}; | ||
use chrono::Datelike; | ||
use chrono::Local; | ||
use chrono::{format::ParseError, DateTime, FixedOffset}; | ||
use futures_lite::{Future, StreamExt}; | ||
use http_body_util::BodyExt; | ||
|
@@ -284,6 +286,37 @@ impl AppClient { | |
} else { | ||
None | ||
}; | ||
|
||
#[cfg(feature = "esp32")] | ||
{ | ||
// If the current datetime has not already been set, we use the datetime from | ||
// the config response to set the time of day on the device. This may be replaced | ||
// by calls to an NTP server in the future | ||
let local_dt = Local::now().fixed_offset(); | ||
// Viam does not pre-exist the year 2020, so if the year is before that | ||
// at the very least the current time is wrong and needs to be corrected | ||
if local_dt.year() < 2020 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This value is now referenced in two places that need to remain in sync, should we ever decide to change it. Let's make a constant for it. |
||
if let Some(current_dt) = datetime { | ||
use esp_idf_svc::sys::{settimeofday, timeval}; | ||
let tz = chrono_tz::Tz::UTC; | ||
std::env::set_var("TZ", tz.name()); | ||
Comment on lines
+301
to
+302
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Scrolling down on that page, it looks like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't see anything further about |
||
let tv_sec = current_dt.timestamp() as i32; | ||
let tv_usec = current_dt.timestamp_subsec_micros() as i32; | ||
let current_timeval = timeval { tv_sec, tv_usec }; | ||
let res = unsafe { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You don't really need
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. or the |
||
settimeofday(¤t_timeval as *const timeval, std::ptr::null()) | ||
}; | ||
if res != 0 { | ||
log::error!( | ||
"could not set time of day for timezone {:?} and timestamp {:?}", | ||
tz.name(), | ||
current_dt | ||
); | ||
} | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fine to defer this into a new ticket, but should we consider calling |
||
} | ||
|
||
if r.is_empty() { | ||
return Err(AppClientError::AppClientEmptyBody); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -520,7 +520,7 @@ where | |
Ok(data) => data, | ||
Err(DataSyncError::NoCurrentTime) => { | ||
log::error!("Could not calculate data timestamps, returning without flushing store"); | ||
return Ok(()); | ||
continue; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this right? I think the idea of |
||
} | ||
Err(err) => { | ||
log::error!( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add these to existing import