Elektroda.com
Elektroda.com
X

[BK7231T] My HTTP server, configurator, MQTT support from Home Assistant

p.kaczmarek2 115065 1236
This content has been translated flag-pl » flag-en View the original version here.
  • #661
    p.kaczmarek2
    Moderator Smart Home
    rawilson wrote:
    a strange thing, because I checked with a multimeter and SM2135Eh is connected exactly on these pins - the first is data (p24), the second is clk (p26)

    [BK7231T] My HTTP server, configurator, MQTT support from Home Assistant

    is it possible to initialize i2c even without a driver for a given device to check if something is "speaking" on the other side?


    I have the impression that the previous post did not send or something went wrong (error on the forum?), So I will write again - there is I2C software in the BK7231T SDK, just port it to us:
    [syntax=c]
    // dac i2c interface
    #define I2C_CLK 26
    #define I2C_DAT 27


    static void CLK_OUTPUT_HIGH(void)
    {
    gpio_output_c(I2C_CLK,1);
    }
    static void CLK_OUTPUT_LOW(void)
    {
    gpio_output_c(I2C_CLK,0);
    }

    static void DATA_OUTPUT_HIGH(void)
    {
    gpio_output_c(I2C_DAT,1);
    }

    static void DATA_OUTPUT_LOW(void)
    {
    gpio_output_c(I2C_DAT,0);
    }

    static void SET_DATA_INPUT(void)
    {
    gpio_config_c(I2C_DAT,1);
    }

    static void set_data_output(void)
    {
    UINT32 mode;
    UINT32 val = DATA_INPUT();
    mode = (val
  • #662
    p.kaczmarek2
    Moderator Smart Home
    rawilson wrote:
    @ p.kaczmarek2 it looks like the GU10 bulbs available in Poland woj14415 are based on WBLC5 + SM2135Eh - I2C communication. After dismantling, it turned out that the CLK line is connected to pin 26, date to pin24. Would you provide information on how to configure this bulb?


    I bought Woj14415 and WOJ14413 because I was not up to PLN 40 for free smart delivery.

    For now, I have checked WOJ14413.
    Read the teardown:
    https://www.elektroda.pl/rtvforum/viewtopic.php?p=20045382#20045382
    SM2123EG (PWM LED controller - without I2C!) And ESP8285 (TYLC5)

    woj14415 next in line. I'll test it in a few days.
  • #663
    kuba2k2
    Level 12  
    Meanwhile, I've been working on a method for better flashing firmware and OTA updates at the same time - using Microsoft's open-source UF2 format. While this required a bit of work, I think the results are pretty satisfying - everything happens after just pressing "upload":
    Building in release mode
    Linking .pio\build\wr3\firmware.elf
    |-- Image 1: firmware.ota1.elf
    |   |-- image_0x00B000.ota1.bin
    |   |   |-- ota1.ram_2.r.bin
    |   |   |-- ota1.xip_image2.bin
    |   |   |-- ota1.rdp.bin
    |-- Image 2: firmware.ota2.elf
    |   |-- image_0x0D0000.ota2.bin
    |   |   |-- ota2.ram_2.r.bin
    |   |   |-- ota2.xip_image2.bin
    |   |   |-- ota2.rdp.bin
    Checking size .pio\build\wr3\firmware.elf
    Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
    RAM:   [          ]   1.4% (used 3688 bytes from 262144 bytes)
    Flash: [          ]   4.3% (used 34972 bytes from 806912 bytes)
    Building UF2 OTA image
    |-- arduinotest_22.06.02_wr3_RTL8710B_lt0.4.0.uf2
    Configuring upload protocol...
    AVAILABLE: uart
    CURRENT: upload_protocol = uart
    Looking for upload port...
    Auto-detected: COM60
    Uploading arduinotest_22.06.02_wr3_RTL8710B_lt0.4.0.uf2
    |-- arduinotest 22.06.02 @ 2022-06-02 22:45:00 -> wr3 via uart
    |   |-- Connecting...
    |   |-- Flashing image to OTA 2...
    |   |-- Writing 35036 bytes to 0x80d0000
    |-- Finished in 1.578 s

    The same .UF2 file can be flashed directly to device (using UART) or via OTA - because it has all the info about the SoC type, target partition names/offsets, etc. I think this is a very clean solution to OTA.
    Also, on Realtek we need to use dual-OTA schemes - OTA1 flashes OTA2 and OTA2 flashes OTA1 (AFAIK Beken doesn't work the same way). The UF2 image has both OTA images embedded, and the CPU just chooses what to flash, and where. And, of course, the file format is the same for every SoC that I'll implement.

    EDIT: OTA working in ESPHome over HTTP web server
    [BK7231T] My HTTP server, configurator, MQTT support from Home Assistant
  • #664
    rawilson
    Level 11  
    It is possible that you came across an older search with an esp on board. All in all, you can easily check the wifi chip manufacturer by its mac address.
  • #665
    p.kaczmarek2
    Moderator Smart Home
    How I ordered after your post ....

    Well, there is war14415 in the queue to be checked and maybe Beken will be there. Then I will embrace you with I2C.

    But are you sure it is on I2C and not also SM2123EG or similar?
  • #666
    rawilson
    Level 11  
    Yes - there is the SM2135EH.
    [BK7231T] My HTTP server, configurator, MQTT support from Home Assistant

    And the wifi chip along with the rest of the trash - as you can see WBLC5 (described here ) has only 3 useful pins, so normal PWM control is omitted.
    [BK7231T] My HTTP server, configurator, MQTT support from Home Assistant
  • #667
    p.kaczmarek2
    Moderator Smart Home
    Okay, @rawilson, so I open my GU10 and let me know what's in there.

    Did you rip a batch from this BK, preferably after pairing with the test wifi network (because then the SSID and password may leak)? It would be useful to do an OTA hack for tuya-cloudcutter to be able to program them remotely. The entire 2MB batch is ripped.
  • #668
    rawilson
    Level 11  
    Unfortunately not - I can do it when flashing next pieces. As for the opening, I had a problem with the opening - the upper plate sits tightly and it cannot be meaningfully undone. That's why I decided to make a hole on the other side of the casing and push it out from the back - there are no components in the marked place, so you can drill easily.
    [BK7231T] My HTTP server, configurator, MQTT support from Home Assistant

    If you can drop the first 6 characters from the MAC address - we'll forget what's sitting there before the gut.
  • #669
    p.kaczmarek2
    Moderator Smart Home
    I have no way to drop the MAC now because I don't have how to connect it ... I don't have a connector under it.

    For now, I took the glass off, hammered its edge with a watchmaker's screwdriver.

    There is an I2C chip. Rather it will be okay.
    [BK7231T] My HTTP server, configurator, MQTT support from Home Assistant
    Now it's time to remove the PCB with LEDs. I wonder how it will go.

    But I will pair it anyway and play the original batch, because you have to make a cloudcutter for them to program without opening the case.
  • #670
    rawilson
    Level 11  
    Do you know how the cloudcutter and OTA flashing is progressing? As if you had to perform some tests - I will be happy to help.
  • #671
    sharathbk1912
    Level 7  
    Hi @p.kaczmarek2

    When ever time permits can you please add . Poweronstate ?? And eventually power on restore aswell ?

    Also the ha mqtt manual integration yaml is changing . From sep i think old way of platform mqtt will be deprecated . Has started giving warnings from 2022.6 version now .

    Thanks and regards
    Sharath B K
  • #672
    p.kaczmarek2
    Moderator Smart Home
    @rawilson at the moment, probably only me actively helping with cloudcutter. I know how to prepare an OTA hack for a standard batch using an automatic offset finding tool, assuming that the dump firmware is full and was previously paired with Tuya servers because then the schema is already downloaded in it.

    I have already given them, for example, a pull request for one socket:
    https://github.com/tuya-cloudcutter/tuya-cloudcutter/pull/97

    Do you know assembler and C and Python that you want to help? Do you just test?
  • #673
    p.kaczmarek2
    Moderator Smart Home
    @sharathbk1912 I will look into it.

    Right now I have added configurator for BL0937 and I also fixed several bugs, including the non-working MQTT without user and pass.

    What has changed exactly in the HA yaml?


    PS: but you know that you can already do a power on state by autoexec.bat or by short startup command, right?
  • #674
    sharathbk1912
    Level 7  
    Tats awesome news .

    Tried ith bl0937 . Just select the pins from the config and save. Next in the cmd section issue: startDriver BL0937
    So this started the driver and logs show the reporting

    Info:BL0942:Voltage 240.691650, current 0.000000, power 0.000000
    Info:MAIN:Time 365, free 105000, MQTT 1, bWifi 1, secondsWithNoPing -1, socks 2/38
    Info:BL0942:Voltage pulses 1740, current 0, power 0

    Calibration also works.

    However the main page/status page gives me only relay control option
    [BK7231T] My HTTP server, configurator, MQTT support from Home Assistant


    Also the homeassistant config generator does not generate the voltage/current/power related config entries .

    Can you please help what is to be done apart from the steps mentioned?

    Mqtt changes

    sensor:
    - platform: "mqtt"
    name: "My sensor"
    state_topic: "some-state-topic"

    Is to be changed to

    mqtt:
    sensor:
    - name: "My sensor"
    state_topic: "some-state-topic".


    This is applicable to all devices like lights fans etc etc anything using platform mqtt is going to be deprecated.


    And ya i completely forgot abt it the startup cmnd . Yes let me use that . We can have a page which collates all commands will help.


    Thanks
    Sharath b k
  • #675
    p.kaczmarek2
    Moderator Smart Home
    You are indeed correct. A mere function call was missing. It is added now.

    Thank you for testing @sharathbk1912 , it is very valuable. Tell me if there any more bugs.

    PS: Remember that BL0937 measurement precision will be increased soon and then you will have to do calibration again (after updating openbk)



    sharathbk1912 wrote:

    Mqtt changes

    sensor:
    - platform: "mqtt"
    name: "My sensor"
    state_topic: "some-state-topic"

    Is to be changed to

    mqtt:
    sensor:
    - name: "My sensor"
    state_topic: "some-state-topic".


    This is applicable to all devices like lights fans etc etc anything using platform mqtt is going to be deprecated.

    Is this that change caused by Home Assistant update or am I confusing things? I haven't looked into it yet.
  • #676
    sharathbk1912
    Level 7  
    Yes sure I will check .
    update: so i did try the version 1.4.1 . So I do see the update on main page . However with this version I am reading all values as 0 in the logs aswell.
    If i flash 1.3.2 the values are reported as expected. Can you please take a look ?

    Mqtt
    Ya that update is caused by the home assistant . Only the home assistant config genrator shd be updated going forward to accomodate this change .

    openbeken update meaning via rbl itself right ?

    Thanks and regards
    Sharath b k
  • #677
    TommyNZ
    Level 2  
    I have purchased a few different smart switches from Hidintech on Alibaba. The sales person confirms they are all BK chips and I am waiting for full board schematics from them including pinouts etc...
    In the meantime I thought I'd investigate how I can flash them and found this great work! I'm not very technical but have been using Tasmota for many years.... Maybe with some team effort we could also add the Hidintech devices to the supported list?
    I can post photos and what every technical info they send me?
    Hidintech MFA03 light switch is the first one I have opened to see the inside board.
  • #678
    p.kaczmarek2
    Moderator Smart Home
    Please post all photos and technical information you can get. I will do my best to ensure your device is supported.

    Are you saying that the seller will send you schematics?
  • #679
    eborokhov
    Level 2  
    I've flashed the Feit Smart plug from Costco marked as BPPLUG/WIFI/3 and it works great so far. It has WB2S module thats need to be de-soldered.

    The config is:

    P10 - LED_N
    P24 - REL
    P26 - Btn_Tgl_All

    [BK7231T] My HTTP server, configurator, MQTT support from Home Assistant [BK7231T] My HTTP server, configurator, MQTT support from Home Assistant
  • #680
    p.kaczmarek2
    Moderator Smart Home
    Nice, can you submit a pull request for quick config?

    I am adding save/power on state.
  • #681
    eborokhov
    Level 2  
    p.kaczmarek2 wrote:
    Nice, can you submit a pull request for quick config?

    I am adding save/power on state.


    Will try to do it soon
  • #682
    p.kaczmarek2
    Moderator Smart Home
    Polish tuyaMCU guide released, translation coming soon:
    https://www.elektroda.pl/rtvforum/topic3898502.html

    I also added saving of relays state (optional, per-channel configurable), just need to test it a bit more and I will release it tomorrow. @sharathbk1912
  • #683
    sharathbk1912
    Level 7  
    That is cool !! Sure . I will also test once realeased

    Also i did test bl0937 with latest version however i see the below issue

    update: so i did try the version 1.4.1 . So I do see the update on main page . However with this version I am reading all values as 0 in the logs aswell.
    If i flash 1.3.2 the values are reported as expected. Can you please take a look ?

    Is there any recommendation to try on new version to get bl0937 working ?

    Thanks and regards
    Sharath B K
  • #684
    p.kaczmarek2
    Moderator Smart Home
    Are you sure? I just tested, it works for me.
    Did you forget to start your driver? or to calibrate?
    [BK7231T] My HTTP server, configurator, MQTT support from Home Assistant

    Retain channel value configuration -> Go to config -> Startup,
    for each channel, set:
    - value 0 if you want it to be off at start
    - value 1 if you want it to be on at start
    - value 100 for PWM (full bright)
    - also can set 25 or anything for PWM
    - special value - -1 - if you want it to remember last state
    WARNING: the current version does not save/retain correctly the states of "newled" driver, the "led_basecolor", "led_dimmer", etc, this is all TODO
    [BK7231T] My HTTP server, configurator, MQTT support from Home Assistant
  • #685
    sharathbk1912
    Level 7  
    I just tried 1.4.10 also it doesnt seem to work

    THis is my config [BK7231T] My HTTP server, configurator, MQTT support from Home Assistant

    This is the main page:
    [BK7231T] My HTTP server, configurator, MQTT support from Home Assistant

    Also one strange thing i notice is that my relay_n is now reversed as compared to rel_n from 1.3.2.
    could this hint something ?

    ALso logs indicate no pulses
    Info:MAIN:Time 457, free 104864, MQTT 1, bWifi 1, secondsWithNoPing -1, socks 2/38

    Info:BL0942:Voltage pulses 0, current 0, power 0

    Info:BL0942:Voltage 0.000000, current 0.000000, power 0.000000

    Info:MAIN:Time 458, free 104864, MQTT 1, bWifi 1, secondsWithNoPing -1, socks 2/38

    Info:BL0942:Voltage pulses 0, current 0, power 0

    Info:BL0942:Voltage 0.000000, current 0.000000, power 0.000000

    Info:MAIN:Time 459, free 104864, MQTT 1, bWifi 1, secondsWithNoPing -1, socks 2/38

    Info:BL0942:Voltage pulses 0, current 0, power 0

    Info:BL0942:Voltage 0.000000, current 0.000000, power 0.000000

    Thanks and Regards
    Sharath b K
  • #686
    p.kaczmarek2
    Moderator Smart Home
    sharathbk1912 wrote:

    Also one strange thing i notice is that my relay_n is now reversed as compared to rel_n from 1.3.2.
    could this hint something ?

    There was a bug where Relay_N was not set to 1 on start (because default start channel value is 0, and 0 negated gives 1). It is fixed now. So it was incorrect before and now is OK.
    You can change initial channel values in Config->Startup.


    sharathbk1912 wrote:

    THis is my config

    Is the configuration correct?
    Did you restart after changing config?
    You have to restart in order to get interrupt handler and pulses counting.

    Why do you have different config than default one?
    Code: c
    Log in, to see the code

    Is your device different and is using pin 9 for CF1 or maybe it's a mistake?

    It's still working for me.
    [BK7231T] My HTTP server, configurator, MQTT support from Home Assistant
  • #687
    sharathbk1912
    Level 7  
    Yes this is a different device and the config seems right . Cause with 1.3.2 It just works fine.

    Yes i have saved and rebooted once the config was done.

    If i just ota the 1.3.2 rbl , it just starts working for me as the startup commands start the driver for me.



    OTA to 1.3.2 from 1.4.10



    Info:BL0942:Voltage pulses 0, current 0, power 0

    Info:BL0942:Voltage 0.000000, current 0.000000, power 0.000000

    Info:MAIN:Time 6593, free 104696, MQTT 1, bWifi 1, secondsWithNoPing -1, socks 2/38

    Info:BL0942:Consumed 255 unwanted non-header byte in BL0942 buffer

    Info:BL0942:Voltage pulses 0, current 0, power 0

    Info:BL0942:Voltage 0.000000, current 0.000000, power 0.000000

    Info:MAIN:Time 6595, free 104696, MQTT 1, bWifi 1, secondsWithNoPing -1, socks 2/38

    Info:OTA:134000
    Info:OTA:148000
    Info:BL0942:Consumed 255 unwanted non-header byte in BL0942 buffer

    Info:BL0942:Voltage pulses 0, current 0, power 0

    Info:BL0942:Voltage 0.000000, current 0.000000, power 0.000000

    Info:MAIN:Time 6600, free 79392, MQTT 1, bWifi 1, secondsWithNoPing -1, socks 3/38

    Info:GEN:dhcp=0 ip=192.168.3.249 gate=192.168.3.1 mask=255.255.255.0 mac=38:1f:8d:16:41:30

    Info:OTA:14c000
    Info:OTA:150000
    Info:OTA:16c000
    Info:OTA:170000
    Info:OTA:174000
    Info:BL0942:Consumed 255 unwanted non-header byte in BL0942 buffer

    Info:BL0942:Voltage pulses 0, current 0, power 0

    Info:BL0942:Voltage 0.000000, current 0.000000, power 0.000000

    Info:MAIN:Time 6601, free 103664, MQTT 1, bWifi 1, secondsWithNoPing -1, socks 2/38

    Info:MAIN:Module reboot in 2...

    current 0.000000, power 0.000000

    Info:MAIN:Time 5, free 109656, MQTT 0, bWifi 0, secondsWithNoPing 0, socks 2/38

    Debug:MAIN:Registered for wifi changes

    Info:BL0942:Voltage pulses 1746, current 0, power 0

    Info:BL0942:Voltage 231.397598, current 0.000000, power 0.000000

    Info:MAIN:Time 6, free 105696, MQTT 0, bWifi 0, secondsWithNoPing 0, socks 2/38

    Info:BL0942:Voltage pulses 2, current 0, power 0

    Info:BL0942:Voltage 0.265060, current 0.000000, power 0.000000

    Info:MAIN:Time 7, free 105696, MQTT 0, bWifi 0, secondsWithNoPing 0, socks 2/38

    Info:MAIN:wl_status 3

    Info:MAIN:Main_OnWiFiStatusChange - WIFI_STA_CONNECTING

    Info:BL0942:Voltage pulses 2, current 0, power 0

    Info:BL0942:Voltage 0.265060, current 0.000000, power 0.000000

    Info:MAIN:Time 8, free 105520, MQTT 0, bWifi 0, secondsWithNoPing 0, socks 2/38

    Info:BL0942:Voltage pulses 1745, current 0, power 0

    Info:BL0942:Voltage 231.265060, current 0.000000, power 0.000000

    Info:MAIN:Time 9, free 105520, MQTT 0, bWifi 0, secondsWithNoPing 0, socks 2/38

    Info:BL0942:Voltage pulses 1745, current 1, power 0


    It just starts working fine with 1.3.2 so i assume all config are correct.

    Is it possible something else changed along with this ? may be new sdk isnt working for this device or something ?


    Thanks and Regards
    Sharath B K
  • #688
    p.kaczmarek2
    Moderator Smart Home
    Before we proceed, can you try:
    [BK7231T] My HTTP server, configurator, MQTT support from Home Assistant
    channge P9 role to nothing and P8 to BL0937 CF1?

    Right now I suspect that you have chosen wrong pin for CF1 role and older version works for you because it always uses default pins.

    look, here a history bl0937 changes
    https://github.com/openshwprojects/OpenBK7231T_App/commits/main/src/driver/drv_bl0937.c
    not much have changed during last days
  • #689
    sharathbk1912
    Level 7  
    I think you are right . i verified my images and feel Pwm2 is the pin looks like. Let me try that and update here .

    Update:
    It worked!! Thanks for the catch!!

    Also the power on state works well. I am using the high on poweron.

    Thanks
    Sharath b k
  • #690
    p.kaczmarek2
    Moderator Smart Home
    sharathbk1912 wrote:

    It worked!! Thanks for the catch!!

    I'm glad it worked out, sometimes it's just good to check the pin indexes twice because it's easy to confuse them.

    So, what is the next thing to be added now, in your opinion?

    I will fix the logging name/labels because it's using BL0942 for BL0937.... or just change it to BL09XX.