Difference between revisions of "WelcomeSwitch"

From i3Detroit
Jump to: navigation, search
m
(updated batchfile to reflect recover-from-crashed-camera changes)
Line 48: Line 48:
 
Updated batch file, this is the one currently running on nate's desktop at home:
 
Updated batch file, this is the one currently running on nate's desktop at home:
 
<pre>
 
<pre>
 +
echo off
 
rem set currentstate=off
 
rem set currentstate=off
 
set camerahost=i3detroit.dyndns.org:5000
 
set camerahost=i3detroit.dyndns.org:5000
Line 57: Line 58:
 
:begin
 
:begin
 
del getdi.cgi
 
del getdi.cgi
wget --user=%camerauser% --password=%camerapass% http://%camerahost%/cgi-bin/getdi.cgi
+
wget --user=%camerauser% --password=%camerapass% --timeout=5 --tries=2 http://%camerahost%/cgi-bin/getdi.cgi
 
find "DI=H" <getdi.cgi
 
find "DI=H" <getdi.cgi
 
echo %errorlevel%
 
echo %errorlevel%
Line 71: Line 72:
 
:itson
 
:itson
 
echo It's on!
 
echo It's on!
 +
wget --user=%camerauser% --password=%camerapass% --timeout=5 http://%camerahost%/cgi-bin/setdo.cgi?do=h --output-document=NUL
 
if "%currentstate%" EQU "on" goto loop
 
if "%currentstate%" EQU "on" goto loop
 
set currentstate=on
 
set currentstate=on
 
echo Switch set to ON state, %time% %date% >> log
 
echo Switch set to ON state, %time% %date% >> log
wget --user=%camerauser% --password=%camerapass% http://%camerahost%/cgi-bin/setdo.cgi?do=h --output-document=NUL
 
 
rem wget --user=%twitteruser% --password=%twitterpass% --post-data="status=The space is OPEN FOR GUESTS as of %time%, please drop in!" http://twitter.com/statuses/update.xml --output-document=NUL
 
rem wget --user=%twitteruser% --password=%twitterpass% --post-data="status=The space is OPEN FOR GUESTS as of %time%, please drop in!" http://twitter.com/statuses/update.xml --output-document=NUL
 
del video.jpg
 
del video.jpg
wget --user=%camerauser% --password=%camerapass% http://%camerahost%/cgi-bin/video.jpg
+
wget --user=%camerauser% --password=%camerapass% --timeout=5 http://%camerahost%/cgi-bin/video.jpg
 
curl --form username=%twitteruser% --form password=%twitterpass% --form media=@video.jpg --form-string "message=The space is OPEN FOR GUESTS, and here's who flipped the switch! Drop in?" http://twitpic.com/api/uploadAndPost
 
curl --form username=%twitteruser% --form password=%twitterpass% --form media=@video.jpg --form-string "message=The space is OPEN FOR GUESTS, and here's who flipped the switch! Drop in?" http://twitpic.com/api/uploadAndPost
 
goto loop
 
goto loop
Line 87: Line 88:
 
echo Switch set to OFF state, %time% %date% >> log
 
echo Switch set to OFF state, %time% %date% >> log
 
wget --user=%twitteruser% --password=%twitterpass% --post-data="status=The space is closed as of %time% %date%" http://twitter.com/statuses/update.xml --output-document=NUL
 
wget --user=%twitteruser% --password=%twitterpass% --post-data="status=The space is closed as of %time% %date%" http://twitter.com/statuses/update.xml --output-document=NUL
wget --user=%camerauser% --password=%camerapass% http://%camerahost%/cgi-bin/setdo.cgi?do=l --output-document=NUL
+
wget --user=%camerauser% --password=%camerapass% --timeout=5 http://%camerahost%/cgi-bin/setdo.cgi?do=l --output-document=NUL
 
goto loop
 
goto loop
 
</pre>
 
</pre>

Revision as of 19:03, 7 March 2010

Wiring

On the camera, there's a hacked-up PoE cable that does the following:

1 wht/org ethernet
2 org/wht ethernet
3 wht/grn ethernet
4 blu/wht GND, also Digital Input -
5 wht/blu Digital Input +
6 grn/wht ethernet
7 wht/brn Relay Output
8 brn/wht +12V, also Relay Input

This allows the camera to be positioned away from the door by running a single cable. Without this, you'd need one for power, one for network, AND one for the I/O pins. Using a single 24ga wire for power is suboptimal, but the camera doesn't draw much power, and it hasn't been an issue yet.

In the box above the door: Ethernet pins pass through to Ethernet input (into which is plugged the feed from the back of the space.) GND from power input goes to GND from camera, also to LED cathode and SSR negative. +12 from power input goes to +12 from camera, also to switch contact. Relay Output from camera goes to LED anode and SSR positive. Digtal Input + from camera goes to switch contact. SSR isn't currently connected; signals are on orange wires, shrinkwrapped to prevent shorts in the time being.

(To accommodate a future local OPEN sign, provision has been made for connecting the big solid-state relay, which can switch anything we could throw at it.)

Software

The most important part of all this! Camera documentation: [1]


Proof-of-concept batch file:

:top
del getdi.cgi
wget --user=port --password=port http://i3detroit.dyndns.org:5000/cgi-bin/getdi.cgi
find "DI=L" <getdi.cgi
echo %errorlevel%
if %errorlevel% EQU 0 wget --user=port --password=port http://i3detroit.dyndns.org:5000/cgi-bin/setdo.cgi?do=l --output-document=NUL
rem This turns the LED off when the switch is down.
find "DI=H" <getdi.cgi
echo %errorlevel%
if %errorlevel% EQU 0 wget --user=port --password=port http://i3detroit.dyndns.org:5000/cgi-bin/setdo.cgi?do=h --output-document=NUL
rem This turns the LED on when the switch is up. 
sleep 1
goto top

Updated batch file, this is the one currently running on nate's desktop at home:

echo off
rem set currentstate=off
set camerahost=i3detroit.dyndns.org:5000
set camerauser=port
set camerapass=port
set twitteruser=contact@i3detroit.com
set twitterpass=redacted-from-wiki

:begin
del getdi.cgi
wget --user=%camerauser% --password=%camerapass% --timeout=5 --tries=2 http://%camerahost%/cgi-bin/getdi.cgi
find "DI=H" <getdi.cgi
echo %errorlevel%
if %errorlevel% EQU 0 goto itson
find "DI=L" <getdi.cgi
echo %errorlevel%
if %errorlevel% EQU 0 goto itsoff

:loop
sleep 10
goto begin

:itson
echo It's on!
wget --user=%camerauser% --password=%camerapass% --timeout=5 http://%camerahost%/cgi-bin/setdo.cgi?do=h --output-document=NUL
if "%currentstate%" EQU "on" goto loop
set currentstate=on
echo Switch set to ON state, %time% %date% >> log
rem wget --user=%twitteruser% --password=%twitterpass% --post-data="status=The space is OPEN FOR GUESTS as of %time%, please drop in!" http://twitter.com/statuses/update.xml --output-document=NUL
del video.jpg
wget --user=%camerauser% --password=%camerapass% --timeout=5 http://%camerahost%/cgi-bin/video.jpg
curl --form username=%twitteruser% --form password=%twitterpass% --form media=@video.jpg --form-string "message=The space is OPEN FOR GUESTS, and here's who flipped the switch! Drop in?" http://twitpic.com/api/uploadAndPost
goto loop

:itsoff
echo It's off!
if "%currentstate%" EQU "off" goto loop
set currentstate=off
echo Switch set to OFF state, %time% %date% >> log
wget --user=%twitteruser% --password=%twitterpass% --post-data="status=The space is closed as of %time% %date%" http://twitter.com/statuses/update.xml --output-document=NUL
wget --user=%camerauser% --password=%camerapass% --timeout=5 http://%camerahost%/cgi-bin/setdo.cgi?do=l --output-document=NUL
goto loop