Hey ihr,
ich versuche aktuell ein paar Messwerte zusammen zutragen und weiter zu verarbeiten. Allerdings scheitert es bei mir schon an dem Zusammentragen der Daten.
Ich nutze dafür 4 ESP32 mit DHT11 Sensor, welche auf einen ESP32 senden sollen.
Die Geräte sind alle mit den internen Antennen und die zu überbrückende Distanz sind etwa 7-8 Meter.
Allerdings kriege ich nur Reichweiten von etwa 1Meter hin.
Das reicht natürlich nicht, um die Sensoren in der Wohnung zu verteilen.
Hier mein Code vom Master:
#include <esp_now.h>
#include <WiFi.h>
// Structure example to receive data
// Must match the sender structure
typedef struct struct_message {
int id;
int t;
int h;
}struct_message;
// Create a struct_message called myData
struct_message myData;
// Create a structure to hold the readings from each board
struct_message board1;
struct_message board2;
struct_message board3;
struct_message board4;
// Create an array with all the structures
struct_message boardsStruct[4] = {board1, board2, board3, board4};
// callback function that will be executed when data is received
void OnDataRecv(const uint8_t * mac_addr, const uint8_t *incomingData, int len) {
char macStr[18];
Serial.print("Packet received from: ");
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);
memcpy(&myData, incomingData, sizeof(myData));
Serial.printf("Board ID %u: %u bytes\n", myData.id, len);
// Update the structures with the new incoming data
boardsStruct[myData.id-1].t = myData.t;
boardsStruct[myData.id-1].h = myData.h;
Serial.printf("Temperatur: %d \n", myData.t);
Serial.printf("Luftfeuchtigkeit: %d \n", myData.h,"%");
Serial.println("ping");
}
void setup() {
//Initialize Serial Monitor
Serial.begin(115200);
//Set device as a Wi-Fi Station
WiFi.mode(WIFI_STA);
WiFi.channel(7);
//Init ESP-NOW
if (esp_now_init() != ESP_OK) {
Serial.println("Error initializing ESP-NOW");
return;
}
// Once ESPNow is successfully Init, we will register for recv CB to
// get recv packer info
esp_now_register_recv_cb(OnDataRecv);
}
void loop() {
// Acess the variables for each board
/*int board1X = boardsStruct[0].x;
int board1Y = boardsStruct[0].y;
int board2X = boardsStruct[1].x;
int board2Y = boardsStruct[1].y;
int board3X = boardsStruct[2].x;
int board3Y = boardsStruct[2].y;*/
delay(10000);
}
hier der Code meiner Slaves mit geänderten IDs natürlich.
#include <esp_now.h>
#include <WiFi.h>
// Structure example to receive data
// Must match the sender structure
typedef struct struct_message {
int id;
int t;
int h;
}struct_message;
// Create a struct_message called myData
struct_message myData;
// Create a structure to hold the readings from each board
struct_message board1;
struct_message board2;
struct_message board3;
struct_message board4;
// Create an array with all the structures
struct_message boardsStruct[4] = {board1, board2, board3, board4};
// callback function that will be executed when data is received
void OnDataRecv(const uint8_t * mac_addr, const uint8_t *incomingData, int len) {
char macStr[18];
Serial.print("Packet received from: ");
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);
memcpy(&myData, incomingData, sizeof(myData));
Serial.printf("Board ID %u: %u bytes\n", myData.id, len);
// Update the structures with the new incoming data
boardsStruct[myData.id-1].t = myData.t;
boardsStruct[myData.id-1].h = myData.h;
Serial.printf("Temperatur: %d \n", myData.t);
Serial.printf("Luftfeuchtigkeit: %d \n", myData.h,"%");
Serial.println("ping");
}
void setup() {
//Initialize Serial Monitor
Serial.begin(115200);
//Set device as a Wi-Fi Station
WiFi.mode(WIFI_STA);
WiFi.channel(7);
//Init ESP-NOW
if (esp_now_init() != ESP_OK) {
Serial.println("Error initializing ESP-NOW");
return;
}
// Once ESPNow is successfully Init, we will register for recv CB to
// get recv packer info
esp_now_register_recv_cb(OnDataRecv);
}
void loop() {
// Acess the variables for each board
/*int board1X = boardsStruct[0].x;
int board1Y = boardsStruct[0].y;
int board2X = boardsStruct[1].x;
int board2Y = boardsStruct[1].y;
int board3X = boardsStruct[2].x;
int board3Y = boardsStruct[2].y;*/
delay(10000);
}
Auf meinem Schreibtisch funktioniert alles, aber sobald ich die ESP von einander entferne geht nichts mehr über das ESP NOW.
Ich habe die alle schon extra auf Kanal 7 gelegt und mein WLAN auf die 11, im Umkreis sind keine anderen WLAN-Netze.
Ich habe auch gerade mal auf die ESP einen WLAN AP aufgespielt und mal die Signalstärken gemessen, diese sind sehr gering auf ~50cm.(YourAP1)
Immer her mit euren Ideen, mir fällt nichts mehr ein.


