ESP32 SPI/ESP-NOW working; add watch scripts; sender colors RGB

This commit is contained in:
Pi User
2025-10-01 22:56:24 +13:00
parent 1844a2e4c5
commit f9188b694e
87 changed files with 15115 additions and 15204 deletions

View File

@@ -17,7 +17,7 @@ static const char *TAG = "SPI_SLAVE";
#define SPI_SLAVE_HOST SPI2_HOST
#define SPI_SLAVE_MOSI 10
#define SPI_SLAVE_MISO 9
#define SPI_SLAVE_SCLK 20
#define SPI_SLAVE_SCLK 8
#define SPI_SLAVE_CS 7
#define SPI_SLAVE_DMA_CHAN SPI_DMA_CH_AUTO
@@ -75,6 +75,7 @@ static esp_err_t espnow_init(void)
ESP_ERROR_CHECK(esp_wifi_set_storage(WIFI_STORAGE_RAM));
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA));
ESP_ERROR_CHECK(esp_wifi_start());
// Keep defaults (no explicit channel pinning) and no power-save changes
// Initialize ESP-NOW
ESP_ERROR_CHECK(esp_now_init());
@@ -85,6 +86,7 @@ static esp_err_t espnow_init(void)
esp_now_peer_info_t peer;
memset(&peer, 0, sizeof(esp_now_peer_info_t));
memcpy(peer.peer_addr, broadcast_mac, ESP_NOW_ETH_ALEN);
// Use 0 so ESP-NOW uses the current primary channel (default behavior)
peer.channel = 0;
peer.ifidx = WIFI_IF_STA;
peer.encrypt = false;
@@ -180,8 +182,15 @@ void app_main(void)
}
if (received_bytes % 16 != 0) printf("\n");
// Broadcast received data via ESP-NOW
// Log received payload as UTF-8 string (for JSON visibility), then broadcast as-is
if (received_bytes > 0) {
{
uint8_t to_copy = received_bytes > ESPNOW_MAX_PAYLOAD ? ESPNOW_MAX_PAYLOAD : received_bytes;
char json_buf[ESPNOW_MAX_PAYLOAD + 1];
memcpy(json_buf, recvbuf, to_copy);
json_buf[to_copy] = '\0';
ESP_LOGI(TAG, "SPI RX (len=%d): %s", received_bytes, json_buf);
}
broadcast_spi_data(recvbuf, received_bytes);
}