BluetoothSerial.h库函数使用手册

679 阅读3分钟

Arduino开发esp32使用蓝牙用到,英文粗略翻译

  1. BluetoothSerial(void) :构造函数,用于初始化BluetoothSerial对象。
  2. ~BluetoothSerial(void) :析构函数,用于释放BluetoothSerial对象使用的资源。
  3. bool begin(String localName=String(), bool isMaster=false) :开始蓝牙连接。如果需要,可以设置本地名称(localName)和主/从设备角色(isMaster)。
  4. bool begin(unsigned long baud) :这是一个兼容函数,用于与Arduino的Serial.begin()兼容。实际上,它只是调用了begin()函数。
  5. int available(void) :返回可读取的字节数。
  6. int peek(void) :返回缓冲区中的首个字节,但不会将其从缓冲区中移除。
  7. bool hasClient(void) :检查是否已连接到客户端设备。
  8. int read(void) :从缓冲区中读取一个字节。
  9. size_t write(uint8_t c) :将一字节写入缓冲区。
  10. *size_t write(const uint8_t buffer, size_t size) :将缓冲区中的数据写入蓝牙设备。
  11. void flush() :刷新缓冲区,将数据发送到蓝牙设备。
  12. void end(void) :关闭蓝牙连接。
  13. void setTimeout(int timeoutMS) :设置超时时间(以毫秒为单位)。
  14. void onData(BluetoothSerialDataCb cb) :设置数据接收回调函数。当接收到数据时,将调用该函数。
  15. esp_err_t register_callback(esp_spp_cb_t callback) :注册SPP回调函数。当发生SPP事件时,将调用该函数。
  16. void onConfirmRequest(ConfirmRequestCb cb) :设置确认请求回调函数。当接收到确认请求时,将调用该函数。
  17. void onAuthComplete(AuthCompleteCb cb) :设置身份验证完成回调函数。当身份验证完成后,将调用该函数。
  18. void confirmReply(boolean confirm) :回复确认请求。
  19. void enableSSP() :启用SSP(Secure Simple Pairing)功能。
  20. *bool setPin(const char pin) :设置PIN码。
  21. bool connect(String remoteName) :连接到指定名称的远程设备。
  22. bool connect(uint8_t remoteAddress[], int channel=0, esp_spp_sec_t sec_mask=(ESP_SPP_SEC_ENCRYPT|ESP_SPP_SEC_AUTHENTICATE), esp_spp_role_t role=ESP_SPP_ROLE_MASTER) :连接到指定地址的远程设备,并设置通道、安全模式和角色。
  23. bool connect() :连接到最近连接的设备。
  24. bool connected(int timeout=0) :检查是否已连接到远程设备。
  25. bool isClosed() :检查连接是否已关闭。
  26. bool isReady(bool checkMaster=false, int timeout=0) :检查设备是否准备好进行数据传输。
  27. bool disconnect() :断开与远程设备的连接。
  28. bool unpairDevice(uint8_t remoteAddress[]) :解除与指定地址的设备的配对。
  29. BTScanResults discover(int timeout=0x301280)**:扫描周围的蓝牙设备,并返回发现的设备列表。
  30. bool discoverAsync(BTAdvertisedDeviceCb cb, int timeout=0x30*1280) :异步扫描周围的蓝牙设备,并调用回调函数以返回发现的设备。
  31. void discoverAsyncStop() :停止异步扫描。
  32. void discoverClear() :清除发现的设备列表。
  33. *BTScanResults getScanResults()**:返回最近一次扫描发现的设备列表。
  34. std::map<int, std::string> getChannels(const BTAddress &remoteAddress) :获取指定远程设备的可用通道列表。
  35. const int INQ_TIME = 1280:设置查询时间,单位为毫秒。
  36. const int MIN_INQ_TIME = (ESP_BT_GAP_MIN_INQ_LEN * INQ_TIME) :设置最小查询时间。
  37. const int MAX_INQ_TIME = (ESP_BT_GAP_MAX_INQ_LEN * INQ_TIME) :设置最大查询时间。
  38. operator bool() const:将BluetoothSerial对象转换为布尔值。
  39. *void getBtAddress(uint8_t mac) :获取蓝牙设备的MAC地址,并将其复制到提供的数组中。
  40. BTAddress getBtAddressObject() :获取蓝牙设备的MAC地址,作为BTAddress对象返回。
  41. String getBtAddressString() :获取蓝牙设备的MAC地址,作为字符串返回。