logo elektroda
logo elektroda
X
logo elektroda

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

p.kaczmarek2 178134 1242
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #631 20029948
    theosoft
    Level 10  
    In control.vue line 188 ff ....

         channelclick(channel){
            if (this.channels[channel]) {
              this.channels[channel] = 0;
            } else {
              this.channels[channel] = 100;
            }
    


    But just change the value is to simple, isn't it??
    regards
  • ADVERTISEMENT
  • #632 20030147
    p.kaczmarek2
    Moderator Smart Home
    If you change 100 to 1 then you will break the toggling on-off of PWM dimmer. App needs to know whether a channel is a dimmer or relay/led/something else binary.
    Helpful post? Buy me a coffee.
  • #633 20030630
    theosoft
    Level 10  
    In control.vue
    
          channelclick(channel){
            if (this.channels[channel]) {
              this.channels[channel] = 0;
            } else {
              if (this.outputchannelrolenames[channel] === 'Rel' || this.outputchannelrolenames[channel] === 'Rel_n'){
              this.channels[channel] = 1;
                      } else {
              this.channels[channel] = 100;
                      }
            }
            this.channelchange(channel);
          },
    


    Update: I successfully have done a pull request....
  • ADVERTISEMENT
  • #634 20031573
    p.kaczmarek2
    Moderator Smart Home
    Are you sure that is correct?

    Setup a device with LEDs only. And by "with LEDs" I mean setup pins to IOR_LED. IOR_LED is the same as relay but only different name, it's used to make it easier for user to see which pin is connected to relay and which to led (showing relay state).

    I think your code would still give 100 in this case.

    @sharathbk1912 and all the BL0937 team, are you still here?
    I started prelimary BL0937 testing:
    [BK7231T] My HTTP server, configurator, MQTT support from Home Assistant
    but I have to introduce external timer to my code, because the current measurement method is for testing only and not reliable
    Helpful post? Buy me a coffee.
  • #635 20031652
    theosoft
    Level 10  
    I have implemented the patch in that way and in my projekt it is ok now. I don't have a dimmer..
    I see toogleing of the value in WEBAPP between 0 and 1 and HA follows On / Off. MQTT published values are 0 and 1.
    I had some trouble regarding cache in firefox. Firefox stores very long the content of the webapp page. Deleteing cache and webpage content including restart solved that :-)

    regards
  • #636 20031713
    p.kaczmarek2
    Moderator Smart Home
    Ok, I will merge your changes, let it be that way for now.
    Helpful post? Buy me a coffee.
  • #637 20031868
    theosoft
    Level 10  
    BTW. Firefox mostly has a bad responsetime. I have to wait 5 sec :-(. Chrome does show the content of the device internal html immediately.
    Is there an explanation for that? Is it only my firefox with this behavior?

    regards
  • #638 20034962
    kuba2k2
    Level 13  
    Hello again,
    Today I was able to run ESPHome on RTL8710BN - I'm probably the first in the world to do this :D
    [BK7231T] My HTTP server, configurator, MQTT support from Home Assistant

    I've ported the core of ESPHome to work with LibreTuya, so WiFi and HomeAssistant API connection works. After I port other peripherals (such as I2C, SPI, GPIO, ADC, PWM) most sensors supported by ESPHome should work out of the box - without the need of writing new drivers by hand.

    As LibreTuya is made to be universally compatible with each platform (requiring minimal porting/HAL), it means that porting ESPHome to BK7231T/N or something else should now be a breeze...
  • ADVERTISEMENT
  • #639 20035062
    p.kaczmarek2
    Moderator Smart Home
    @kuba2k2 Nice progress with RTL, but I don't know if you aware of it or not, but RTL8710BN is a totally different chip than BK7231T/N, with different architecture and manufacturer. So you would have basically to redo all the work again in order to support Beken chips.

    And you have still 0 Beken-related code in the codebase...

    With OpenBeken HAL system, adding new platforms is very easy and I already added support for non-beken chips like BL602 and XR809. I will be also adding RTL support soon.

    theosoft wrote:
    BTW. Firefox mostly has a bad responsetime. I have to wait 5 sec :-(. Chrome does show the content of the device internal html immediately.
    Is there an explanation for that? Is it only my firefox with this behavior?

    I have just checked on Firefox and I experienced no problems.
    What do you mean by "internal html"?

    PS: BL0937 voltage/current/power metering chip is now working as well, only precision improvements left.
    Helpful post? Buy me a coffee.
  • #640 20035306
    jimbolaya
    Level 2  
    p.kaczmarek2 wrote:
    @jimbolaya it's the same as with other devices. Check if you have anything else connetced on TX/RX line. Maybe a MCU or a button or anything?


    I'm not entirely sure how do do that. I've got a few multimeters I could check resistance/circuits with. I've always been under the impression that can cause damage if you don't know what you're doing, and I don't really. I could try randomly unsoldering things like the buttons or microphone.

    I'll try again in few weeks when i have more time.
  • #641 20035338
    kuba2k2
    Level 13  
    p.kaczmarek2 wrote:
    but I don't know if you aware of it or not, but RTL8710BN is a totally different chip than BK7231T/N,

    Of course I'm aware (I'm not that stupid..).

    p.kaczmarek2 wrote:
    So you would have basically to redo all the work again in order to support Beken chips.

    No, most work is already done. I designed it so that adding new platforms is as easy as possible. I'm putting as most as I can into the common module (like web servers, MDNS clients, other libraries). Adding new platforms requires simply writing a core (GPIO, etc) and peripheral access layers (flash, I2C, wifi, etc). Everything else is already done, and this is the only thing needed before running ESPHome or something else.

    p.kaczmarek2 wrote:
    And you have still 0 Beken-related code in the codebase...

    Just because the device I have with RTL was of a higher priority. On the other hand, you have five different repositories to maintain separately, and you also needed to write a HAL for each one. Your project started a few months before mine, so naturally you have more HALs written.

    p.kaczmarek2 wrote:
    With OpenBeken HAL system, adding new platforms is very easy

    And that's exactly what I need to do in order to add new platforms. See? A "HAL" means the same for every project.
  • #642 20036184
    khoam
    Level 42  
    kuba2k2 wrote:
    Today I was able to run ESPHome on RTL8710BN - I'm probably the first in the world to do this

    kuba2k2 wrote:
    See? "HAL" means the same for any project.

    I like this approach to the "theme", ie enabling the operation of existing and proven IoT solutions for other SoCs. ESPHome does not require an Arduino Core (it's optional) which makes porting and testing on new platforms very easy, but you still need to know C ++ ;)
  • #643 20037534
    sharathbk1912
    Level 8  
    Excited to see bl0937 support . Is there a page to go about how to set it up ? Since 042 was uart based nothing much had to be done with pins . Any reference would help .

    Thanks and regards
    Sharath b k
  • #644 20037551
    p.kaczmarek2
    Moderator Smart Home
    @sharathbk1912 BL0937 driver will be improved so you might wait a week before setting it up. I will make a step by step guide for that as well.
    @jimbolaya you should test your circuit with multimeter with circuit disconnected from power, and it is not possible to damage your circuit just by probing it. Use continuity test with buzzer.
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • #645 20038527
    xabean
    Level 6  
    @p.kaczmarek2 what OS do you do development under most? Windows or Linux?

    I ask because the OpenBK7231T_App github repo has a lot of C files that have mixed line endings, both CRLF (dos or windows) and LF (Linux) -- I can make a pull request that sets the line endings to which ever one you want for you developing, and then on my side I can configure git to convert to LF line endings for me for under Linux on git checkout, and configure it to change them back when I do a git commit ... the files just have to be consistent in the first place in order for it to work correctly :)
  • #646 20038557
    pepesuriano
    Level 9  
    p.kaczmarek2 wrote:

    pepesuriano wrote:
    UART has been impossible to me and I cannot find info on how to flash with SPI.

    did you read @DarkMan1 post? he had issues with CP2102 UART to USB converter but CH340 worked for him, maybe you need second usb to uart converter as well?

    I have flashed a lot of bk devices and all of them worked so far.


    Hi, I tried with an arduino UNO (which has CH340), it's still not working, here is what I tried:

    - Wired TX and RX to arduino UNO RX and TX (it seems to be ok since I can hear the relay clicking when I hit the "read flash" button on bkwriter, if I do nothing the relay stops clicking
    - wired 3v3 from arduino to VBAT on WB2S and GND as well
    - removed 3v3 and connected 5v from arduino to 5v input of AMS1117

    The result is always the same:

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

    As mentioned, I assume RX and TX is ok since the relay starts clicking when I hit "read flash", I tried all baudrates and BK7231/BK7231N modes, nothing works for the moment :(

    A new finding that can be useful, I found that RX1 pad is connected to R1 resistor and K1 (power button), can that be part of the issues?
    Here some pictures for guidance (look trace with yellow question mark):
    [BK7231T] My HTTP server, configurator, MQTT support from Home Assistant
    [BK7231T] My HTTP server, configurator, MQTT support from Home Assistant
  • #647 20038565
    p.kaczmarek2
    Moderator Smart Home
    @xabean I am doing development on Windows in my old MSVC 2008, because I use newer MSVC for more commercial projects and it's easy for me to have two visual studios open and quickly navigate between them. Still, I will most likely add a VScode project soon as well.

    @pepesuriano this is taking too long and it's too complicated. I would suggest you a different approach. Get a soldering iron with clean tip, get flux and solder wick. Put some flux on WB2S module "legs", melt and remove the solder with the wire wick. Remove the WB2S module from board. Then program it, the same way I do it on my tutorials here on Elektroda. So just solder 4 wires to WB2S (3.3V, gnd, TX and RX). In this case you dont need CEN, just reboot by powering on and off. Remember, 3.3V, not 5V directly from USB.

    Do not be afraid of soldering. You can do it even with a cheapo few-bucks aliexpress soldering iron. Just keep tip clean, use flux and remove excell solder with wire wick.

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

    EDIT: of course second option would be to just cut RX trace and bridge it again after flashing.
    Remember to do a full flash memory read (whole 2MB) for tuya-cloudcutter guys to make OTA for similiar devices.
    Helpful post? Buy me a coffee.
  • #648 20038807
    kuba2k2
    Level 13  
    xabean wrote:
    I can make a pull request that sets the line endings to which ever one you want

    Just as a note: it's most common to use only LF endings in the git repo, and configure local git clients to convert line endings to match your OS.
  • #649 20041909
    Dark Man
    Level 13  
    I bought a new lamp from ACTION for PLN 45 (regular price)
    LSC LED Flood Light with sensor (3003366)
    Art. 3003366
    970740 v1.0
    [BK7231T] My HTTP server, configurator, MQTT support from Home Assistant

    WB3S module
    i dumped it on cloudcutter
    https://github.com/tuya-cloudcutter/tuya-cloudcutter/issues/100

    Interestingly, my first approach was that the circuit is in the main lamp housing.
    I tried to disassemble it, but the housing is not unscrewed - the glass is glued in. Heating up did not help.
    The next day, I found a hint - open the PIR sensor :)
    The smarts put the WB3S module in the PIR sensor :) The sensor housing was welded.
    [BK7231T] My HTTP server, configurator, MQTT support from Home Assistant

    The setup for her is
    P8 PWM 4
    P9 PWM 5
    P6 PIR sensor digital In
    P23 ADC - light sensor

    While the PWMs work for me, I don't know how to configure:
    P6 to turn on both PWMs for a certain amount of time
    P23 how to read the brightness and send it to HA and how to connect with P6 so that the light is only switched on when the brightness is specified
  • #650 20042617
    p.kaczmarek2
    Moderator Smart Home
    I tought I used
    git config --global core.autocrlf true
    previously but maybe I forget it or set it incorrectly. Let's see how it works now.

    I am adding hsv library.
    Helpful post? Buy me a coffee.
  • #651 20042646
    xabean
    Level 6  
    p.kaczmarek2 wrote:
    I tought I used
    git config --global core.autocrlf true
    previously but maybe I forget it or set it incorrectly. Let's see how it works now.

    I am adding hsv library.


    I added a .gitattributes in my pull request that should do the right thing, for everyone -- regardless of what people have set in
    git config --global core.autocrlf true


    it should make the repo have LF, and do what your OS wants, for "text" files on checkout.
  • #652 20042730
    rawilson
    Level 11  
    @ 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?
  • #653 20042812
    p.kaczmarek2
    Moderator Smart Home
    Dark Man wrote:

    P23 how to read brightness and send to HA

    ADC? You would have to run the ADC itself on Beken at all, I haven't touched that yet.
    https://github.com/tuya/tuya-iotos-embeded-sd.../bk7231t/bk7231t_cos/beken37adc_os/beken37adc.
    It is a pity that the functions from here are unresolved and there is no C:
    https://github.com/tuya/tuya-iotos-embeded-sd...31t/bk7231t_driver/bekken378_driver/bekken378

    Dark Man wrote:

    P6 to turn on both PWMs for a certain amount of time

    This could be done with commands, although it probably isn't complete yet, but I can try to prepare you for this support. This has to be done much sooner than the ADC.

    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 do not have the SM2135Eh driver yet because I did not have a bulb with this system. If I buy, I can add it without any problems. The SM2135Eh protocol is well known and I2C on Beken is already fired.

    Where can I buy WOJ14415, preferably Paypal?
    Helpful post? Buy me a coffee.
  • #654 20042898
    rawilson
    Level 11  
    @ p.kaczmarek2 - I bought it on the allegro, I see that it is currently for less than PLN 30. How can I define custom PINs to support i2c?
  • #655 20042899
    Betriebsdirektor
    Level 1  
    Hi,

    in Germany I bought a different LSC-Smart-Power-Plug-Model with CB2S (BK7231N) than the preconfigurated one in new_builtin_devices.c. This one has a red LED1 and a blue LED2. The platine is printed as "WF02GE" and is produced in august 2021. The packaging (see appended photos) seems to show no differnces. Your binaries working fine.

    Thank you for your efforts and work.

    void Setup_Device_LSC_Smart_Connect_Plug_CB2S_WF02GE(){
    	CFG_ClearPins();
    
    	PIN_SetPinRoleForPinIndex(6, IOR_Relay);
    	PIN_SetPinChannelForPinIndex(6, 1);
    
    	PIN_SetPinRoleForPinIndex(7, IOR_Button);
    	PIN_SetPinChannelForPinIndex(7, 1);
    
    	PIN_SetPinRoleForPinIndex(8, IOR_LED1);
    	PIN_SetPinChannelForPinIndex(8, 1);
    
    	PIN_SetPinRoleForPinIndex(26, IOR_LED2);
    	PIN_SetPinChannelForPinIndex(26, 1);
    
    	CFG_Save_SetupTimer();
    }

    Greetings
    [BK7231T] My HTTP server, configurator, MQTT support from Home Assistant [BK7231T] My HTTP server, configurator, MQTT support from Home Assistant [BK7231T] My HTTP server, configurator, MQTT support from Home Assistant
  • #656 20042907
    p.kaczmarek2
    Moderator Smart Home
    BK7231 has two I2C ports - I2C1 and I2C2 on pins strictly defined by the manufacturer.
    Helpful post? Buy me a coffee.
  • #657 20042986
    rawilson
    Level 11  
    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?
  • #658 20043122
    xabean
    Level 6  
    hey @p.kaczmarek2 - I'm trying to figure out how best to make this line of code in the HTTP server not always respond with "OFF" even after executing a "Power1+on" command.

    https://github.com/openshwprojects/OpenBK7231T_App/blob/main/src/httpserver/http_fns.c#L1150

    I'm trying to use the OpenBK app to control power on my 3d printer with Octoprint, and the Octoprint Tasmota plugin that talks directly to the HTTP interface, not over MQTT. It's _so close_ to working, I just need http_fn_cm to respond correctly with ON/OFF state.

    I noticed there's a variable called g_buttons that has all the expected pin states, which can get out-of-sync with the hardware state if you reconfigure a pin to be inverting or not (LED_N v.s. LED)

    Would a new function in HAL for "get GPIO configuration" that returns the pin direction (input, output) and state (high, low) that can be used in http_fns.c to ask the hardware what the current state of a specific GPIO pin is, after CMD_ExecuteCommand has executed? It could even reduce the need on having the current state (high, low) in g_buttons.
  • #659 20043133
    p.kaczmarek2
    Moderator Smart Home
    @xabean Tasmota HTTP is on my TODO list, I know this protocol and I used it for example here:
    https://www.elektroda.com/rtvforum/topic3789324.html
    I also is required on for Tasmota-Control app from Google play compatibility

    My original idea for handling replies was to pass the COMMAND_FLAG_SOURCE_HTTP flag with command execution and generate JSON reply in the command itself. I chose this way because the reply content depends on the command you have sent. I have planned for this code to be only a placeholder and execute if command didnt produce any json string yet:
    [BK7231T] My HTTP server, configurator, MQTT support from Home Assistant
    I can look into it sooner, if you need it.

    Right now I am not sure why would your proposed change be required.

    And the On/Off state from Tasmota HTTP is obviously before inverting for "LED_N" and "Relay_N".
    Helpful post? Buy me a coffee.
  • #660 20043218
    Dark Man
    Level 13  
    p.kaczmarek2 wrote:
    Dark Man wrote:
    P23 how to read brightness and send to HA

    ADC? You would have to run the ADC itself on Beken at all, I haven't touched that yet.
    https://github.com/tuya/tuya-iotos-embeded-sd...1t/bk7231t_os/beken378/driver/saradc/saradc.h
    It is a pity that the functions from here are unresolved and there is no C:
    https://github.com/tuya/tuya-iotos-embeded-sd...1t_os/beken378/func/user_driver/BkDriverAdc.h

    Dark Man wrote:
    P6 to turn on both PWMs for a certain amount of time

    This could be done with commands, although it probably isn't complete yet, but I can try to prepare you for this support. This has to be done much sooner than the ADC.

    It is a pity that the ADC is not working at the moment, without it, the lamp will be activated during the day, if you make additional commands for temporary switching on.
    In that case, at the moment I will do transplantations on ESP12, but I must admit that I will probably not finish on this one lamp, so when there is ADC and command support (for time switching), I will probably buy another one, the more that maybe the cloudcutter will handle it then.

Topic summary

The discussion revolves around the development and implementation of custom firmware for devices using the BK7231T and BK7231N chips, particularly focusing on creating a mini HTTP server, MQTT support, and integration with Home Assistant. Users share their experiences flashing various smart devices, troubleshooting issues related to UART connections, and configuring GPIO pins for different functionalities. The conversation also touches on the challenges of maintaining WiFi connectivity, the importance of proper pin configuration, and the potential for using I2C for additional device control. Several users report successful firmware updates and the addition of new features, including support for various sensors and devices.
Summary generated by the language model.
ADVERTISEMENT