I'm trying to send data from on ESP32 to another ESP32 via ESPNOW, but the receiving ESP32 is not receiving anything. Here is my code.
ESP32 Sender:
#include <Arduino.h>
#include <esp_now.h>
#include <WiFi.h>
uint8_t address[] = { 0x0C, 0xDC, 0x7E, 0x89, 0x4F, 0x84 };
touch_pad_t touchPin;
void callback() {}
void espnow_enable();
void setup()
{
Serial.begin(115200);
}
void loop()
{
WiFi.mode(WIFI_STA);
espnow_enable();
touchPin = esp_sleep_get_touchpad_wakeup_status();
int touchData = 0;
if(touchPin == 0) { touchData = 1; }
else if(touchPin == 1) { touchData = 2; }
else if(touchPin == 2) { touchData = 3; }
else if(touchPin == 3) { touchData = 4; }
else if(touchPin == 4) { touchData = 5; }
else if(touchPin == 5) { touchData = 6; }
else if(touchPin == 6) { touchData = 7; }
else if(touchPin == 7) { touchData = 8; }
else if(touchPin == 8) { touchData = 10; }
else if(touchPin == 9) { touchData = 11; }
else { touchData = 0; }
esp_now_send(address, (uint8_t*) &touchData, sizeof(touchData));
delay(25);
WiFi.disconnect(true);
WiFi.mode(WIFI_OFF);
delay(25);
esp_sleep_enable_touchpad_wakeup();
touchAttachInterrupt(T0, callback, 50);
touchAttachInterrupt(T1, callback, 39);
touchAttachInterrupt(T2, callback, 62);
touchAttachInterrupt(T3, callback, 60);
touchAttachInterrupt(T4, callback, 58);
touchAttachInterrupt(T5, callback, 54);
touchAttachInterrupt(T6, callback, 52);
touchAttachInterrupt(T7, callback, 44);
touchAttachInterrupt(T8, callback, 44);
touchAttachInterrupt(T9, callback, 42);
esp_deep_sleep_start();
}
void espnow_enable()
{
WiFi.mode(WIFI_STA);
delay(25);
if(esp_now_init() != ESP_OK) { delay(25); return; }
esp_now_peer_info_t peerInfo;
memset(&peerInfo, 0, sizeof(peerInfo));
memcpy(peerInfo.peer_addr, address, 6);
peerInfo.channel = 0;
peerInfo.encrypt = false;
if(esp_now_add_peer(&peerInfo) != ESP_OK) { delay(25); return; }
delay(25);
}
ESP32 Receiver:
#include <Arduino.h>
#include <WiFi.h>
#include <esp_now.h>
uint8_t address[] = {0x0C, 0xDC, 0x7E, 0x89, 0x4A, 0xCC};
void espnow_enable();
void espnow_receive(const uint8_t * mac, const uint8_t *data, int len);
void setup()
{
Serial.begin(115200);
}
void loop()
{
espnow_enable();
}
void espnow_enable()
{
WiFi.mode(WIFI_STA);
delay(25);
if(esp_now_init() != ESP_OK) { delay(25); return; }
// esp_now_peer_info_t peerInfo;
// memset(&peerInfo, 0, sizeof(peerInfo));
// memcpy(peerInfo.peer_addr, address, 6);
// peerInfo.channel = 0;
// peerInfo.encrypt = false;
// if(esp_now_add_peer(&peerInfo) != ESP_OK) { return; }
// delay(25);
esp_now_register_recv_cb(espnow_receive);
}
void espnow_receive(const uint8_t * mac, const uint8_t *data, int len)
{
int * messagePointer = (int*)data;
if(*messagePointer != 0)
{
Serial.println(*messagePointer);
}
else
{
Serial.println("Nothing");
}
}
(There is nothing else hooked up to these ESP32's beside power)
Is there some code to tell me if all the wifi and bluetooth radio things are working properly. Thanks for your time.