Hi!
I'm wiriting in english so that more user can understand and answer to my problem. I created some sort of homeautomatisation using an ESP32 (Deneyap S2 mini) running with 80 MHz, using ESP now AND WiFi at the same time!
Compiled some weeks before everything worked. After an update nothing worked again. I found out, that the code for ESP32 is crashing using Boards Library 3.1.0. Switching back to 3.0.7 it is running again.
But there is one problem left: in case turning on WiFi the controller does not receive the ESP now messages from several ESP8266 controllers in my house. Turning off by commenting off WiFi.begin() the ESP32 receives the ESP now messages. So it is clear that something happened during updateing the libraries. Of course I do not know which version of which library was used before the update. Does anyone know something about this problem???
I do not want to install a separate controller for WiFi... it is NOT necessary as I know running my old version...
Best regards and thanks for all hints...
Is it a Boards 3 problem? See documentation at HERE!
I have experienced the same problems with libraries. I now place them in the sketch folder with my program. The default ones like AVR etc I do not copy as they have been stable for a long time.
I expect also that ESPAsyncWebServer versions younger than 3.x could solve the problem. But in the Arduino IDE these are not longer available.
I'm plannig to freeze my software and libraries after I solved my actual problems. But this is not the best solution. Normally software should be compatible to older versions. But for several times I cannot confirm that library updates or boards updates are working... ![]()
Are you confusing Library versions and Board Versions? Post a screen grab of the board you selected, post your source code in code tags and verbose compile errors in code tags so I can try.
Thanks for your offer but I don't believe it is possible to run my complete home automatisation elsewhere. The code for the ESP32 is some 1000 lins of code and furthermore you need at least to further controller to send their data to the main controller (which is the ESP32). But I will try to reduce the code instead and perhaps I manage to post it here after success. Thank you very much...
Okay, I stripped my code lines for the ESP32 from 2400 to less than 400.
Since the latest library update I got another error: mbedtls_md5_xxx functions could not be found.... Then I tried to change the use of libraries like ESP Aysnc Server. Before facing to my problems I used ESPAsyncWebServer by lacamera V3.1.0..... changing to "ESP Async Webserver" by ESP32Async solved this.
(I'm completely confused by the varity of these libraries).
But this changed many things. Regardless whether I'm starting the Access Point Server for providing a HTML page to control my ESP32 or not - the data by ESP now data is received. At the moment the HTML Page is not working, perhaps it was stripped to much. I will work on this topic at the weekend and report what I found out.
In the original code I do not have this behaviour. Starting Wifi for my HTML page will suppress ESP now messages to receive. ... at the moment
Okay... I stripped my code further more....
My libraries are now changed to "ESP Async WebServer" by ESP32Async und "ESP Async TCP" by ESP32Async. Latest version for both.
Confusing for me is that sending by ESP now is working now but calling
HTML Page 192.168.4.1/temp does not show anything. Before I was faced to the actual problems it was completely vice versa.... HTML Page could be seen, ESP now data were not received.
The code for my ESP32 (Deneyap Mini S2) is:
#include <esp_now.h>
#include <esp_wifi.h> // zum esp_wifi_set_channel
#include <WiFi.h> // for ESP32
#include <ESPAsyncWebServer.h> // for ESP32
const char* ssid = "ESP33_EssZi";
const char* password = "EssZi_ESP33";
// Achtung! mit 0x95 vorne gab es Ärger, deswegen wird zum Test Byte 2 geändert! _ret_, 15.12.2024
uint8_t newMACAddress[] = { 0x94, 0x3D, 0xC6, 0x33, 0x68, 0x00 };
//uint8_t newMACAddress[] = {0x94, 0x3C, 0xC6, 0x33, 0x68, 0x00};
IPAddress LOCAL_IP(192,168,4,1);
IPAddress GATEWAY(192,168,4,1);
IPAddress SUBNET(255,255,255,0);
#define FERNSTROMZAEHLER_ID 14
#define PUMPE_AN HIGH
#define PUMPE_AUS LOW
void Init_WLAN_and_ESP_now( void ); // Initialisierung von WLAN/WiFi und ESP now
// für das Merken des Stromzählerstands: (wird als INT gespeichert und damit Faktor 10000 zu hoch)
int StromZaehlerStand[ 7 ];
esp_now_peer_info_t peerInfo;
#define PUMPEN_PIN_OUT 14
AsyncWebServer server(80);
String SendHTML( void ); // die Hauptseite des Controllers
String urltext = ""; // das ist der Text der URL, die wird verarbeitet, _ret_, 30.8.2021
typedef struct struct_message {
int id;
int temp;
int hum;
int press;
char add_Text[150];
} struct_message;
struct_message incomingReadings;
struct_message sendingData;
int esp_init; // Variable zum Erkennen ob ESPnow init klappte
// callback function that will be executed when data is received
void OnDataRecv(const uint8_t * mac_addr, const uint8_t *incomingData, int len)
{
// Copies the sender mac address to a string
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(&incomingReadings, incomingData, sizeof(incomingReadings));
Serial.printf("Board ID %u: %u bytes\n", incomingReadings.id, len);
Serial.printf("t value: %d \n", incomingReadings.temp);
Serial.printf("h value: %d \n", incomingReadings.hum);
Serial.printf("h value: %d \n", incomingReadings.press);
Serial.printf("add_Text value: %s \n", incomingReadings.add_Text);
Serial.println();
esp_init = 2;
} // void OnDataRecv(const uint8_t * mac_addr, const uint8_t *incomingData, int len)
// callback when data is sent
void OnDataSent(const uint8_t *mac_addr, esp_now_send_status_t status)
{
#ifdef DEBUG
Serial.print("\r\nLast Packet Send Status:\t");
Serial.println(status == ESP_NOW_SEND_SUCCESS ? "Delivery Success" : "Delivery Fail");
#endif // DEBUG
} // void OnDataSent(const uint8_t *mac_addr, esp_now_send_status_t status)
void handle_Temp_Page( AsyncWebServerRequest *request )
{
urltext = "";
for (int i = 0; i < request->args(); i++ )
{
urltext += request->argName(i) + "="; //Get the name of the parameter
urltext += request->arg(i) + "\n"; //Get the value of the parameter
}
} // void handle_Temp_Page( AsyncWebServerRequest *request )
void setup()
{
Serial.begin(115200);
Init_WLAN_and_ESP_now();
server.on( "/temp", HTTP_GET, [](AsyncWebServerRequest *request )
{
request->send( 200, "text/html", SendHTML() );
});
}
void loop()
{
}
String SendHTML( void )
{
String ptr = "<!DOCTYPE html> <html> <body>\n";
ptr += "<h1>My First Heading</h1>";
ptr += "<p>My first paragraph.</p>";
ptr +="</body>\n";
ptr +="</html>\n";
return ptr;
} // String SendHTML( void )
void Init_WLAN_and_ESP_now( void )
{
Serial.println( "einrichten WLAN" );
WiFi.mode( WIFI_AP_STA ); // Access Point
while( ! WiFi.STA.started() )
delay( 100 );
esp_err_t err = esp_wifi_set_mac(WIFI_IF_STA, &newMACAddress[0]);
if (err == ESP_OK)
Serial.println("Success changing Mac Address");
else
Serial.println("ERROR changing Mac Address!!!!!!!!!!!!!!!!!!!!");
// channel fixieren klappt nicht! Doch, seit Februar 2025
esp_wifi_set_promiscuous( true );
esp_wifi_set_channel( 1, WIFI_SECOND_CHAN_NONE );
esp_wifi_set_promiscuous( false );
WiFi.setSleep(false); // das soll die Empfangslage deutlich verbessern! bringt vermutlich nix wenn selbst AP
esp_init = 0;
if (esp_now_init() == ESP_OK)
{
Serial.println("ESPNow Init success");
esp_init = 1;
}
else
Serial.println("ESPNow Init fail");
WiFi.softAP( ssid, password );
IPAddress myIP = WiFi.softAPIP();
Serial.println( myIP );
// Once ESPNow is successfully Init, we will register for recv CB to
// get recv packer info
if( esp_init == 1 )
{
esp_now_register_recv_cb( esp_now_recv_cb_t( OnDataRecv ) );
esp_now_register_send_cb( OnDataSent );
}
// Set device as a Wi-Fi/WLAN Station
WiFi.begin(ssid, password);
delay(500);
} // void Init_WLAN_and_ESP_now( void )
//////////////////////////////////////////////////////////////////////
Here is a dummy code for my nodeMCU 0.9 (ESP8266) to send DATA by ESP now:
#include <ESP8266WiFi.h>
#include <espnow.h>
// fixe MacAddress
//uint8_t NewMACAddr[] = { 0x94, 0x3C, 0xC6, 0x33, 0x68, 0x0E };
// REPLACE WITH RECEIVER MAC Address
// for real ESP32 EssZimmerSchaltung use:
//uint8_t broadcastAddress[] = {0x94, 0x3C, 0xC6, 0x33, 0x68, 0x00}; // EssZi Schaltung
// for dummy ESP 32 use:
uint8_t broadcastAddress[] = { 0x94, 0x3D, 0xC6, 0x33, 0x68, 0x00 };
// GPIO16 = D0 gebraucht für Reset WakeUp
#define POWER_PIN D3 // GPIO00 = D3
#define FERNSTROMZAEHLER_ID 14
typedef struct struct_message
{
int id; // ID=0xE=14 für StromZaehler_ID
int temp;
int hum;
int press;
char add_text[150];
} struct_message;
// Create a struct_message called myData
struct_message myData;
uint8_t channel = 1;
int StromZaehlerStand;
int StromVerbrauch;
void hibernate( void );
void tryNextChannel( void )
{
Serial.printf( "wifi channel=" );
Serial.println( WiFi.channel() );
Serial.println("Changing channel from " + String(channel) + " to " + String(channel+1));
channel = channel % 13 + 1;
wifi_promiscuous_enable(true);
wifi_set_channel(channel);
wifi_promiscuous_enable(false);
} // void tryNextChannel( void )
boolean channelFound;
int success;
// Callback when data is sent
void OnDataSent( uint8_t *mac_addr, uint8_t sendStatus )
{
Serial.printf( "sendStatus=");
Serial.println( sendStatus );
if( sendStatus == 0 )
{
Serial.println( "Sending successfull" );
success = 1;
}
else
{
Serial.println( "Delivery Fail" );
// tryNextChannel(); // If message was not delivered, it tries on another wifi channel.
success = 0;
}
} // void OnDataSent( uint8_t *mac_addr, uint8_t sendStatus )
void setup()
{
// Achtung!!! Fixe 9600 Baud weil der Stromzaehler auch nur mit 9600 Baud sendet!!!
Serial.begin( 9600 );
delay( 100 );
pinMode( POWER_PIN, OUTPUT );
delay( 100 );
digitalWrite( POWER_PIN, HIGH );
delay( 100 );
WiFi.mode( WIFI_STA );
delay( 500 );
if (esp_now_init() != 0)
{
Serial.println( "ESPNow Init fail" );
hibernate();
}
wifi_promiscuous_enable(true);
wifi_set_channel(1);
wifi_promiscuous_enable(false);
esp_now_set_self_role( ESP_NOW_ROLE_CONTROLLER );
esp_now_register_send_cb( OnDataSent );
uint8_t result = esp_now_add_peer( broadcastAddress, ESP_NOW_ROLE_SLAVE, 1, NULL, 0 );
if( result != 0 )
{
Serial.println("Failed to add peer");
hibernate();
}
// Set values to send
myData.id = FERNSTROMZAEHLER_ID;
myData.temp = (float) 0.0;
myData.hum = (float) 0.0;
myData.press = (float) 0.0;
strcpy( &myData.add_text[0], "62999876_553" );
// Send message via ESP-NOW
success = 0;
int cnt = 0;
while( ( success == 0 ) && ( cnt < 10 ) )
{
success = esp_now_send( broadcastAddress, (uint8_t *) &myData, sizeof( myData ) );
Serial.print( "cnt=" + String(cnt) );
Serial.println( " success=" + String( success) );
delay( 500 );
cnt++;
}
delay(500);
hibernate();
} // setup( void )
void loop( void )
{
// do nothing
} // void loop( void )
void hibernate( void )
{
digitalWrite( POWER_PIN, LOW );
delay( 100 );
unsigned long sleeptime = (unsigned long) 90e7; // einmal alle 15min
ESP.deepSleep( sleeptime );
delay( 500 );
} // void hibernate( void )
// End of Code
Solved!
It is a "server.begin()" missing
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.