As is, this project provides a simple activity sensor using a radar module (or PIR... and notice that the Wemos D1 mini has a useful 5v pin for powering such 5v sensors).
More usefully, a second unit can be used as a networked remote monitor for the first unit.
I have purposely kept the script generic to offer easy networking without need for individual network configurations... so the same script runs both the Sensor and Monitor units (assuming the gpio's are not different).
If both units had sensors they could act as remote monitors for each other.
Multiple remote monitors could be used with a sender if wished.
Multiple senders could also be used, but you'd probably prefer to include facility to send and receive individual unique IDs, which means modifying the code to send and receive your specific ID info. That's easily enough done by appending your own info to the end of
udpwrite udpaddr, udpport, "RemoteAlert" & "Your data here"
in the [TRIGGERED] subroutine, and obviously you then need to extract it in [UDPMSG] and respond as required, so that's down to you.
The project is intended as a useful 'starting point' to be taken further as wished, so hopefully the code should be fairly easy to follow and modify as needed.
Despite the project being based around a Radar module, the minimal hardware for the standalone unit is just any sort of sensor or switch or button for input to trigger alerts, and an LED indicator for showing local alerts.
Be aware that, unlike a PIR, a Radar sensor may detect activity outside of its line of sight, ie: behind walls or other obstacles.
The minmal hardware for a Sender is just a sensor or switch to trigger alerts.
The minimal hardware for a Monitor is just an LED indicator for showing remote alerts.
So it doesn't get much simpler than this, and offers much potential for adding your own knobs and whistles.
The Radar modules default inactivity timeout of 2 secs could be altered by changing one tiny SMD cap... good luck with that!
I would prefer to do it in software: Esp-Basic hardware interrupts are generated when their pin goes Hi or Lo, so basically it's a matter of not declaring a Clear immediately when the Alert pin becomes inactive in [TRIGGERED], but what you do and how you do it (eg: whether using a timer or blocking delay, and whether ignoring subsequent alerts during the extended timeout, etc) is up to you.
Note that interrupt sensorpin, [TRIGGERED] is not declared until the end of [BLINKIP] to ignore any sensor triggers until after the blink IP initialisation has completed.
The blink IP facility allows you to save the same generic script to all units, configure all their SETTINGS the same with appropriate SSID and password and set them all to Autorun, then power them online one by one (even out in the field), watching for their last IP address byte to be blinked out about 30 secs later (after wifi connection). It is assumed you already know your routers subnet address, therefore you just need to know what DHCP node address (the last address byte) it has been allocated so you can connect to it with your browser if needed.
Note that a zero is denoted by 10 LED blinks because none would have been very misleading!
EDIT
A dual-action button-press plug-in has been added at the bottom if anyone wants it.
'Activity Monitor - developed on Esp-Basic V3 A69
'Uses radar module to monitor activity
'One unit can be used by itself for stand-alone use.
'Two units can be networked without mods as a sensor Sender and receiver Monitor pair.
'In which case they need configuring with suitable wifi router SSID and password in SETTINGS
' plus configure for autorun (tick "Run default.bas at startup:" box in SETTINGS)
'Watch for the last IP address byte to be blinked on the local led after reconnection
' or use a serial port monitor at bootup to view their assigned IP address
'Repeated triggering extends Alert time, Clear is sent after the modules default 2 sec inactivity timeout
memclear
nodeIP = mid(ip(),instrrev(ip(),".")+1)
print ip()
buttonpin = 0 'Optional "Clear Alerts" button - needs a pullup resistor
buttonoff = 1 'Default button OFF state if using the optional hardware button
interrupt buttonpin, [PRESSED]
sensorpin = 5 ' From Radar or PIR module OUTput
sensoroff = 0 'Default sensor OFF state
'interrupt sensorpin, [TRIGGERED] has been moved to the bottom of [BLINKIP]
locLEDpin = 2 'Local activity alert indicator led or relay
locLEDoff = 1 'Default local alert pin OFF state (if is active high or low)
if locLEDoff = 1 then io(po,locLEDpin,1) else io(po,locLEDpin,0) 'initialise local led to OFF
remLEDpin = 4 'Remote activity alert indicator led or relay (optional Remote Monitor)
remLEDoff = 1 'Default remote alert pin OFF state (if is active high or low)
if remLEDoff = 1 then io(po,remLEDpin,1) else io(po,remLEDpin,0) 'initialise remote led to OFF
udpport = 1010 'Change port if wished, but don't forget to also change any other units
udpaddr = "255.255.255.255" 'Change to your own subnet if you don't want to broadcast to all
udpbegin udpport
udpbranch [UDPMSG]
localerts = 0
remalerts = 0
status = "Ready"
html "<BR><BR>"
textbox localerts
html "Local Alerts"
html "<BR><BR>"
textbox remalerts
html "Remote Alerts"
html "<BR><BR>"
textbox status
html "Last Status Msg"
html "<BR><BR>"
button "Clear", [CLEAR]
html "<BR><BR>"
button "Exit", [EXIT]
html "<BR><BR>"
timer 1000, [BLINKIP]
wait
[TRIGGERED]
if io(laststat,sensorpin) = sensoroff then
status = "Local Clear"
if locLEDoff = 1 then io(po,locLEDpin,1) else io(po,locLEDpin,0)
udpwrite udpaddr, udpport, "RemoteClear"
else
status = "Local Alert"
localerts = localerts + 1
if locLEDoff = 0 then io(po,locLEDpin,1) else io(po,locLEDpin,0)
udpwrite udpaddr, udpport, "RemoteAlert"
endif
wait
[UDPMSG]
msg = udpread()
if instr(msg,"RemoteAlert") >0 then
status = "Remote Alert"
remalerts = remalerts + 1
if remLEDoff = 1 then io(po,remLEDpin,0) else io(po,remLEDpin,1)
endif
if instr(msg,"RemoteClear") >0 then
status = "Remote Clear"
if remLEDoff = 1 then io(po,remLEDpin,1) else io(po,remLEDpin,0)
endif
return
[CLEAR]
status = "Reset"
localerts = 0
remalerts = 0
if locLEDoff = 1 then io(po,locLEDpin,1) else io(po,locLEDpin,0)
if remLEDoff = 1 then io(po,remLEDpin,1) else io(po,remLEDpin,0)
wait
[PRESSED]
if io(laststat,buttonpin) <> buttonoff then
status = "Button Pressed"
goto [CLEAR]
endif
wait
[EXIT]
status = "Halted"
end
wait
[BLINKIP]
'Blinks the last IP address byte, 0 is represented by 10 blinks
timer 0
blinkon = 200
blinkoff = 400
blinkpause = 1000
if locLEDoff = 0 then io(po,locLEDpin,0) else io(po,locLEDpin,1) ' turn led off
for pos = 1 to len(nodeIP)
digitchr = mid(nodeIP,pos,1)
if digitchr = "0" then digit = val("10") else digit = val(digitchr)
for count = 1 to digit
if locLEDoff = 0 then io(po,locLEDpin,1) else io(po,locLEDpin,0)
delay blinkon
if locLEDoff = 0 then io(po,locLEDpin,0) else io(po,locLEDpin,1)
delay blinkoff
next count
delay blinkpause
next pos
delay 1000
interrupt sensorpin, [TRIGGERED]
wait
'----- End of script -----
Dual-Action Button-Press
Just copy the following code over the top of the existing [PRESSED] subroutine in the above code to provide alternative Short (<1sec) or Long (>1sec) button press actions - in this case a Short press 'simulates' a local Alert trigger whereas a Long press Clears accumulated alerts.
[PRESSED]
'Allows different actions for short and long button presses
stop = 0
if io(laststat,buttonpin) <> buttonoff then start = millis() else stop = millis()
if stop > start then
if stop-start < 1000 then goto [SHORTPRESS] else goto [LONGPRESS]
endif
wait
[SHORTPRESS]
'Place to put users short-press button goto
goto [TRIGGERED]
wait
[LONGPRESS]
'Place to put users long-press button goto
goto [CLEAR]
wait