You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It's a custom PCB that I made, it's connected via I2C to MC3419 (accelerometer). Then with "PWM" it's connected to AL1783 (led driver), and with a mosfet for running a buzzer.
Hi,
I'm working on a project that requires both the use of ESPNOW with other ESP32-C3 and BLE for connecting to a smartphone.
The problem is that when BLE is initialised the device doesn't receive any data from other ESPs via ESPNOW. If i delete initBLE() in the setup, then it espnow works flawlessly.
I need to use both protocols at the "same" time (I mean that I won't be sending data continuously with BLE nor with ESPNOW, just occasionally, like a few times every 2 seconds or so for ESPNOW, while it will be more rarely with BLE)
In the debug message you can see that at the end the devices tries to broadcast a message and it works since I can see it with another esp, but when this one replies back it says that there was an error and indeed the message is not received by the first one.
Sketch
#include<BLEDevice.h>
#include<BLEUtils.h>
#include<BLEServer.h>
#include<BLE2902.h>
#include"ESP32_NOW.h"
#include"WiFi.h"
#include"structs.cpp"
#include<esp_mac.h>// For the MAC2STR and MACSTR macros/* Definitions */
#defineESPNOW_WIFI_CHANNEL6classESP_NOW_Slave_Class : publicESP_NOW_Peer {
public:bool isAlive = true;
int battery = 0;
// Constructor of the classESP_NOW_Slave_Class(constuint8_t *mac_addr, uint8_t channel, wifi_interface_t iface, constuint8_t *lmk) : ESP_NOW_Peer(mac_addr, channel, iface, lmk) {}
// Destructor of the class~ESP_NOW_Slave_Class() {}
// Function to register the master peerbooladd_peer() {
if (!add()) {
log_e("Failed to register the peer");
returnfalse;
}
returntrue;
}
// Function to print the received messages from slaves voidonReceive(constuint8_t *data, size_t len, bool broadcast) {
isAlive = true;
//Serial.printf("Received message from: (%s), data*: %d\n", MAC2STR(addr()), *data);if (*data == ACK_PACK_TYPE) return;
if (*data == BATTERY_PACK_TYPE) {
BATTERY *packet = (BATTERY *) data;
battery = packet->batt;
}
}
voidonSent(bool success) {
isAlive = success;
Serial.printf("onSent(), %d\n\n", isAlive);
}
booldeinitialise() {
Serial.printf("I'm removing the peer\n");
returnremove();
}
// Function to send a message to the peerboolsend_message(constuint8_t *data, size_t len) {
if (!send(data, len)) {
log_e("Failed to broadcast message");
returnfalse;
}
returntrue;
}
};
BLEServer* pServer = NULL;
BLEService *serviceBattery = NULL;
BLECharacteristic *batteryLevelChar = NULL;
BLE2902* pBLE2902_battery = NULL;
#defineSERVICE_BATTERY_UUID"180f"
#defineBATTERY_LEVEL_CHARACTERISTIC_UUID"492c2d04-f173-4814-9630-e12aedc4f7f6"classServerCallbacks: publicBLEServerCallbacks {
voidonConnect(BLEServer* pServer) {
Serial.println("Device connected");
connectedBLE = true;
};
voidonDisconnect(BLEServer* pServer) {
Serial.println("Device disconnected");
connectedBLE = false;
//resart the advertisingBLEDevice::startAdvertising();
}
};
voidinitBLE() {
BLEDevice::init("B_Rainbow");
pServer = BLEDevice::createServer();
pServer->setCallbacks(newServerCallbacks());
serviceBattery = pServer->createService(SERVICE_BATTERY_UUID);
batteryLevelChar = serviceBattery->createCharacteristic(
BATTERY_LEVEL_CHARACTERISTIC_UUID,
BLECharacteristic::PROPERTY_NOTIFY | BLECharacteristic::PROPERTY_READ
);
pBLE2902_battery = newBLE2902();
pBLE2902_battery->setNotifications(true);
batteryLevelChar->addDescriptor(pBLE2902_battery);
serviceBattery->start();
BLEAdvertising *pAdvertising = BLEDevice::getAdvertising();
pAdvertising->addServiceUUID(SERVICE_BATTERY_UUID);
pAdvertising->setScanResponse(true);
pAdvertising->setMinPreferred(0x06); // functions that help with iPhone connections issue
pAdvertising->setMinPreferred(0x12);
BLEDevice::startAdvertising();
Serial.println("Finished BLE init");
}
voidsetup() {
Serial.begin(115200);
// Initialize the Wi-Fi module
WiFi.mode(WIFI_STA);
WiFi.setChannel(ESPNOW_WIFI_CHANNEL);
while (!WiFi.STA.started()) {
delay(100);
}
// Register the broadcast peerif (!broadcast_peer.begin()) {
Serial.println("Failed to initialize broadcast peer");
Serial.println("Reebooting in 5 seconds...");
delay(5000);
ESP.restart();
}
ESP_NOW.onNewPeer(register_new_master, NULL);
initBLE();
startupTime = millis();
}
voidloop() {
//just sending some data with ESPNOW occasionally
}
Board
ESP32-C3 custom PCB
Device Description
It's a custom PCB that I made, it's connected via I2C to MC3419 (accelerometer). Then with "PWM" it's connected to AL1783 (led driver), and with a mosfet for running a buzzer.
Hardware Configuration
18 and 19 are for USB data
#define LED_R_PIN 0
#define LED_G_PIN 1
#define LED_B_PIN 4
#define SDA_PIN 5
#define SCL_PIN 6
#define ACCEL_INT_PIN 9
#define BUZZER 2
#define BATTERY_PIN 3 (to check voltage)
Version
latest master (checkout manually)
IDE Name
Arduino IDE
Operating System
Ubuntu 24
Flash frequency
80MHz
PSRAM enabled
no
Upload speed
921600
Description
Hi,
I'm working on a project that requires both the use of ESPNOW with other ESP32-C3 and BLE for connecting to a smartphone.
The problem is that when BLE is initialised the device doesn't receive any data from other ESPs via ESPNOW. If i delete initBLE() in the setup, then it espnow works flawlessly.
I need to use both protocols at the "same" time (I mean that I won't be sending data continuously with BLE nor with ESPNOW, just occasionally, like a few times every 2 seconds or so for ESPNOW, while it will be more rarely with BLE)
I know it should work because it's written here https://docs.espressif.com/projects/esp-idf/en/latest/esp32c3/api-guides/coexist.html
In the debug message you can see that at the end the devices tries to broadcast a message and it works since I can see it with another esp, but when this one replies back it says that there was an error and indeed the message is not received by the first one.
Sketch
Debug Message
Other Steps to Reproduce
No response
I have checked existing issues, online documentation and the Troubleshooting Guide
The text was updated successfully, but these errors were encountered: