i have coding errors in the following code, can you help? : #include <espnow.h> #include…
- User
i have coding errors in the following code, can you help? : #include <esp_now.h> #include <WiFi.h> //#include <Adafruit_GFX.h> //#include <Adafruit_SSD1306.h> #include <Wire.h>
#define SCREEN_WIDTH 128 #define SCREEN_HEIGHT 64 #define OLED_RESET -1 #define SCREEN_ADDRESS 0x3C
//Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
#define CHANNEL 1 #define MAX_DATA_SIZE 27 #define BUFFER_SIZE (SCREEN_WIDTH * SCREEN_HEIGHT / 8) //uint8_t dataArray[MAX_DATA_SIZE]; //uint8_t dataIndex = 0; uint8_t dataBuffer[BUFFER_SIZE]; unsigned int bufferHead = 0; unsigned int bufferTail = 0; unsigned int currentDataSize = 0; // Current size of data received
void InitESPNow() { WiFi.disconnect(); if (esp_now_init() == ESP_OK) { Serial.println("ESPNow Init Success"); } else { Serial.println("ESPNow Init Failed"); ESP.restart(); } }
void configDeviceAP() { const char SSID[] = "Slave_1"; if (!WiFi.softAP(SSID, "Slave_1_Password", CHANNEL, 0)) { Serial.println("AP Config failed."); ESP.restart(); } else { Serial.print("AP Config Success. Broadcasting with AP: "); Serial.println(SSID); Serial.print("AP CHANNEL "); Serial.println(WiFi.channel()); } }
void setup() { Serial.begin(115200);
/* if (!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) { Serial.println(F("SSD1306 allocation failed")); while (true); // Infinite loop }
display.clearDisplay(); */ WiFi.mode(WIFI_AP); configDeviceAP(); InitESPNow(); esp_now_register_recv_cb(OnDataRecv); }
void OnDataRecv(const uint8_t *mac_addr, const uint8_t *data, int data_len) { char macStr[18]; snprintf(macStr, sizeof(macStr), "%02x:%02x:%02x:%02x:%02x:%02x", mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]); Serial.println(macStr); // Log the MAC address
code// Store the received data in the data array// for (int i = 0; i < data_len; i++) { // dataArray[dataIndex++] = data[i]; // if (dataIndex >= MAX_DATA_SIZE) { // dataIndex = 0; // } bufferHead = (bufferHead + 1) % BUFFER_SIZE; // Wrap around if buffer is full dataBuffer[bufferHead] = *data; if (bufferHead == bufferTail) { bufferTail = (bufferTail + 1) % BUFFER_SIZE; // Remove oldest data when buffer is full }
code// Print the received data to serial for (int i = 0; i < data_len; i++) { Serial.print(*data[i], HEX); Serial.print(" "); } Serial.println();} // Write the received data directly to the OLED Wire.beginTransmission(SCREEN_ADDRESS); for (int i = 0; i < data_len; i++) { Wire.write(data[i]); } Wire.endTransmission(); }
void loop() { // Nothing to do here }
- Assistant