1technophile / OpenMQTTGateway

MQTT gateway for ESP8266 or ESP32 with bidirectional 433mhz/315mhz/868mhz, Infrared communications, BLE, Bluetooth, beacons detection, mi flora, mi jia, LYWSD02, LYWSD03MMC, Mi Scale, TPMS, BBQ thermometer compatibility & LoRa.
https://docs.openmqttgateway.com
GNU General Public License v3.0
3.63k stars 799 forks source link

Allow programatic BLE connect/disconnect #1791

Closed ov1d1u closed 9 months ago

ov1d1u commented 1 year ago

Is your feature request related to a problem? Please describe. Some devices, like Qingping CGD1 require a sequence of data to be written on a characteristic. For example, to change the time on this clock you need to write an auth key on a specific characteristic and then a command on the same characteristic. Writing the auth key, disconnecting and then writing the command will not work.

Describe the solution you'd like To prevent breaking the current implementation, maybe a map of [MAC : flag] to enable/disable automatic connection management for each device should be kept. Aside from that, we will need two new endpoints to the /commands/MQTTtoBT/config to connect/disconnect from a specific device

Describe alternatives you've considered Right now I'm using an ESPHome configuration to control this clock, but there is no way in ESPHome to read a characteristic by request.

h2zero commented 1 year ago

Sounds like a write_multiple command would need to be created for this situation.

ov1d1u commented 1 year ago

I don't think this is the ideal approach, as sometimes you might need to write - read - write something in the same session.

1technophile commented 1 year ago

We should define something that could be used by other gateways like Theengs. We could have a json with a list commands for a specific mac:

  1. Connect
  2. Service
  3. Characteristic write
  4. Command
  5. Read
  6. Disconnect So that this json could be reused by any gateway. If this match your approach what would be this json for this device?
ov1d1u commented 1 year ago

Specifically for this device something like sending a list of payload would work, e.g.:

[
  {
    "ble_write_address": "58:2D:34:55:8A:87",
    "ble_write_service": "22210000-554a-4546-5542-46534450464d",
    "ble_write_char": "00000001-0000-1000-8000-00805f9b34fb",
    "ble_write_value": "1101ea600e964287ea7d17894900da6174bd",
    "value_type": "HEX",
    "ttl": 4,
    "immediate": true
  },
  {
    "ble_write_address": "58:2D:34:55:8A:87",
    "ble_write_service": "22210000-554a-4546-5542-46534450464d",
    "ble_write_char": "00000001-0000-1000-8000-00805f9b34fb",
    "ble_write_value": "0509b9414265",
    "value_type": "HEX",
    "ttl": 4,
    "immediate": true
  },
]

although it might not be ideal for other purposes, like when you need to read something from a characteristic between two writes.

github-actions[bot] commented 10 months ago

This issue is stale because it has been open for 90 days with no activity.

github-actions[bot] commented 9 months ago

This issue was closed because it has been inactive for 14 days since being marked as stale.