趁双十一买了一块esp32S3单片,尝试之后发现他的蓝牙只支持ble,我的机器人以前是使用手机控制的,我想借此机会,为他添加一个esp32S3的大脑。
查了一下资料,写了一个demo,记录一下代码:
#include "BLEDevice.h"
//#include "BLEScan.h"
//hc-08的ble需要至少两个uuid,一个是服务serviceUUID2,一个是读写charUUID,
//还有一个服务是扫描时用到serviceUUID1,这个服务是hc-08的广播服务,做为过滤蓝牙使用,这里也可以使用蓝牙的名字
// The remote service we wish to connect to.
//static BLEUUID serviceUUID("4fafc201-1fb5-459e-8fcc-c5c9c331914b");
static BLEUUID serviceUUID1("0000ffe1-0000-1000-8000-00805f9b34fb");
// The characteristic of the remote service we are interested in.
//static BLEUUID charUUID("0000ffe1-0000-1000-8000-00805f9b34fb");
static BLEUUID serviceUUID2("0000ffe0-0000-1000-8000-00805f9b34fb");
static BLEUUID charUUID("0000fff0-0000-1000-8000-00805f9b34fb");
static String name="RS-BLE";
/*
Advertised Device: Name: RS-BLE
, Address: 44:ee:14:4e:66:66, manufacturer data: 48432d30380000000000000000000000000000000000, serviceUUID: 0000ffe1-0000-1000-8000-00805f9b34fb, txPower: 4, rssi: -55
*/static boolean doConnect = false;
static boolean connected = false;
static boolean doScan = false;
static BLERemoteCharacteristic *pRemoteCharacteristic;
static BLEAdvertisedDevice *myDevice;static void notifyCallback(BLERemoteCharacteristic *pBLERemoteCharacte