logo elektroda
logo elektroda
X
logo elektroda

[BK7231N] BK7231N Tuya Wifi PIR Motion Sensor GPIO Configuration Issues

Kinsi55 639 8
ADVERTISEMENT
  • #1 21347428
    Kinsi55
    Level 4  
    I recently bought this motion sensor: https://aliexpress.com/item/1005007542667555.html

    I received it today, backed up its firmware and flashed OpenBeken on it which worked flawlessly. I tried to figure out pins using GPIO finder but while the PIR / LED responded to me being in its FOV / not, neither of the GPIOs had any I/O - I then manually had a look and it seems like the only connections are RX/TX to a secondary MCU (So probably TuyaMCU) AND there is a transistor on GND of the WB3S which turns it off / on (I guess this is how they achieve low idle power instead of just using deep sleep...... smh) that's also controlled by the secondary MCU

    Has somebody here dealt with a device similar to this? I have not yet bothered to hook up my logic analyzer to make sense of it.

    Electronic motion sensor with PCB and WB3S module.
  • ADVERTISEMENT
  • #3 21348241
    Kinsi55
    Level 4  
    >>21347530 You are correct, my bad, thank you!

    Added after 55 [minutes]:

    I tried to copy their config and it seems like their sensor has a different version / firmware. I have ran the TuyaMCU Explorer myself and found out that fnId 101 is for presence and fnId 102 is for the battery state

    Respectively, I have adjusted my config like this:

    startDriver TuyaMCU
    startDriver tmSensor
    setChannelType 101 readonly
    //Link dpid to channel 1
    linkTuyaMCUOutputToChannel 101 val 1
    setChannelType 102 readonly
    linkTuyaMCUOutputToChannel 102 val 3
    SetChannel 101 102


    Now this generally works, however I only get a 1 published on channel 1 when there is presence - According to the Analyzer, a 0 is sent when there is no presence, but that one is never published for me. Would that be due to my configuration?

    Edit:

    Nevermind I figured it out, this would be correct. The Signal is inverted, 1 is no presence, 0 is presence

    startDriver TuyaMCU
    startDriver tmSensor
    setChannelType 101 readonly
    //Link dpid to channel 1
    linkTuyaMCUOutputToChannel 101 val 1
    setChannelType 102 readonly
    linkTuyaMCUOutputToChannel 102 val 3
    SetChannel 1 2
  • ADVERTISEMENT
  • #4 21348905
    spin55
    Level 17  
    Can you connect the USB adapter to pin 11 of CB3S? Restart the device and show the captured Log?
  • #5 21352836
    Kinsi55
    Level 4  
    I tried, unfortunately my Serial board resets whenever I power the Sensor from it and I don't have another 3.3v source handy right now - How would the information be of use seeing as I seem to have figured it out?
  • ADVERTISEMENT
  • #6 21353078
    spin55
    Level 17  
    Only connect the Rx Cable from the USB Adapter to pin 11 of the CB3S and the GND cable from the Adapter to the GND of the board or (-) of the power supply. Open Realterm or equivalent program (for example Arduino serial port reader) set the transfer speed to 9600 bps. Get started and capture and publish the Arduino or Realterm Log. If no readable information appears, you may have to change the speed to 115200 bps.

    Diagram of CB3S module with pin labeling.
  • ADVERTISEMENT
  • #7 21354330
    Kinsi55
    Level 4  
    This is everything logged for a presence detection before the CB3S is turned off again by the 2nd Chip

    Again tho in case I havent made it clear: Everything now works perfectly fine

    V:BK7231N_1.0.1
    REG:cpsr     spsr     r13      r14
    SVC:000000D3          00401C1C 000033AC
    IRQ:000000d2 00000010 00401e0c ffeffefb 
    FIR:000000d1 00000010 00401ffc ff6ef53f 
    SYS:000000df          0040192c 00000158 
    ST:00000000
    J 0x10000
    bk_misc_init_start_type 0 0
    prvHeapInit-start addr:0x4144d8, size:113448
    [Flash]id:0xeb6015
    sctrl_sta_ps_init
    cset:0 0 0 0
    Entering initLog()...
    Commands registered!
    initLog() done!
    Info:MAIN:Main_Init_Before_Delay
    Info:CFG:####### Boot Count 190 #######
    Warn:CFG:CFG_InitAndLoad: Correct config has been loaded with 42 changes count.
    Error:CMD:no file early.bat err -2
    Info:GEN:PIN_SetupPins pins have been set up.
    Info:MAIN:Main_Init_Before_Delay done
    
    Main_Init_Before_Delay done
    Info:MAIN:Main_Init_Delay
    
    Main_Init_Delay
    
    delaying start
    bandgap_calm_in_efuse=0x70
    [load]bandgap_calm=0x70->0x30,vddig=4->5
    [FUNC]rwnxl_init
    [bk]tx_txdes#Startup delayed 0ms#
    cyed 0ms#
    [FUNC]intc_init
    [FUNC]calibration_main
    gpio_level=1,txpwr_state=15<\n>user define rfcali mode:1 
    get rfc#Startup delayed 10ms#
    a delayed 10ms#
    DPLL Unlock
    DPLL Unlock
    #Startup delayed 20ms#
    #Startup delayed 30ms#
    #Startup delayed 40ms#
    #Startup delayed 50ms#
    #Startup delayed 60ms#
    #Startup delayed 70ms#
    #Startup delayed 80ms#
    #Startup delayed 90ms#
    #Startup delayed 100ms#
    #Startup delayed 110ms#
    #Startup delayed 120ms#
    #Startup delayed 130ms#
    #Startup delayed 140ms#
    #Startup delayed 150ms#
    #Startup delayed 160ms#
    #Startup delayed 170ms#
    #Startup delayed 180ms#
    #Startup delayed 190ms#
    #Startup delayed 200ms#
    #Startup delayed 210ms#
    #Startup delayed 220ms#
    #Startup delayed 230ms#
    #Startup delayed 240ms#
    #Startup delayed 250ms#
    #Startup delayed 260ms#
    #Startup delayed 270ms#
    #Startup delayed 280ms#
    #Startup delayed 290ms#
    #Startup delayed 300ms#
    #Startup delayed 310ms#
    #Startup delayed 320ms#
    #Startup delayed 330ms#
    #Startup delayed 340ms#
    #Startup delayed 350ms#
    #Startup delayed 360ms#
    #Startup delayed 370ms#
    #Startup delayed 380ms#
    DPLL Unlock
    DPLL Unlock
    #Startup delayed 390ms#
    #Startup delayed 400ms#
    #Startup delayed 410ms#
    #Startup delayed 420ms#
    #Startup delayed 430ms#
    #Startup delayed 440ms#
    #Startup delayed 450ms#
    DPLL Unlock
    DPLL Unlock
    #Startup delayed 460ms#
    calibration_main over<\n>flash txpwr table:0xf
    dif g and n20 ID in flash:4
    dif g and n40 ID in flash:4
    read txpwr tab from flash success
    temp in flash is:237
    xtal in flash is:90
    xtal_cali:90
    --init_xt#Startup delayed 470ms#
    aelayed 470ms#
    [FUNC]ps_init
    [FUNC]func_init_extended OVER!!!
    
    start_type:0
    Version:
    Initializing TCP/IP st#Startup delayed 480ms#a
    
    app_init finished
    #Startup delayed 490ms#
    #Startup delayed 500ms#
    #Startup delayed 510ms#
    #Startup delayed 520ms#
    #Startup delayed 530ms#
    #Startup delayed 540ms#
    #Startup delayed 550ms#
    #Startup delayed 560ms#
    #Startup delayed 570ms#
    #Startup delayed 580ms#
    #Startup delayed 590ms#
    #Startup delayed 600ms#
    #Startup delayed 610ms#
    #Startup delayed 620ms#
    #Startup delayed 630ms#
    #Startup delayed 640ms#
    #Startup delayed 650ms#
    #Startup delayed 660ms#
    #Startup delayed 670ms#
    #Startup delayed 680ms#
    #Startup delayed 690ms#
    #Startup delayed 700ms#
    #Startup delayed 710ms#
    #Startup delayed 720ms#
    #Startup delayed 730ms#
    #Startup delayed 740ms#
    
    starting....
    Info:MAIN:Main_Init_Delay done
    
    Main_Init_Delay done
    Info:MAIN:Main_Init_After_Delay
    Info:MAIN:Using SSID [XXXXXX]
    Info:MAIN:Using Pass [XXXXX]
    Info:MQTT:MQTT_RegisterCallback called for bT obkE5338527/ subT obkE5338527/+/set
    Info:MQTT:MQTT_RegisterCallback called for bT bekens_n/ subT bekens_n/+/set
    Info:MQTT:MQTT_RegisterCallback called for bT cmnd/obkE5338527/ subT cmnd/obkE5338527/+
    Info:MQTT:MQTT_RegisterCallback called for bT cmnd/bekens_n/ subT cmnd/bekens_n/+
    Info:MQTT:MQTT_RegisterCallback called for bT obkE5338527/ subT obkE5338527/+/get
    Info:CMD:CMD_StartScript: started autoexec.bat at the beginning
    Info:MAIN:Main_Init_After_Delay done
    Info:MAIN:Started TuyaMCU.
    Info:MAIN:Started tmSensor.
    Info:GEN:Channel 101 type changed to readonly
    Info:GEN:Channel 102 type changed to readonly
    Info:GEN:CHANNEL_Set channel 1 has changed to 2 (flags 0)<\n>
    Info:MQTT:Channel has changed! Publishing 2 to channel 1 
    cal_bias!
    DPLL Unlock
    cal dpll!
    temperature_type=1<\n>temp_code:-30 - adc_code:348 - adc_trend:[13]:237->[3]:337
    Info:MAIN:Time 1, idle 255392/s, free 78136, MQTT 0(0), bWifi 0, secondsWithNoPing -1, socks 2/38 
    Info:TuyaMCU:Received: 55 AA 00 01 00 24 7B 22 70 22 3A 22 72 6A 7A 6F 6E 39 6B 79 78 70 6F 65 6B 73 6A 33 22 2C 22 76 22 3A 22 31 2E 30 2E 30 22 7D 26 
    Info:TuyaMCU:ProcessIncoming[v=0]: cmd 1 (QueryProductInformation) len 43
    Info:TuyaMCU:ParseQueryProductInformation: received {"p":"rjzon9kyxpoeksj3","v":"1.0.0"}
    temp_code:-30 - adc_code:348 - adc_trend:[3]:337->[2]:347
    Info:MAIN:Time 2, idle 185280/s, free 78136, MQTT 0(0), bWifi 0, secondsWithNoPing -1, socks 2/38 
    Info:MAIN:Time 3, idle 185914/s, free 78136, MQTT 0(0), bWifi 0, secondsWithNoPing -1, socks 2/38 
    Info:MAIN:Time 4, idle 185775/s, free 78136, MQTT 0(0), bWifi 0, secondsWithNoPing -1, socks 2/38 
    supplicant_main_exiting
    supplicant_exit_done
    [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
    hapd_intf_add_vif,type:2, s:0, id:0
    wpa_dInit
    wpa_supplicant_req_scan
    Setting scan[retry16] request: 0.100000 sec
    MANUAL_SCAN_REQ
    enter low level!
    mac XXXXXXX
    leave low level!
    net_wlan_add_netif done!, vif_idx:0
    Info:MAIN:Time 5, idle 188161/s, free 78136, MQTT 0(0), bWifi 0, secondsWithNoPing -1, socks 2/38 
    Info:MAIN:Registered for wifi changes
    Info:MAIN:Connecting to SSID [XXXXXX]
    Info:MAIN:ssid:XXXXXX key:XXXXX
    wpa_supplicant_scan
    wpa_drv_scan
    wpa_send_scan_req
    ht in scan
    scan_start_req_handler
    Info:MAIN:Time 6, idle 176989/s, free 72448, MQTT 0(0), bWifi 0, secondsWithNoPing -1, socks 2/38 
    Info:MAIN:Boot complete time reached (5 seconds)
    Info:CFG:####### Set Boot Complete #######
    Info:MAIN:Time 7, idle 179244/s, free 72448, MQTT 0(0), bWifi 0, secondsWithNoPing -1, socks 2/38 
    wpa_driver_scan_cb
    wpa_get_scan_rst:2
    cipher2security 2 2 16 16<\n>Info:MAIN:Time 8, idle 88440/s, free 72264, MQTT 0(0), bWifi 0, secondsWithNoPing -1, socks 2/38 
    Info:MAIN:Time 9, idle 0/s, free 72264, MQTT 0(0), bWifi 0, secondsWithNoPing -1, socks 2/38 
    Info:MAIN:Time 10, idle 0/s, free 72264, MQTT 0(0), bWifi 0, secondsWithNoPing -1, socks 2/38 
    Info:GEN:dhcp=0 ip=0.0.0.0 gate=0.0.0.0 mask=0.0.0.0 mac=XXXXXXX
    Info:GEN:sta: 0, softap: 0, b/g/n
    wpa_supplicant_connect
    Cancelling scan request
    wpa_driver_associate
    Info:MAIN:Main_OnWiFiStatusChange - WIFI_STA_CONNECTING - 1
    ssid:XXXXXX, 1
    found scan rst rssi -54 < -50
    dis ht_support
    no ht in scan
    scan_start_req_handler
    aready open
    aready open
    me_set_ps_disable:840 0 0 1 0 3
    sm_auth_send:1
    sm_auth_handler
    ht NOT in assoc req
    sm_assoc_rsp_handler
    rc_init: station_id=0 format_mod=0 pre_type=0 short_gi=0 max_bw=0<\n>rc_init: nss_max=0 mcs_max=255 r_idx_min=0 r_idx_max=11 no_samples=10<\n>---------SM_CONNECT_IND_ok
    wpa_driver_assoc_cb
    Cancelling scan request
    __l2_packet_send: ret 0
    
    new ie: 0 : XXXXX
    new ie: 1 : XXXXX
    new ie: 3 : XXXXX
    new ie: 2d : XXXXX
    new ie: 30 : XXXXX
    
    __l2_packet_send: ret 0
    hapd_intf_add_key CCMP
    add sta_mgmt_get_sta
    sta:0, vif:0, key:0
    sta_mgmt_add_key
    add hw key idx:24
    hapd_intf_add_key CCMP
    add is_broadcast_ether_addr
    sta:255, vif:0, key:2
    add hw key idx:2
    ctrl_port_hdl:1
    me_set_ps_disable:840 0 0 0 0 3
    Info:MAIN:Main_OnWiFiStatusChange - WIFI_STA_CONNECTED - 4
    sta_ip_start
    
    configuring interface mlan (with DHCP client)WARN: TCPIP mutex is NOT locked (1) caller 53C9F<\n>WARN: TCPIP mutex is NOT locked (1) caller 53C9F<\n>ip_addr: XXXXX
    Info:MAIN:Main_OnWiFiStatusChange - WIFI_STA_CONNECTED - 4
    Info:MAIN:Time 11, idle 84800/s, free 72824, MQTT 0(0), bWifi 1, secondsWithNoPing -1, socks 2/38 
    Info:TuyaMCU:Received: 55 AA 00 02 00 00 01 
    Info:TuyaMCU:ProcessIncoming[v=0]: cmd 2 (MCUconf) len 7
    Info:TuyaMCU:ProcessIncoming: TUYA_CMD_MCU_CONF, TODO!
    Info:MAIN:Time 12, idle 185221/s, free 72864, MQTT 0(0), bWifi 1, secondsWithNoPing -1, socks 2/38 
    Info:MQTT:mqtt_userName mq
    mqtt_pass tt
    mqtt_clientID obkE5338527
    mqtt_host XXXXX.38:1883
    Info:MAIN:Time 13, idle 184773/s, free 72776, MQTT 0(1), bWifi 1, secondsWithNoPing -1, socks 2/38 
    Info:MQTT:mqtt_connection_cb: Successfully connected
    Info:MQTT:mqtt_subscribed to obkE5338527/+/set
    Info:MQTT:mqtt_subscribed to bekens_n/+/set
    Info:MQTT:mqtt_subscribed to cmnd/obkE5338527/+
    Info:MQTT:mqtt_subscribed to cmnd/bekens_n/+
    Info:MQTT:mqtt_subscribed to obkE5338527/+/get
    Info:MQTT:Publishing val obkE5338527 to obkE5338527/host retain=0
    Info:MAIN:Time 14, idle 180536/s, free 72776, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 2/38 
    Info:TuyaMCU:Received: 55 AA 00 02 00 00 01 
    Info:TuyaMCU:ProcessIncoming[v=0]: cmd 2 (MCUconf) len 7
    Info:TuyaMCU:ProcessIncoming: TUYA_CMD_MCU_CONF, TODO!
    Info:TuyaMCU:Received: 55 AA 00 08 00 0C 00 02 02 02 02 02 02 65 04 00 01 00 89 
    Info:TuyaMCU:ProcessIncoming[v=0]: cmd 8 (QueryState) len 19
    Info:TuyaMCU:V0_ParseRealTimeWithRecordStorage: processing id 101, dataType 4-enum and 1 data bytes
    Info:TuyaMCU:V0_ParseRealTimeWithRecordStorage: byte 0
    Info:GEN:CHANNEL_Set channel 1 has changed to 0 (flags 0)<\n>
    Info:MQTT:Channel has changed! Publishing 0 to channel 1 
    Info:MQTT:Publishing val 0 to obkE5338527/1/get retain=0
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic obkE5338527/1/get
    Info:MQTT:Publishing val OpenBK7231N 1.17.799 Dec 13 2024 21:16:19 to obkE5338527/build retain=0
    Info:MAIN:Time 15, idle 184991/s, free 72504, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 2/38 
    Info:TuyaMCU:Received: 55 AA 00 05 00 05 66 04 00 01 02 76 
    Info:TuyaMCU:ProcessIncoming[v=0]: cmd 5 (WiFiSelect) len 12
    Info:TuyaMCU:V0_ParseRealTimeWithRecordStorage: processing id 102, dataType 4-enum and 1 data bytes
    Info:TuyaMCU:V0_ParseRealTimeWithRecordStorage: byte 2
    Info:GEN:CHANNEL_Set channel 3 has changed to 2 (flags 0)<\n>
    Info:MQTT:Channel has changed! Publishing 2 to channel 3 
    Info:MQTT:Publishing val 2 to obkE5338527/3/get retain=0
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic obkE5338527/3/get
    Info:MQTT:Publishing val XXXXXXX to obkE5338527/mac retain=0
    Info:MAIN:Time 16, idle 185380/s, free 72776, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 2/38 
    Info:MQTT:Publishing val 31.72 to obkE5338527/temp retain=0
    Info:MAIN:Time 17, idle 187166/s, free 72776, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 2/38 
    Info:MQTT:Publishing val XXXXXX to obkE5338527/ssid retain=0
    Info:MAIN:Time 18, idle 186004/s, free 72776, MQTT 1(1), bWifi 1, secondsWitèÀ<\0><\0><\0><\0><\0><\0><\0><\0><\0><\0><\0><\0><\0><\0><\0><\0><\0><\0><\0><\0><\0><\0><\0><\0><\0><\0><\0><\0><\0><\0><\0><\0>
  • Helpful post
    #8 21354427
    spin55
    Level 17  
    Kinsi55 wrote:
    Again tho in case I havent made it clear: Everything now works perfectly fine

    I didn't doubt it, but I was interested in seeing the TuyaMCU firmware version. Thank you so much.

    It is curious that with the same firmware version they use different DPs.

    Info:TuyaMCU:Received: 55 AA 00 01 00 24 7B 22 70 22 3A 22 72 6A 7A 6F 6E 39 6B 79 78 70 6F 65 6B 73 6A 33 22 2C 22 76 22 3A 22 31 2E 30 2E 30 22 7D 26
    Info:TuyaMCU:ProcessIncoming[v=0]: cmd 1 (QueryProductInformation) len 43
    Info:TuyaMCU:ParseQueryProductInformation: received {"p":"rjzon9kyxpoeksj3","v":"1.0.0"}
    
    Info:TuyaMCU:Received: 55 AA 00 08 00 0C 00 02 02 02 02 02 02 01 04 00 01 01 26
    Info:TuyaMCU:ProcessIncoming[v=0]: cmd 8 (QueryState) len 19
    Info:TuyaMCU:V0_ParseRealTimeWithRecordStorage: processing id 1, dataType 4-enum and 1 data bytes
    Info:TuyaMCU:V0_ParseRealTimeWithRecordStorage: byte 1
    
    Info:TuyaMCU:Received: 55 AA 00 05 00 05 03 04 00 01 02 13
    Info:TuyaMCU:ProcessIncoming[v=0]: cmd 5 (WiFiSelect) len 12
    Info:TuyaMCU:V0_ParseRealTimeWithRecordStorage: processing id 3, dataType 4-enum and 1 data bytes
    Info:TuyaMCU:V0_ParseRealTimeWithRecordStorage: byte 2
  • #9 21355082
    Kinsi55
    Level 4  
    spin55 wrote:
    I didn't doubt it, but I was interested in seeing the TuyaMCU firmware version


    Ah okay, just wanted to make sure you don't waste time looking for an issue that doesn't exist :D

Topic summary

The discussion revolves around the configuration issues faced with the BK7231N Tuya WiFi PIR Motion Sensor after flashing OpenBeken firmware. The user initially struggled to identify GPIO pins and discovered that the device primarily communicates via RX/TX to a secondary MCU, likely TuyaMCU. After some troubleshooting, the user successfully configured the TuyaMCU settings to monitor presence and battery state, but encountered an issue with the presence signal being inverted. Other participants provided suggestions for connecting a USB adapter for logging and capturing data, which ultimately led to a resolution of the user's configuration problems.
Summary generated by the language model.
ADVERTISEMENT