Skip to content

Commit cced5a8

Browse files
authored
Merge pull request #1 from fffer1234/fix/rs485-timezone
fix: make RS485 MQTT log timezone respect system settings
2 parents e43e1e6 + 67e2a53 commit cced5a8

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

  • feeds/lorawan-gateway/rs485-module/src

feeds/lorawan-gateway/rs485-module/src/main.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,29 @@ use tokio::io::{AsyncReadExt, AsyncWriteExt};
1212
use tokio::time::sleep;
1313
use tokio_serial::{DataBits, Parity, StopBits, SerialPortBuilderExt};
1414

15+
/// Initialize timezone from UCI system configuration
16+
fn init_timezone() {
17+
match Command::new("uci")
18+
.args(&["get", "system.@system[0].timezone"])
19+
.output()
20+
{
21+
Ok(output) if output.status.success() => {
22+
if let Ok(tz) = String::from_utf8(output.stdout) {
23+
let tz = tz.trim();
24+
if !tz.is_empty() && tz != "UTC" {
25+
std::env::set_var("TZ", tz);
26+
// Notify that timezone was loaded
27+
eprintln!("Timezone set from UCI: {}", tz);
28+
}
29+
}
30+
}
31+
_ => {
32+
// Fallback to UTC if UCI read fails
33+
std::env::set_var("TZ", "UTC");
34+
}
35+
}
36+
}
37+
1538
// Mqtt and Serial Configuration Structures
1639
#[derive(Debug, Clone, PartialEq)]
1740
struct Config {
@@ -437,6 +460,9 @@ async fn setup_serial(
437460

438461
#[tokio::main]
439462
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
463+
// Initialize timezone from UCI system configuration
464+
init_timezone();
465+
440466
// Initialize logger
441467
let logger = Arc::new(Logger::new());
442468
logger.init()?;

0 commit comments

Comments
 (0)