lemmingDev / ESP32-BLE-Gamepad

Bluetooth LE Gamepad library for the ESP32
Other
979 stars 165 forks source link

Sending data from PC to my ESP32 via BLE #195

Open akuttervrinsightde opened 8 months ago

akuttervrinsightde commented 8 months ago

Ladies and gentlemen,

this is my first time writing here. I created a simple gamepad to send a few buttons and three axis via BLE to the PC. Works like a charm. But is it possible to send infos from my Unity application to the ESP32? Like a float value, an int value or at least a bool? I would like to use it for example to trigger the vibration strenght or colorize an RGB LED. Or at least switch the vibration or the LED on and off with a bool.

I am not very experienced tbh, so looking forward to your help!

LeeNX commented 8 months ago

Congratulations.

Similar question has been asked a few times in different ways. https://github.com/lemmingDev/ESP32-BLE-Gamepad/issues/165 https://github.com/lemmingDev/ESP32-BLE-Gamepad/issues/99 https://github.com/lemmingDev/ESP32-BLE-Gamepad/issues/43

My own work in this area paused at https://github.com/LeeNX/ESP32-BLE-Gamepad/tree/test-led, which could be further basically tested with https://nondebug.github.io/webhid-explorer/ but using Chrome.

My research has me thinking there is no real standard way to do this from the OS. I was thinking getting a working tech demo and patch SDL to support this, but I have not had time to go further yet. Plus the branch is a little old.

Hope this helps and we all make some progress.

akuttervrinsightde commented 7 months ago

Thank you @LeeNX very much appreciated.

Ok I understand the issue. I will dig a bit deeper into this, let's see what my simple developer mind can achieve :-D

AlEnterni commented 6 months ago

Hello, I am reaching out to inquire about the feasibility of retrieving data from a characteristic created in a similar fashion to the following code snippet:

pCharacteristic_FFB = pService->createCharacteristic( NIMBLE_PROPERTY::READ | NIMBLE_PROPERTY::WRITE );

This characteristic is intended to be utilized within a function, and the goal is to write to this characteristic from Python or any other program using a BLE library. I am not well-versed in Bluetooth and BLE, and I'm curious to know if this approach is viable. Any insights or guidance on how this can be achieved would be greatly appreciated. Thank you for your time and assistance.

Best regards,

LeeNX commented 6 months ago

I believe it should be possible, but I currently have not got a working example yet. I think the HID/report interface might be easier, like using the webhid-explorer using Chrome.

My PlayerLEDs branch might help, commit https://github.com/LeeNX/ESP32-BLE-Gamepad/commit/8096d8e9597e79891329dbb9d7b5005e87208de8 has a start

I also think you need to add Characteristic to a Service, plus if you want to write into it, you would need a callBack, which is in my branch.

Let us know how you go with this.

AlEnterni commented 6 months ago

I'm encountering difficulties with Nimble, and I'm seeking assistance in resolving the issue. I've followed the examples provided by the library, but I'm still unable to write to characteristics that should be writable.

To provide a bit more context, I'm using nRF Connect on my mobile device for the connection. While I can successfully read data from the characteristics, writing to them seems to be problematic. I'm wondering if anyone else has faced a similar issue or if there are insights into what might be causing this inconvenience.

LeeNX commented 6 months ago

@AlEnterni are you having issues with the NimBLE library or the ESP32-BLE-Gamepad library?

Currently ESP32-BLE-Gamepad library does not have write support.

If you have an example or PR to extending the ESP32-BLE-Gamepad that would be awesome.

EmanresuEmanreztuneb commented 3 months ago

I'll make it short:

If this is still active, im willing to support/donate with more then just a smile!

lemmingDev commented 3 months ago

Might be something usable here https://github.com/afpineda/Nus-NimBLE-Serial

LeeNX commented 3 months ago

Thanks @lemmingDev , I was looking at adding the option for NUS type service, but I could just not get it added as an option in the ESP32-BLE-Gamepad library. This is more a limitation of my C skills, than any other problem.

Thou the linked library looks to do way more than I was thinking of adding.

If only there was an easy way to add BLE services without them been all tied together.

AlEnterni commented 3 months ago

Hello everyone,

I've been working on modifying a BLE library for my project. My goal is to write a value to a characteristic and create a function to retrieve that value. However, due to my limited programming knowledge, I'm encountering an error that I can't seem to resolve. Here's the code snippet along with the error message:

---Blegamepad.h---


class BleGamepad
{
private:
    ...
    NimBLECharacteristic *pBeefCharacteristic;
    ...

public:
    ...
    void WriteData();
    ...
};

---Blegamepad.cpp---


...
void BleGamepad::taskServer(void *pvParameter)
    ...
    NimBLEService* pDeadService = pServer->createService("DEAD");
    NimBLECharacteristic* pBeefCharacteristic = pDeadService->createCharacteristic(
                                               "BEEF",
                                               NIMBLE_PROPERTY::READ |
                                               NIMBLE_PROPERTY::WRITE |
                                              );

    pBeefCharacteristic->setValue("Burger");

    ...

void BleGamepad::WriteData( )
{
    Serial.println((this->pBeefCharacteristic->getValue().c_str()));
}

When I try to run this code on my Arduino, I encounter the following error:


rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0030,len:1344
load:0x40078000,len:13964
load:0x40080400,len:3600
entry 0x400805f0
Starting BLE work!

abort() was called at PC 0x400d4f3c on core 0

Backtrace: 0x40083949:0x3ffce0b0 0x40093515:0x3ffce0d0 0x40098a29:0x3ffce0f0 0x400d4f3c:0x3ffce170 0x400d31aa:0x3ffce1b0 0x400d2c62:0x3ffce1e0

ELF file SHA256: fab548ad5f8ea5c0

I would greatly appreciate any assistance or guidance on how to resolve this issue and successfully modify the code as intended. Thank you in advance for your help!

Best regards,

LeeNX commented 2 months ago

I ran into similar issues, but my C skills are so little, maybe @lemmingDev could help make my branch work - https://github.com/LeeNX/ESP32-BLE-Gamepad/tree/leet-uart

The last three commits is where I tried to add NUS