logo elektroda
logo elektroda
X
logo elektroda

[BK7231N] [CB2S] Tuya Generic Smart Life 16A Mini DIY Switch - Off-Centre Toggle Button

divadiow 2781 3
ADVERTISEMENT
  • #1 20980036
    divadiow
    Level 34  
    I thought I'd give this device a look-over as I hadn't had one with the toggle button in the top left of the front casing. Maybe I'd get the T34 as seen in https://www.elektroda.com/rtvforum/topic4036852.html posted by @Advian1

    The unit, as if often the case, from Ali Express. https://vi.aliexpress.com/item/1005006014373963.html

    Smart Switch 16A Wi-Fi with 2.4GHz on Digitaling Store, promotional price £3.44.

    There is no power monitoring chip and only a standard CB2S module with BK7231N. Kind of interesting the relay print suggests 20A and there are unused pads for the seemingly more popular central push button and LED.

    Close-up of a CB2S module with visible pins 3V3, GND, RX1, TX1, P24, P26, and probes connected to the pins. Components of a DIY smart switch, including a casing, PCB, and box. CB2S module with integrated circuit and connectors on a wooden background. Electronic module with pins and labels on a wooden surface View of the device's circuit board with connectors and electronic components. Close-up of a green PCB with clearly visible solder pads labeled SW3 and LED2. Relay module on a circuit board with green terminals. Close-up of an electronic module with a relay and capacitors. PCB with a relay and CB2S module on a beige surface. Wi-Fi smart switch with manual and box. White square Tuya switch with a dotted pattern and packaging with QR codes. Smart Switch with technical label and illuminated LED.

    I desoldered the module and captured the boot log on RX2/TX2

    
    V:BK7231N_1.0.1
    REG:cpsr     spsr     r13      r14
    SVC:000000D3          00401C1C 000033AC
    IRQ:000000d2 00000010 00401e0c 6e82ba5c
    FIR:000000d1 00000010 00401ffc 33089693
    SYS:000000df          0040192c 00000158
    ST:00000000
    J 0x10000
    bk_misc_init_start_type 0 0
    prvHeapInit-start addr:0x4111b0, size:126544
    [Flash]id:0xeb6015
    [01-01 18:12:15 TUYA I][lr:0xa584d] mqc app init ...
    [01-01 18:12:15 TUYA I][lr:0xb087b] thread_create name:sys_timer,stackDepth:4096,totalstackDepth:4096,priority:5
    [01-01 18:12:15 TUYA I][lr:0xb087b] thread_create name:cmmod,stackDepth:4096,totalstackDepth:8192,priority:4
    [01-01 18:12:15 TUYA D][lr:0xa5767] mq_pro:5 cnt:1
    [01-01 18:12:15 TUYA D][lr:0xa5767] mq_pro:31 cnt:2
    [01-01 18:12:15 TUYA D][lr:0xd402f] svc online log init success
    [01-01 18:12:15 TUYA D][lr:0xb0707] Thread:sys_timer Exec Start. Set to Running Stat
    [01-01 18:12:15 TUYA E][lr:0xcc9a5] logseq empty
    [01-01 18:12:15 TUYA I][lr:0xb087b] thread_create name:wk_th-0,stackDepth:5120,totalstackDepth:13312,priority:3
    [01-01 18:12:15 TUYA E][lr:0xb47e9] wd_protected_read fails gw_bi -23
    [01-01 18:12:15 TUYA D][lr:0xb4a5b] gw base read finish:-23
    [01-01 18:12:15 TUYA D][lr:0xd1beb] ty bt cmmod regist ok:1
    dev id key: 16
    d4 1d 8c d9 8f 00 b2 04 e9 80 09 98 ec f8 42 7e
    [PLATFORM DEBUG]bt_port_init
    [01-01 18:1ble mac:c4-82-e1-29-1d-2:15 TUYA N][lr:0xa1d6595
    !!!!!!init_type=0
    ] ble sdk re_inited
    [ble_appm_send_gapm_reset[01-01 18:12:15 TUYA D]_cmd]
    !!!!!!init_type=1
    llm_init:312
    [lr:0xd[gapm_cmp_evt_handler] 2651] bt active init
    conidx:0,operation:0x1,s[01-01 18:12:15 TUYA N]tatus:0x0
    cmd->addr.ad[lr:0xd1cd9] ty bt sdk dr[5] :0
    !!!!!!init_tyinit success finish
    [0pe=2
    [gapm_cmp_evt_hand1-01 18:12:15 TUYA N][ller] conidx:0,operationr:0x5cb9b] --- pre_devi:0x3,status:0x0
    gapm_cce_init:57 ---
    mp_evt:GAPM_SET_DEV_CONFIG
    gapm_cmp_evt:wait GAPM_GEN_RAND_NB
    [gapm_cmp_evt_handler] conidx:0,operation:0x1a,status:0x0
    gapm_cmp_evt:GAPM_GEN_RAND_NB
    [gapm_cmp_evt_handler] conidx:0,operation:0x1a,status:0x0
    gapm_cmp_evt:GAPM_GEN_RAND_NB
    [gapm_cmp_evt_handler] conidx:0,operation:0x28,status:0x0
    gapm_cmp_evt:BLE_STACK_OK
    [PLATFORM NOTICE]STACK INIT OK
    ble create new db
    ble_env->start_hdl = 0x10
    [PLATFORM NOTICE]CREATE DB OK
    adv_state:1
    [gapm_cmp_evt_handler] conidx:0,operation:0x1b,status:0x0
    adv_actv_idx:0,tx_pwr:0
    [PLATFORM DEBUG]UNKNOW EVENT:17
    [gapm_cmp_evt_handler] conidx:0,operati[01-01 18:12:15 TUYA N]on:0xa0,status:0x0
    [ap[lr:0x5d0ff] find led[1pm_adv_fsm_next] cur adv]_lv none
    [01-01 18:12_state:1
    adv_state:2
    :15 TUYA N][lr:0x5d12f][ble_appm_set_adv_data] find led[1]_pin none
    set data
    end adv_state[01-01 18:12:15 TUYA N]:2
    [PLATFORM DEBUG]UNK[lr:0x5d265] channel iniNOW EVENT:16
    [gapm_cmpt success
    [01-01 18:12_evt_handler] conidx:0,:15 TUYA N][lr:0x60199]operation:0xa9,status:0 reset [pwr] cnt:5,timex0
    [appm_adv_fsm_next]:5s
    [01-01 18:12:15 TUY cur adv_state:2
    adv_sA N][lr:0x601bb] reset tate:3
    end adv_state:3[sw] cnt:10,time:10s
    
    [PLATFORM DEBUG]UNKNOW[01-01 18:12:15 TUYA N] EVENT:16
    [gapm_cmp_ev[lr:0x601c3] reset typet_handler] conidx:0,oper:7
    [PLATFORM NOTICE]bka
                        [appm_adv_fsm_next] c_cur adv_state:3
    ur adv_state:3
    [01-01 18:12:15 TUYA N]
                           [ble_appm_start_advert[lr:0x5aef1] read pwr uising]
    end adv_state:6f data:{cnt=0}
    [01-01
    [PLATFORM DEBUG]UNKNOW18:12:15 TUYA N][lr:0x5 EVENT:16
    [gapm_cmp_evt_handler] conidx:0,opead93] write pwrration:0 cnt:{cnt=1}
    xa4,status:0x0
    [appm_adv_fsm_next] cur adv_state:6
    adv_state:7
    end adv_state:7
    [PLATFORM DEBUG]UNKNOW EVENT:16
    [01-01 18:12:15 TUYA N][lr:0xca9c7] key_addr: 0x1ee000   block_sz 4096
    [01-01 18:12:15 TUYA N][lr:0xcaa97] get key:
    0xdb 0xe5 0xf5 0xde 0x2a 0x14 0x41 0x6a 0xbe 0x3e 0xfa 0x8d 0xb6 0x43 0xbe 0xf8
    [load]bandgap_calm=0x65->0x25,vddig=4->5
    [bk]tx_txdesc_flush
    [FUNC]intc_init
    [FUNC]calibration_main
    gpio_level=1,txpwr_state=15
    get rfcali_mode:1
    DPLL Unlock
    DPLL Unlock
    calibration_main over
    temp in flash is:334
    xtal in flash is:70
    [FUNC]func_init_extended OVER
    Version:
    tcp_port:62642
    app_init finished
    [01-01 18:12:16 TUYA N][lr:0x5c9bd] mf_init succ
    [01-01 18:12:16 TUYA N][lr:0x5cbc3] --- app_init:553 ---
    [01-01 18:12:16 TUYA N][lr:0x5cbcf] < TUYA IOT SDK V:2.3.3 BS:40.00_PT:2.2_LAN:3.4_CAD:1.0.5_CD:1.0.0 >
    < BUILD AT:2022_12_07_15_29_01 BY ci_manage FOR ty_iot_sdk AT bk7231n >
    IOT DEFS < WIFI_GW:1 DEBUG:1 KV_FILE:0 SHUTDOWN_MODE:0 LITTLE_END:1 TLS_MODE:2 ENABLE_CLOUD_OPERATION:0 OPERATING_SYSTEM:2 ENABLE_SYS_RPC:0 RELIABLE_TRANSFER:0 ENABLE_LAN_ENCRYPTION:1 ENABLE_LAN_LINKAGE:0 ENABLE_LAN_DEV:0 >
    
    [01-01 18:12:16 TUYA N][lr:0x5cbd9] oem_bk7231n_control_switch:1.3.10
    [01-01 18:12:16 TUYA N][lr:0x5cbe3] firmware compiled at Dec 12 2022 14:09:13
    [PLATFORM NOTICE]bk_rst:0 tuya_rst:0
    [01-01 18:12:16 TUYA N][lr:0x5cbef] system restart reason is:0
    [01-01 18:12:16 TUYA N][lr:0x603b7] json cfg:[,rl1_lv:1,on_off_cnt:10,onoff_rst_m:1,onoff_clear_t:10,rand_dpid:42,net_trig:4,onoff_n:5,netled1_lv:0,jv:110.0.0,onoff_rst_type:2,ffc_select:0,total_bt_pin:8,nety_led:2,total_stat:0,reset_t:5,netled1_pin:7,remote_add_dp:49,remote_list_dp:50,net_type:0,inch_dp:44,module:CB2S,ch_cddpid1:9,inch_en1:0,onoff1:26,clean_t:5,init_conf:38,zero_select:0,onoff_type:0,series_ctrl:0,total_bt_lv:0,cyc_dpid:43,ch_num:1,rl1_pin:24,netn_led:2,ch_dpid1:1,crc:100,}ZZZZZZ▒▒A]
    [01-01 18:12:16 TUYA N][lr:0x6117f] ctrl lock init
    [01-01 18:12:16 TUYA N][lr:0x60eef] wd key[wd_lock_mem] is null
    [01-01 18:12:16 TUYA E][lr:0x60f6b] wd save data err:1
    [01-01 18:12:16 TUYA N][lr:0x61199] read ctrl lock err:1
    [01-01 18:12:16 TUYA N][lr:0x5de0b] wd key[wd_cfg_mem] is null
    [01-01 18:12:16 TUYA N][lr:0x5ff35] read power on stat fail:1, use json default value
    [01-01 18:12:16 TUYA N][lr:0x5ff51] read stat: [POWER]:0
    ******* ch[0] *******
    [RELAY] - pin:24,        io_drive:2
    [KEY] - pin:26,  io_drive:1,     type:2,         long_press:0
    
    ******* system *******
    [WIFI LED] - pin:7,      io_drive:1
    [TOTAL KEY] - pin:8,     io_drive:0,     long_press:5
    [WIFI MTHD]-5, [WIFI LED]-8, [KEY TRIG]-0
    
    [01-01 18:12:16 TUYA E][lr:0x566b7] OPRT_INVALID_PARM
    [01-01 18:12:16 TUYA N][lr:0x5de0b] wd key[wd_cfg_mem] is null
    [01-01 18:12:16 TUYA N][lr:0x600b5] read key type fail:1, default key type:0
    [01-01 18:12:16 TUYA N][lr:0x600c5] read stat:[KEY_TYPE]:0
    [01-01 18:12:16 TUYA N][lr:0x600cf] device [onoff] init success.
    [01-01 18:12:16 TUYA N][lr:0x60409] app read_gw_wsm.nc_tp:[1][0]
    [01-01 18:12:16 TUYA N][lr:0x5ca29] current product ssid name:tuya_mdev_test1
    [sa_sta]MM_RESET_REQ
    [bk]tx_txdesc_flush
    [sa_sta]ME_CONFIG_REQ
    [sa_sta]ME_CHAN_CONFIG_REQ
    [sa_sta]MM_START_REQ
    sizeof(wpa_supplicant)=928
    hapd_intf_add_vif,type:2, s:0, id:0
    wpa_dInit
    enter low level!
    mac c4:82:e1:29:1d:94
    leave low level!
    net_wlan_add_netif done!, vif_idx:0
    scan SSID: 74 75 79 61 5F 6D 64 65 76 5F 74 65 73 74 31
    wpa_supplicant_req_scan
    Setting scan[retry16] request: 0.000000 sec
    wpa_supplicant_scan
    wpa_supplicant_scan 866
    wpa_drv_scan
    ht in scan
    scan_start_req_handler
    wpa_driver_scan_start_cb
    temperature_type=2
    temp_code:20 - adc_code:345 - adc_trend:[13]:334->[12]:344
    wpa_driver_scan_cb
    Scan completed in 2.340000 seconds
    [PLATFORM ERROR]scan err
    [01-01 18:12:18 TUYA N][lr:0x5cc4f] --- device_init start:1854! remain heap:64800---
    [01-01 18:12:18 TUYA N][lr:0xb9a53] wifi soc init. pid:keyjnuy4s3kre7m7 firmwarekey:keyjnuy4s3kre7m7 ver:1.3.10
    [PLATFORM NOTICE]bk_rst:0 tuya_rst:0
    [01-01 18:12:18 TUYA N][lr:0xb3c9b] Last reset reason: 0
    [01-01 18:12:18 TUYA N][lr:0xb3d77] serial_no:c482e1291d94
    rw_ieee80211_set_country code:
    code: CN
    channel: 1 - 13
    mode: MANUAL
    bk_wlan cca closed
    [01-01 18:12:18 TUYA N][lr:0xb3db5] gw_cntl.gw_wsm.stat:0
    [01-01 18:12:18 TUYA N][lr:0xb82c5] gw_cntl->gw_wsm.nc_tp:1
    [01-01 18:12:18 TUYA N][lr:0xb82cd] gw_cntl->gw_wsm.md:0
    [01-01 18:12:18 TUYA N][lr:0xb3f11] gw_cntl.gw_if.abi:0 input:0
    [01-01 18:12:18 TUYA N][lr:0xb3f1f] gw_cntl.gw_if.product_key:keyjnuy4s3kre7m7, input:keyjnuy4s3kre7m7
    [01-01 18:12:18 TUYA N][lr:0xb3f29] gw_cntl.gw_if.tp:0, input:0
    [01-01 18:12:18 TUYA N][lr:0xb3f39] gw_cntl.gw_if.firmware_key:keyjnuy4s3kre7m7, input:keyjnuy4s3kre7m7
    [01-01 18:12:18 TUYA N][lr:0xd1d57] ty bt upd product:keyjnuy4s3kre7m7 1
    [01-01 18:12:18 TUYA N][lr:0x57141] wd_common_read failed op_ret:-6
    [01-01 18:12:18 TUYA N][lr:0x57141] wd_common_read failed op_ret:-6
    [01-01 18:12:18 TUYA N][lr:0x581c9] start tuya_inch_time_init..
    [01-01 18:12:18 TUYA N][lr:0x6062f] remote rf433 not enable
    [01-01 18:12:18 TUYA N][lr:0x60bdf] not have dltj!
    [01-01 18:12:18 TUYA N][lr:0x5ccb5] --- device_init success:1917! remain heap:56896 ---
    wpa_supplicant_req_scan
    Setting scan[retry16] request: 0.000000 sec
    wpa_supplicant_scan
    wpa_supplicant_scan 866
    wpa_drv_scan
    ht in scan
    scan_start_req_handler
    wpa_driver_scan_start_cb
    [01-01 18:12:20 TUYA N][lr:0x5ae2d] pwr clear time arrive!
    [01-01 18:12:20 TUYA N][lr:0x5ad93] write pwr cnt:{cnt=0}
    wpa_driver_scan_cb
    Scan completed in 2.330000 seconds
    net_wlan_remove_netif done!, vif_idx:0
    Cancelling scan request
    scanu completed
    Soft_AP_start
    [saap]MM_RESET_REQ
    [bk]tx_txdesc_flush
    [saap]ME_CONFIG_REQ
    [saap]ME_CHAN_CONFIG_REQ
    [saap]MM_START_REQ
    apm start with vif:0
    me_set_ps_disable:842 0 0 1 0 0
    ------beacon_int_set:100 TU
    set_active param 0
    [msg]APM_STOP_CFM
    update_ongoing_1_bcn_update
    hal_machw_enter_monitor_mode
    [01-01 18:12:21 TUYA N][lr:0x601f5] wifi stat --> 1
    [01-01 18:12:21 TUYA N][lr:0xa1c83] update bound stat:0
    dev id key: 16
    a3 4d ed 2f a7 b4 85 ff cd db 4c 2a b6 46 73 53
    [PLATFORM DEBUG]bt rst adv
    adv_state:12
    [gapm_cmp_evt_handler] conidx:0,operation:0xa9,status:0x0
    [appm_adv_fsm_next] cur adv_state:c
    adv_state:13
    end adv_state:d
    [PLATFORM DEBUG]UNKNOW EVENT:19
    [PLATFORM DEBUG]UNKNOW EVENT:16
    [gapm_cmp_evt_handler] conidx:0,operation:0xaa,status:0x0
    [appm_adv_fsm_next] cur adv_state:d
    adv_state:7
    end adv_state:7
    [PLATFORM DEBUG]UNKNOW EVENT:20
    [PLATFORM DEBUG]UNKNOW EVENT:16
    [01-01 18:12:21 TUYA N][lr:0xa1a55] ble adv && resp changed
    temp_code:24 - adc_code:337 - adc_trend:[12]:344->[13]:334
    


    The firmware version 1.3.10 is on the known patched list so no good for Tuya-Cloudcutter.

    I attach a factory firmware dump and the pin assignments are as follows
    - Pair/Toggle All Button on P8
    - WiFi LED on P7
    - TglChannelToggle (channel 1) on P26
    - Relay (channel 1) on P24


    Code: JSON
    Log in, to see the code


    Despite this being so similar to other 16/20A breakers in the device list, there isn't an exact pin match, so here is OBK

    Code: JSON
    Log in, to see the code
  • ADVERTISEMENT
  • ADVERTISEMENT
  • #3 20981399
    divadiow
    Level 34  
    to complete the setup, the autoexec.bat:

    alias mode_wifi setPinRole 7 WifiLED_n
    alias mode_relay setPinRole 7 LED_n
    alias mode_relay2 setpinchannel 7 1
    
    // at reboot, set WiFiLEd
    mode_wifi
    // then, setup handlers
    addChangeHandler WiFiState == 4 mode_relay
    addChangeHandler WiFiState == 4 mode_relay2
    addChangeHandler WiFiState != 4 mode_wifi 


    behaviour is:
    -flashing blue LED on wifi connecting
    -LED off with relay open (off)
    -LED on with relay closed (on)
  • #4 21337039
    kkarmah
    Level 6  
    Hello everybody,
    I've had a switch like this working for a few months now, however today I noticed that something wasn't right. It is controlling the charging of a tablet, where it turns on at 20% battery and turns off at 80%. But what is happening is that in the HA it often has an unknown status, which causes the tablet to shut down due to lack of battery... Could it be that it does not correctly send the data via mqtt to the HA? Another thing I noticed is that if I do a restart via the web, it turns back on in another state and not the one it was in before turning off. But I have flag 10, 21 and 34 activated. Thanks
ADVERTISEMENT