Add 868MHz envs, fix MAC id, offset timesync
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
#include "data_model.h"
|
||||
#include <WiFi.h>
|
||||
#include <esp_mac.h>
|
||||
|
||||
void init_device_ids(uint16_t &short_id, char *device_id, size_t device_id_len) {
|
||||
uint8_t mac[6] = {0};
|
||||
WiFi.macAddress(mac);
|
||||
// Read base MAC without needing WiFi to be started.
|
||||
esp_read_mac(mac, ESP_MAC_WIFI_STA);
|
||||
short_id = (static_cast<uint16_t>(mac[4]) << 8) | mac[5];
|
||||
snprintf(device_id, device_id_len, "dd3-%04X", short_id);
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ static SenderStatus g_sender_statuses[NUM_SENDERS];
|
||||
static bool g_ap_mode = false;
|
||||
static WifiMqttConfig g_cfg;
|
||||
static uint32_t g_last_timesync_ms = 0;
|
||||
static constexpr uint32_t TIME_SYNC_OFFSET_MS = 15000;
|
||||
|
||||
static void init_sender_statuses() {
|
||||
for (uint8_t i = 0; i < NUM_SENDERS; ++i) {
|
||||
@@ -124,6 +125,9 @@ static void sender_cycle() {
|
||||
}
|
||||
|
||||
static void receiver_loop() {
|
||||
if (g_last_timesync_ms == 0) {
|
||||
g_last_timesync_ms = millis() - (TIME_SYNC_INTERVAL_SEC * 1000UL - TIME_SYNC_OFFSET_MS);
|
||||
}
|
||||
LoraPacket pkt = {};
|
||||
if (lora_receive(pkt, 0) && pkt.protocol_version == PROTOCOL_VERSION && pkt.payload_type == PayloadType::MeterData) {
|
||||
uint8_t decompressed[256];
|
||||
|
||||
@@ -16,6 +16,7 @@ static uint32_t g_last_test_ms = 0;
|
||||
static uint16_t g_test_code_counter = 1000;
|
||||
static uint32_t g_last_timesync_ms = 0;
|
||||
static constexpr uint32_t TEST_SEND_INTERVAL_MS = 30000;
|
||||
static constexpr uint32_t TEST_TIMESYNC_OFFSET_MS = 15000;
|
||||
|
||||
void test_sender_loop(uint16_t short_id, const char *device_id) {
|
||||
LoraPacket rx = {};
|
||||
@@ -76,6 +77,9 @@ void test_sender_loop(uint16_t short_id, const char *device_id) {
|
||||
}
|
||||
|
||||
void test_receiver_loop(SenderStatus *statuses, uint8_t count, uint16_t self_short_id) {
|
||||
if (g_last_timesync_ms == 0) {
|
||||
g_last_timesync_ms = millis() - (TIME_SYNC_INTERVAL_SEC * 1000UL - TEST_TIMESYNC_OFFSET_MS);
|
||||
}
|
||||
if (millis() - g_last_timesync_ms > TIME_SYNC_INTERVAL_SEC * 1000UL) {
|
||||
g_last_timesync_ms = millis();
|
||||
time_send_timesync(self_short_id);
|
||||
|
||||
Reference in New Issue
Block a user