Xinyuan-LilyGO / T-keyboard

mini ble Keyboard for IOS/Android/Windows
MIT License
67 stars 29 forks source link

esp32 client for T-keyboard #6

Closed allthemod closed 2 weeks ago

allthemod commented 1 year ago

This is an example of how to connect your esp32 to your T-keyboard and read keys from it.

svenhum commented 2 weeks ago

Hello, @allthemod tried this code and got this error.

error: conversion from 'BLEScanResults*' to non-scalar type 'BLEScanResults' requested 19 | BLEScanResults res =pBLEScan->start(5, false);

I am a beginner so forgive me if this is trivial, but what should i change?

allthemod commented 2 weeks ago

First of all woah you found this two years after I posted it. Second I'll check the code. Third I'm also not that good.

allthemod commented 2 weeks ago

image

Hello, @allthemod tried this code and got this error.

error: conversion from 'BLEScanResults*' to non-scalar type 'BLEScanResults' requested 19 | BLEScanResults res =pBLEScan->start(5, false);

I am a beginner so forgive me if this is trivial, but what should i change?

What does your ide says?

allthemod commented 2 weeks ago

And are you using platform io?

svenhum commented 2 weeks ago

And are you using platform io?

Arduino IDE.

I fixed the error by the way, initially i downgraded my ESP32 version to the one around your post date and confirmed it worked, then i used copilot to make compatible for the latest version v3.0.5 ... maybe you are still on a prior version? this is the code the worked for me. Thanks for the reply!

`#include

include

include

include

include "TKeyboardClient.h"

BLEClient* pClient = nullptr;

void setup() { Serial.begin(921600); Serial.println("Starting..."); MyAdvertisedDeviceCallbacks callbackDev = MyAdvertisedDeviceCallbacks(); BLEDevice::init("T-Keyboard client"); BLEScan pBLEScan = BLEDevice::getScan(); pBLEScan->setInterval(1349); pBLEScan->setWindow(449); pBLEScan->setActiveScan(true); BLEScanResults res = pBLEScan->start(5, false); // Change to pointer int count = res->getCount(); // Dereference pointer Serial.printf("count %1d \n", count); for(int i = 0; i < count; i++){ Serial.print(i); Serial.println(" checking..."); callbackDev.onResult(res->getDevice(i)); // Dereference pointer } if(connectToServer()){ Serial.println("We are now connected to the BLE Server."); } delay(5000); }

void loop() {

} `

allthemod commented 2 weeks ago

And are you using platform io?

Arduino IDE.

I fixed the error by the way, initially i downgraded my ESP32 version to the one around your post date and confirmed it worked, then i used copilot to make compatible for the latest version v3.0.5 ... maybe you are still on a prior version? this is the code the worked for me. Thanks for the reply!

`#include

include

include

include

include "TKeyboardClient.h"

BLEClient* pClient = nullptr;

void setup() { Serial.begin(921600); Serial.println("Starting..."); MyAdvertisedDeviceCallbacks callbackDev = MyAdvertisedDeviceCallbacks(); BLEDevice::init("T-Keyboard client"); BLEScan pBLEScan = BLEDevice::getScan(); pBLEScan->setInterval(1349); pBLEScan->setWindow(449); pBLEScan->setActiveScan(true); BLEScanResults res = pBLEScan->start(5, false); // Change to pointer int count = res->getCount(); // Dereference pointer Serial.printf("count %1d \n", count); for(int i = 0; i < count; i++){ Serial.print(i); Serial.println(" checking..."); callbackDev.onResult(res->getDevice(i)); // Dereference pointer } if(connectToServer()){ Serial.println("We are now connected to the BLE Server."); } delay(5000); }

void loop() {

} `

Cool, happy for you and have fun using your esp32 to access your keyboard. It feels really good knowing that somebody used some code I made