2018-03-24 23:22 GMT+01:00 Lyndon Nerenberg <lyn...@orthanc.ca>:
> By far the easiest way to do this is to connect a switch to the door that 
> opens/closes as the door opens/closes.  This assumes that when you say "the 
> door moves" you really meant "is opened or closed".
>
> Whether the switch is normally open or normally closed doesn't matter.  Wire 
> the switch to a serial port; connect one side to DTR, the other to CD.

Serial ports are long gone on todays laptops sadly.

> Now you can write a program that runs a loop that (1) opens the blocking tty 
> device, then (2) reads the descriptor, which will block until CD drops 
> returning an error from read(2), at which point you close the descriptor and 
> repeat the loop.

A method I implemented in the past at our hackerspace was to use an
ethernet nic, and some kind of modified loopback cable. Wire 1(tx+) to
3(rx+) and a switch or a photoresistor between 2(tx-) and 6(rx-). When
the switch closes the loopback is completed and the link goes up.
ifstated(8) detects it and runs whatever you want. Send a mail,
logger(1) to a remote syslog, snmp trap...

You can even use a cheap managed switch and very cheaply add plenty of
ports for on/off sensors. The switch sends a trap when a link goes
up/down and there you go.

Kudos to the project that gave me this idea:
http://www.newtonnet.co.uk/catfeeder/ :)

Reply via email to