Hi
I have two sets of code that work well on their own but then when I try to integrate them they don't and throw up the error.
The philosophy of the code is fairly simple, PicoVoice sits on the central device, listens and then switches on the relay on the peripheral.
error: variable or field 'controlLed' declared void void controlLed(BLEDevice peripheral) {
and
error: 'BLEDevice' was not declared in this scope
The code is a PicoVoice code fairly standard, then LED Control central device code adaptation from the ArduinoBLE.h examples library.
This is the full code
// PicoVoice code prior to void setup
#include <Picovoice_EN.h>
#include "params.h"
#define MEMORY_BUFFER_SIZE (70 * 1024)
static const char* ACCESS_KEY = "TXri4IYq4oBvFVxMIZc9yAHGJ1tqoTy4Qb1aVSB2D5ryrGcGWsMHMw==";
static pv_picovoice_t *handle = NULL;
static int8_t memory_buffer[MEMORY_BUFFER_SIZE] __attribute__((aligned(16)));
static const float PORCUPINE_SENSITIVITY = 0.75f;
static const float RHINO_SENSITIVITY = 0.5f;
int relayState = 0;
static void wake_word_callback(void) {
Serial.println("PicoVoice Word - DETECTED!");
relayState = 1;
}
static void inference_callback(pv_inference_t *inference) {
Serial.println("{");
Serial.print(" is_understood : ");
Serial.println(inference->is_understood ? "true" : "false");
if (inference->is_understood) {
Serial.print(" intent : ");
Serial.println(inference->intent);
if (inference->num_slots > 0) {
Serial.println(" slots : {");
for (int32_t i = 0; i < inference->num_slots; i++) {
Serial.print(" ");
Serial.print(inference->slots[i]);
Serial.print(" : ");
Serial.println(inference->values[i]);
}
Serial.println(" }");
}
}
Serial.println("}\n");
pv_inference_delete(inference);
}
// end of PicoVoice code prior to void setup
#include <ArduinoBLE.h>
// variables for button (redundant as using PicoVoice instead of buttons)
//const int buttonPin = 2;
//int oldButtonState = LOW;
void setup() {
Serial.begin(9600);
while (!Serial);
// begin PicoVoice code within void setup
pv_status_t status = pv_audio_rec_init();
if (status != PV_STATUS_SUCCESS) {
Serial.print("Audio init failed with ");
Serial.println(pv_status_to_string(status));
while (1);
}
status = pv_picovoice_init(
ACCESS_KEY,
MEMORY_BUFFER_SIZE,
memory_buffer,
sizeof(KEYWORD_ARRAY),
KEYWORD_ARRAY,
PORCUPINE_SENSITIVITY,
wake_word_callback,
sizeof(CONTEXT_ARRAY),
CONTEXT_ARRAY,
RHINO_SENSITIVITY,
true,
inference_callback,
&handle);
if (status != PV_STATUS_SUCCESS) {
Serial.print("Picovoice init failed with ");
Serial.println(pv_status_to_string(status));
while (1);
}
const char *rhino_context = NULL;
status = pv_picovoice_context_info(handle, &rhino_context);
if (status != PV_STATUS_SUCCESS) {
Serial.print("retrieving context info failed with");
Serial.println(pv_status_to_string(status));
while (1);
}
Serial.println("Wake word: Picovoice");
Serial.println(rhino_context);
// end PicoVoice code within void setup
// initialize the Bluetooth® Low Energy hardware
BLE.begin();
Serial.println("Bluetooth® Low Energy Central - Relay control"); // aka LED Control
// start scanning for peripherals
BLE.scanForUuid("19b10000-e8f2-537e-4f6c-d104768a1214");
}
void loop() {
// check if a peripheral has been discovered
BLEDevice peripheral = BLE.available();
if (peripheral) {
// discovered a peripheral, print out address, local name, and advertised service
Serial.print("Found ");
Serial.print(peripheral.address());
Serial.print(" '");
Serial.print(peripheral.localName());
Serial.print("' ");
Serial.print(peripheral.advertisedServiceUuid());
Serial.println();
if (peripheral.localName() != "LED") {
return;
}
// stop scanning
BLE.stopScan();
controlLed(peripheral);
// peripheral disconnected start scanning again
BLE.scanForUuid("19b10000-e8f2-537e-4f6c-d104768a1214");
}
}
void controlLed(BLEDevice peripheral) {
// connect to the peripheral
Serial.println("Connecting ...");
if (peripheral.connect()) {
Serial.println("Connected");
} else {
Serial.println("Failed to connect!");
return;
}
// discover peripheral attributes
Serial.println("Discovering attributes ...");
if (peripheral.discoverAttributes()) {
Serial.println("Attributes discovered");
} else {
Serial.println("Attribute discovery failed!");
peripheral.disconnect();
return;
}
// retrieve the LED characteristic
BLECharacteristic ledCharacteristic = peripheral.characteristic("19b10001-e8f2-537e-4f6c-d104768a1214");
if (!ledCharacteristic) {
Serial.println("Peripheral does not have LED characteristic!");
peripheral.disconnect();
return;
} else if (!ledCharacteristic.canWrite()) {
Serial.println("Peripheral does not have a writable LED characteristic!");
peripheral.disconnect();
return;
}
while (peripheral.connected())
{
const int16_t *buffer = pv_audio_rec_get_new_buffer();
if (buffer) {
const pv_status_t status = pv_picovoice_process(handle, buffer);
if (status != PV_STATUS_SUCCESS) {
Serial.print("Picovoice process failed with ");
Serial.println(pv_status_to_string(status));
while(1);
}
}
// while the peripheral is connected
if (relayState == 1)
{
// PicoVoice changed state to ON THEN write 0x01 to turn the Relay on
ledCharacteristic.writeValue((byte)0x01);
}
}
Serial.println("Peripheral disconnected");
}
After rolling it back to only the LED Control.ino code then adding small sections of the picoVoice code gradually it becomes clear that it is the addition of this code:
static void wake_word_callback(void) {
Serial.println("PicoVoice Word - DETECTED!");
relayState = 1;
}
So I researched it and tried moving it up and down and re-ordering but I haven't gained any traction.
Any help appreciated. Thanks :_))