The code that I am using works, but it's very finnicky.
Here is what you have to do in order to connect successfully.
1. Remove device from paired devices (if it's in there)
2. go to add device and select bluetooth
3. find device in list.
4. Reset device, and in the same moment, click it in windows pairing window. (very important)
5 device will now connect.
If you don't press the buttons in the right moment it doesn't work. If you disconnect and then reconnect, the mouse doesn't work, even thought in windows it says that it is connected.
Here is the code that I'm using for the BLE server
Code: Select all
void taskServer(void*){
BLEDevice::init("ESP32_Omni_Device");
BLEServer *pServer = BLEDevice::createServer();
pServer->setCallbacks(new MyCallbacks());
hid = new BLEHIDDevice(pServer);
input = hid->inputReport(1); // <-- input REPORTID from report map
std::string name = "Assist_IoT";
hid->manufacturer()->setValue(name);
hid->pnp(0x02, 0xe502, 0xa111, 0x0210);
hid->hidInfo(0x00,0x01);
BLESecurity *pSecurity = new BLESecurity();
pSecurity->setKeySize();
pSecurity->setAuthenticationMode(ESP_LE_AUTH_BOND);
hid->reportMap((uint8_t*)_hidReportDescriptor, sizeof(_hidReportDescriptor));
hid->setBatteryLevel(5);
hid->startServices();
BLEAdvertising *pAdvertising = BLEDevice::getAdvertising();
// The setAppearance function only changes what is passed in the adv packet...it does not set the communication protocol
//pAdvertising->setAppearance(HID_KEYBOARD);
//pAdvertising->setAppearance(HID_JOYSTICK);
pAdvertising->setAppearance(HID_MOUSE);
pAdvertising->addServiceUUID(hid->hidService()->getUUID());
BLEDevice::startAdvertising();
Serial.print("Advertising started!");
vTaskDelay(portMAX_DELAY);
};
Code: Select all
void setup() {
// join I2C bus (I2Cdev library doesn't do this automatically)
#if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE
Wire.begin();
Wire.setClock(400000); // 400kHz I2C clock. Comment this line if having compilation difficulties
#elif I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_FASTWIRE
Fastwire::setup(400, true);
#endif
xTaskCreate(taskServer, "server", 20000, NULL, 5, NULL);
/*..... Uninmportant code ommited*/
}
I am pretty new to this and don't have any idea where to even start, so any suggestion is appreciated.
Most of the past 2 days has been spent working with HID Descriptors and how to use them.