Reworked esp32 wroom to esp32c3 zero board
- Fixed minor Bug from Testing with multiple Nodes
This commit is contained in:
parent
b09819e76f
commit
185587cdb6
@ -1,5 +1,6 @@
|
||||
#include "esp_log.h"
|
||||
#include "esp_timer.h"
|
||||
#include "freertos/idf_additions.h"
|
||||
|
||||
#include "communication_handler.h"
|
||||
|
||||
@ -27,12 +28,12 @@ void init_com() {
|
||||
|
||||
// return any inactive client field for new usage
|
||||
int getNextFreeClientId() {
|
||||
for (int i = 0; i < numClients; i++) {
|
||||
for (int i = 0; i < MAX_CLIENTS; i++) {
|
||||
if (!clients[i].isAvailable) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
void add_peer(uint8_t *macAddr) {
|
||||
@ -46,8 +47,10 @@ void add_peer(uint8_t *macAddr) {
|
||||
|
||||
esp_err_t result = esp_now_add_peer(&peerInfo);
|
||||
if (result == ESP_OK) {
|
||||
ESP_LOGI(TAG, "Peer added: %02X:%02X:%02X:%02X:%02X:%02X", macAddr[0],
|
||||
macAddr[1], macAddr[2], macAddr[3], macAddr[4], macAddr[5]);
|
||||
ESP_LOGI(TAG, "Peer added: %02X:%02X:%02X:%02X:%02X:%02X",
|
||||
peerInfo.peer_addr[0], peerInfo.peer_addr[1],
|
||||
peerInfo.peer_addr[2], peerInfo.peer_addr[3],
|
||||
peerInfo.peer_addr[4], peerInfo.peer_addr[5]);
|
||||
|
||||
if (!IS_BROADCAST_ADDR(macAddr)) {
|
||||
|
||||
@ -116,10 +119,30 @@ void master_broadcast_task(void *param) {
|
||||
}
|
||||
}
|
||||
|
||||
void master_broadcast_ping(void *param) {
|
||||
while (1) {
|
||||
// BroadCastPayload payload = {};
|
||||
PingPayload payload = {};
|
||||
payload.timestamp = esp_timer_get_time();
|
||||
BaseMessage message =
|
||||
MessageBuilder(PingPage, *(PayloadUnion *)&payload, sizeof(payload));
|
||||
ESP_ERROR_CHECK(esp_now_send(broadcast_address, (uint8_t *)&message,
|
||||
sizeof(BaseMessage)));
|
||||
ESP_LOGI(TAG, "Broadcast PING Message sent");
|
||||
vTaskDelay(pdMS_TO_TICKS(2500));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void master_ping_task(void *param) {
|
||||
while (1) {
|
||||
for (size_t i = 0; i < MAX_CLIENTS; ++i) {
|
||||
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));
|
||||
PingPayload payload = {};
|
||||
payload.timestamp = esp_timer_get_time();
|
||||
BaseMessage message = MessageBuilder(
|
||||
@ -127,6 +150,7 @@ 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));
|
||||
@ -136,7 +160,6 @@ void master_ping_task(void *param) {
|
||||
void master_receive_callback(const esp_now_recv_info_t *esp_now_info,
|
||||
const uint8_t *data, int data_len) {
|
||||
ESP_LOGI(TAG, "MASTER GOT MESSAGE");
|
||||
ESP_LOGI(TAG, "Message: %.*s", data_len, data);
|
||||
|
||||
const BaseMessage *message = (const BaseMessage *)data;
|
||||
switch (message->commandPage) {
|
||||
@ -158,7 +181,8 @@ 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();
|
||||
ESP_LOGI(TAG, "Updated client %d last ping time to %lu", i,
|
||||
ESP_LOGI(TAG, "Updated client %d: %s last ping time to %lu", i,
|
||||
MACtoString(clients[i].macAddr),
|
||||
clients[i].lastSuccessfullPing);
|
||||
break;
|
||||
}
|
||||
@ -202,9 +226,9 @@ void master_receive_callback(const esp_now_recv_info_t *esp_now_info,
|
||||
default:
|
||||
ESP_LOGI(TAG, "Unknown Message %i", checkPeer);
|
||||
}
|
||||
|
||||
break;
|
||||
default:
|
||||
ESP_LOGI(TAG, "Unknown CommandPage %i", message->commandPage);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -79,6 +79,7 @@ BaseMessage MessageBuilder(CommandPages commandPage, PayloadUnion payload,
|
||||
|
||||
void master_broadcast_task(void *param);
|
||||
void master_ping_task(void *param);
|
||||
void master_broadcast_ping(void *param);
|
||||
void master_receive_callback(const esp_now_recv_info_t *esp_now_info,
|
||||
const uint8_t *data, int data_len);
|
||||
|
||||
|
||||
@ -5,12 +5,14 @@
|
||||
#include "esp_rom_gpio.h"
|
||||
#include "esp_timer.h"
|
||||
#include "esp_wifi.h"
|
||||
#include "freertos/idf_additions.h"
|
||||
#include "hal/uart_types.h"
|
||||
#include "nvs_flash.h"
|
||||
|
||||
#include "communication_handler.h"
|
||||
#include "main.h"
|
||||
#include "uart_handler.h"
|
||||
#include "communication_handler.h"
|
||||
#include <stdbool.h>
|
||||
|
||||
static const char *TAG = "ALOX - MAIN";
|
||||
|
||||
@ -58,9 +60,12 @@ void app_main(void) {
|
||||
ESP_LOGI(TAG, "Started in Mastermode");
|
||||
add_peer(broadcast_address);
|
||||
xTaskCreate(master_broadcast_task, "MasterBroadcast", 4096, NULL, 1, NULL);
|
||||
xTaskCreate(master_ping_task, "MasterPing", 4096, NULL, 1, NULL);
|
||||
// xTaskCreate(master_ping_task, "MasterPing", 4096, NULL, 1, NULL);
|
||||
xTaskCreate(master_broadcast_ping, "MasterBroadcastPing", 4096, NULL, 1,
|
||||
NULL);
|
||||
xTaskCreate(client_monitor_task, "MonitorClientTask", 4096, NULL, 1, NULL);
|
||||
init_uart();
|
||||
xTaskCreate(uart_status_task, "MasterUartStatusTask", 4096, NULL, 1, NULL);
|
||||
} else {
|
||||
ESP_LOGI(TAG, "Started in Slavemode");
|
||||
xTaskCreate(client_data_sending_task, "ClientDataSending", 4096, NULL, 1,
|
||||
|
||||
@ -14,6 +14,6 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#define MASTER_MODE_PIN GPIO_NUM_23 // Jumper-Erkennungspin
|
||||
#define MASTER_MODE_PIN GPIO_NUM_0 // Jumper-Erkennungspin
|
||||
|
||||
#endif
|
||||
|
||||
@ -1,8 +1,10 @@
|
||||
#include "driver/uart.h"
|
||||
#include "driver/gpio.h"
|
||||
#include "driver/uart.h"
|
||||
#include "esp_log.h"
|
||||
#include "freertos/idf_additions.h"
|
||||
#include "hal/uart_types.h"
|
||||
#include "nvs_flash.h"
|
||||
#include "portmacro.h"
|
||||
|
||||
#include "uart_handler.h"
|
||||
|
||||
@ -36,3 +38,10 @@ void uart_read_task(void *param) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void uart_status_task(void *param) {
|
||||
while (1) {
|
||||
uart_write_bytes(MASTER_UART, "c1,status,0\n\r", sizeof("c1,status,0\n\r"));
|
||||
vTaskDelay(1000 / portTICK_PERIOD_MS);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,13 +1,14 @@
|
||||
#ifndef UART_HANDLER_H
|
||||
#define UART_HANDLER_H
|
||||
|
||||
#define MASTER_UART UART_NUM_2
|
||||
#define TXD_PIN (GPIO_NUM_17)
|
||||
#define RXD_PIN (GPIO_NUM_16)
|
||||
#define MASTER_UART UART_NUM_1
|
||||
#define TXD_PIN (GPIO_NUM_1)
|
||||
#define RXD_PIN (GPIO_NUM_2)
|
||||
|
||||
#define BUF_SIZE (1024)
|
||||
|
||||
void init_uart();
|
||||
void uart_read_task(void *param);
|
||||
void uart_status_task(void *param);
|
||||
|
||||
#endif
|
||||
|
||||
@ -1,3 +1,8 @@
|
||||
# Roadmap
|
||||
- [ ] SEND STATUS OF DEVICE OVER UART
|
||||
- [ ] CONFIGURE PEERS OVER MASTER
|
||||
- [ ] SAVE PIN CONFIG ON PEERS
|
||||
|
||||
# Machbarkeits-Studie
|
||||
|
||||
## 1.0 Hardware-Features
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user