<h1 id="wemos-close-to-scan">wemos-close-to-scan</h1>
<p>Use a Wemos to monitor if the lid is open or closed on a network scanner.</p>
<ul>
<li><a href="https://github.com/kenfallon/wemos-close-to-scan">https://github.com/kenfallon/wemos-close-to-scan</a></li>
<li><a href="https://hackerpublicradio.org/eps.php?id=3275">https://hackerpublicradio.org/eps.php?id=3275</a></li>
</ul>
<h2 id="history">History</h2>
<p>In episode <a href="https://hackerpublicradio.org/eps.php?id=2430">hpr2430 :: Scanning books</a>, I had a bash file trigger a network scan. This required two steps, one to close the lid and the next to press a key for <a href="scantoimage.bash">scantoimage.bash</a> to trigger the next page of the scan.</p>
<p>In the intervening time I looked at several solutions to improve this situation.</p>
<p>The most obvious step was to put a magnetic switch on the scanner lid so that a device could detect the lid been closed.</p>
<p>I tried a Raspberry PI but my scanner drivers are only available for Intel and not Arm. Then then accessing the pi using Remote GPIO, but it got very complex to setup and run.</p>
<p>Inspired by <a href="https://hackerpublicradio.org/eps.php?id=3077">hpr3077 :: Video conference Push to Talk</a> Hosted by DanNixon on 2020-05-19, I tried using an arduino talking over serial to a Intel Compute Stick. But that was very flakey.</p>
<h2 id="hardware">Hardware</h2>
<p>Finally I settled on using a <a href="https://www.wemos.cc/en/latest/d1/d1_mini.html">Clone of LOLIN D1 mini</a>, and some Reed Contacts.</p>
<ul>
<li><a href="https://www.amazon.co.uk/gp/product/B071S8MWTY">Makerfire D1 Mini NodeMcu 4M Bytes Lua WIFI Development Board Base on ESP8266 ESP-12F N Compatible NodeMcu Arduino</a></li>
<li><a href="https://www.digikey.com/en/products/detail/zf-electronics/MP201801/361987">https://www.digikey.com/en/products/detail/zf-electronics/MP201801/361987</a></li>
<li><a href="https://switches-sensors.zf.com/us/product/magnetic-position-sensor-mp2018/">https://switches-sensors.zf.com/us/product/magnetic-position-sensor-mp2018/</a></li>
<li><a href="https://www.conrad.nl/p/zf-mp201801-reedcontact-1x-no-175-vdc-175-vac-500-ma-10-w-276124">ZF MP201801 Reedcontact 1x NO 175 V/DC, 175 V/AC 500 mA 10 W</a></li>
<li><a href="https://www.conrad.nl/p/zf-as201801-bedienmagneet-voor-reedcontact-276116">ZF AS201801 Bedienmagneet voor reedcontact</a><br /></li>
</ul>
<h2 id="wiring">Wiring</h2>
<p>Wire one end of the reed contact to 3.3v, and the other end to ground via a 10K resistor.</p>
<p>Have a sensor wire go from the 10K resistor to pin D5 on the D1 Mini.</p>
<p><img src="eps/hpr3275/circuitdiagram.png" title="Circuit Diagram" alt="circuitdiagram" /></p>
<p><img src="eps/hpr3275/breadboard.png" title="Breadboard" alt="breadboard" /></p>
<p><img src="eps/hpr3275/photo.png" title="Photo" alt="photo" /></p>
<h2 id="code">Code</h2>
<h3 id="d1-mini">D1 Mini</h3>
<p>See <a href="eps/hpr3275/wemos-close-to-scan.ino">wemos-close-to-scan.ino</a></p>
<h3 id="laptop">Laptop</h3>
<p>See <a href="eps/hpr3275/wemos-scantoimage.bash">wemos-scantoimage.bash</a></p>
<h1 id="operation">Operation</h1>
<ol>
<li>Plug in D1 Mini and monitor the serial port to get its IP Address.</li>
<li>Change the <code>server="YOUR-WEMOS-IP-ADDRESS"</code> in <a href="eps/hpr3275/wemos-scantoimage.bash">wemos-scantoimage.bash</a> to the ip address.</li>
<li>Change the <code>image_path="/PATH/TO/YOUR/SCANS/"</code> in <a href="eps/hpr3275/wemos-scantoimage.bash">wemos-scantoimage.bash</a> to where your want the files saved.</li>
<li>Close scanner and scan.</li>
</ol>
