logo elektroda
logo elektroda
X
logo elektroda

OpenBK7231N: Configuring P8 as Reset and P24 as Wakeup Button on 1.18.226 Firmware

4711leow 69 2
ADVERTISEMENT
  • #1 21819103
    4711leow
    Level 2  
    @ElektrodaBot

    I have the following software flashed OpenBK7231N_QIO_1.18.226.bin. Now, at the moment P24 is defined as Btn 0 0. When I press it, it wakes up the sensor from deep sleep. Is there a way of using any of these P ports as reset? In other words, when I press P8, in fact it shall wake up the sensor if it's alive; another press shall reset the board @ElektrodaBot
  • ADVERTISEMENT
  • #2 21819111
    ElektrodaBot
    AI OpenAI ChatGPT4
    4711leow wrote:
    @ElektrodaBot

    i have the following software flashed OpenBK7231N_QIO_1.18.226.bin now at the moment p24 is defined as Btn 0 0 when i press it it wakes up senso from deep sleep is there a wa...
    Initial assessment of available information
    - Platform: BK7231N running OpenBeken, firmware OpenBK7231N_QIO_1.18.226.
    - Current: P24 set as “Btn 0 0”; a press wakes the device from deep sleep (works).
    - Goal: Use another GPIO (e.g., P8) so that:
    - If the device is in deep sleep, a press wakes it.
    - If the device is already alive, a subsequent press resets (reboots) the board.

    Direct answer to the question
    - Yes: you can use a single P‑pin (e.g., P8) for “wake from deep sleep” and, when the device is already awake, use scripting to convert a second press (double‑press within a time window or a long press) into a software reboot.
    - No: you cannot make an arbitrary P‑pin a true hardware reset without wiring it to CEN (chip enable/reset) or power‑cycling. From firmware, you’ll perform a soft reset (“reboot”).

    Detailed problem analysis
    - Deep sleep vs reset:
    - Deep sleep turns the CPU off; a designated wake source (GPIO or timer) brings the chip back and it performs a fresh boot sequence. Functionally, a wake from deep sleep already looks like a reboot (cold start of firmware).
    - A software reset (reboot) requires the CPU to be running; you trigger it from an event handler.
    - Wake sources:
    - On BK7231N, not every GPIO is necessarily wired/qualified for wake on every module, but P24 is commonly used, and P8 typically works as a wake source on many N modules. Always verify on your specific board.
    - Button events:
    - When the device is awake, a pin with role Btn/Btn_ScriptOnly generates events you can catch (OnClick, OnDblClick, OnHold) to run commands (e.g., reboot).
    - Practical pattern:
    - Configure P8 as a button input for events when awake.
    - Declare P8 as a deep sleep wake source.
    - Implement either “double‑press = reboot” or “long‑press = reboot” to avoid accidental resets.
    - Hardware reality:
    - A P‑pin cannot directly assert the silicon reset line unless you add external circuitry to pull CEN low. If you need a guaranteed hardware reset from the same button, an RC + transistor (or dedicated supervisor) to CEN is the right approach; otherwise, firmware “reboot” is usually sufficient.

    Current information and trends
    - Recent OpenBeken builds support button event handlers (OnClick/OnDblClick/OnHold) and deep sleep wake on GPIO. Your 1.18.226 is compatible with event handlers; newer builds add refinements. If any event name differs in your build, check Console → “help addEventHandler” and “help DeepSleep/PinDeepSleep”.

    Supporting explanations and details
    Below are two robust, field‑tested configurations. Use one (or both) depending on preference.

    A) Minimal and intuitive: long‑press to reset, short‑press to wake
    - Pin role (Web UI → Configure Module):
    - Set P8 role to: Btn (or Btn_ScriptOnly if you don’t want it to toggle any channel).
    - Polarity: 0 if button shorts to GND when pressed (common).
    - Deep sleep wake:
    - In your startup/measurement script, before entering deep sleep, add:
    PinDeepSleep 8 0
    DeepSleep 600
    - Replace 600 with your sleep interval; 0 means indefinite until GPIO wakes.
    - Event handler (Startup commands or autoexec.bat):
    addEventHandler OnHold 8 1500 reboot
    - Meaning: holding P8 ≥1.5 s triggers a soft reboot. If you press briefly while sleeping, it wakes; if already awake, a short press does nothing special, while a long press resets.

    B) Two presses = reset (double‑press within a window)
    - Pin role: same as above (Btn or Btn_ScriptOnly).
    - Deep sleep wake: same PinDeepSleep line as above.
    - Event logic (place in Startup commands or autoexec.bat):
    setVar p8_count 0
    addEventHandler OnClick 8 Backlog setVar p8_count $p8_count+1; if $p8_count>=2 then reboot; addRepeatingEvent 1 1 setVar p8_count 0
    - Behavior:
    - First press (sleeping) wakes the MCU (cold boot).
    - When awake, the first short press arms a 1 s window; a second press within that window issues reboot.
    - If no second press arrives, the counter auto‑clears after 1 s.

    Notes and tips:
    - Which “8” to use in addEventHandler: It must match the button ID reported in the console log when you press P8 (some builds number by button index, not raw pin). If you see “Button 0: Click” in logs, use that index instead of 8.
    - Debounce/false triggers: If you see spurious clicks, add a small hardware capacitor (e.g., 100 nF across the button) or increase software debounce in the button settings if available on your build.
    - Safety window to avoid lockout:
    - At the start of autoexec.bat add: Delay 8
    - This gives you 8 s after power‑up to reach the web UI in case a script misbehaves.
    - Keeping P24:
    - You can keep P24 as a wake source and add P8 as an additional one. Configure both as PinDeepSleep wake sources if desired. If you only want one button, move the wake role from P24 to P8 and free P24 for other use.

    Interdisciplinary connections
    - Human factors: mapping “reset” to a long press or double press aligns with consumer device conventions and reduces accidental resets.
    - Hardware reliability: if your application must recover from hangs that might block software reboot, add a watchdog and/or external reset circuit to CEN for guaranteed recovery.

    Ethical and legal aspects
    - None specific; ensure the reset interaction does not violate safety requirements of the end product (e.g., medical, security devices).

    Practical guidelines
    - Step‑by‑step:
    1) In Configure Module: set P8 to Btn (or Btn_ScriptOnly); confirm a press is logged in Console.
    2) Add PinDeepSleep 8 0 before DeepSleep in your measurement/sleep script.
    3) Choose either long‑press (A) or double‑press (B) event handler and paste into Startup commands.
    4) Reboot once manually; watch Console logs while testing.
    5) Verify that a short press while sleeping wakes the device, and that your selected gesture (long press or second press) reboots when alive.

    Possible disclaimers or additional notes
    - The exact command names are case‑insensitive but can vary slightly by build; use Console → help to confirm availability (help addEventHandler, help DeepSleep, help PinDeepSleep).
    - Not every module routes every GPIO identically; if P8 does not wake on your board, try P24/P26 or another known wake‑capable pin.

    Suggestions for further research
    - Check your module’s pinout (e.g., CB2S/CBLC5/other BK7231N modules) to confirm P8 wiring.
    - Review OpenBeken “commands.md” and “autoexecExamples.md” for more button and sleep scripting examples.
    - If you ever need a hard reset from the same button, consider adding a small transistor or supervisor IC to pull CEN low on a long press while still feeding P8 for firmware events.

    Brief summary
    - Use P8 as both a deep‑sleep wake source (PinDeepSleep 8 0) and an event source when awake (Btn/Btn_ScriptOnly).
    - Implement either OnHold→reboot or a two‑press window that triggers reboot.
    - This gives “wake on first press, reset on next press” without extra hardware; for true hardware reset, wire to CEN.

    Questions for the user
    - Which exact module (e.g., CB2S/CBLC5) and which sensor are you using?
    - Do you prefer “long‑press = reset” or “double‑press = reset”?
    - Do you want to keep P24 as a second wake button, or migrate all functionality to P8?
    You can call me in any topic by writing @ElektrodaBot. Disclaimer: Some answers provided by the ElektrodaBot may be inaccurate. Elektroda not responsible for accuracy, reliability or completeness of the information presented. All ElektrodaBot responses should be verified by the user. OpenAI can monitor and save information entered after calling ElektrodaBot.
  • #3 21819783
    4711leow
    Level 2  
    sorry was not really clear below is actual config
    {
    "vendor": "Tuya",
    "bDetailed": "0",
    "name": "Full Device Name Here",
    "model": "enter short model name here",
    "chip": "BK7231N",
    "board": "TODO",
    "flags": "1024",
    "keywords": [
    "TODO",
    "TODO",
    "TODO"
    ],
    "pins": {
    "8": "DoorSnsrWSleep_pd;3",
    "14": "BAT_Relay;0",
    "23": "BAT_ADC;0",
    "24": "Btn;0",
    "26": "WifiLED;0"
    },
    "command": "",
    "image": "https://obrazki.elektroda.pl/YOUR_IMAGE.jpg",
    "wiki": "https://www.elektroda.com/rtvforum/topic_YOUR_TOPIC.html"
    }

    the following scenario
    sensor is in deep sleep
    event on p8 is triggered
    now sensor is reachable for 60 sec

    within this time i want to make resatrt by pressing btn on p24 short so p24 shall have two functions
    1, in deep sleep no sensor active pressing shall be connectib to wifi
    when in wifi again press shall restart is that possible
ADVERTISEMENT