logo elektroda
logo elektroda
X
logo elektroda

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

p.kaczmarek2 178155 1242
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #601 20025740
    echojjj
    Level 8  
    p.kaczmarek2 wrote:
    Here is the basic draft of what has to be done:
    1. Cut the RX and TX tracks (between TuyaMCU and CB2S)
    2. Read the flash memory of CB2S (to be sure, do it several times) and send flash bin to tuya-cloudcutter guys so futher devices can be programmed remotely
    3. Flash OpenBK
    4. Connect tracks again
    5. Try the dpIDs from Tasmota page.
    See this: https://github.com/openshwprojects/OpenBK7231T_App/pull/75 for reference
    OpenBK script:
    // start MCU driver
    startDriver TuyaMCU
    // let's say that channel 1 is dpid1 - fan on/off
    setChannelType 1 toggle
    // map dpid1 to channel1, var type 1 (boolean)
    linkTuyaMCUOutputToChannel 1 1 1


    Check if it works, you can also do the same for light:
    // let's say that channel 2 is dpid9 - light on/off
    setChannelType 2 toggle
    // map dpid2 to channel2, var type 1 (boolean)
    linkTuyaMCUOutputToChannel 2 1 2


    Check if it works.


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

    It works. Got two relays toggling on/off. Click Click! Wahoo!!! Now I'll have to find a fan and light to connect to for further testing.

    p.kaczmarek2 wrote:
    I see they have several dpIDs:
    Quote:
    dpid1 - fan on/off
    dpid3 - fan speed (0 = low, 1 = med, 2 = hi)
    dpid6 - self timer (0 = off, 1 = 1hr, 2 = 2hr, 4 = 4hr, 8 = 8hr)
    dpid9 - light on/off
    dpid7 - timer remaining
    dpid17 - ???



    dpid9 - light on/off is confirmed
    setChannelType 2 toggle
    linkTuyaMCUOutputToChannel 9 1 2


    Added after 4 [hours] 9 [minutes]:

    @p.kaczmarek2
    Did I do this fan speed correctly? I really need to hook this thing up to my ceiling fan for testing, but I'm only one person, and I'm afraid I'd need 2 people to do it! I have a 3-speed portable fan in the back room I will try to hook it up to that for now.

    I added to my script:
    //channel 3 is dpid3 - fan speed
    setChannelType 3 LowMidHigh
    // map dpid3 to channel3, var type 4 (enum)
    linkTuyaMCUOutputToChannel 3 4 3


    And now I have fan speed control in the UI
    [BK7231T] My HTTP server, configurator, MQTT support from Home Assistant
  • ADVERTISEMENT
  • #602 20026132
    p.kaczmarek2
    Moderator Smart Home
    Hey, great progress @echojjj , I will have more time to comment later, but first of all, can you double-check if the communication is two way, I mean, can you control relays from both OpenBK and the RF remote?

    @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?

    The flash procedure is following:
    1. connect UART to PC , start bkwriter
    [BK7231T] My HTTP server, configurator, MQTT support from Home Assistant
    2. select UART in bkWriter, press Read (it should start trying to connect), also better set full 2mb read
    [BK7231T] My HTTP server, configurator, MQTT support from Home Assistant
    3. connect the second cable for power, the bkWriter should start actively reading
    [No screenshot, but you will see the read progress on the UI and a progress bar filling with green bars]
    4. wait for read finish, done
    Helpful post? Buy me a coffee.
  • #603 20026207
    echojjj
    Level 8  
    p.kaczmarek2 wrote:
    can you double-check if the communication is two way, I mean, can you control relays from both OpenBK and the RF remote?

    Yes I can control the relays from both OpenBK and the RF remote. Is it possible to make the UI update/sync whenever I use the remote? The log output is like:
    Info:GEN:CHANNEL_Set channel 2 has changed to 1
    or
    Info:GEN:CHANNEL_Set channel 2 has changed to 0
    regardless of how I control the light.
  • #604 20027255
    echojjj
    Level 8  
    Well I got up on the ladder and put the fan controller in the fan. Fan on/off works. Light on/off works. Fan speed Lo/Mid/High also works.

    I found dpid17 = beep on/off so I added to the script:
    //dpId 17 = beep on/off
    setChannelType 6 toggle
    linkTuyaMCUOutputToChannel 17 1 6
  • #605 20027286
    p.kaczmarek2
    Moderator Smart Home
    Great progress! I've been busy with learning tuya-cloudcutter along with profile creation for new devices but there are still some issues to resolve.

    @echojjj , what about the timer?

    Btw, @echojjj , I am not sure if you already got this, but if you map, for example, the beeper to to channel 6, you can easily control it from MQTT. Home assistant Yaml:
    
    switch:
      - platform: mqtt
        name: "Beeper"
        state_topic: "obk61B58A1C/6/get"
        command_topic: "obk61B58A1C/6/set"
        qos: 1
        payload_on: 0
        payload_off: 1
        retain: true
    

    this should work for relays as well, of course...

    basically, the way to access channels is by :
    
        state_topic: "obk61B58A1C/6/get"
    

    
        command_topic: "obk61B58A1C/6/set"
    


    Added after 10 [hours] 51 [minutes]:

    Ok @echojjj , now regarding the timer....
    What do we know?

    Quote:

    dpid6 - self timer (0 = off, 1 = 1hr, 2 = 2hr, 4 = 4hr, 8 = 8hr)
    dpid7 - timer remaining

    Do we know, from Tasmota docs, what is the type here for dpid6 and 7? Are they enums? Or raws?

    The dpid6 is to set and dpid7 is read only? Is that correct?

    I added two debug channel field types, let's test how it works.
    
    // here you will be able to enter value
    setChannelType 10 TextField
    // this will only display value 
    setChannelType 11 ReadOnly
    

    channel numbers can be any value (that is not used yet)
    
    // linkTuyaMCUOutputToChannel dpId varType channelID 
    // dpId  6 is for setting, link to text field
    linkTuyaMCUOutputToChannel 6 enum 10
    // dpId  7 is for reading, link to display field
    linkTuyaMCUOutputToChannel 7 val 11
    

    I am not sure if "enum" and "val" are correct here, you must try if it works and if not then try different modes...
    [BK7231T] My HTTP server, configurator, MQTT support from Home Assistant

    so add the scripts command i shown (for example, from console without restarting, if you dont want to change your config, or by config and then restart)
    you will get smth like this:
    [BK7231T] My HTTP server, configurator, MQTT support from Home Assistant
    Test it by entering, for example, 1 to text field, press "Set" (this will send 1h delay),
    then click "Return to menu" to refresh page, and check if value frm field 11 (timer remaining) changes...

    of course those channels types are for testing only, we will create a better UI later

    WARNING!! you will have to do OTA with new version of firmware from me, but OTA removes littlefs text autoexec config (everything else stays intact). Please make a backup of your text config from little FS. Post your config text here for reference or something like that. Is that clear?
    Updated binary for BK7231N (CB2S) below:
    Helpful post? Buy me a coffee.
  • #606 20027910
    echojjj
    Level 8  
    p.kaczmarek2 wrote:
    Ok @echojjj , now regarding the timer....
    What do we know?

    p.kaczmarek2 wrote:
    The dpid6 is to set and dpid7 is read only? Is that correct?

    yes,
    dpId 6 = set timer
    dpId 7 = timer remaining

    p.kaczmarek2 wrote:
    Do we know, from Tasmota docs, what is the type here for dpid6 and 7? Are they enums? Or raws?

    I got dpId6 is dataType 4-DP_TYPE_ENUM and dpId7 is dataType 2-DP_TYPE_VALUE magically from the logs:

    Info:TuyaMCU:TUYAMCU received: 55 AA 03 07 00 05 06 04 00 01 00 19
    Info:TuyaMCU:TuyaMCU_ProcessIncoming: processing command 7 (State) with 12 bytes
    Info:TuyaMCU:TuyaMCU_ParseStateMessage: processing dpId 6, dataType 4-DP_TYPE_ENUM and 1 data bytes
    Info:TuyaMCU:TuyaMCU_ParseStateMessage: raw data 1 byte:

    Info:TuyaMCU:TUYAMCU received: 55 AA 03 07 00 08 07 02 00 04 00 00 00 00 1E
    Info:TuyaMCU:TuyaMCU_ProcessIncoming: processing command 7 (State) with 15 bytes
    Info:TuyaMCU:TuyaMCU_ParseStateMessage: processing dpId 7, dataType 2-DP_TYPE_VALUE and 4 data bytes
    Info:TuyaMCU:TuyaMCU_ParseStateMessage: raw data 4 int: 0

    p.kaczmarek2 wrote:
    WARNING!! you will have to do OTA with new version of firmware from me, but OTA removes littlefs text autoexec config (everything else stays intact). Please make a backup of your text config from little FS. Post your config text here for reference or something like that. Is that clear?

    Got it! I have actually had to OTA a few times now because if I change my config and press SAVE button it doesn't always save correctly. Like if I have made the file smaller, it keeps some that I have deleted at the end of the file. Like this, this is the last line after I pressed SAVE (and after reloading the file in the editor):
    linkTuyaMCUOutputToChannel 7 2 8nnel 17 1 6

    Here's my config. I think it's correct.
    // start MCU driver
    startDriver TuyaMCU
    // let's say that channel 1 is dpid1 - fan on/off
    setChannelType 1 toggle
    // map dpid1 to channel1, var type 1 (boolean)
    linkTuyaMCUOutputToChannel 1 1 1
    // let's say that channel 2 is dpid9 - light on/off
    setChannelType 2 toggle
    // map dpid9 to channel2, var type 1 (boolean)
    linkTuyaMCUOutputToChannel 9 1 2
    //channel 3 is dpid3 - fan speed
    setChannelType 3 LowMidHigh
    // map dpid3 to channel3, var type 4 (enum)
    linkTuyaMCUOutputToChannel 3 4 3
    //dpId 17 = beep on/off
    setChannelType 6 toggle
    linkTuyaMCUOutputToChannel 17 1 6
    //
    //
    //dpId 6, dataType 4-DP_TYPE_ENUM = set timer
    setChannelType 7 TextField
    linkTuyaMCUOutputToChannel 6 4 7
    //
    //
    //dpId 7, dataType 2-DP_TYPE_VALUE = timer remaining
    setChannelType 8 ReadOnly
    linkTuyaMCUOutputToChannel 7 2 8


    But something's a little off. I'll test more and try to find out what exactly is happening.
    It's like if I set 1 and refresh time remaining = 60. Then, if I set 2 and refresh timer remaining = 60. Then, if I set 1 and refresh timer remaining = 120. I haven't quite figured that out.
    [BK7231T] My HTTP server, configurator, MQTT support from Home Assistant
    Also setting the timer to 0 doesn't do anything. There's no way to cancel the timer on the RF remote either. Maybe just turn fan off I guess.

    p.kaczmarek2 wrote:
    I am not sure if you already got this, but if you map, for example, the beeper to to channel 6, you can easily control it from MQTT.

    Yes! I have already added to Home Assistant and already have voice control for my fan and light using Alexa via Node-RED!
    [BK7231T] My HTTP server, configurator, MQTT support from Home Assistant

    p.kaczmarek2 wrote:
    basically, the way to access channels is by :
    state_topic: "obk61B58A1C/6/get"

    command_topic: "obk61B58A1C/6/set"

    MQTT topic "get" is missing on this updated firmware?

    Added after 3 [hours] 57 [minutes]:

    @p.kaczmarek2 Can I do something like this to set fan speed?

    MQTT publish
    topic: ceiling-fan/7/set
    payload: x

    x = 0/1/2
  • ADVERTISEMENT
  • #607 20028295
    p.kaczmarek2
    Moderator Smart Home
    echojjj wrote:

    @p.kaczmarek2 Can I do something like this to set fan speed?

    MQTT publish
    topic: ceiling-fan/7/set
    payload: x

    x = 0/1/2

    it should be working, try it from Home Assistant MQTT publish tool (the one used to ease the development)


    echojjj wrote:

    Got it! I have actually had to OTA a few times now because if I change my config and press SAVE button it doesn't always save correctly. Like if I have made the file smaller, it keeps some that I have deleted at the end of the file. Like this, this is the last line after I pressed SAVE (and after reloading the file in the editor):
    linkTuyaMCUOutputToChannel 7 2 8nnel 17 1 6

    Really? It must be a bug, I will check this out. It seems that our LittleFS contributor didn't test it well enough before submiting a pull request.
    Great find.


    echojjj wrote:

    But something's a little off. I'll test more and try to find out what exactly is happening.
    It's like if I set 1 and refresh time remaining = 60. Then, if I set 2 and refresh timer remaining = 60. Then, if I set 1 and refresh timer remaining = 120.

    First of all: are you aware that if you set a timer to certain number of hours, and refresh by browser "refresh" button, it will resend the 'set the timer' command? This is because the command is a get request to http server. You should refresh by "return to menu" button.
    I will improve the html page later, maybe make it autorefreshing with Ajax.

    I will add soon ability to set better names for channels so you can create labels like "Fan speed", "Set timeout [h]", "Remaining minutes", etc. What is also left to do?
    Helpful post? Buy me a coffee.
  • #608 20028337
    echojjj
    Level 8  
    p.kaczmarek2 wrote:
    You should refresh by "return to menu" button.

    Yes this is how I do it.
  • #609 20028347
    p.kaczmarek2
    Moderator Smart Home
    And the issue still happens?

    What if you wait few seconds between refreshes, maybe TuyaMCU needs to send back a reply?

    Aside from that, are there any other problems or issues?
    Helpful post? Buy me a coffee.
  • #610 20028605
    xabean
    Level 6  
    I got JTAG working, it's the same pins used for SPI programming, so I didn't need to rewire anything. Drop the below config into bk7321t.cfg, and run openocd -f bk7321t.cfg to start it up.

    
    source [find interface/raspberrypi2-native.cfg]
    
    ## https://docs.microsoft.com/en-us/windows/iot-core/learn-about-hardware/pinmappings/pinmappingsrpi
    ##
    ## CEN  -> (bcm)GPIO 22 / RPI3b pin 15
    ## SCLK -> (bcm)GPIO 11 / RPI3b pin 23
    ## CSN  -> (bcm)GPIO 08 / RPI3b pin 24
    ## SI   -> (bcm)GPIO 10 / RPI3b pin 19
    ## SO   -> (bcm)GPIO 9 / RPI3b pin 21
    
    
    # Each of the JTAG lines need a (bcm) gpio number set:
    #                     tck tms tdi tdo
    bcm2835gpio_jtag_nums 11  8   10  9
    
    #                     srst
    bcm2835gpio_srst_num  22
    
    # we only have CEN (aka chip enable, system reset)
    reset_config srst_only
    
    # CEN is normally pulled high, but sometimes it can help to force it high, not just low.
    reset_config srst_push_pull
    
    # on connect, deassert (reset to HIGH) the SRST pin
    reset_config connect_deassert_srst
    
    # we have no TRST pin, tell OpenOCD to imagine it's tied to SRST.
    reset_config srst_pulls_trst
    
    # use JTAG.
    transport select jtag
    
    # go slow.
    adapter speed 100
    
    # wait 200ms after releasing srst before we send JTAG commands over TMS,
    # we will never reset into halt because we have no tRST pin :(
    adapter srst delay 200
    
    if { [info exists CHIPNAME] } {
       set _CHIPNAME $CHIPNAME
    } else {
       set _CHIPNAME bk7321t
    }
    
    if { [info exists ENDIAN] } {
       set _ENDIAN $ENDIAN
    } else {
      # this defaults to a little endian
       set _ENDIAN little
    }
    
    if { [info exists CPUTAPID] } {
       set _CPUTAPID $CPUTAPID
    } else {
       set _CPUTAPID 0x15968001
    }
    
    jtag newtap $_CHIPNAME cpu -irlen 4 -expected-id $_CPUTAPID
    
    set _TARGETNAME $_CHIPNAME.cpu
    target create $_TARGETNAME arm966e -endian $_ENDIAN -chain-position $_TARGETNAME
    


    Then you can read the flash chip ID over the OpenOCD telnet interface on port 4444,

    
    xabean@raspberrypi:~ $ telnet localhost 4444
    Trying 127.0.0.1...
    Connected to localhost.
    Escape character is '^]'.
    Open On-Chip Debugger
    > mww 0x00803000 74
    > mdw 0x00803010 1
    0x00803010: 001c7015
    
    > bk7321t.cpu arm reg                
    System and User mode registers
          r0: 00000001       r1: 00000069       r2: 00090080       r3: 00100000 
          r4: 00408b5e       r5: 00000001       r6: 00405d80       r7: 00000010 
          r8: 08080808       r9: 09090909      r10: 10101010      r11: 11111111 
         r12: 0000000a   sp_usr: 00420870   lr_usr: 00016dfd       pc: 00016dc2 
        cpsr: 6000003f 
    
    FIQ mode shadow registers
      r8_fiq: 00000000   r9_fiq: 00000000  r10_fiq: 00000000  r11_fiq: 00000000 
     r12_fiq: 00000000   sp_fiq: 00400fe0   lr_fiq: b51edf9b spsr_fiq: 00000010 
    
    Supervisor mode shadow registers
      sp_svc: 004027a0   lr_svc: 00016dc6 spsr_svc: 6000003f 
    
    Abort mode shadow registers
      sp_abt: 004007e0   lr_abt: df9ff7e5 spsr_abt: 00000010 
    
    IRQ mode shadow registers
      sp_irq: 00401fd0   lr_irq: 00059ae8 spsr_irq: 6000001f 
    
    Undefined instruction mode shadow registers
      sp_und: 004007e0   lr_und: bb0de3bc spsr_und: 00000010 
    
    
    
  • #611 20028636
    kuba2k2
    Level 13  
    Nice! Finally something useful.
    Would you mind if I borrowed this config file for my LibreTuya project (in the future)? I can give you proper attribution, of course.
  • #612 20028639
    xabean
    Level 6  
    kuba2k2 wrote:
    Nice! Finally something useful.
    Would you mind if I borrowed this config file for my LibreTuya project (in the future)? I can give you proper attribution, of course.


    Anybody can use it. No attribution required.
  • ADVERTISEMENT
  • #613 20028689
    echojjj
    Level 8  
    p.kaczmarek2 wrote:
    What if you wait few seconds between refreshes, maybe TuyaMCU needs to send back a reply?
    Aside from that, are there any other problems or issues?

    You're right... I didn't check logs on this initially but it's true I have to wait.

    echojjj wrote:
    MQTT publish
    topic: ceiling-fan/7/set
    payload: x

    x = 0/1/2

    p.kaczmarek2 wrote:
    it should be working, try it from Home Assistant MQTT publish tool (the one used to ease the development)

    I don't think it works. Do I need to recompile?

    p.kaczmarek2 wrote:
    I will improve the html page later, maybe make it autorefreshing with Ajax.
    I will add soon ability to set better names for channels so you can create labels like "Fan speed", "Set timeout [h]", "Remaining minutes", etc. What is also left to do?

    Both would be major improvements! Looking forward to it!

    Also, I have no mqtt topic "get" with this version. It would be helpful to follow state.
  • #614 20028736
    p.kaczmarek2
    Moderator Smart Home
    @xabean good work, which JTAG programmer do you use with that? Would ST-Link V2 work?
    From a quick glance at opencd documentation it seems yet:
    Quote:

    Interface Driver: st-link
    This is a driver that supports STMicroelectronics adapters ST-LINK/V2 (from firmware V2J24) and STLINK-V3, thanks to a new API that provides directly access the arm ADIv5 DAP.

    The new API provide access to multiple AP on the same DAP, but the maximum number of the AP port is limited by the specific firmware version (e.g. firmware V2J29 has 3 as maximum AP number, while V2J32 has 8). An error is returned for any AP number above the maximum allowed value.

    Note: Either these same ad


    @xabean which platform have you used for SPI flashing? I have one locked device and will need to unlock it someday. @btsimonh managed to flash by SPI on Raspberry, but reported problems with Arduino

    echojjj wrote:

    echojjj wrote:
    MQTT publish
    topic: ceiling-fan/7/set
    payload: x

    x = 0/1/2

    p.kaczmarek2 wrote:
    it should be working, try it from Home Assistant MQTT publish tool (the one used to ease the development)

    I don't think it works. Do I need to recompile?

    it should work. Also, judging from your config here:
    
    //channel 3 is dpid3 - fan speed
    setChannelType 3 LowMidHigh
    // map dpid3 to channel3, var type 4 (enum)
    linkTuyaMCUOutputToChannel 3 4 3

    the Fan Speed channel has assigned number 3, not 7. Maybe you are just using wrong number?


    @kuba2k2 how are things going, I remember you were toying around Realtek, have you managed to get OTA working? It would be a great contribution for OpenBeken, as I am ready to port it to RTL devices soon.
    Helpful post? Buy me a coffee.
  • #615 20028771
    kuba2k2
    Level 13  
    p.kaczmarek2 wrote:
    @kuba2k2 how are things going, I remember you were toying around Realtek, have you managed to get OTA working? It would be a great contribution for OpenBeken, as I am ready to port it to RTL devices soon


    Not yet, I was nearly able to run a barebones version of ESPHome on RTL, but it also needed MDNS library, which I didn't port yet. So I started upgrading vendor LWIP to v2.0.0, which has built in MDNS support (I wanted something platform independent). Then I had a temporary lack of time, but I'll get back to it.

    As for OTA, I do actually have a great idea for implementing it well on all platforms. If you still want to manage a separate SDK, then good luck, as compiling it can sometimes be a real pain...
  • #616 20028841
    p.kaczmarek2
    Moderator Smart Home
    Actually, the compiling is very simple and it even works online on github, so I don't even need to have compilers on my machine in order to run and test OpenBeken. And that is for all my platforms, BK7231T, BK7231N, XR809 and BL602.
    Look, all of that was done automatically, can you believe it? I just did a push from Sourcetree and voila!
    [BK7231T] My HTTP server, configurator, MQTT support from Home Assistant

    I also don't need to worry about LWIP 2.0, it is already in all SDKs (maybe except XR809 but I will update it if it's needed).

    As per portable OTA... I might or might not do it, but it's certainly possible. It's debatable whether that's needed, because if RTL has an already working OTA example in the SDK, then it might be faster (even in the longer term) to use it instead of making one from scratch.

    PS: For the record, keep in mind that by "portable OTA" I mean of course the portable code for writing to flash memory, which can be very specific... because the "download OTA file from HTTP server" or "receive OTA file drag&dropped into Chrome" parts are already portable in my SDK so there is no need to worry about them.
    PS2: Of course, did I mention that I support two ways of getting OTA file? By sending HTTP request to github URL directly or by drag and dropping file from file explorer to OpenBeken page in web browser?
    Helpful post? Buy me a coffee.
  • #617 20028868
    kuba2k2
    Level 13  
    p.kaczmarek2 wrote:
    Look, all of that was done automatically, can you believe it? I just did a push from Sourcetree and voila!

    Yes, I have GitHub actions in most of my more-serious repos.

    p.kaczmarek2 wrote:
    I also don't need to worry about LWIP 2.0, it is already in all SDKs (maybe except XR809 but I will update it if it's needed).

    I didn't know that. I know that Realtek's official SDK doesn't have 2.0.0. Maybe Tuya SDKs do have it updated, but afaik it doesn't.

    p.kaczmarek2 wrote:
    As per portable OTA... I might or might not do it, but it's certainly possible. It's debatable whether that's needed, because if RTL has an already working OTA example in the SDK, then it might be faster (even in the longer term) to use it instead of making one from scratch.

    Well, I'll definitely do it. Then making OTA for new platforms will just require providing a flash access layer. These vendor examples suck. Why should I stick to a different format for each vendor? I'm also not going to reinvent the wheel, but use a format that's already widely recognized and standardized. After all, OTA is just a way of writing flash by the MCU itself.
    I might publish this as a separate library, so that others could use it, even in projects not related to Tuya.
    It's just that I hate all Tuya's software solutions - their bloated, often modified SDKs, absolutely awful build systems, weird, undocumented and proprietary OTA formats.... you can recognize Chinese code without even looking at their broken-english code comments.

    p.kaczmarek2 wrote:
    Actually, the compiling is very simple and it even works online on github, so I don't even need to have compilers on my machine

    PlatformIO has ready to use GitHub actions, and also runs straight on GitHub. It also runs on every other Windows/Linux/Mac machine which has Python. You don't need Cygwin, MinGW, Msys or anything else to compile natively. You have full VSCode and other IDE support, like code analysis and completion. It's well recognized, very popular and standardized.

    I just don't see any reason to write or use bad code anymore.
  • #618 20028879
    p.kaczmarek2
    Moderator Smart Home
    kuba2k2 wrote:
    These vendor examples suck. Why should I stick to a different format for each vendor?


    Are you saying that you are dropping the possibility of doing tuya-cloudcutter hack for RTL devices? I mean, the devices before flashing it for the first time.
    Helpful post? Buy me a coffee.
  • #619 20029205
    echojjj
    Level 8  
    p.kaczmarek2 wrote:
    the Fan Speed channel has assigned number 3, not 7. Maybe you are just using wrong number?

    Yes you're right... tired eyes and sevens taking over the brain - I apologize.
  • #620 20029312
    xabean
    Level 6  
    p.kaczmarek2 wrote:
    @xabean good work, which JTAG programmer do you use with that? Would ST-Link V2 work?


    Yes, as long as ST-Link V2 does 3.3v, it should be fine. Normal JTAG, not SWD+DAP, I couldn't get SWD to negotiate correctly with the bk7231t.

    p.kaczmarek2 wrote:
    @xabean which platform have you used for SPI flashing? I have one locked device and will need to unlock it someday. @btsimonh managed to flash by SPI on Raspberry, but reported problems with Arduino


    I mostly followed the work of @btsimonh, everything done on a Raspberry PI. I'm not an expert I just read a bunch of code and documentation and tried to think through it all!

    The most interesting part of the process was understanding that the bk7231t by default doesn't let you talk to the onboard flash over SPI without first telling it you want to talk to the flash by sending it a whole bunch of 0xD2 bytes over SPI first. That oddity may be what prevented most arduino SPI programmer code from working correctly -- you couldn't tell the bk7231t to switch into SPI mode. I actually managed to use flashrom to read/write the EN25QH16B flash by basically putting this code into a stand alone spimode.py script that just flips the bk7231t into "flash spi mode":

    
    # from bkutils/chip/BK3435DownloadFormat.py
    def CHIP_BK3435_Reset(spi_downloader, DownFormat):
        spi_downloader.ChipReset()
        send_buf = bytearray(150)
        for _ in range(150):
            send_buf[0] = 0xD2
            reply = spi_downloader.spi.xfer2(send_buf)
    


    One thing I did notice in the bk7231t SDK is that if you compile your app with JTAG support -- the SDK has #ifdef in the GPIO functions to prevent you from changing the configuration of the JTAG pins. It will just skip over any request to change them input/output, high/low etc. I think "normal" firmware (that doesn't have the #ifdef for JTAG) can cause JTAG to break because it's changed the configuration of those pins.
  • #621 20029315
    p.kaczmarek2
    Moderator Smart Home
    @echojjj also, are you sure about the changes not being send over MQTT? I think that MQTT update should be sent when TuyaMCU changes the value of, for example, remaining time in minutes...
    [BK7231T] My HTTP server, configurator, MQTT support from Home Assistant
    Ah... maybe you are correct... it seems that publish call for missing for custom channels....
    https://github.com/openshwprojects/OpenBK7231...mmit/588938f303eb5a1ae8654d33a0710e0aefff2bab
    Try the updated firmware attached below:
    Helpful post? Buy me a coffee.
  • #622 20029509
    theosoft
    Level 10  
    Hello,
    Three remarks / Bugs ??
    1. OTA directly from Github failes. HTTP vs. HTTPS. Device log says: "not found"
    2. Webapp server down ? Git is also empty... Any change i missed? I host webapp from my server and just tested it today with the official source
    Update: Effect is related to Pi-hole :-) ... somehow
    Added after 11 [minutes]:
    3.
    What is the right value for "switch" ??
    This is in the log, when i use the buttons on the device ...

    
    Info:MQTT:Publishing 1 = 0 
    Info:MQTT:Publishing 1 = 100 
    Info:MQTT:Publishing 1 = 0 
    Info:MQTT:Publishing 1 = 100 
    


    here is the log, when homeassistant is used for switching ...
    
    
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic br-ks-811-3-001/1/set
    Info:MQTT:MQTT in topic br-ks-811-3-001/1/set
    Info:MQTT:channelSet topic 4205788
    Info:MQTT:channelSet part topic 1/set
    Info:MQTT:channelSet channel 1
    
    Info:MQTT:MQTT client in mqtt_incoming_data_cb data is 1 for ch 1
    Info:MQTT:Publishing 1 = 1 
    
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic br-ks-811-3-001/1/set
    Info:MQTT:MQTT in topic br-ks-811-3-001/1/set
    Info:MQTT:channelSet topic 4205788
    Info:MQTT:channelSet part topic 1/set
    Info:MQTT:channelSet channel 1
    
    Info:MQTT:MQTT client in mqtt_incoming_data_cb data is 0 for ch 1
    Info:MQTT:Publishing 1 = 0 
    
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic br-ks-811-3-001/1/set
    Info:MQTT:MQTT in topic br-ks-811-3-001/1/set
    Info:MQTT:channelSet topic 4205788
    Info:MQTT:channelSet part topic 1/set
    Info:MQTT:channelSet channel 1
    
    Info:MQTT:MQTT client in mqtt_incoming_data_cb data is 1 for ch 1
    Info:MQTT:Publishing 1 = 1 
    


    0,1 vs 0,100


    There is a missmatch in the channel value. I think 100 is wrong .... (Dimmer max value?)

    regards
  • #623 20029555
    p.kaczmarek2
    Moderator Smart Home
    theosoft wrote:

    2. Webapp server down ? Git is also empty... Any change i missed? I host webapp from my server and just tested it today with the official source

    Are you sure about that?
    App works for me.
    [BK7231T] My HTTP server, configurator, MQTT support from Home Assistant


    theosoft wrote:

    What is the right value for "switch" ??
    There is a missmatch in the channel value. I think 100 is wrong .... (Dimmer max value?)

    Let's check...
    [BK7231T] My HTTP server, configurator, MQTT support from Home Assistant
    Hm it seems you are correct. But does it affect the Home Assistant in any negative way?
    The 100 is here because the Toggle code was changed to also work with dimmers, but maybe it should be smart enough to detect how is the channel used.
    Helpful post? Buy me a coffee.
  • #624 20029562
    theosoft
    Level 10  
    Yes, homeassistant switch isn't updated correct. Switch symbol follows to "on" (0), but stays on, because of the 100....

    Edit: i am on 1.2.1 :-) OTA using webapp is ok (drag & Drop)
  • #625 20029567
    p.kaczmarek2
    Moderator Smart Home
    theosoft wrote:

    1. OTA directly from Github failes. HTTP vs. HTTPS. Device log says: "not found"

    Github supports both HTTP and HTTPS so if there is some issue with HTTPS you can just use HTTP URL.

    The older versions had too small buffer for longer links but it's fixed now as well, otherwise you'll get:
    
    Info:HTTP_CLIENT:Parse url http://github.com/openshwprojects/OpenBK7231T_App/releases/download/1.2.1/OpenBK7231T_1.2.1.rbl
    
    Info:HTTP_CLIENT:host: 'github.com', port: 80
    Error:HTTP_CLIENT:Path str is too small (64 >= 79)
    Error:HTTP_CLIENT:httpclient_parse_url returned -7
    
    Error:HTTP_CLIENT:httpclient_send_header is error,ret = -7
    Error:HTTP_CLIENT:httpclient_send_request is error,ret = -7
    


    Added after 8 [minutes]:

    theosoft wrote:
    Yes, homeassistant switch isn't updated correct. Switch symbol follows to "on" (0), but stays on, because of the 100....


    Ok, is this what you needed?
    https://github.com/openshwprojects/OpenBK7231...mmit/de813f9d73270aec7b88a2b81223f867d592ab00
    Please double check and report any futher issues, I will try to fix them ASAP
    Helpful post? Buy me a coffee.
  • #626 20029596
    theosoft
    Level 10  
    My log from OTA http tryout ...
    
    Info:HTTP_CLIENT:Parse url http://github.com/openshwprojects/OpenBK7231T_App/releases/download/1.2.1/OpenBK7231N_1.2.1.rbl
    Info:HTTP_CLIENT:host: 'github.com', port: 80
    Info:HTTP_CLIENT:HAL_TCP_Establish: created socket 2
    Error:HTTP_CLIENT:success to establish tcp, fd=2
    Debug:HTTP_CLIENT:Written 156 bytes
    Info:OTA:init OTA, startaddr 0x12a000
    Info:OTA:
    myhttpclientcallback state 0 total 0/0
    Info:HTTP_CLIENT:httpclient_recv 161 bytes has been read
    Debug:HTTP_CLIENT:Reading headersHTTP/1.1 301 Moved Permanently
    Debug:HTTP_CLIENT:Read header : Content-Length: 0
    Debug:HTTP_CLIENT:Read header : Location: https://github.com/openshwproje
    Error:HTTP_CLIENT:Could not found
    Error:HTTP_CLIENT:httpclient_recv_response is error,ret = -43
    Error:HTTP_CLIENT:closesocket(2) error -1
    Info:OTA:
    Info:OTA:close OTA, addr 0x12a000
    


    BTW: When OTA file receive NOT ok, don't start OTA/RESET :-)

    Added after 4 [minutes]:
    p.kaczmarek2 wrote:


    Ok, is this what you needed?
    https://github.com/openshwprojects/OpenBK7231...mmit/de813f9d73270aec7b88a2b81223f867d592ab00
    Please double check and report any futher issues, I will try to fix them ASAP


    Quick check ....

    Hmmm, why not inside of the loop? "Find right value" per channel? What happens in mixed configs?
    Quick check 2:
    A single query... so may work ...
    Real check. flashing 1.2.2 solved it. Now the value toogles between 0 and 1. HA is updated correct.

    Thank you :-)

    regards...
  • ADVERTISEMENT
  • #627 20029822
    kuba2k2
    Level 13  
    p.kaczmarek2 wrote:
    I also don't need to worry about LWIP 2.0, it is already in all SDKs

    Yup, RTL8710BN SDKs from Tuya don't have 2.0 as well as vendor SDKs. My current updated version (which I'm trying to compile) is here:
    https://github.com/libretuya/lwip/tree/v2.0.0-amb1

    p.kaczmarek2 wrote:
    Are you saying that you are dropping the possibility of doing tuya-cloudcutter hack for RTL devices? I mean, the devices before flashing it for the first time.

    Probably not. I have an idea for this, and we'll see how things work out a bit later.
  • #628 20029854
    p.kaczmarek2
    Moderator Smart Home
    kuba2k2 wrote:
    p.kaczmarek2 wrote:
    I also don't need to worry about LWIP 2.0, it is already in all SDKs

    Yup, RTL8710BN SDKs from Tuya don't have 2.0 as well as vendor SDKs. My current updated version (which I'm trying to compile) is here:
    https://github.com/libretuya/lwip/tree/v2.0.0-amb1

    By "all SDKs" I obviously meant all SDKs that I support at the moment. I can't vouch for SDKs that I don't know.
    I had LWIP 1 issue at XR809, but I solved it by just porting only the MQTT client from V2 to V1.
    Helpful post? Buy me a coffee.
  • #629 20029865
    theosoft
    Level 10  
    Regarding value's...

    Webapp is also sending 100 :-( --> update issue for HA. Value fix has to be made also for webapp.
    regards
  • #630 20029870
    p.kaczmarek2
    Moderator Smart Home
    @theosoft webapp is maintained mostly by @btsimonh , so I will have to look where is this value set. I will try to do it tomorrow. If you happen to find it earlier, make a pull request, I will merge it as I have a full access to app repo.

    EDIT: most likely here: https://github.com/OpenBekenIOT/webapp/blob/gh-pages/vue/control.vue
    Helpful post? Buy me a coffee.

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