Hardware.wakereason() == WAKEREASON_POWER_RESTORED

Hi gang, long time no forum.

I have a USB powered C3V0 (imp002) running as a power and internet monitor. It is reporting wake reasons in the device and MessageManager timeouts from the agent. It’s backed by an old, spare UPS and is monitoring the mains power using a 3V3 power adapter connected to pin1.

It’s doing a pretty good job of letting me know when the internet has disconnected but is doing really badly at telling me why.

  1. Most times it reboots with wakereason WAKEREASON_POWER_RESTORED (11). What does this code mean?
  2. Why is it rebooting at all when my initialisation sequence is:
imp.setsendbuffersize(8096);
cm <- ConnectionManager({ "blinkupBehavior": CM_BLINK_ON_DISCONNECT, "startBehaviour": CM_START_CONNECTED, "stayConnected": true, "errorPolicy": RETURN_ON_ERROR_NO_DISCONNECT });
mm <- MessageManager({ "retryInterval": 10, "messageTimeout": 5, "autoRetry": true, "maxAutoRetries": 0, "connectionManager": cm });

Any thoughts would be appreciated.

Sounds like a partial brownout, which I believe is what will give you power restored on an 002.

Essentially, the device has lost 3v3 enough that the CPU got reset, but the NVRAM was still preserved. This usually means 3v3 has dropped below about 2.7v, but now lower than about 1.8v (which is where NVRAM gets lost).

Could be the PSU the imp is run from?

It’s happening in two locations, 100km apart. One has a UPS and the other doesn’t (yet). Both devices are C3V0’s with generic USB power supplies. They SEEM to be rebooting after a network outage not a power outage for example this sequence of alarms …

[2023-02-20 14:43:19] Site1 [101.182.110.71] Offline: Response timeout
[2023-02-20 14:46:51] Site1 [1.145.169.27] Online: Cold boot [11] (247 secs offline)
[2023-02-20 14:48:59] Site1 [1.145.169.27] Offline: Response timeout
[2023-02-20 14:49:12] Site1 [101.182.110.71] Online: Cold boot [11] (48 secs offline)

Note the IP address changes. This shows the imp is going offline and coming back on my router’s SIM card backup. Then a couple of minutes later it is falling back to the cable internet. The outages are correct but the boot reason of 11 makes little sense here.

Hmm. Fair point. Though, if the code is still running, it hasn’t re-woken so the wake reason won’t have changed? That’s the reason from the original power on.

These logs should only be executed when the system reboots but I will double check to make sure I am not mistaken.

Yeh, I set my boot reason variable to null as soon as I use it and it can only be set again at boot.
This is the entirety of my device code.

cm <- ConnectionManager({ "blinkupBehavior": CM_BLINK_ON_DISCONNECT, "startBehaviour": CM_START_CONNECTED, "stayConnected": true, "errorPolicy": RETURN_ON_ERROR_NO_DISCONNECT });
mm <- MessageManager({ "retryInterval": 10, "messageTimeout": 5, "autoRetry": true, "maxAutoRetries": 0, "connectionManager": cm });
imp.setsendbuffersize(8096);

reason <- getWakeReason();
booted <- clock().tointeger(); // Adjustment for soft-boots
poweralarming <- false;

// Respond to ping requests from the agent
mm.on("ping", function(message, reply) {
    if (reason) {
        // We recently booted so send that as a reason
        local booted = time() - clock().tointeger() + booted;
        reply({ "status": "alarm", "reason": reason, "booted": booted });
        reason = null;
    } else if (poweralarming) {
        reply({ "status": "alarm", "reason": "power out" });
    } else {
        // Just reply acknowledging we received the message
        reply({ "status": "ok" });
    }
});


// Power monitoring via pin1 (high = powered, low = unpowered)
debounce_timer <- null;
hardware.pin1.configure(DIGITAL_IN_PULLDOWN, function() {
    if (debounce_timer) return;
    debounce_timer = imp.wakeup(1, function() {
        debounce_timer = null;
        poweralarming = !hardware.pin1.read();
        // server.log("The power on pin1 is now: " + (poweralarming ? "power off" : "power on"));
    })
});

This topic was automatically closed after 60 days. New replies are no longer allowed.