change time units to milliseconds
Signed-off-by: YoungSoo Shin <shinys000114@gmail.com>
This commit is contained in:
@@ -70,7 +70,7 @@ class OdroidPowerLogger:
|
||||
|
||||
# Write header
|
||||
header = [
|
||||
'timestamp', 'uptime_sec',
|
||||
'timestamp', 'uptime_ms',
|
||||
'vin_voltage', 'vin_current', 'vin_power',
|
||||
'main_voltage', 'main_current', 'main_power',
|
||||
'usb_voltage', 'usb_current', 'usb_power'
|
||||
@@ -97,10 +97,10 @@ class OdroidPowerLogger:
|
||||
# Process only if the payload type is 'sensor_data'
|
||||
if status_message.WhichOneof('payload') == 'sensor_data':
|
||||
sensor_data = status_message.sensor_data
|
||||
ts_dt = datetime.fromtimestamp(sensor_data.timestamp)
|
||||
ts_dt = datetime.fromtimestamp(sensor_data.timestamp_ms / 1000)
|
||||
ts_str = ts_dt.strftime('%Y-%m-%d %H:%M:%S')
|
||||
|
||||
print(f"--- {ts_str} (Uptime: {sensor_data.uptime_sec}s) ---")
|
||||
print(f"--- {ts_str} (Uptime: {sensor_data.uptime_ms / 1000}s) ---")
|
||||
|
||||
# Print data for each channel
|
||||
for name, channel in [('VIN', sensor_data.vin), ('MAIN', sensor_data.main),
|
||||
@@ -111,7 +111,7 @@ class OdroidPowerLogger:
|
||||
# Write to CSV if enabled
|
||||
if csv_writer:
|
||||
row = [
|
||||
ts_dt.isoformat(), sensor_data.uptime_sec,
|
||||
ts_dt.isoformat(), sensor_data.uptime_ms,
|
||||
sensor_data.vin.voltage, sensor_data.vin.current, sensor_data.vin.power,
|
||||
sensor_data.main.voltage, sensor_data.main.current, sensor_data.main.power,
|
||||
sensor_data.usb.voltage, sensor_data.usb.current, sensor_data.usb.power
|
||||
|
||||
@@ -25,8 +25,8 @@ typedef struct _SensorData {
|
||||
SensorChannelData main;
|
||||
bool has_vin;
|
||||
SensorChannelData vin;
|
||||
uint32_t timestamp;
|
||||
uint32_t uptime_sec;
|
||||
uint64_t timestamp_ms;
|
||||
uint64_t uptime_ms;
|
||||
} SensorData;
|
||||
|
||||
/* Contains WiFi connection status */
|
||||
@@ -85,8 +85,8 @@ extern "C" {
|
||||
#define SensorData_usb_tag 1
|
||||
#define SensorData_main_tag 2
|
||||
#define SensorData_vin_tag 3
|
||||
#define SensorData_timestamp_tag 4
|
||||
#define SensorData_uptime_sec_tag 5
|
||||
#define SensorData_timestamp_ms_tag 4
|
||||
#define SensorData_uptime_ms_tag 5
|
||||
#define WifiStatus_connected_tag 1
|
||||
#define WifiStatus_ssid_tag 2
|
||||
#define WifiStatus_rssi_tag 3
|
||||
@@ -111,8 +111,8 @@ X(a, STATIC, SINGULAR, FLOAT, power, 3)
|
||||
X(a, STATIC, OPTIONAL, MESSAGE, usb, 1) \
|
||||
X(a, STATIC, OPTIONAL, MESSAGE, main, 2) \
|
||||
X(a, STATIC, OPTIONAL, MESSAGE, vin, 3) \
|
||||
X(a, STATIC, SINGULAR, UINT32, timestamp, 4) \
|
||||
X(a, STATIC, SINGULAR, UINT32, uptime_sec, 5)
|
||||
X(a, STATIC, SINGULAR, UINT64, timestamp_ms, 4) \
|
||||
X(a, STATIC, SINGULAR, UINT64, uptime_ms, 5)
|
||||
#define SensorData_CALLBACK NULL
|
||||
#define SensorData_DEFAULT NULL
|
||||
#define SensorData_usb_MSGTYPE SensorChannelData
|
||||
@@ -172,7 +172,7 @@ extern const pb_msgdesc_t StatusMessage_msg;
|
||||
#define LoadSwStatus_size 4
|
||||
#define STATUS_PB_H_MAX_SIZE SensorData_size
|
||||
#define SensorChannelData_size 15
|
||||
#define SensorData_size 63
|
||||
#define SensorData_size 73
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
#include "monitor.h"
|
||||
#include <nconfig.h>
|
||||
#include <sys/time.h>
|
||||
#include <time.h>
|
||||
#include "climit.h"
|
||||
#include "esp_log.h"
|
||||
@@ -89,9 +90,10 @@ static void send_pb_message(const pb_msgdesc_t* fields, const void* src_struct)
|
||||
|
||||
static void sensor_timer_callback(void* arg)
|
||||
{
|
||||
int64_t uptime_us = esp_timer_get_time();
|
||||
uint32_t uptime_sec = (uint32_t)(uptime_us / 1000000);
|
||||
uint32_t timestamp = (uint32_t)time(NULL);
|
||||
struct timeval tv;
|
||||
gettimeofday(&tv, NULL);
|
||||
uint64_t timestamp_ms = (uint64_t)tv.tv_sec * 1000 + (uint64_t)tv.tv_usec / 1000;
|
||||
uint64_t uptime_ms = (uint64_t)esp_timer_get_time() / 1000;
|
||||
|
||||
StatusMessage message = StatusMessage_init_zero;
|
||||
message.which_payload = StatusMessage_sensor_data_tag;
|
||||
@@ -120,8 +122,8 @@ static void sensor_timer_callback(void* arg)
|
||||
|
||||
// datalog_add(timestamp, channel_data_log);
|
||||
|
||||
sensor_data->timestamp = timestamp;
|
||||
sensor_data->uptime_sec = uptime_sec;
|
||||
sensor_data->timestamp_ms = timestamp_ms;
|
||||
sensor_data->uptime_ms = uptime_ms;
|
||||
|
||||
send_pb_message(StatusMessage_fields, &message);
|
||||
}
|
||||
|
||||
@@ -216,7 +216,7 @@ function updateSingleChart(chart, metric, data, timeLabel) {
|
||||
* @param {Object} data - The new sensor data object from the WebSocket.
|
||||
*/
|
||||
export function updateCharts(data) {
|
||||
const timeLabel = new Date(data.timestamp * 1000).toLocaleTimeString();
|
||||
const timeLabel = new Date(data.timestamp).toLocaleTimeString();
|
||||
|
||||
updateSingleChart(charts.power, 'power', data, timeLabel);
|
||||
updateSingleChart(charts.voltage, 'voltage', data, timeLabel);
|
||||
|
||||
@@ -88,13 +88,13 @@ function onWsMessage(event) {
|
||||
USB: sensorData.usb,
|
||||
MAIN: sensorData.main,
|
||||
VIN: sensorData.vin,
|
||||
timestamp: sensorData.timestamp
|
||||
timestamp: sensorData.timestampMs
|
||||
};
|
||||
updateSensorUI(sensorPayload);
|
||||
|
||||
// Update uptime separately from the sensor data payload
|
||||
if (sensorData.uptimeSec !== undefined) {
|
||||
updateUptimeUI(sensorData.uptimeSec);
|
||||
if (sensorData.uptimeMs !== undefined) {
|
||||
updateUptimeUI(sensorData.uptimeMs / 1000);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -25,6 +25,7 @@ export function debounce(func, delay) {
|
||||
* @returns {string} The formatted uptime string.
|
||||
*/
|
||||
export function formatUptime(totalSeconds) {
|
||||
totalSeconds = Math.floor(totalSeconds);
|
||||
const days = Math.floor(totalSeconds / 86400);
|
||||
const hours = Math.floor((totalSeconds % 86400) / 3600);
|
||||
const minutes = Math.floor((totalSeconds % 3600) / 60);
|
||||
|
||||
@@ -12,8 +12,8 @@ message SensorData {
|
||||
SensorChannelData usb = 1;
|
||||
SensorChannelData main = 2;
|
||||
SensorChannelData vin = 3;
|
||||
uint32 timestamp = 4;
|
||||
uint32 uptime_sec = 5;
|
||||
uint64 timestamp_ms = 4;
|
||||
uint64 uptime_ms = 5;
|
||||
}
|
||||
|
||||
// Contains WiFi connection status
|
||||
|
||||
Reference in New Issue
Block a user