Compare commits
2 Commits
185587cdb6
...
b4ce1a5055
| Author | SHA1 | Date | |
|---|---|---|---|
| b4ce1a5055 | |||
| d3b6e63cdb |
6
components/partitions.csv
Normal file
6
components/partitions.csv
Normal file
@ -0,0 +1,6 @@
|
||||
nvs, data, nvs, 0x9000, 0x4000
|
||||
otadata, data, ota, 0xd000, 0x2000
|
||||
phy_init, data, phy, 0xf000, 0x1000
|
||||
ota_0, app, ota_0, 0x10000, 1900K
|
||||
ota_1, app, ota_1, , 1900K
|
||||
nvs_data, data, nvs, , 200K
|
||||
|
@ -63,6 +63,7 @@ void add_peer(uint8_t *macAddr) {
|
||||
memcpy(newClient.macAddr, macAddr, ESP_NOW_ETH_ALEN);
|
||||
newClient.isAvailable = true;
|
||||
newClient.lastSuccessfullPing = xTaskGetTickCount();
|
||||
newClient.lastPing = 0;
|
||||
clients[getNextFreeClientId()] = newClient;
|
||||
ESP_LOGI(TAG, "New client added.");
|
||||
}
|
||||
@ -133,13 +134,9 @@ void master_broadcast_ping(void *param) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void master_ping_task(void *param) {
|
||||
while (1) {
|
||||
for (size_t i = 0; i < MAX_CLIENTS; i++) {
|
||||
// ESP_LOGI(TAG, "WANT TO SEND PING TO CLIENT %zu isAvailiable %d", i,
|
||||
// clients[i].isAvailable);
|
||||
if (clients[i].isAvailable) {
|
||||
ESP_LOGI(TAG, "SEND PING TO %zu: %s", i,
|
||||
MACtoString(clients[i].macAddr));
|
||||
@ -150,7 +147,6 @@ void master_ping_task(void *param) {
|
||||
esp_now_send(clients[i].macAddr, (uint8_t *)&message,
|
||||
sizeof(BaseMessage));
|
||||
ESP_LOGI(TAG, "SENDING PING!!!!");
|
||||
vTaskDelay(pdMS_TO_TICKS(5));
|
||||
}
|
||||
}
|
||||
vTaskDelay(pdMS_TO_TICKS(1000));
|
||||
@ -181,6 +177,7 @@ void master_receive_callback(const esp_now_recv_info_t *esp_now_info,
|
||||
memcmp(clients[i].macAddr, esp_now_info->src_addr,
|
||||
ESP_NOW_ETH_ALEN) == 0) {
|
||||
clients[i].lastSuccessfullPing = xTaskGetTickCount();
|
||||
clients[i].lastPing = (diff/1000);
|
||||
ESP_LOGI(TAG, "Updated client %d: %s last ping time to %lu", i,
|
||||
MACtoString(clients[i].macAddr),
|
||||
clients[i].lastSuccessfullPing);
|
||||
@ -321,3 +318,7 @@ void client_monitor_task(void *pvParameters) {
|
||||
vTaskDelay(interval_ticks);
|
||||
}
|
||||
}
|
||||
|
||||
ClientInfo *get_client_info(int entry) {
|
||||
return &clients[entry];
|
||||
}
|
||||
|
||||
@ -68,6 +68,7 @@ typedef struct {
|
||||
int rssi;
|
||||
bool isAvailable;
|
||||
TickType_t lastSuccessfullPing;
|
||||
TickType_t lastPing;
|
||||
} ClientInfo;
|
||||
|
||||
void init_com();
|
||||
@ -88,4 +89,6 @@ void client_receive_callback(const esp_now_recv_info_t *esp_now_info,
|
||||
void client_data_sending_task(void *param);
|
||||
void client_monitor_task(void *pvParameters);
|
||||
|
||||
ClientInfo *get_client_info(int entry);
|
||||
|
||||
#endif
|
||||
|
||||
15
main/main.c
15
main/main.c
@ -11,11 +11,23 @@
|
||||
|
||||
#include "communication_handler.h"
|
||||
#include "main.h"
|
||||
#include "portmacro.h"
|
||||
#include "uart_handler.h"
|
||||
#include <stdbool.h>
|
||||
|
||||
static const char *TAG = "ALOX - MAIN";
|
||||
|
||||
void SendClientInfoTask() {
|
||||
int clientId = 0;
|
||||
while (1) {
|
||||
ClientInfo info = *get_client_info(clientId);
|
||||
send_client_info(clientId, info.isAvailable, info.lastPing);
|
||||
clientId += 1;
|
||||
clientId = clientId%20;
|
||||
vTaskDelay(100 / portTICK_PERIOD_MS);
|
||||
}
|
||||
}
|
||||
|
||||
void app_main(void) {
|
||||
esp_err_t ret = nvs_flash_init();
|
||||
if (ret == ESP_ERR_NVS_NO_FREE_PAGES ||
|
||||
@ -65,7 +77,8 @@ void app_main(void) {
|
||||
NULL);
|
||||
xTaskCreate(client_monitor_task, "MonitorClientTask", 4096, NULL, 1, NULL);
|
||||
init_uart();
|
||||
xTaskCreate(uart_status_task, "MasterUartStatusTask", 4096, NULL, 1, NULL);
|
||||
//xTaskCreate(uart_status_task, "MasterUartStatusTask", 4096, NULL, 1, NULL);
|
||||
xTaskCreate(SendClientInfoTask, "SendCientInfo", 4096, NULL, 1, NULL);
|
||||
} else {
|
||||
ESP_LOGI(TAG, "Started in Slavemode");
|
||||
xTaskCreate(client_data_sending_task, "ClientDataSending", 4096, NULL, 1,
|
||||
|
||||
@ -5,6 +5,8 @@
|
||||
#include "hal/uart_types.h"
|
||||
#include "nvs_flash.h"
|
||||
#include "portmacro.h"
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "uart_handler.h"
|
||||
|
||||
@ -45,3 +47,10 @@ void uart_status_task(void *param) {
|
||||
vTaskDelay(1000 / portTICK_PERIOD_MS);
|
||||
}
|
||||
}
|
||||
|
||||
void send_client_info(int clientid, bool isAvailable, TickType_t lastPing) {
|
||||
char buf[128];
|
||||
snprintf(buf, sizeof(buf), "c%d,status,2,%d,%u\r\n", clientid,
|
||||
isAvailable ? 1 : 0, (unsigned int)lastPing);
|
||||
uart_write_bytes(MASTER_UART, buf, strlen(buf));
|
||||
}
|
||||
|
||||
@ -11,4 +11,6 @@ void init_uart();
|
||||
void uart_read_task(void *param);
|
||||
void uart_status_task(void *param);
|
||||
|
||||
void send_client_info(int clientid, bool isAvailable, TickType_t lastPing);
|
||||
|
||||
#endif
|
||||
|
||||
14
sdkconfig
14
sdkconfig
@ -450,14 +450,14 @@ CONFIG_ESPTOOLPY_FLASHFREQ_80M=y
|
||||
# CONFIG_ESPTOOLPY_FLASHFREQ_20M is not set
|
||||
CONFIG_ESPTOOLPY_FLASHFREQ="80m"
|
||||
# CONFIG_ESPTOOLPY_FLASHSIZE_1MB is not set
|
||||
CONFIG_ESPTOOLPY_FLASHSIZE_2MB=y
|
||||
# CONFIG_ESPTOOLPY_FLASHSIZE_4MB is not set
|
||||
# CONFIG_ESPTOOLPY_FLASHSIZE_2MB is not set
|
||||
CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y
|
||||
# CONFIG_ESPTOOLPY_FLASHSIZE_8MB is not set
|
||||
# CONFIG_ESPTOOLPY_FLASHSIZE_16MB is not set
|
||||
# CONFIG_ESPTOOLPY_FLASHSIZE_32MB is not set
|
||||
# CONFIG_ESPTOOLPY_FLASHSIZE_64MB is not set
|
||||
# CONFIG_ESPTOOLPY_FLASHSIZE_128MB is not set
|
||||
CONFIG_ESPTOOLPY_FLASHSIZE="2MB"
|
||||
CONFIG_ESPTOOLPY_FLASHSIZE="4MB"
|
||||
# CONFIG_ESPTOOLPY_HEADER_FLASHSIZE_UPDATE is not set
|
||||
CONFIG_ESPTOOLPY_BEFORE_RESET=y
|
||||
# CONFIG_ESPTOOLPY_BEFORE_NORESET is not set
|
||||
@ -471,13 +471,13 @@ CONFIG_ESPTOOLPY_MONITOR_BAUD=115200
|
||||
#
|
||||
# Partition Table
|
||||
#
|
||||
CONFIG_PARTITION_TABLE_SINGLE_APP=y
|
||||
# CONFIG_PARTITION_TABLE_SINGLE_APP is not set
|
||||
# CONFIG_PARTITION_TABLE_SINGLE_APP_LARGE is not set
|
||||
# CONFIG_PARTITION_TABLE_TWO_OTA is not set
|
||||
# CONFIG_PARTITION_TABLE_TWO_OTA_LARGE is not set
|
||||
# CONFIG_PARTITION_TABLE_CUSTOM is not set
|
||||
CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions.csv"
|
||||
CONFIG_PARTITION_TABLE_FILENAME="partitions_singleapp.csv"
|
||||
CONFIG_PARTITION_TABLE_CUSTOM=y
|
||||
CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="components/partitions.csv"
|
||||
CONFIG_PARTITION_TABLE_FILENAME="components/partitions.csv"
|
||||
CONFIG_PARTITION_TABLE_OFFSET=0x8000
|
||||
CONFIG_PARTITION_TABLE_MD5=y
|
||||
# end of Partition Table
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user