thanks for the reply...
i might be wrong but im pretty sure the ESP32 i bought has bluetooth.. i'll double check the ebay listing.. i tried to get the exact same one as the person who made it work previously...
here is the video they made to get it working.. id ask that person if i could but it appears they arent active on their youtube page now...
i'll post the sketch below... i have the joystick connected to the corresponding pins at the top of the sketch so i think thats OK.. appreciate any insight..
#include "BLEDevice.h"
//#include "BLEScan.h"
const int SW_pin = 34; // digital pin connected to switch output
const int X_pin = 32; // analog pin connected to X output
const int Y_pin = 35; // analog pin connected to Y output
int Y_axis = 1800;
int X_axis = 1800;
// The remote service we wish to connect to.
static BLEUUID serviceUUID("0000fee9-0000-1000-8000-00805f9b34fb");
// The characteristic of the remote service we are interested in.
static BLEUUID charUUID("d44bc439-abfd-45a2-b575-925416129600");
static BLEAddress *pServerAddress;
static boolean doConnect = false;
static boolean connected = false;
static BLERemoteCharacteristic* pRemoteCharacteristic;
static void notifyCallback(
BLERemoteCharacteristic* pBLERemoteCharacteristic,
uint8_t* pData,
size_t length,
bool isNotify) {
Serial.print("Notify callback for characteristic ");
Serial.print(pBLERemoteCharacteristic->getUUID().toString().c_str());
Serial.print(" of data length ");
Serial.println(length);
}
bool connectToServer(BLEAddress pAddress) {
Serial.print("Forming a connection to ");
Serial.println(pAddress.toString().c_str());
BLEClient* pClient = BLEDevice::createClient();
Serial.println(" - Created client");
// Connect to the remove BLE Server.
pClient->connect(pAddress);
Serial.println(" - Connected to server");
// Obtain a reference to the service we are after in the remote BLE server.
BLERemoteService* pRemoteService = pClient->getService(serviceUUID);
if (pRemoteService == nullptr) {
Serial.print("Failed to find our service UUID: ");
Serial.println(serviceUUID.toString().c_str());
return false;
}
Serial.println(" - Found our service");
// Obtain a reference to the characteristic in the service of the remote BLE server.
pRemoteCharacteristic = pRemoteService->getCharacteristic(charUUID);
if (pRemoteCharacteristic == nullptr) {
Serial.print("Failed to find our characteristic UUID: ");
Serial.println(charUUID.toString().c_str());
return false;
}
Serial.println(" - Found our characteristic");
// Read the value of the characteristic.
std::string value = pRemoteCharacteristic->readValue();
Serial.print("The characteristic value was: ");
Serial.println(value.c_str());
//pRemoteCharacteristic->registerForNotify(notifyCallback);
}
/**
* Scan for BLE servers and find the first one that advertises the service we are looking for.
*/
class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks {
/**
* Called for each advertising BLE server.
*/
void onResult(BLEAdvertisedDevice advertisedDevice) {
Serial.print("BLE Advertised Device found: ");
Serial.println(advertisedDevice.toString().c_str());
// We have found a device, let us now see if it contains the service we are looking for.
if (advertisedDevice.haveServiceUUID() && advertisedDevice.getServiceUUID().equals(serviceUUID)) {
//
Serial.print("Found our device! address: ");
advertisedDevice.getScan()->stop();
pServerAddress = new BLEAddress(advertisedDevice.getAddress());
doConnect = true;
} // Found our server
} // onResult
}; // MyAdvertisedDeviceCallbacks
void setup() {
pinMode(SW_pin, INPUT);
digitalWrite(SW_pin, HIGH);
Serial.begin(115200);
Serial.println("Starting Arduino BLE Client application...");
BLEDevice::init("");
// Retrieve a Scanner and set the callback we want to use to be informed when we
// have detected a new device. Specify that we want active scanning and start the
// scan to run for 30 seconds.
BLEScan* pBLEScan = BLEDevice::getScan();
pBLEScan->setAdvertisedDeviceCallbacks(new MyAdvertisedDeviceCallbacks());
pBLEScan->setActiveScan(true);
pBLEScan->start(30);
} // End of setup.
// This is the Arduino main loop function.
void loop() {
// If the flag "doConnect" is true then we have scanned for and found the desired
// BLE Server with which we wish to connect. Now we connect to it. Once we are
// connected we set the connected flag to be true.
if (doConnect == true) {
if (connectToServer(*pServerAddress)) {
Serial.println("We are now connected to the BLE Server.");
connected = true;
} else {
Serial.println("We have failed to connect to the server; there is nothin more we will do.");
}
doConnect = false;
}
// If we are connected to a peer BLE Server, update the characteristic each time we are reached
// with the current time since boot.
if (connected) {
int Y_axis = analogRead(X_pin);
int X_axis = analogRead(Y_pin);
//Up
if (X_axis < 1665){
const uint8_t onPacket[] = {0x06, 0x10, 0x01, 0x0e, 0x89, 0xc2, 0xbc, 0x06, 0x10, 0x02, 0x08, 0x00, 0x31, 0xeb};
pRemoteCharacteristic->writeValue((uint8_t*)onPacket, 14, true);
}
//Down
if (X_axis > 1900){
const uint8_t onPacket[] = {0x06, 0x10, 0x03, 0x08, 0x00, 0x06, 0xdb, 0x06, 0x10, 0x01, 0x01, 0x76, 0xcc, 0x72};
pRemoteCharacteristic->writeValue((uint8_t*)onPacket, 14, true);
}
//Left
if (Y_axis < 1700){
const uint8_t onPacket[] = {0x06, 0x10, 0x02, 0x08, 0x00, 0x31, 0xeb, 0x06, 0x10, 0x03, 0x01, 0x76, 0xa2, 0x12};
pRemoteCharacteristic->writeValue((uint8_t*)onPacket, 14, true);
}
//Right
if (Y_axis > 1935){
const uint8_t onPacket[] = {0x06, 0x10, 0x02, 0x08, 0x00, 0x31, 0xeb, 0x06, 0x10, 0x03, 0x0d, 0xd9, 0xa3, 0x7a};
pRemoteCharacteristic->writeValue((uint8_t*)onPacket, 14, true);
}
}
delay(50); // Delay a second between loops.
} // End of loop