Add 868MHz envs, fix MAC id, offset timesync
This commit is contained in:
@@ -224,6 +224,8 @@ inline constexpr uint16_t EXPECTED_SENDER_IDS[NUM_SENDERS] = { 0xF19C };
|
|||||||
## Build Environments
|
## Build Environments
|
||||||
- `lilygo-t3-v1-6-1`: production build
|
- `lilygo-t3-v1-6-1`: production build
|
||||||
- `lilygo-t3-v1-6-1-test`: test build with `ENABLE_TEST_MODE`
|
- `lilygo-t3-v1-6-1-test`: test build with `ENABLE_TEST_MODE`
|
||||||
|
- `lilygo-t3-v1-6-1-868`: production build for 868 MHz modules
|
||||||
|
- `lilygo-t3-v1-6-1-868-test`: test build for 868 MHz modules
|
||||||
|
|
||||||
## Limits & Known Constraints
|
## Limits & Known Constraints
|
||||||
- **Compression**: uses lightweight RLE (good for JSON but not optimal).
|
- **Compression**: uses lightweight RLE (good for JSON but not optimal).
|
||||||
|
|||||||
@@ -38,7 +38,10 @@ constexpr uint8_t PIN_OLED_CTRL = 14;
|
|||||||
constexpr uint8_t PIN_METER_RX = 34;
|
constexpr uint8_t PIN_METER_RX = 34;
|
||||||
|
|
||||||
// LoRa settings
|
// LoRa settings
|
||||||
constexpr long LORA_FREQUENCY = 433E6;
|
#ifndef LORA_FREQUENCY_HZ
|
||||||
|
#define LORA_FREQUENCY_HZ 433E6
|
||||||
|
#endif
|
||||||
|
constexpr long LORA_FREQUENCY = LORA_FREQUENCY_HZ;
|
||||||
constexpr uint8_t LORA_SPREADING_FACTOR = 12;
|
constexpr uint8_t LORA_SPREADING_FACTOR = 12;
|
||||||
constexpr long LORA_BANDWIDTH = 125E3;
|
constexpr long LORA_BANDWIDTH = 125E3;
|
||||||
constexpr uint8_t LORA_CODING_RATE = 5;
|
constexpr uint8_t LORA_CODING_RATE = 5;
|
||||||
@@ -52,7 +55,8 @@ constexpr uint32_t OLED_AUTO_OFF_MS = 10UL * 60UL * 1000UL;
|
|||||||
|
|
||||||
constexpr uint8_t NUM_SENDERS = 1;
|
constexpr uint8_t NUM_SENDERS = 1;
|
||||||
inline constexpr uint16_t EXPECTED_SENDER_IDS[NUM_SENDERS] = {
|
inline constexpr uint16_t EXPECTED_SENDER_IDS[NUM_SENDERS] = {
|
||||||
0xF19C
|
//0xF19C //433mhz sender
|
||||||
|
0x7EB4 //868mhz sender
|
||||||
};
|
};
|
||||||
|
|
||||||
DeviceRole detect_role();
|
DeviceRole detect_role();
|
||||||
|
|||||||
@@ -31,3 +31,30 @@ lib_deps =
|
|||||||
knolleary/PubSubClient@^2.8
|
knolleary/PubSubClient@^2.8
|
||||||
build_flags =
|
build_flags =
|
||||||
-DENABLE_TEST_MODE
|
-DENABLE_TEST_MODE
|
||||||
|
|
||||||
|
[env:lilygo-t3-v1-6-1-868]
|
||||||
|
platform = espressif32
|
||||||
|
board = ttgo-lora32-v1
|
||||||
|
framework = arduino
|
||||||
|
lib_deps =
|
||||||
|
sandeepmistry/LoRa@^0.8.0
|
||||||
|
bblanchon/ArduinoJson@^6.21.5
|
||||||
|
adafruit/Adafruit SSD1306@^2.5.9
|
||||||
|
adafruit/Adafruit GFX Library@^1.11.9
|
||||||
|
knolleary/PubSubClient@^2.8
|
||||||
|
build_flags =
|
||||||
|
-DLORA_FREQUENCY_HZ=868E6
|
||||||
|
|
||||||
|
[env:lilygo-t3-v1-6-1-868-test]
|
||||||
|
platform = espressif32
|
||||||
|
board = ttgo-lora32-v1
|
||||||
|
framework = arduino
|
||||||
|
lib_deps =
|
||||||
|
sandeepmistry/LoRa@^0.8.0
|
||||||
|
bblanchon/ArduinoJson@^6.21.5
|
||||||
|
adafruit/Adafruit SSD1306@^2.5.9
|
||||||
|
adafruit/Adafruit GFX Library@^1.11.9
|
||||||
|
knolleary/PubSubClient@^2.8
|
||||||
|
build_flags =
|
||||||
|
-DENABLE_TEST_MODE
|
||||||
|
-DLORA_FREQUENCY_HZ=868E6
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
#include "data_model.h"
|
#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) {
|
void init_device_ids(uint16_t &short_id, char *device_id, size_t device_id_len) {
|
||||||
uint8_t mac[6] = {0};
|
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];
|
short_id = (static_cast<uint16_t>(mac[4]) << 8) | mac[5];
|
||||||
snprintf(device_id, device_id_len, "dd3-%04X", short_id);
|
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 bool g_ap_mode = false;
|
||||||
static WifiMqttConfig g_cfg;
|
static WifiMqttConfig g_cfg;
|
||||||
static uint32_t g_last_timesync_ms = 0;
|
static uint32_t g_last_timesync_ms = 0;
|
||||||
|
static constexpr uint32_t TIME_SYNC_OFFSET_MS = 15000;
|
||||||
|
|
||||||
static void init_sender_statuses() {
|
static void init_sender_statuses() {
|
||||||
for (uint8_t i = 0; i < NUM_SENDERS; ++i) {
|
for (uint8_t i = 0; i < NUM_SENDERS; ++i) {
|
||||||
@@ -124,6 +125,9 @@ static void sender_cycle() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void receiver_loop() {
|
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 = {};
|
LoraPacket pkt = {};
|
||||||
if (lora_receive(pkt, 0) && pkt.protocol_version == PROTOCOL_VERSION && pkt.payload_type == PayloadType::MeterData) {
|
if (lora_receive(pkt, 0) && pkt.protocol_version == PROTOCOL_VERSION && pkt.payload_type == PayloadType::MeterData) {
|
||||||
uint8_t decompressed[256];
|
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 uint16_t g_test_code_counter = 1000;
|
||||||
static uint32_t g_last_timesync_ms = 0;
|
static uint32_t g_last_timesync_ms = 0;
|
||||||
static constexpr uint32_t TEST_SEND_INTERVAL_MS = 30000;
|
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) {
|
void test_sender_loop(uint16_t short_id, const char *device_id) {
|
||||||
LoraPacket rx = {};
|
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) {
|
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) {
|
if (millis() - g_last_timesync_ms > TIME_SYNC_INTERVAL_SEC * 1000UL) {
|
||||||
g_last_timesync_ms = millis();
|
g_last_timesync_ms = millis();
|
||||||
time_send_timesync(self_short_id);
|
time_send_timesync(self_short_id);
|
||||||
|
|||||||
Reference in New Issue
Block a user