Skip to content
Snippets Groups Projects
Commit 893af224 authored by Moritz Perschke's avatar Moritz Perschke
Browse files

added time sync code to lilygo host

parent 6ecb78b6
No related branches found
No related tags found
4 merge requests!39Merge Develop into Main,!19development into master,!17Inital Host, initial Client,!14Merge gsm host into development
This diff is collapsed.
{
// See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": [
"platformio.platformio-ide"
],
"unwantedRecommendations": [
"ms-vscode.cpptools-extension-pack"
]
}
// AUTOMATICALLY GENERATED FILE. PLEASE DO NOT MODIFY IT MANUALLY
//
// PIO Unified Debugger
//
// Documentation: https://docs.platformio.org/page/plus/debugging.html
// Configuration: https://docs.platformio.org/page/projectconf/section_env_debug.html
{
"version": "0.2.0",
"configurations": [
{
"type": "platformio-debug",
"request": "launch",
"name": "PIO Debug",
"executable": "/home/moritz/Documents/TEAM/sensor-system/host/esp-t-sim7000g/.pio/build/esp-wrover-kit/firmware.elf",
"projectEnvName": "esp-wrover-kit",
"toolchainBinDir": "/home/moritz/.platformio/packages/toolchain-xtensa-esp32/bin",
"internalConsoleOptions": "openOnSessionStart",
"preLaunchTask": {
"type": "PlatformIO",
"task": "Pre-Debug"
}
},
{
"type": "platformio-debug",
"request": "launch",
"name": "PIO Debug (skip Pre-Debug)",
"executable": "/home/moritz/Documents/TEAM/sensor-system/host/esp-t-sim7000g/.pio/build/esp-wrover-kit/firmware.elf",
"projectEnvName": "esp-wrover-kit",
"toolchainBinDir": "/home/moritz/.platformio/packages/toolchain-xtensa-esp32/bin",
"internalConsoleOptions": "openOnSessionStart"
},
{
"type": "platformio-debug",
"request": "launch",
"name": "PIO Debug (without uploading)",
"executable": "/home/moritz/Documents/TEAM/sensor-system/host/esp-t-sim7000g/.pio/build/esp-wrover-kit/firmware.elf",
"projectEnvName": "esp-wrover-kit",
"toolchainBinDir": "/home/moritz/.platformio/packages/toolchain-xtensa-esp32/bin",
"internalConsoleOptions": "openOnSessionStart",
"loadMode": "manual"
}
]
}
{
"cmake.configureOnOpen": false
}
\ No newline at end of file
...@@ -13,8 +13,8 @@ platform = espressif32 ...@@ -13,8 +13,8 @@ platform = espressif32
board = esp-wrover-kit board = esp-wrover-kit
framework = arduino framework = arduino
monitor_speed = 115200 monitor_speed = 115200
monitor_port = /dev/ttyACM0 ; monitor_port = /dev/ttyACM0
upload_port = /dev/ttyACM0 ; upload_port = /dev/ttyACM0
build_flags = build_flags =
-I include -I include
-DCORE_DEBUG_LEVEL=5 -DCORE_DEBUG_LEVEL=5
......
...@@ -61,6 +61,18 @@ TinyGsm modem(SerialAT); ...@@ -61,6 +61,18 @@ TinyGsm modem(SerialAT);
#define SD_CS 13 #define SD_CS 13
#define LED_PIN 12 #define LED_PIN 12
enum MessageType{
dataAck,
hostChange
};
typedef struct response{
MessageType type;
uint8_t mac[6];
long time;
}response;
uint8_t BROADCAST_MAC[6] = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
ESP32Time rtc; ESP32Time rtc;
SemaphoreHandle_t xMutex; SemaphoreHandle_t xMutex;
...@@ -123,6 +135,18 @@ void on_data_recv(const uint8_t *mac, const uint8_t *incomingData, int len) ...@@ -123,6 +135,18 @@ void on_data_recv(const uint8_t *mac, const uint8_t *incomingData, int len)
memcpy(data, incomingData, len); memcpy(data, incomingData, len);
esp_log_write(ESP_LOG_DEBUG, TAG_ESPNOW.c_str(), "Raw received Data: %s\n", data); esp_log_write(ESP_LOG_DEBUG, TAG_ESPNOW.c_str(), "Raw received Data: %s\n", data);
if(!esp_now_is_peer_exist(mac)){
esp_now_peer_info_t client = {};
memcpy(client.peer_addr, mac, 6);
client.encrypt = false;
client.channel = 0;
esp_err_t status = esp_now_add_peer(&client);
if(status != ESP_OK){
esp_log_write(ESP_LOG_DEBUG, TAG_ESPNOW.c_str(), "Failed to add new Peer: %d", status);
}
}
DynamicJsonDocument doc = parseReceivedJsonData(data); DynamicJsonDocument doc = parseReceivedJsonData(data);
String macAddress = getMacAddressAsString(mac); String macAddress = getMacAddressAsString(mac);
...@@ -144,6 +168,14 @@ void on_data_recv(const uint8_t *mac, const uint8_t *incomingData, int len) ...@@ -144,6 +168,14 @@ void on_data_recv(const uint8_t *mac, const uint8_t *incomingData, int len)
xSemaphoreTake(xMutex, portMAX_DELAY); xSemaphoreTake(xMutex, portMAX_DELAY);
queue.push(lineData); queue.push(lineData);
xSemaphoreGive(xMutex); xSemaphoreGive(xMutex);
response response;
response.type = dataAck;
esp_read_mac(response.mac, ESP_MAC_WIFI_STA);
response.time = rtc.getEpoch();
esp_err_t success = esp_now_send(mac, (uint8_t*) &response, sizeof(response));
esp_log_write(ESP_LOG_DEBUG, TAG_ESPNOW.c_str(),
(success == ESP_OK) ? "Response sent." : "Failed to respond");
} }
String documentToLineProtocolString(const DynamicJsonDocument &doc) String documentToLineProtocolString(const DynamicJsonDocument &doc)
...@@ -283,6 +315,12 @@ void setup() ...@@ -283,6 +315,12 @@ void setup()
} }
syncUTCTimeToRTC(); syncUTCTimeToRTC();
response announce = {};
announce.type = hostChange;
esp_read_mac(announce.mac, ESP_MAC_WIFI_STA);
announce.time = rtc.getEpoch();
esp_now_send(BROADCAST_MAC, (uint8_t *) &announce, sizeof(announce));
} }
void syncUTCTimeToRTC() void syncUTCTimeToRTC()
{ {
......
This diff is collapsed.
{
// See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": [
"platformio.platformio-ide"
],
"unwantedRecommendations": [
"ms-vscode.cpptools-extension-pack"
]
}
// AUTOMATICALLY GENERATED FILE. PLEASE DO NOT MODIFY IT MANUALLY
//
// PIO Unified Debugger
//
// Documentation: https://docs.platformio.org/page/plus/debugging.html
// Configuration: https://docs.platformio.org/page/projectconf/section_env_debug.html
{
"version": "0.2.0",
"configurations": [
{
"type": "platformio-debug",
"request": "launch",
"name": "PIO Debug",
"executable": "/home/moritz/Documents/TEAM/sensor-system/host/esp32-espnow-recv/.pio/build/esp32-c3-devkitm-1/firmware.elf",
"projectEnvName": "esp32-c3-devkitm-1",
"toolchainBinDir": "/home/moritz/.platformio/packages/toolchain-riscv32-esp/bin",
"internalConsoleOptions": "openOnSessionStart",
"preLaunchTask": {
"type": "PlatformIO",
"task": "Pre-Debug"
}
},
{
"type": "platformio-debug",
"request": "launch",
"name": "PIO Debug (skip Pre-Debug)",
"executable": "/home/moritz/Documents/TEAM/sensor-system/host/esp32-espnow-recv/.pio/build/esp32-c3-devkitm-1/firmware.elf",
"projectEnvName": "esp32-c3-devkitm-1",
"toolchainBinDir": "/home/moritz/.platformio/packages/toolchain-riscv32-esp/bin",
"internalConsoleOptions": "openOnSessionStart"
},
{
"type": "platformio-debug",
"request": "launch",
"name": "PIO Debug (without uploading)",
"executable": "/home/moritz/Documents/TEAM/sensor-system/host/esp32-espnow-recv/.pio/build/esp32-c3-devkitm-1/firmware.elf",
"projectEnvName": "esp32-c3-devkitm-1",
"toolchainBinDir": "/home/moritz/.platformio/packages/toolchain-riscv32-esp/bin",
"internalConsoleOptions": "openOnSessionStart",
"loadMode": "manual"
}
]
}
{
"cmake.configureOnOpen": false
}
\ No newline at end of file
  • Developer

    Still needs to be tested, I was not able to connect the lilygo device to my machine.

0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment