Hello
I am new to this site and I have a problem with turning on an esp8266 or WEmos as a transmitter and an esp32 as a receiver. I use the site
https://randomnerdtutorials.com/esp32-esp-now-wi-fi-web-server/
I use the ESP32 receiver as is.
When I send the mac address FF everywhere in the mac address it works but on the other hand when I put the correct mac address (which has been verified) in other programs I have an error.
Here is an image of the serial ports which shows us the error
Here is the transmitter program for esp8266
#include <Arduino.h>
#include <espnow.h>
#include <Adafruit_Sensor.h>
#include <DHT.h>
#include <ESP8266WiFi.h>
#include <Adafruit_BME280.h>
#include <Adafruit_Sensor.h>
// Set your Board ID (ESP32 Sender #1 = BOARD_ID 1, ESP32 Sender #2 = BOARD_ID 2, etc)
#define BOARD_ID 1
#define DHTPIN 2
// Uncomment the type of sensor in use:
#define DHTTYPE DHT11 // DHT 11
//#define DHTTYPE DHT22 // DHT 22 (AM2302)
//#define DHTTYPE DHT21 // DHT 21 (AM2301)
DHT dht(DHTPIN, DHTTYPE);
//MAC Address of the receiver
//uint8_t broadcastAddress[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
//uint8_t broadcastAddress[] = {0x80, 0x7D, 0x3A, 0x94, 0xAD, 0xD4};
uint8_t broadcastAddress[] = {0x24, 0x0A, 0xC4, 0xAA, 0x3F, 0xB8};
//Structure example to send data
//Must match the receiver structure
typedef struct struct_message {
int id;
float temp;
float hum;
int readingId;
} struct_message;
//Create a struct_message called myData
struct_message myData;
unsigned long previousMillis = 0; // Stores last time temperature was published
const long interval = 10000; // Interval at which to publish sensor readings
unsigned int readingId = 0;
// Insert your SSID
constexpr char WIFI_SSID[] = “michel”;
int32_t getWiFiChannel(const char *ssid) {
if (int32_t n = WiFi.scanNetworks()) {
for (uint8_t i=0; i<n; i++) {
if (!strcmp(ssid, WiFi.SSID(i).c_str())) {
return WiFi.channel(i);
}
}
}
return 0;
}
float readDHTTemperature() {
// Sensor readings may also be up to 2 seconds ‘old’ (its a very slow sensor)
// Read temperature as Celsius (the default)
float t = dht.readTemperature();
// Read temperature as Fahrenheit (isFahrenheit = true)
//float t = dht.readTemperature(true);
// Check if any reads failed and exit early (to try again).
if (isnan(t)) {
Serial.println(“Failed to read from DHT sensor!”);
return 0;
}
else {
Serial.println(t);
return t;
}
}
float readDHTHumidity() {
// Sensor readings may also be up to 2 seconds ‘old’ (its a very slow sensor)
float h = dht.readHumidity();
if (isnan(h)) {
Serial.println(“Failed to read from DHT sensor!”);
return 0;
}
else {
Serial.println(h);
return h;
}
}
// Callback when data is sent
void OnDataSent(uint8_t *mac_addr, uint8_t sendStatus) {
Serial.print(“Last Packet Send Status: “);
if (sendStatus == 0){
Serial.println(“Delivery success”);
}
else{
Serial.println(“Delivery fail”);
}
}
void setup() {
//Init Serial Monitor
Serial.begin(115200);
dht.begin();
//initBME();
// Set device as a Wi-Fi Station and set channel
WiFi.mode(WIFI_STA);
int32_t channel = getWiFiChannel(WIFI_SSID);
WiFi.printDiag(Serial); // Uncomment to verify channel number before
wifi_promiscuous_enable(1);
wifi_set_channel(channel);
wifi_promiscuous_enable(0);
WiFi.printDiag(Serial); // Uncomment to verify channel change after
// Init ESP-NOW
if (esp_now_init() != 0) {
Serial.println(“Error initializing ESP-NOW”);
return;
}
// Once ESPNow is successfully Init, we will register for Send CB to
// get the status of Trasnmitted packet
esp_now_set_self_role(ESP_NOW_ROLE_CONTROLLER);
esp_now_add_peer(broadcastAddress, ESP_NOW_ROLE_SLAVE, 1, NULL, 0);
esp_now_register_send_cb(OnDataSent);
}
void loop() {
unsigned long currentMillis = millis();
if (currentMillis – previousMillis >= interval) {
// Save the last time a new reading was published
previousMillis = currentMillis;
//Set values to send
myData.id = BOARD_ID;
myData.temp = readDHTTemperature();
myData.hum = readDHTHumidity();
myData.readingId = readingId++;
esp_now_send(NULL, (uint8_t *) &myData, sizeof(myData));
Serial.print(“loop”);
}
}
I have a google nest router. (Mesh network) Can there be some link with this router.
Hi.
In our previous discussion I didn’t understand that you were using an ESP32 as receiver and ESP8266 as a transmitter. I understood that you were using just ESP8266 boards.
I’ll try it with an ESP32 and an ESP8266 and then I’ll reach out again.
Regards,
Sara
Hi again.
1) The following line
esp_now_add_peer(broadcastAddress, ESP_NOW_ROLE_SLAVE, 1, NULL, 0);
Sets the peer and the communication channel to 1. The channel should be set to the one we’ve got on the channel variable. So, that line should be as follows:
esp_now_add_peer(broadcastAddress, ESP_NOW_ROLE_SLAVE, channel, NULL, 0);
Despite these changes, I also got the same problem. If I put the receiver MAC address it doesn’t work. If I put the broadcast FF MAC address. It works.
I’ve tried several scenarios and was not able to make it work.
2)
A workaround for the problem would be using the FF broadcast MAC address or using an ESP8266 as a receiver.
3)
Before writing the ESP-NOW Web Server project, we tried another approach that worked for the ESP32 boards. It is an approach that is not described in the current tutorial. At the time, I didn’t test it for ESP8266 boards.
This approach involved setting the receiver both as a station and access point, and then connect the sender to the receiver access point.
If you want, I may try this approach with the ESP8266. If it works I can share the code with you.
Regards,
Sara
Hi again.
I’ve tested the other approach I’ve told you and I did not succeed.
The same problem happens: when I put the FF broadcast address everything works fine. However, if I specify the receiver MAC address, the delivery fails.
I’m without ideas on what might be causing the issue and how to fix it.
I’m sorry that I can’t help much in this issue.
Meanwhile, if you find something, just let me know.
Regards,
Sara
Salut Sara
Je travailles sur ce problème. Aussitôt trouvé quelques choses, c’est sûr que je te tiens au courant.
Merci de ton aide
Hello Sara
I did some testing and I can work with your code (for esp8286) and the full esp32 esp_now program and wifi server. However, the esp_now just works. The problem does not come from the wifi channel (which are the same) but the wifi itself. That is, if I block WiFi.begin (sta_ssid, sta_password) on the esp32 server program by putting a comment in front, the esp_now works. So there are a few things with WiFi.mode (WIFI_AP_STA) ;; . Looks like it doesn’t separate the wifi network from the esp_now network. Check out this github
https://github.com/espressif/arduino-esp32/issues/878. Take a closer look at the name beegee-tokyo.
Also, the execution speed of the 8286 is too slow versus an esp32.
I’m looking for a way to turn off the wifi while receiving the esp_now or something like that. If you have an idea
Michel
Hi.
I see… Maybe he is right, and it doesn’t work on the ESP8266.
However, it does work when using only ESP32 boards.
Meanwhile, let me know if you find out something new.
Regards,
Sara
Bonjour Sara
Au lieu de mettre le mac adresse du wifi , j ai essayé de mettre le mac adresse AP. Essai ça. Dans l emetteur
#include “WiFi.h”
void setup() {
Serial.begin(115200);
WiFi.mode(WIFI_MODE_AP);
Serial.println(WiFi.softAPmacAddress());
}
void loop() {}
Moi çca semble fonctionner
Michel
void setup() {
Serial.begin(115200);
WiFi.mode(WIFI_MODE_AP);
Serial.println(WiFi.softAPmacAddress());
}
void loop() {}
Moi çca semble fonctionner
Michel
yes it works great. I have an esp8286 transmitter and an esp32 receiver. Remember that there are two mac addresses on the cards. A mac AP address and a Mac Wifi address. Mac AP is very important in this project for espnow You should put this in your texts because it can be confusing. michel