Elektroda.com
Elektroda.com
X
Elektroda.com

[BK7231N CB2S] Smart socket LSC 0 - firmware change

danmar 954 13
This content has been translated flag-pl » flag-en View the original version here.
  • Last summer I bought a socket in the action store:

    [BK7231N CB2S] Smart socket LSC 0 - firmware change [BK7231N CB2S] Smart socket LSC 0 - firmware change
    [BK7231N CB2S] Smart socket LSC 0 - firmware change
    Now is the time to disconnect from the cloud. It took a while, but I found descriptions of how to do it without disassembling the device and soldering the wires.
    I took advantage of https://github.com/tuya-cloudcutter/tuya-cloudcutter and https://github.com/openshwprojects/OpenBK7231T_App
    I used the existing configuration for the LSC Smart Connect Plug and the socket works without internet connection.
    Unfortunately, not everything was as in the original. I had only one blue LED for this, which should indicate the WiFi connection and indicated the activation of the relay.
    That's why I decided to look inside.
    [BK7231N CB2S] Smart socket LSC 0 - firmware change
    The case was opened without damage.
    [BK7231N CB2S] Smart socket LSC 0 - firmware change [BK7231N CB2S] Smart socket LSC 0 - firmware change [BK7231N CB2S] Smart socket LSC 0 - firmware change [BK7231N CB2S] Smart socket LSC 0 - firmware change
    As you can see, the power supply is not isolated, so I do not recommend connecting to 230 V with the housing open. There may be a phase on the mass!
    [BK7231N CB2S] Smart socket LSC 0 - firmware change [BK7231N CB2S] Smart socket LSC 0 - firmware change [BK7231N CB2S] Smart socket LSC 0 - firmware change [BK7231N CB2S] Smart socket LSC 0 - firmware change [BK7231N CB2S] Smart socket LSC 0 - firmware change
    I looked at the paths on the pcb from the MCU to the button, LEDs and relay.
    [BK7231N CB2S] Smart socket LSC 0 - firmware change [BK7231N CB2S] Smart socket LSC 0 - firmware change [BK7231N CB2S] Smart socket LSC 0 - firmware change
    Inspection results:
    P6 - switching on the relay by R5 and Q1
    P7 - SW1 button
    P8 - LED1 (red)
    P26 - LED2 (blue)
    Power supply 3.3 V and mass obvious and the others not connected.
    After assembling the case, I was able to modify the pin settings:
    [BK7231N CB2S] Smart socket LSC 0 - firmware change
    On the left is the proposed configuration for a similar outlet, and on the right is my setting.
    The socket now works as I wanted, and although it lacks even a timer, I hope that soon the software will become similar to Tasmota.

    Cool? Ranking DIY
    About Author
    danmar
    Level 12  
    Offline 
    danmar wrote 22 posts with rating 10. Been with us since 2003 year.
  • #3
    p.kaczmarek2
    Moderator Smart Home
    As of yesterday, the firmware became compatible with ioBroker. To enable Tasmota-style TELE sending (necessary for the ioBroker sonoff plugin), flag 30 must be enabled.
    Demonstration:


  • #4
    krisRaba
    Level 31  
    Every now and then I see topics about replacing fw in these various factory devices.

    Where can I find some information about this system to sort out what it is and what it can do?

    I understand that it's about the fact that all these finished products use the same wireless module and by replacing the fw we gain direct control over them, setting what is connected to the built-in module?

    What does the controls look like then? These modules connect to a local WiFi network, which we will write to them? And then we have an app that catches devices on this network that report?

    I am interested in this because I am before designing an installation at home and it would be good to know what it can do, what devices are already figured out, which can be controlled, etc.
    I used to think about some kind of my own control, but life verifies it and unfortunately I don't have enough free time to do it in a reasonable period of time :/
    Therefore, I would like to use something ready that can be adapted to the needs :)
  • #5
    danmar
    Level 12  
    krisRaba wrote:
    I understand that it's about the fact that all these finished products use the same wireless module and by replacing the fw we gain direct control over them, setting what is connected to the built-in module?

    It's not that good. There are more and more modules, the differences are sometimes big.
    krisRaba wrote:
    What does the controls look like then? These modules connect to a local WiFi network, which we will write to them? And then we have an app that catches devices on this network that report?

    More or less like that, although today an app can be, for example, a web browser tab without a menu.
    If you have 2-3 of these devices, tabs in the browser for each device will probably be enough. But if we want to use the dependencies between devices more or we want to use some system, such as Home Assistant.
    I changed the firmware to disconnect from the cloud and get rid of the company's applications on the smartphone. It is no longer convenient when you need a dedicated application for each device.
    For me, it is more convenient to have access to the home LAN from the world than to send everything from home to the cloud to, for example, turn off the light in the next room. And these are the solutions we get by default when we buy a device and follow the manual.
  • #6
    krisRaba
    Level 31  
    Ok, but in general you can create some local WiFi even without going out into the world and such a Home Assistant will handle everything locally? :D
  • #7
    Robgie
    Level 27  
    Yes. HA, you can also give access to the world, the most important thing is that you have one application, no clouds in China, and you can manage it freely and some devices can influence others, etc etc.
  • #8
    krisRaba
    Level 31  
    Nice, I need to know about this :)
    It would suit me best if it was only locally or if so, from the outside, using some VPN, but that direct traffic from the net for devices would be impossible. I have to look if it can be done, e.g. on a router :)
  • #9
    krisRaba
    Level 31  
    danmar wrote:

    I looked at the paths on the pcb from the MCU to the button, LEDs and relay.
    [BK7231N CB2S] Smart socket LSC 0 - firmware change [BK7231N CB2S] Smart socket LSC 0 - firmware change [BK7231N CB2S] Smart socket LSC 0 - firmware change

    After assembling the case, I was able to modify the pin settings:
    [BK7231N CB2S] Smart socket LSC 0 - firmware change


    I have a question for the experts on the subject. I look at these photos and in this socket there is a module that has very few pins brought out to the world, because in total, what else is needed in such a device.
    On the other hand, the pin configuration shows as many as 28 positions...
    Is it possible to buy a module that would have as many lines as possible, put it on your PCB and freely configure it, e.g. here PWM one, the other, here some on/offs, here inputs, etc.?
    And then add it to HA as your own module that does something there? :D Damn, because it would speed up the development and integration of some of your inventions :D

    Are there any interface pushers in this as well? For example, from the HA level, define that it should push a frame to this module, which in turn sends further via its UART, or something else? :D

    I watched a trailer for HA 2022.10 and I like it more and more :D I was so afraid it was contagious :lol:
  • #10
    p.kaczmarek2
    Moderator Smart Home
    Please note that I am answering in context mine project OpenBeken , although Tasmota for the popular ESP also has a scriptable Rules system, but I have not seen so many, for example, possible relays there (in the panel I can choose from 1 to ... 8):
    [BK7231N CB2S] Smart socket LSC 0 - firmware change

    krisRaba wrote:

    On the other hand, the pin configuration shows as many as 28 positions...
    Is it possible to buy a module that would have as many lines as possible, put it on your PCB and freely configure it, e.g. here PWM one, the other, here some on/offs, here inputs, etc.?
    And then add it to HA as your own module that does something there? :D Damn, because it would speed up the development and integration of some of your inventions :D

    Each free pin can be scripted and used, we are only limited by the fact that, for example, PWM data the MCU can only support on specific pins.

    krisRaba wrote:

    Are there any interface pushers in this as well? For example, from the HA level, define that it should push a frame to this module, which in turn sends further via its UART, or something else? :D

    In my firmware, there are up to 64 channels with different roles, you can freely pair buttons, switches, relays, PWMs, ADC, you can trigger events based on readings or clicks (single, double, triple, quadruple click), you can create timers (e.g. turn off the relay after 5 minutes), you can control the peripherals (I add new drivers on a regular basis), etc...
    You can connect DHT11 and script it (without writing C code, in ready firmware, without HA) that when the temperature exceeds the limit, it performs some action (switches on the relay for 10 minutes)
    OpenBeken can also send and receive any things via MQTT or send e.g. GET to the server (and you can put measurement results into GET...)

    Example for example with I2C:
    p.kaczmarek2 wrote:
    New I2C update!
    I added the MCP23017 driver.
    The MCP23017 is a 16-bit port expander.
    It allows you to connect e.g. 16 relays to a single I2C bus.
    In the current system, it is possible to map the 16 pins of the MCP23017 to OpenBeken channels.
    Here the command is used:
    
    backlog setChannelType 5 toggle; setChannelType 6 toggle; setChannelType 7 toggle; setChannelType 8 toggle; setChannelType 9 toggle; setChannelType 10 toggle; setChannelType 11 toggle; addI2CDevice_MCP23017 I2C1 0x27; MCP23017_MapPinToChannel I2C1 0x27 7 5; MCP23017_MapPinToChannel I2C1 0x27 6 6; MCP23017_MapPinToChannel I2C1 0x27 5 7; MCP23017_MapPinToChannel I2C1 0x27 4 8; MCP23017_MapPinToChannel I2C1 0x27 3 9; MCP23017_MapPinToChannel I2C1 0x27 2 10; MCP23017_MapPinToChannel I2C1 0x27 1 11
    

    The command was used on the controller of 4 relays. Channels 5, 6, 7 etc. are mapped to expander bits.
    Here's what it looks like in the UI (I didn't bother adding all 16 channels, just a few):
    [BK7231N CB2S] Smart socket LSC 0 - firmware change
    Here are the LEDs during the test:
    [BK7231N CB2S] Smart socket LSC 0 - firmware change
    Here is the whole setup (ignore the TC74 temperature sensors on the I2C bus, let's focus on the MCP23017):
    [BK7231N CB2S] Smart socket LSC 0 - firmware change
    With annotations:
    [BK7231N CB2S] Smart socket LSC 0 - firmware change
    Now you may ask - why? Why 16 channels? Why MCP23017?
    This is because it allows you to use this module:
    [BK7231N CB2S] Smart socket LSC 0 - firmware change
    [BK7231N CB2S] Smart socket LSC 0 - firmware change
    [BK7231N CB2S] Smart socket LSC 0 - firmware change
    That would be a very cheap and cool way to control multiple relays. Also, you can have multiple MCPs on the same I2C bus...

    .


    Another example, fan control on three relays, script at the user's request with simulation because I didn't have such a device :
    p.kaczmarek2 wrote:

    Hello again @digitalsko,
    thanks to our OpenBeken Device Simulator which allows me to simulate any device on Windows and create scripts quickly, I made the following script for you:
    
    
    setChannelType 10 OffLowMidHigh
    setChannelLabel 1 "Relay 1"
    setChannelLabel 2 "Relay 2"
    setChannelLabel 3 "Relay 3"
    setChannelLabel 10 "Fan Speed"
    
    // hide raw relay channel buttons from gui
    setChannelVisible 1 0
    setChannelVisible 2 0
    setChannelVisible 3 0
    
    // optional gui buttons
    startDriver httpButtons
    
    setButtonLabel 0 "Toggle Fan"
    setButtonLabel 1 "Next Fan Speed"
    setButtonCommand 0 Do_Power_Press
    setButtonCommand 1 Do_Cycle_Press
    setButtonEnabled 0 1
    setButtonEnabled 1 1
    
    // button colour
    addChangeHandler Channel10 == 0 setButtonColor 0 red
    addChangeHandler Channel10 != 0 setButtonColor 0 green
    // off by default
    setButtonColor 0 red
    
    // translate fan state (0-4) to relay states
    addChangeHandler Channel10 == 0 backlog SetChannel 1 0; SetChannel 2 0; SetChannel 3 0
    // Fan on Low - R2 on
    addChangeHandler Channel10 == 1 backlog SetChannel 1 1; SetChannel 2 0; SetChannel 3 0
    // Fan on Medium - R2, R3 on
    addChangeHandler Channel10 == 2 backlog SetChannel 1 1; SetChannel 2 1; SetChannel 3 0
    // Fan on High - R2, R3, R4 on
    addChangeHandler Channel10 == 3 backlog SetChannel 1 1; SetChannel 2 1; SetChannel 3 1
    // change to OnClick if you want?
    addEventHandler OnPress 11 Do_Power_Press
    addEventHandler OnPress 9 Do_Cycle_Press
    // power press will just toggle channel 10 - so if non zero it goes to 0, if zero, then goes to 1
    alias Do_Power_Press toggleChannel 10
    // cycle press will cycle values 0, 1, 2 and 3 for channel 10?
    // AddChannel [ChannelIndex][ValueToAdd][ClampMin][ClampMax][bWrapInsteadOfClamp]
    alias Do_Cycle_Press addChannel 10 1 1 3 1
    

    I'm not sure if this is exactly what you need, but you can modify it to suit your needs and if there is any problem I can also do the modification for you. I'm here to help.

    Here is a short presentation of the script:



    You must update to the latest version to use all the features of this script.


    Other examples:
    Quote:


    - CB2S + DHT11 test circuit:
    [BK7231N CB2S] Smart socket LSC 0 - firmware change [BK7231N CB2S] Smart socket LSC 0 - firmware change [BK7231N CB2S] Smart socket LSC 0 - firmware change
    - WB2S + LCD 2x16 with I2C driver + MCP23017 port expander test circuit:
    [BK7231N CB2S] Smart socket LSC 0 - firmware change [BK7231N CB2S] Smart socket LSC 0 - firmware change [BK7231N CB2S] Smart socket LSC 0 - firmware change
    - WB2S + bistable switch and potentiometer test circuit:
    [BK7231N CB2S] Smart socket LSC 0 - firmware change [BK7231N CB2S] Smart socket LSC 0 - firmware change [BK7231N CB2S] Smart socket LSC 0 - firmware change
    - WB2S + IR receiver test circuit:
    [BK7231N CB2S] Smart socket LSC 0 - firmware change [BK7231N CB2S] Smart socket LSC 0 - firmware change [BK7231N CB2S] Smart socket LSC 0 - firmware change
    - WB2S + Software SPI test:
    [BK7231N CB2S] Smart socket LSC 0 - firmware change [BK7231N CB2S] Smart socket LSC 0 - firmware change [BK7231N CB2S] Smart socket LSC 0 - firmware change
    More about my test setups will be covered in dedicated OBK topic.


    Another example:
    - Genio Galaxy Smart Lamp - BK7231T - Teardown + Guide

    In the case of Tasmota you can easily run a lot of ready-made drivers on ESP, in the case of OpenBeken you can run on 'unknown Chinese modules' such as BK7231 (T and N), BL602, W800/W801, W600/W601, XR809 and soon more
  • #11
    krisRaba
    Level 31  
    Great, thank you very much for the above information.

    So the scripting language can perform the logic on the module itself, that it performs its function independently.
    In addition, it can be connected, for example, with Home Assistant and there you can make some master schedules, monitor the status, etc :D
    A beautiful thing

    I need to review the modules mentioned and see which one is best suited and then it would be appropriate to embrace something in combat to feel it better :)

    For now, I'm arranging individual elements of the electrical system in my head and possibly whether something "smear" in a given place or not ;)