Skip to content

Commit 0db11a0

Browse files
Time synchronization is now possible via the LoRaWAN network
1 parent 328fb8a commit 0db11a0

File tree

5 files changed

+44
-12
lines changed

5 files changed

+44
-12
lines changed

code/components/jomjol_helper/Helper.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,6 @@ float temperatureRead()
697697
return -1.0;
698698
}
699699
#endif
700-
}
701700

702701
time_t addDays(time_t startTime, int days)
703702
{

code/components/jomjol_lorawan/interface_lorawan.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,17 @@ void task_lorawan_communication(void *pvParameter) {
173173
// (state 0 = no downlink, state 1/2 = downlink in window Rx1/Rx2)
174174
if(state > 0) {
175175
if (downlinkSize > 0){
176+
uint32_t networkTime = 0;
177+
uint8_t fracSecond = 0;
178+
if(node->getMacDeviceTimeAns(&networkTime, &fracSecond, true) == RADIOLIB_ERR_NONE) {
179+
ESP_LOGE(LORAWAN_LOG_TAG, "DeviceTime Unix:\t%lu", networkTime);
180+
ESP_LOGE(LORAWAN_LOG_TAG, "DeviceTime second:\t1/%u", fracSecond);
181+
struct timeval now;
182+
now.tv_sec = networkTime;
183+
now.tv_usec = static_cast<long>(fracSecond / 256 * 1000000);
184+
settimeofday(&now, NULL);
185+
}
186+
176187
//check if it is a wifi toggle command
177188
if (downlinkDetails.fPort == 1 ) {
178189
if (downlinkPayload[0] == 1){
@@ -233,14 +244,6 @@ void task_lorawan_communication(void *pvParameter) {
233244
ESP_LOGE(LORAWAN_LOG_TAG, "LinkCheck margin:\t%u",margin);
234245
ESP_LOGE(LORAWAN_LOG_TAG, "LinkCheck count:\t%u", gwCnt);
235246
}
236-
237-
uint32_t networkTime = 0;
238-
uint8_t fracSecond = 0;
239-
if(node->getMacDeviceTimeAns(&networkTime, &fracSecond, true) == RADIOLIB_ERR_NONE) {
240-
ESP_LOGE(LORAWAN_LOG_TAG, "DeviceTime Unix:\t%lu", networkTime);
241-
ESP_LOGE(LORAWAN_LOG_TAG, "DeviceTime second:\t1/%u", fracSecond);
242-
}
243-
244247
} else {
245248
ESP_LOGE(LORAWAN_LOG_TAG, "No downlink received");
246249
}

code/components/jomjol_time_sntp/time_sntp.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,9 +278,9 @@ bool setupTime() {
278278
esp_sntp_config_t config = ESP_NETIF_SNTP_DEFAULT_CONFIG(timeServer.c_str());
279279
config.sync_cb = time_sync_notification_cb;
280280
esp_netif_sntp_init(&config);
281-
282-
setTimeZone(timeZone);
283281
}
282+
283+
setTimeZone(timeZone);
284284

285285
/* The RTC keeps the time after a restart (Except on Power On or Pin Reset)
286286
* There should only be a minor correction through NTP */

code/dependencies.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ dependencies:
1010
source:
1111
type: idf
1212
version: 5.4.0
13-
manifest_hash: d0e5c11de62d42d31acd29b96ce1e6a6a70ddaa81415b7ad25e0ff9cc51abe3f
13+
manifest_hash: 9fbc82b4d26d714ae67e8ed2103405e03969eda639b2c1fd08db12c0195f223d
1414
target: esp32s3
1515
version: 1.0.0

code/sdkconfig.esp32-s3-wroom-1

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2174,6 +2174,36 @@ CONFIG_WIFI_PROV_STA_ALL_CHANNEL_SCAN=y
21742174
# CONFIG_WIFI_PROV_STA_FAST_SCAN is not set
21752175
# end of Wi-Fi Provisioning Manager
21762176

2177+
#
2178+
# mDNS
2179+
#
2180+
CONFIG_MDNS_MAX_INTERFACES=3
2181+
CONFIG_MDNS_MAX_SERVICES=10
2182+
CONFIG_MDNS_TASK_PRIORITY=1
2183+
CONFIG_MDNS_ACTION_QUEUE_LEN=16
2184+
CONFIG_MDNS_TASK_STACK_SIZE=4096
2185+
# CONFIG_MDNS_TASK_AFFINITY_NO_AFFINITY is not set
2186+
CONFIG_MDNS_TASK_AFFINITY_CPU0=y
2187+
# CONFIG_MDNS_TASK_AFFINITY_CPU1 is not set
2188+
CONFIG_MDNS_TASK_AFFINITY=0x0
2189+
CONFIG_MDNS_SERVICE_ADD_TIMEOUT_MS=2000
2190+
CONFIG_MDNS_TIMER_PERIOD_MS=100
2191+
# CONFIG_MDNS_NETWORKING_SOCKET is not set
2192+
# CONFIG_MDNS_SKIP_SUPPRESSING_OWN_QUERIES is not set
2193+
# CONFIG_MDNS_ENABLE_DEBUG_PRINTS is not set
2194+
CONFIG_MDNS_ENABLE_CONSOLE_CLI=y
2195+
# CONFIG_MDNS_RESPOND_REVERSE_QUERIES is not set
2196+
CONFIG_MDNS_MULTIPLE_INSTANCE=y
2197+
2198+
#
2199+
# MDNS Predefined interfaces
2200+
#
2201+
CONFIG_MDNS_PREDEF_NETIF_STA=y
2202+
CONFIG_MDNS_PREDEF_NETIF_AP=y
2203+
CONFIG_MDNS_PREDEF_NETIF_ETH=y
2204+
# end of MDNS Predefined interfaces
2205+
# end of mDNS
2206+
21772207
#
21782208
# Camera configuration
21792209
#

0 commit comments

Comments
 (0)