Are there any rules on dynamic pin re-assignment? The following code bricks the imp and only a power cycle will bring it back to life. Is it because I’m doing the re-assignment of the pin the caused the event handler to run?
Thanks as always
/`/ Event handler for PIR
function swEvent()
{
// Idle for 50ms to allow switch to settle
imp.sleep(0.15);
// Get PIR state
local state = hardware.pin1.read();
// PIR movement
if(state == 1 && movement == 0){
triggerCount++;
server.log("tc:"+triggerCount);
if(triggerCount == 5){
movement =1;
server.log("Movement - wait "+ reArmDelay +" secs - " + format("rssi: %d dBm", imp.rssi()) );
local _httpOut="l|020|5|"+getDateTime()+"|Monitor-Movement|PIR";
_wsOut.set(_httpOut);
hardware.pin1.configure(DIGITAL_OUT);
imp.wakeup(reArmDelay, reArm);
}
}
Well, hang on, what’s connected to pin1? (Feel free to reply privately if need be.) But if you’re in an event handler 'cos something’s driving pin1 high, and the imp then tries to drive it low, you’re going to have a bad time.
Peter, ok that’s what I’ve done but still bricks the imp.
Could I confirm that whitest in shallow sleep e.g. imp.wakeup that a pin event handler will be called e.g it isn’t blocked?
Hope I’m making sense not too sure if I am these days!
Yes it does include blocking an InputPort setter, and yes the wiki should say so. I’ll head off there now.
And all Squirrel runtime errors cause a reboot (or certainly should do), whether the Squirrel in question is being run on startup or in an event handler or timer callback.