-
Notifications
You must be signed in to change notification settings - Fork 7.6k
ESP NOW compilation issue of #11243
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Please provide minimal (full) example that we can try to compile and debug. Maybe also have a look at our own ESP-NOW library that is included in the core |
Hello'
Thank you very much for your reply.
I am attaching my complete code.
1. The file espNowServer.h is a reduced H file. Compiling this sketch shows
that the only error is about this line.
2. Renaming espNowServer.h.txt by removing the .txt will yield the full
code code. (in this case the file espNowCommon.h completes the declarations
with those common to both sides..
2.1 The only error is for line 131 in the file espNowServer.h.txt.
2.2 Commenting line 131 there will yield a no-error compilation.
Basically, I started from the application "
https://randomnerdtutorials.com/esp-now-auto-pairing-esp32-esp8266/", but
rewrothe the pairing mechanism so it is done only once, during the
non-server stations powering. This is because my application maintains a
timely keep-alive data messaging.
There are other parts that are not completed yet, but this issue is
holding my project.
Best regards
On Mon, Apr 14, 2025 at 11:36 AM Me No Dev ***@***.***> wrote:
Please provide minimal (full) example that we can try to compile and
debug. Maybe also have a look at our own ESP-NOW library that is included
in the core
—
Reply to this email directly, view it on GitHub
<#11243 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AXTKTCBZG7N23OBRDKURTPL2ZNXQVAVCNFSM6AAAAAB3A5HRQWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDQMBQHA4DMOBXGI>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
*me-no-dev* left a comment (espressif/arduino-esp32#11243)
<#11243 (comment)>
Please provide minimal (full) example that we can try to compile and
debug. Maybe also have a look at our own ESP-NOW library that is included
in the core
—
Reply to this email directly, view it on GitHub
<#11243 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AXTKTCBZG7N23OBRDKURTPL2ZNXQVAVCNFSM6AAAAAB3A5HRQWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDQMBQHA4DMOBXGI>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
#ifndef espNowServer_h
#define espNowServer_h
#include "espNowCommon.h"
class espNowServerClass {
private:
#define loopbackFlag
#define ackInterval 100
#define ESP_NOW_VERBOSE
int channel = 1;
unsigned int previousMessageNum;
bool acknowledgeReceived;
/*********************************************************************************/
bool addPeer(const uint8_t *incomingData) { // Server side
structPairing peer;
memcpy(&peer, incomingData, sizeof(peer));
if ((peer.peerId > maxClientsCount) || (peer.peerId == 0)) {
#ifdef ESP_NOW_VERBOSE
Serial.print("Corrupted ID: " + String(peer.peerId));
#endif
return LOW;
}
// Send pairing acknowledge
peer.msgType = PAIR_ACK;
peer.channel = channel;
for (uint8_t i = 0; i < macAddrLen; i++)
peer.macAddr[i] = serverAddr[i];
bool sucs = (esp_now_send(peer.macAddr, (uint8_t *)&peer, sizeof(peer)) == ESP_NOW_SEND_SUCCESS);
uint8_t id = peer.peerId;
if (sucs) { // Register the paired slave in the peersList array.
memcpy(&peersList[id].macAddr, peer.macAddr, macAddrLen);
peersList[id].missesCount = 0;
peersList[id].pairingStatus = PAIR_PAIRED;
} else
peersList[id].pairingStatus = NOT_PAIRED;
#ifdef ESP_NOW_VERBOSE
Serial.print("A message of type PAIRING from station ");
Serial.print(id);
Serial.print(" at mac address ");
for (uint8_t i = 0; i < macAddrLen; i++) {
Serial.print(peer.macAddr[i], HEX);
Serial.print(":");
}
Serial.print("; Pairing status: ");
if (sucs)
Serial.println(" success");
else
Serial.println(" failure");
#endif
return sucs;
}
/*********************************************************************************/
// callback when data is sent
void OnDataSent() {
#ifdef ESP_NOW_VERBOSE
Serial.print("Transmition finished");
#endif
}
/*********************************************************************************/
esp_now_recv_cb_t OnDataRecv(const esp_now_recv_info_t *info, const uint8_t *incomingData, int len){
// esp_now_recv_cb_t OnDataRecv(const uint8_t *mac_addr, const uint8_t *incomingData, int len) {
#ifdef ESP_NOW_VERBOSE
Serial.println("New data received.");
#endif
if ((incomingData[1] == 0) || (incomingData[1] > maxClientsCount))
return (esp_now_recv_cb_t)LOW;
uint8_t type = incomingData[0];
if (type == PAIR_INIT) { // Pairing init message
addPeer(incomingData);
return (esp_now_recv_cb_t)HIGH;
}
// Check if: the packet is illegal in this context, and the peer is paired
if (((type != DATA) && (type != DATA_ACK)))
return (esp_now_recv_cb_t)LOW;
// Data receive
struct_message rxPacket;
memcpy(&rxPacket, incomingData, sizeof(rxPacket));
if ((rxPacket.peerId > maxClientsCount) || (rxPacket.peerId == 0)) // Not to us
return (esp_now_recv_cb_t)LOW;
if (rxPacket.messageNum == previousMessageNum) { // Continuation of previously received message
#ifdef ESP_NOW_VERBOSE
Serial.print("Bad message sequencing in data message");
#endif
return (esp_now_recv_cb_t)LOW;
}
receivedMessage += String(rxPacket.data).substring(0, rxPacket.dataLen - 1);
messageReceived = (type == DATA);
return (esp_now_recv_cb_t)ESP_OK;
}
/*********************************************************************************/
public:
void begin();
void transmitData(uint8_t id, String txDataE);
bool checkMissesCounter(uint8_t id);
} espNowServer;
/*********************************************************************************/
bool espNowServerClass::checkMissesCounter(uint8_t id) {
if (++peersList[id].missesCount >= maxPeersMisses) { // Too many misses - remove the peer from the list
peersList[id].pairingStatus = NOT_PAIRED;
peersList[id].missesCount = 0;
#ifdef ESP_NOW_VERBOSE
Serial.println("Successfully removed");
#endif
return HIGH;
} else
return LOW;
}
/*********************************************************************************/
void espNowServerClass::begin() {
if (esp_wifi_get_mac(WIFI_IF_STA, baseMac) == ESP_OK) {
#ifdef ESP_NOW_VERBOSE
Serial.println("MAC address");
for (uint8_t i = 0; i < macAddrLen - 1; i++)
Serial.println(String(baseMac[i], HEX) + ":");
Serial.println(String(macAddrLen - 1, HEX));
#endif
} else {
#ifdef ESP_NOW_VERBOSE
Serial.println("Failed to read MAC address");
#endif
return;
}
// esp_now_register_recv_cb(OnDataRecv);
esp_now_register_recv_cb(esp_now_recv_cb_t(OnDataRecv));
for (uint8_t i1 = 0; i1 < maxClientsCount; i1++) {
peersList[i1].pairingStatus = NOT_PAIRED;
peersList[i1].missesCount = 0;
}
Serial.println((esp_now_init() != ESP_OK) ? "pass" : "fail");
}
/*********************************************************************************/
void espNowServerClass::transmitData(uint8_t id, String txDataE) {
struct_message txPacket;
txPacket.peerId = id;
txPacket.targetId = 0;
txPacket.messageNum = messageCounter++;
bool tooBig = (txDataE.length() > maxMessageLen);
while (tooBig) {
txPacket.msgType = DATA_ACK;
strcpy(txPacket.data, txDataE.substring(0, maxMessageLen - 1).c_str());
txPacket.dataLen = maxMessageLen;
if (localId == 0)
esp_now_send(peersList[id].macAddr, (uint8_t *)&txPacket, sizeof(txPacket));
else
esp_now_send(serverAddr, (uint8_t *)&txPacket, sizeof(txPacket));
acknowledgeReceived = LOW;
unsigned long ackIntervalC = millis();
while (!acknowledgeReceived && (millis() - ackIntervalC) < ackInterval)
; // Wait for the acknowledgement
if (!acknowledgeReceived) { // Acknowlegement packet received within the time limit
Serial.println("Error - partial message transmitted or acknowledge not received");
return;
}
txDataE = txDataE.substring(maxMessageLen); // Ramainder of the data that should be transmitted
tooBig = (txDataE.length() > maxMessageLen);
acknowledgeReceived = LOW;
}
txPacket.msgType = DATA;
memset(txPacket.data, '0', maxMessageLen);
strcpy(txPacket.data, txDataE.c_str());
txPacket.dataLen = txDataE.length();
esp_now_send(peersList[id].macAddr, (uint8_t *)&txPacket, sizeof(txPacket));
if (messageReceived)
Serial.println(receivedMessage);
receivedMessage = "";
}
#endif // espNewServer_h
#ifndef espNowServer_h
#define espNowServer_h
//#include "espNowCommon.h"
#include "ESP32_NOW.h"
class espNowServerClass {
private:
int channel = 1;
unsigned int previousMessageNum;
bool acknowledgeReceived;
/*********************************************************************************/
esp_now_recv_cb_t OnDataRecv(const esp_now_recv_info_t *info, const uint8_t *incomingData, int len){
// esp_now_recv_cb_t OnDataRecv(const uint8_t *mac_addr, const uint8_t *incomingData, int len) {
#ifdef ESP_NOW_VERBOSE
Serial.println("New data received.");
#endif
return (esp_now_recv_cb_t)ESP_OK;
}
/*********************************************************************************/
public:
void begin();
void transmitData(uint8_t id, String txDataE);
bool checkMissesCounter(uint8_t id);
} espNowServer;
/*********************************************************************************/
void espNowServerClass::begin() {
// esp_now_register_recv_cb(OnDataRecv);
esp_now_register_recv_cb(esp_now_recv_cb_t(OnDataRecv));
}
#endif // espNewServer_h
/*
Based on a project prepared by Rui Santos & Sara Santos - Random Nerd Tutorials
Complete project details at https://RandomNerdTutorials.com/esp-now-auto-pairing-esp32-esp8266/
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files.
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
Based on JC Servaye example: https://github.com/Servayejc/esp_now_web_server/
Major changes:
1. Removing wifi server - focusing on EspNow protocols..
2. adding capability to transmit a long string (see the communication protocol below).
3. Pairing method is changed as follows:
a. Server:
i. The server will never start a pairing cycle.
ii. Upon its initiation the server clears its peersList array.
iii. The server is assumed to be functional and responsive as long as at least one peer is active.
iv. When receiving a pair request the server responds to the pear with PAIR_ACK message and registers the peer in the
peersList array.
b. Slave
i. The slave will start pairing sequence by sending PAIR request packet.
ii. The slave will finish the pairing sequence upon receiving a PAIR_ACK packet.
iii. When the sequence is over the slave will record the success and continue to its regular tasks.
4. Communication protocol
a. The protocol will always be initiated by the server.
b. if the message is within the allowed size, or when the packet contains the remainder of the message, the packet will be
of type DATA_FULL. The receiver will process the message and respond with DATA_PART or DATA_FULL packets with reply.
b. If the message is longer than the allowed maximum, the sender will break the message into parts of the maximum allowed
length, and transmit each part separately in DATA_PART packet. The receiver will accumulate the message without processing
it, and respond with DATA_ACK packet.
esp_now_register_recv_cb(OnDataRecv) invalid use of non-static member function 'void espNowServerClass::OnDataRecv(const uint8_t*, const uint8_t*, int)'
esp_now_register_recv_cb(esp_now_recv_cb_t(OnDataRecv)) invalid use of member function 'void espNowServerClass::OnDataRecv(const uint8_t*, const uint8_t*, int)' (did you forget the '()' ?)
*/
#ifndef espNewCommon_h
#define espNewCommon_h
#include <Arduino.h>
#include "esp_now.h"
#include <WiFi.h>
#include <esp_wifi.h>
#define MAX_CHANNEL 11 // 11 in North America or 13 in Europe
#define maxMessageLen 40
#define macAddrLen 6
#define loopbackFlag
#define ackInterval 100
#define maxPeersMisses 5
enum MessageType { PAIR_INIT,
PAIR_ACK,
DATA,
DATA_ACK,
};
enum PairingStatus { NOT_PAIRED,
PAIR_REQUEST,
PAIR_REQUESTED,
PAIR_PAIRED,
};
typedef struct struct_message {
MessageType msgType; // FIXED LOCATION!
uint8_t peerId; // FIXED LOCATION! identifier of local processing station
uint8_t targetId; // Future use - using the server as messages relay
uint8_t dataLen;
uint16_t messageNum;
char data[maxMessageLen];
} structMessage;
typedef struct struct_pairing {
MessageType msgType; // FIXED LOCATION!
uint8_t peerId; // FIXED LOCATION!
uint8_t macAddr[macAddrLen]; // FIXED LOCATION!
uint8_t channel; // Future use - multiple stations
uint8_t targetId; // Future use - multiple stations
const uint8_t *lmk = NULL;
} structPairing;
struct struct_list {
uint8_t macAddr[macAddrLen];
uint8_t missesCount;
PairingStatus pairingStatus;
} peersList[maxClientsCount + 1];
uint8_t baseMac[macAddrLen];
uint8_t serverAddr[macAddrLen] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
#endif // espNewCommon_h
/************************** Server spare code ************************************
WiFi.mode(WIFI_AP_STA); // Set the device as a Station and Soft Access Point simultaneously
WiFi.begin(ssid, password); // Set device as a Wi-Fi Station
chan = WiFi.channel();
WiFi.mode(WIFI_STA);
WiFi.STA.begin();
Serial.print("Waiting for wifi connection: ");
while (WiFi.status() != WL_CONNECTED){
delay(1000);
Serial.print(".");
}
Serial.println("\nconnected to network");
Serial.print("Station IP Address: ");
Serial.println(WiFi.localIP());
Serial.print("Wi-Fi Channel: ");
Serial.println(WiFi.channel());
Serial.print("Server ESP NOW init: ");
Serial.println(WiFi.softAPmacAddress());
Serial.print("Server SOFT AP MAC Address: ");
*/
|
The used examples looks like are not adopted to the changed implementation in Arduino Core 3.x and are conflicting. You can try to remove the provided ESP NOW libs provided in Arduino Core and use only the code you posted / linked. The API calls and |
OK, got it. I isolated the following objects from esp now libraries, and
I'll imitate them: 'esp_now_init';'esp_now_send'; 'ESP_NOW_SEND_SUCCESS';
'esp_wifi_get_mac'; 'esp_wifi_set_channel';
The most urgent, and, actually, those I'm not familiar with, for me are the
call back registration
methods 'esp_now_register_recv_cb' and 'esp_now_recv_cb_t' .
Will you be so kind as to send an implementation example of these methods?
Best regards
Yona
…On Mon, Apr 14, 2025 at 6:20 PM Jason2866 ***@***.***> wrote:
The used examples looks like are not adopted to the changed implementation
in Arduino Core 3.x and are conflicting. You can try to remove the provided
ESP NOW libs provided in Arduino Core and use only the code you posted /
linked. The API calls and esp_now.h from IDF is there in Arduino Core and
working. Using ESP NOW in project Tasmota this way and it is verified
working.
—
Reply to this email directly, view it on GitHub
<#11243 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AXTKTCA5KS4DKGY4JSW7EQD2ZPG3ZAVCNFSM6AAAAAB3A5HRQWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDQMBSGA3DQMRWGA>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
*Jason2866* left a comment (espressif/arduino-esp32#11243)
<#11243 (comment)>
The used examples looks like are not adopted to the changed implementation
in Arduino Core 3.x and are conflicting. You can try to remove the provided
ESP NOW libs provided in Arduino Core and use only the code you posted /
linked. The API calls and esp_now.h from IDF is there in Arduino Core and
working. Using ESP NOW in project Tasmota this way and it is verified
working.
—
Reply to this email directly, view it on GitHub
<#11243 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AXTKTCA5KS4DKGY4JSW7EQD2ZPG3ZAVCNFSM6AAAAAB3A5HRQWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDQMBSGA3DQMRWGA>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
This is github issues, not a place to discuss personal coding questions. Anyways here is an example of an esp now driver used in Tasmota https://github.com/arendst/Tasmota/blob/development/tasmota/tasmota_xdrv_driver/xdrv_57_9_tasmesh.ino |
Dear friend,
Thank you for the reference. However, I still think that this is a package issue.
As you can see in the attached file, I continued the experiments. The code was shrunk to almost the bare minimum. Lines 34 to 37 contain variety of cb registrations. The errors reported in lines 53 to 69 of the same file, show that the issue is only in lines 34 and 36, both are registration variants of onDataReceived, and none to the other registrations in lines 35 and 37. I assume there is some vulnerability of this registration, which causes so many troubles to so many developers.
Unfortunately, I didn’t find online explanation of the lower level of the events handling, and I don’t know what is behind the syntax of these lines, so I can’t further analyze them. I’d appreciate your help here.
Regards
Yona
From: Jason2866 ***@***.***>
Sent: Tuesday, 15 April, 2025 0:27
To: espressif/arduino-esp32 ***@***.***>
Cc: yonagy82 ***@***.***>; Author ***@***.***>
Subject: Re: [espressif/arduino-esp32] ESP NOW compilation issue of (Issue #11243)
This is github issues, not a place to discuss personal coding questions. Anyways here is an example of an esp now driver used in Tasmota ahttps://github.com/arendst/Tasmota/blob/development/tasmota/tasmota_xdrv_driver/xdrv_57_9_tasmesh.ino
—
Reply to this email directly, view it on GitHub <#11243 (comment)> , or unsubscribe <https://github.com/notifications/unsubscribe-auth/AXTKTCBBCVOFVIIODOW2LYT2ZQR3DAVCNFSM6AAAAAB3A5HRQWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDQMBTGA3DKNRVGA> .
You are receiving this because you authored the thread. <https://github.com/notifications/beacon/AXTKTCHZVQ4O5BI4NU477DD2ZQR3DA5CNFSM6AAAAAB3A5HRQWWGG33NNVSW45C7OR4XAZNMJFZXG5LFINXW23LFNZ2KUY3PNVWWK3TUL5UWJTVHCNRTE.gif> Message ID: ***@***.*** ***@***.***> >
<https://avatars.githubusercontent.com/u/24528715?s=20&v=4> Jason2866 left a comment (espressif/arduino-esp32#11243) <#11243 (comment)>
This is github issues, not a place to discuss personal coding questions. Anyways here is an example of an esp now driver used in Tasmota ahttps://github.com/arendst/Tasmota/blob/development/tasmota/tasmota_xdrv_driver/xdrv_57_9_tasmesh.ino
—
Reply to this email directly, view it on GitHub <#11243 (comment)> , or unsubscribe <https://github.com/notifications/unsubscribe-auth/AXTKTCBBCVOFVIIODOW2LYT2ZQR3DAVCNFSM6AAAAAB3A5HRQWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDQMBTGA3DKNRVGA> .
You are receiving this because you authored the thread. <https://github.com/notifications/beacon/AXTKTCHZVQ4O5BI4NU477DD2ZQR3DA5CNFSM6AAAAAB3A5HRQWWGG33NNVSW45C7OR4XAZNMJFZXG5LFINXW23LFNZ2KUY3PNVWWK3TUL5UWJTVHCNRTE.gif> Message ID: ***@***.*** ***@***.***> >
|
Thank you. Do you have examples for Arduino IDE? Regards |
Board
XIAO ESP32-C3
Device Description
XIAO ESP32-C3 stand alone (wifi communication)
Hardware Configuration
XIAO ESP32-C3 stand alone (wifi communication)
Version
v3.1.3
IDE Name
Arduino IDE Version 2.3.5
Operating System
Windows 10
Flash frequency
N/A
PSRAM enabled
no
Upload speed
9600
Description
Hello, friends,
I know that the issue was discussed multiple times. I read the solutions, but none had worked for me. So, regretfully' I have to place the question ove again.
I'm using Aarduino IDE Version 2.3.5, The library is ESP-NOW version 3.1.3. The ESP_NOW sub library is Unicast transmission by Lucas Saavedra Vaz - 2024, downloaded from https://github.com/espressif/arduino-esp32/. It is stored on my computer at c:\Users\USER\AppData\Local\Arduino15\packages\esp32\tools\esp32-arduino-libs\idf-release_v5.4-2f7dcd86-v1\esp32c3/include/esp_wifi/include/esp_now.h
I tried several code variants and combunations of them:
and registrations:
The error message is consistent with small variants:
invalid use of non-static member function 'void (* espNowServerClass::OnDataRecv(const uint8_t*, const uint8_t*, int))(const esp_now_recv_info_t*, const uint8_t*, int),
with or without the suffix(did you forget the '()'?)
When using the non-void version of the method
OnDataRecv
I've noticed another issue: any macro returned by the method invoked two notices:pointer to arithmetic expression
invalid conversion from 'int' to 'esp_now_recv_cb_t' {aka 'void (*)(const esp_now_recv_info*, const unsigned char*, int)'} [-fpermissive]
In both cases the was a note from the .ino -
in expansion of macro '...'
.I'm already on this for quite some time; should I downgrade the library? to which revision? What are the functions or nugs that will be lost? How to do it?
Best regards
Yona
Sketch
Debug Message
Other Steps to Reproduce
N/A - before using the ESP32 module
I have checked existing issues, online documentation and the Troubleshooting Guide
The text was updated successfully, but these errors were encountered: