Hello - I need the hive minds help.
I am trying to build a simple component to monitor the battery state of a Nissan Leaf when the car initially returns home.
Essentials:
- Nissan Leaf
- Lelink2 BLE OBD2 dongle (ELM327)
- GL-S10 ESPHome Bluetooth gateway
Using the built in BLE stack, I am part of the way there:
ble_client:
- mac_address: B4:99:XX:XX:XX:XX
id: lelink
name: LELink BLE OBDII
on_connect:
then:
- lambda: |-
ESP_LOGI("ble_client_lambda", "Connected to lelink");
on_disconnect:
then:
- lambda: |-
ESP_LOGI("ble_client_lambda", "Disconnected from lelink");
text_sensor:
- platform: ble_client
ble_client_id: lelink
internal: True
notify: True
name: "lelink leaf response"
id: lelink_leaf_response_text
service_uuid: "0000ffe0-0000-1000-8000-00805f9b34fb"
characteristic_uuid: "ffe1"
on_notify:
then:
- lambda: |-
ESP_LOGI("ble_client_lambda", "notify from lelink_leaf");
interval:
- interval: 30s
then:
- logger.log:
level: INFO
format: "Sending ATZ"
- ble_client.ble_write:
id: lelink
service_uuid: 0000ffe0-0000-1000-8000-00805f9b34fb
characteristic_uuid: ffe1
# List of bytes to write.
value: [0x41, 0x54, 0x5A, 0x0D, 0x0A] #ATZ\r\n
I have tested the approach via a couple of BLE tools on an iphone, and sending ATZ(cr)(lf) as a ascii byte array works and returns 0d,0d,4f,42,44,49,49,20,20,76,31,2E,35,0d,0d,3e (via a notify)
OBDII
v1-5
>
But I am not getting this consistently with the built in tools.
[15:53:44][I][main:171]: Sending ATZ
[15:53:44][D][ble_client.automation:026]: Write type: ESP_GATT_WRITE_TYPE_RSP
>'
[15:53:45][I][ble_client_lambda:140]: notify from lelink
[15:53:46][D][text_sensor:067]: 'lelink response': Sending state 'A'
[15:54:14][I][main:171]: Sending ATZ
[15:54:14][D][ble_client.automation:026]: Write type: ESP_GATT_WRITE_TYPE_RSP
'
[15:54:14][I][ble_client_lambda:140]: notify from lelink
OBDII v1.'
[15:54:15][I][ble_client_lambda:140]: notify from lelink
>'
[15:54:15][I][ble_client_lambda:140]: notify from lelink
[15:54:44][I][main:171]: Sending ATZ
[15:54:44][D][ble_client.automation:026]: Write type: ESP_GATT_WRITE_TYPE_RSP
[15:54:44][D][text_sensor:067]: 'lelink response': Sending state 'AT'
[15:54:44][I][ble_client_lambda:140]: notify from lelink
'
[15:54:44][I][ble_client_lambda:140]: notify from lelink
>'
[15:54:45][I][ble_client_lambda:140]: notify from lelink
[15:54:46][D][text_sensor:067]: 'lelink response': Sending state 'A'
[15:55:14][I][main:171]: Sending ATZ
[15:55:14][D][ble_client.automation:026]: Write type: ESP_GATT_WRITE_TYPE_RSP
[15:55:14][D][text_sensor:067]: 'lelink response': Sending state 'AT'
[15:55:14][I][ble_client_lambda:140]: notify from lelink
'
[15:55:14][I][ble_client_lambda:140]: notify from lelink
>'
[15:55:15][I][ble_client_lambda:140]: notify from lelink
I am investigating a custom C++ component, but what is the best approach?