Add ESP-NOW master/slave discovery on DIP network channel.
Initialize WiFi and ESP-NOW from shared app config; master broadcasts discover packets and collects slave info, slaves respond on matching network while UART commands stay master-only. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+22
-21
@@ -1,6 +1,8 @@
|
||||
#include "powerpod.h"
|
||||
#include "app_config.h"
|
||||
#include "cmd_handler.h"
|
||||
#include "cmd_version.h"
|
||||
#include "esp_now_comm.h"
|
||||
#include "powerpod.h"
|
||||
#include "driver/gpio.h"
|
||||
#include "driver/i2c_master.h"
|
||||
#include "driver/i2c_types.h"
|
||||
@@ -11,8 +13,6 @@
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/idf_additions.h"
|
||||
#include "led_ring.h"
|
||||
#include "nvs.h"
|
||||
#include "nvs_flash.h"
|
||||
#include "uart.h"
|
||||
#include <stdint.h>
|
||||
|
||||
@@ -38,18 +38,12 @@ enum SLAVE_STATES {
|
||||
SSTATE_OTA_UPDATE,
|
||||
};
|
||||
|
||||
struct app_config_t {
|
||||
uint8_t Master;
|
||||
uint8_t Network;
|
||||
char RunningPartition[17];
|
||||
};
|
||||
|
||||
static const char *TAG = "[Main]";
|
||||
|
||||
static i2c_master_bus_handle_t bus_handle;
|
||||
static i2c_master_dev_handle_t io_expander;
|
||||
|
||||
static struct app_config_t App_Config;
|
||||
static app_config_t app_config;
|
||||
|
||||
static QueueHandle_t cmd_queue;
|
||||
|
||||
@@ -117,22 +111,29 @@ void app_main(void) {
|
||||
|
||||
const esp_partition_t *running = esp_ota_get_running_partition();
|
||||
|
||||
App_Config.Master = (master == true);
|
||||
App_Config.Network = network;
|
||||
memcpy(App_Config.RunningPartition, running->label,
|
||||
sizeof(App_Config.RunningPartition));
|
||||
app_config.master = (master != 0);
|
||||
app_config.network = network;
|
||||
memcpy(app_config.running_partition, running->label,
|
||||
sizeof(app_config.running_partition));
|
||||
|
||||
ESP_LOGI(TAG, "RUNNING CONFIG:");
|
||||
ESP_LOGI(TAG, "Master: %d", App_Config.Master);
|
||||
ESP_LOGI(TAG, "Network: %d", App_Config.Network);
|
||||
ESP_LOGI(TAG, "Running Partition: %s", App_Config.RunningPartition);
|
||||
ESP_LOGI(TAG, "Master: %d", app_config.master);
|
||||
ESP_LOGI(TAG, "Network: %d", app_config.network);
|
||||
ESP_LOGI(TAG, "Running Partition: %s", app_config.running_partition);
|
||||
|
||||
err = esp_now_comm_init(&app_config);
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGE(TAG, "ESP-NOW init failed: %s", esp_err_to_name(err));
|
||||
}
|
||||
|
||||
led_ring_init();
|
||||
|
||||
cmd_queue = xQueueCreate(10, sizeof(generic_msg_t));
|
||||
init_cmdHandler(cmd_queue);
|
||||
init_uart(cmd_queue);
|
||||
cmd_version_register();
|
||||
if (app_config.master) {
|
||||
cmd_queue = xQueueCreate(10, sizeof(generic_msg_t));
|
||||
init_cmdHandler(cmd_queue);
|
||||
init_uart(cmd_queue);
|
||||
cmd_version_register();
|
||||
}
|
||||
|
||||
uint8_t current_digit = 10;
|
||||
while (1) {
|
||||
|
||||
Reference in New Issue
Block a user