wifwucite / esphome-ble-controller

Bluetooth Low Energy (BLE) controller for ESPHome
MIT License
109 stars 21 forks source link

Illegalinstruction error when using esphome-ble-controller #4

Closed manju-rn closed 3 years ago

manju-rn commented 3 years ago

I am trying to expose a template switch, I get the following error

[23:58:39]Fatal exception (0): IllegalInstruction [23:58:39]epc1=0x4008033a, epc2=0x00000000, epc3=0x00000000, excvaddr=0x00000000, depc=0x00000000

YAML

esphome:
  name: esp32bleserver
  platform: ESP32
  board: nodemcu-32s

wifi:
  fast_connect: True
  networks:
  - ssid: !secret myssid
    password: !secret mypass
    hidden: True

captive_portal:

web_server:
  port: 8080

logger:

ota:

api:

external_components:
  - source: github://wifwucite/esphome-ble-controller

esp32_ble_controller:
  services:
  - service: "4fafc201-1fb5-459e-8fcc-c5c9c331915d"
    characteristics:
      - characteristic: "beb5483e-36e1-4688-b7f5-ea07361b26ab"
        exposes: fanon  

remote_transmitter:
  pin: 3
  carrier_duty_percent: 50%

climate:
  - platform: daikin
    id: Aircon_BLE_Server
    name: "Aircon_BLE_Server"
    supports_heat: false

esp32_ble_server:

switch:
  - platform: template
    id: fanon
    turn_on_action:
      - climate.control:
          id: Aircon_BLE_Server
          mode: FAN_ONLY
wifwucite commented 3 years ago

Hmm, could you try if disabling the web server makes any difference?

manju-rn commented 3 years ago

The Climate component is the problem. If I remove the climate component, it works fine. I have a question, let say I have following setup:

  1. ESP - 1 is hosting this BLE Controller with this template switch exposed via the UUID as per your example.
  2. ESP - 2 is connecting as client to ESP - 1 and subscribed for the UUID. I am using the BLE Client setup and on_notify function as per the standard esphome
  3. So if I click the template switch in the ESP - 1 (via webserver), it would notify the ESP -2?
wifwucite commented 3 years ago

I have never tested such a scenario but I believe it should work. If you try it, please let me know, I am curious. :-) One hint: maybe you will have to set "use_BLE2902" to false. I think I have forgotten to document this option. If you enable it (which it is by default), the client has to tell the server that it wants to receive notifications whenever a value changes. I am not sure if the standard BLE client in ESPHome can handle that. If you disable this option, the server will happily send notifications in any case. That might waste some energy, but it should be safer. The option is on the same level as "exposes" or "characteristic".

manju-rn commented 3 years ago

okay - tried this with mixed results, it is very random:

  1. keeping the use_BLE2902 to default (i.e no values given): 1 out of 10 times, it responds to notification. I was using the BLE Client notify=true option. I know this works because i have bunch of iTag and by pressing their buttons, ESP responds very well.
  2. when keeping use_BLE2902 to false: It never notified at all. I check in wireshark as well and seemed like no messages were going through. While my iTag works just fine.

Let me try with some other ESP 32 as well. Range is not a problem since they are right next to each other

manju-rn commented 3 years ago

One observation though, in the ESP client, I get the following. should the descriptor have a value?

[13:09:52][C][ble_sensor:021]: Service UUID : 4FAFC2011FB545-9E8F-CCC5-C9C3-31915D [13:09:52][C][ble_sensor:022]: Characteristic UUID: BEB5483E36E146-88B7-F5EA-0736-1B26AB [13:09:52][C][ble_sensor:023]: Descriptor UUID : 00000000000000-0000-0000-0000-000000

manju-rn commented 3 years ago

okay - ignore the above. I think my esp was a problem. I am able to consistently connect with or without that use_BLE2902 settings. So the notification works perfectly - thanks so much. Now I have to try that text_sensor, this will be a game changer :-)

image

wifwucite commented 3 years ago

Thanks for reporting back. I am glad it is working now. Depending on what you want to do with the text sensor you might also want to have a look at user-defined commands. I like them a lot. ;-)

evlo commented 1 year ago

@manju-rn can you please take a look at https://github.com/wifwucite/esphome-ble-controller/issues/15 and maybe share your server and client yamls so I can see what I'm doing wrong?

It seems from the log you pasted you are using it other way round - so for you the switch is server, right?

So in my case it would be possible with toggling virtual switch on button press on the and light would also toggle on ble_sensor state change?