serial bluetooth and ESP NOW
Posted: Thu Jun 16, 2022 12:02 am
I am not able to get ESP NOW to function properly while using the built in serial bluetooth library.
I can send but not receive, I'm trying broadcast address and it does not work. If I switch back to BLE mode, everything is fine. What am I missing about the basic compatibilities of ESP NOW with serialBluetooth?
Code: Select all
char *pin = "123";//"R069D"; //<- standard pin would be provided by default
SerialBT.begin("abc");//, false);
SerialBT.setPin(pin);
esp_err_t err;
WiFi.mode(WIFI_STA);
err = esp_now_init();
if (err != ESP_OK)
{
Serial.println("Problem during ESP-NOW init");
ESP.restart();
return;
}
else
{
espNowStarted = true;
Serial.println("ESP-NOW init OK");
}
Serial.print("[OLD] ESP32 Board MAC Address: ");
Serial.println(WiFi.macAddress());
esp_now_register_recv_cb(OnDataRecv);
esp_now_register_send_cb(OnDataSent);
// register peer
esp_now_peer_info_t peerInfo;
peerInfo.channel = 0;
peerInfo.encrypt = false;
// register first peer
memcpy(peerInfo.peer_addr, peerAdmin, 6);
if (esp_now_add_peer(&peerInfo) != ESP_OK){
Serial.println("Failed to add peer");
ESP.restart();
return;
}
memcpy(peerInfo.peer_addr, espAll, 6); //can also broadcast with zero (0) which does each individual
if (esp_now_add_peer(&peerInfo) != ESP_OK){ //delivery success always with 0xFF broadcast, so no ack in that mode
Serial.println("Failed to add peer");
ESP.restart();
return;
}