<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="3.9.3">Jekyll</generator><link href="http://www.joshlebo.com/feed.xml" rel="self" type="application/atom+xml" /><link href="http://www.joshlebo.com/" rel="alternate" type="text/html" /><updated>2025-05-14T10:48:28-04:00</updated><id>http://www.joshlebo.com/feed.xml</id><title type="html">joshlebo.com</title><subtitle>Adventures in computing, electronics, making, and modifying of things. </subtitle><entry><title type="html">Garage Door Control with an ESP32, Tasmota, and SmartThings</title><link href="http://www.joshlebo.com/making/2024/01/12/esp32garagedoor.html" rel="alternate" type="text/html" title="Garage Door Control with an ESP32, Tasmota, and SmartThings" /><published>2024-01-12T07:00:00-05:00</published><updated>2024-01-12T07:00:00-05:00</updated><id>http://www.joshlebo.com/making/2024/01/12/esp32garagedoor</id><content type="html" xml:base="http://www.joshlebo.com/making/2024/01/12/esp32garagedoor.html"><![CDATA[<h2 id="this-is-a-work-in-progress">This is a work in progress</h2>

<font color="red">Proceed with caution.</font>
<p>I am not responsible for the destruction of property or wildlife. Use sound judgement.</p>

<p>Newer Liftmaster garage door openers have MyQ cloud support.  It’s possible to use a phone app with the legacy Internet gateway (828LM) to operate the door, but tying that cloud to Samsung SmartThings didn’t seem straightforward.  Decided to build my own solution and link to a SmartThings gateway with Matter over local wifi.  This howto would probably work with Amazon Alexa or Google Nest with a few modifications.</p>

<p>The overall goal was to have my garage door controller communicate with a local SmartThings hub, and leverage that existing cloud connection to provide app functionality.</p>

<p><img src="/assets/images/828lm.jpg" alt="828lm" /></p>

<p><strong>Table of Contents</strong></p>

<p><a href="#overview">1 Tech Overview</a><br />
<a href="#items">2 Items Required</a><br />
<a href="#esp32">3 ESP32 Config</a><br />
<a href="#wiring">4 Wiring</a><br />
<a href="#smartthings">5 Adding Tasmota to SmartThings</a><br />
<a href="#references">6 References</a><br /></p>

<p><a name="overiew"></a></p>
<h3 id="tech-overview">Tech Overview</h3>

<p>The goal is for this build is twofold: report the garage door state, and provide a means to change that state. These two functions will be independent, but are able to be viewed or changed via the SmartThings phone app. Routines can be written to automate as desired, for example “If garage door is open after 11:00pm, close garage door”</p>

<p>An ESP32 running Tasmota communicates with the SmartThings hub, and reports whether the reed switch is open or closed.  If a change in the door state is requested, the ESP32 fires a relay to simulate a button press to initiate door action.</p>

<p>Most older garage door openers have a set of contacts that if closed, trigger action on the garage door. On some newer ‘secure’ garage doors, only a signal from a wall panel or wireless remote can trigger door action. In this howto, my relay will be connected to a wireless remote, but know that it could be wired directly to contacts on an older model.</p>

<p>The SmartThings hub is leveraged to send notifications and automate routines.</p>

<p><a name="items"></a></p>
<h3 id="items-required">Items Required</h3>

<p>Items Required:</p>
<ul>
  <li>ESP32 microcontroller - I use a 38 pin ESP-WROOM-32 dev board with pin headers - $4</li>
  <li>Relay Board - 5V input fairly commond relay board - $5</li>
  <li>Garage Door Opener - $10 knock-offs are available</li>
  <li>Case - use a $10 project box, or 3D print one</li>
  <li>Reed Switch - $3</li>
  <li>Wire, bell wire or Cat5 - $10 for a bundle</li>
</ul>

<p>Prices are rounded up, if you have bins of components like I do, you may have some of the above laying around.</p>

<p><a name="esp32"></a></p>
<h3 id="esp32-config">ESP32 Config</h3>

<p><img src="/assets/images/esp32.png" alt="esp32" /></p>

<p>Find yourself an ESP32 microcontroller on a dev board, and get it programmed with Tasmota <a href="https://tasmota.github.io/">https://tasmota.github.io/</a>.  Keep in mind that you need an ESP32, as an ESP8266 is not supported at the time of this article. The web browser based installer works great for an initial flash.  I’m using Tasmota 13.3 in the examples.</p>

<p>In Tasmota, browse to Configuration -&gt; Configure Module. Set GPIO18 as Relay 1, and GPIO19 as Switch 2.  The pins and values used do not matter as long as you keep track of the values used. Save your config and jot them down!</p>

<p><img src="/assets/images/gpio_config.jpg" alt="gpio_config" /></p>

<p>From the Main Menu again, go to Consoles -&gt; Console. Run the following commands:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>SetOption114 1
PulseTime1 5
SwitchMode2 2
</code></pre></div></div>

<p>Option114 decouples Relays from Switches, as we will have two separate devices (a reed sensor and an independent switch). PulseTime is the duration to toggle the relay, and SwitchMode sets switch2 to inverted follow mode (0 = ON, 1 = OFF)</p>

<p>Tasmota has a ton of config outside of the scope of the howto, but I often set the following:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>SO53 1 = show hostname and IP
SO146 1 = Display internal temp
SO08 1 = Temp in F not C
... and many others
</code></pre></div></div>
<p>Check out <a href="https://tasmota.github.io/docs/">Tasmota docs</a> for further info.</p>

<p><a name="wiring"></a></p>
<h3 id="wiringpinout">Wiring/Pinout</h3>

<p>I purchased a garage door opener clone and paired it with my opener.  One difference I found with this opener is that instead of tapping the button to open the door, I had to hold it for half a second. Easily doable with our relay setup.  On my 3 button remote, I paired the third, largest button to my opener, but you could probably use any of the three.
Pins for Relay and Reed Switch (Contact)
picture of wiring</p>

<p><img src="/assets/images/esp32_pinout.png" alt="esp32_pinout" /></p>

<p><a name="smartthings"></a></p>
<h3 id="adding-tasmota-to-smartthings">Adding Tasmota to SmartThings</h3>

<p>This howto uses the Matter protocol to link the ESP32 to SmartThings.  Start by logging into the Tasmota interface on the ESP32 and navigating to Configure -&gt; Configure Matter.  Check the …</p>

<p>Now we need to ensure the sensors are added to Matter for sharing.</p>

<p>More information surrounding Tasmota’s Matter support can be found <a href="https://tasmota.github.io/docs/Matter/">here</a></p>

<p>Linking Tasmota to SmartThings via Matter is fairly straightforward. Start by adding a new device to SmartThings.  Select Partner Device -&gt; Matter. The phone will request a QR code - point this to the QR code displayed on the Tasmota device. Once scanned the SmartThings app will confirm that you wish to add a unknown manufacturer.  This is acceptable, as the Tasmota/Matter stack is an open source project and not technically a vendor.</p>

<p>The app should now display the Garage Door Relay and Garage Door Sensor (our Reed switch). The first will show the door status, the second will allow you to trigger the garage door. Normal SmartThings functionality will apply in the form of creating Routines and sending alerts.</p>

<p><a name="references"></a></p>
<h3 id="references">References</h3>

<p>Many thanks to the below</p>

<p><a href="https://www.espressif.com/en/products/socs/esp32">Espressif</a> - their ESP32 devices provide a great platform for my projects</p>

<p><a href="https://tasmota.github.io/docs/">Tasmota</a> - Provides a consistent interface to the ESP32, allowing one to focus on implementation instead of chasing documentation</p>

<p><a href="https://digiblur.com/wiki/ha/esphome-garage-opener/">Digiblur</a> - the idea of leveraging an existing remote came from here; adapted to my model of remote</p>

<p>If I missed any references or any of the above is in some way incomplete, reach out and I’ll attempt to remedy.</p>

<h2 id="this-is-a-work-in-progress-1">This is a work in progress</h2>]]></content><author><name></name></author><category term="making" /><summary type="html"><![CDATA[This is a work in progress]]></summary></entry><entry><title type="html">Radio Controlled Lawn Mower Build (updated after 5 years)</title><link href="http://www.joshlebo.com/rcmower/" rel="alternate" type="text/html" title="Radio Controlled Lawn Mower Build (updated after 5 years)" /><published>2022-10-23T08:00:00-04:00</published><updated>2022-10-23T08:00:00-04:00</updated><id>http://www.joshlebo.com/rcmower</id><content type="html" xml:base="http://www.joshlebo.com/rcmower/"><![CDATA[<font color="red">Proceed with caution.</font>
<p>I am not responsible for the destruction of property or wildlife. Use sound judgement.</p>

<p><strong>Table of Contents:</strong></p>

<p><a href="#parts">1 Parts List</a><br />
<a href="#go">2 Making it Go</a><br />
<a href="#safety">3 Safety Concerns</a><br />
<a href="#wiring">4 Wiring Diagram</a><br />
<a href="#frame">5 Frame</a><br />
<a href="#mowing">6 Mowing</a><br />
<a href="#lessons">7 Lessons Learned</a><br />
<a href="#mk2">8 Mk II Rebuild</a><br />
<a href="#mk3">9 Mk III Rebuild</a><br /></p>

<p>This journey will require problem solving as well as trial and error. The below pictures of various builds during my own journey.<br /><br /><br />
<img src="/assets/images/mk3.jpg" alt="mk3" />
<img src="/assets/images/mk2grass.jpg" alt="mk2" />
<img src="/assets/images/withnewtires.jpg" alt="mk1" /></p>

<p><a name="parts"></a></p>
<h4 id="parts-list">Parts List:</h4>

<ul>
  <li>Spektrum AR610 RC receiver - $29</li>
  <li>Spektrum DXe Transmitter - $60 ( I way overbought on this )</li>
  <li>Dimension Engineering 2x60A Motor Controller - $180 (first controller)</li>
  <li>Cytron SmartDriveDuo-60 (MDDS60) - $150 (much better second controller)</li>
  <li>Cheap Used Lawn Mower - $55</li>
  <li>Pride Jet 3 Ultra Wheelchair motors - $100</li>
  <li>Pride Jet 3 Ultra Wheelchair tires - $40 (buy these with the above to save time and headaches) <strong>Update</strong> - used the rims with better tires</li>
  <li>Large front caster wheels - $20</li>
  <li>Tons of Electronics. 12V to cigarette adapter, switches, wire, etc - $50</li>
  <li>Orange strobe light - $20</li>
  <li>Arduino Nano (actually a clone) - 5 for $20, so I guess $4 (update: not used)</li>
  <li>Sainsmart Dual Relay Board - $7 (update: not used)</li>
  <li>Pololu RC Switch and Relay - $10</li>
  <li>Steel stock for the frame - $100</li>
  <li>Poulan Pro all steel deck lawn mower - $150</li>
</ul>

<p>Always looking for a project, I decided to build an RC lawn mower.   This project seemed to combine mechanical, electrical, and drone experience into one. The idea of mowing the grass from my porch while wearing a beer dispensing helmet always appealed to me.</p>

<p><a name="go"></a></p>
<h4 id="making-it-go">Making it go:</h4>

<p>The very first thing that I purchased from eBay was the wheelchair Motors. I made the mistake of not purchasing matching wheels at the same time. This led to a few false starts attempting to match wheel hubs to the motors. In the end I ended up going back to eBay and buying the correct wheels from the same manufacturer for $40.  The only modification I had to do to the wheelchair Motors was to remove the top covers, remove the brakes and cut the electric brake wires. This may sound scary, but while the device is in gear it doesn’t move unless powered.</p>

<p><img src="/assets/images/electricbrake.jpg" alt="electric brake" /></p>

<p>To convert RC signals into motion, I used a Dimension Engineering 2x60 motor controller. This interfaces nicely with a standard RC controller (from Spektrum in this case). I had to mess with the dip switch settings to get the controls correct.  Essentially it’s in RC mode, linear rate, and in mixed mode, not dual-stick tank steering.  No additional programming was needed for the RC controller. Testing via a multimeter was helpful. While mapping from the RC transmitter to the Dimension motor driver.</p>

<p>Power is supplied by two RV/Deep Cycle batteries in a series.  This puts out 24-25 volts of power. This thing is wicked fast and somewhat twitchy.</p>

<p><a name="safety"></a></p>
<h4 id="safety-concerns">Safety Concerns</h4>

<p>I wanted the gasoline lawn mower engine to shut off if A) I toggled a switch on the controller  B)  the transmitter was out of range or C) the transmitter batteries died.  I wanted a setup that ‘failed close’ so that the default resting state of the system was to ground the mower’s magneto.  This would short-circuit around the spark plug, and the mower engine would shutdown.  For the engine to run, the controller had to be in-range, and the relays powered on.</p>

<p>Fortunately, I bought a RC transmitter with way too many toggle switches.  After doing some testing with a multimeter, I found that the Gear toggle had a large delta between on and off, and could be read easily with the Arduino.  I started by creating a basic program on the arduino, and playing with the input pins on the relay.  These devices have a default closed or default open setting, I can’t remember if I had to reverse that while building this project.  If the relay board is receiving a HIGH value, the relays are open.</p>

<p>The gasoline engine magneto had a spade connector which was originally used to ground the ignition system when the safety handle was released.  All I had to do was run one wire from the magneto to one relay contact, and run the other relay contact to a bolt on the frame.  To tie it all together, I used the Arduino program to monitor the value of the Gear signal, then send a HIGH value if we want to engine to run.  If that signal goes away for any reason, the circuit collapses and grounds out the engine.</p>

<p>All of the above are sensitive electronics.  I went through two iterations of project boxes to protect them. Arduino code found <a href="RC_KillSwitch.ino">here</a>.  HOWEVER, IT DOES NOT WORK.</p>

<p>Everything worked on the bench perfectly, but when I attached it to the actual mower I had quite a bit of feedback and bouncing on the RC circuit. The readings would spike and dip, and the relays would chatter on and off.  I tried various circuitry tricks like sinking to grounds and spent hours designing and redesigning electrical circuits and modifying Arduino sketch codes, with no luck.  In the end I found a relay that interfaced with RC controllers.  The Pololu RC Swich with Relay was worth every penny of $10, and I should have bought that FIRST.  Works every time, and lets me shut down the gasoline engine remotely.  When the relay contacts close, the ignition coil is grounded to the frame, bypassing the spark plug.  So for the engine to fire up, the manual safety must be removed, AND the transmitter must be transmitting a good signal. Any form of failure with the power or RC signal causes the engine to shut off.  My original solution was over-engineered. Example video below.
<img src="/assets/images/killswitchfail.jpg" alt="kill switch" />
<img src="/assets/images/pololu.jpg" alt="pololu" /></p>

<iframe width="480" height="270" src="https://www.youtube.com/embed/c1Vxg-9lo8E" frameborder="0" allowfullscreen=""></iframe>

<p><a name="wiring"></a></p>
<h4 id="wiring-diagram">Wiring Diagram</h4>

<p>I’ve recieved many requests to share wiring info, so I threw together a crude diagram to get people started. I leveraged the RC airplane controller to operate the motor controller and kill switch relays.</p>

<p><img src="/assets/images/rcmowerdiagram.png" alt="rc mower diagram" /></p>

<p><a name="frame"></a></p>
<h4 id="creating-the-frame">Creating the Frame</h4>

<p>One of my most anticipated tasks needed to complete this project was the creation of the frame.  I noticed that several RC mowers online made reference to outsourcing the welding - I was interested in doing this myself.  My reasoning was that having someone else do the welding the first time around, I may save some money for the first incarnation, but if I needed to re-do any of the design, I’d quickly burn cash.  Purchasing a welder and all needed accessories was about $250, and frankly, I REALLY wanted to add this kill to my toolkit. Also, as a side note - if you need a quick cheap and simple surface to do basic welding on, a $10 piece of concrete board works GREAT.</p>

<p><img src="/assets/images/weldingtable.jpg" alt="welding table" /> <img src="/assets/images/welding.jpg" alt="welding" /></p>

<p>Purchasing steel stock at Home Depot at retail prices was surprisingly expensive. I know that other stores such as Tractor Supply sell steel stock, but I didn’t check their prices as a comparison.</p>

<p>I used angle iron for the main frame, and used smaller box frame for the cross braces and battery compartment.  One of the elements that I was most proud of was the creation of the rear axle in the brackets that hold the wheelchair motors. Essentially cut and drilled a piece of angle iron to create the motor mounts.  These were then welded to the rest of the frame.</p>

<p>To lower the center of gravity, I recessed the battery boxes INTO the frame.  This over complicated the build, and simply wasn’t necessary.  Even with the batteries ‘on top’ of the frame, there’s no way this thing is tipping over.  Having the recessed sub-frame lengthened the overall designed and hindered the mower deck placement. Update: move the batteries BEHIND the axles, better handling.</p>

<p>Motor brackets leveraged the existing screws on the motor, then welded to the frame.</p>

<p><img src="/assets/images/frame.jpg" alt="frame" />
<img src="/assets/images/enginebracket2.jpg" alt="engine bracket" /></p>

<p>Once I had it all together, a quick coat of primer and ‘Toro Red’ spray paint from Tractor Supply. Makes it look less scary and more legit.</p>

<p><img src="/assets/images/paint.jpg" alt="paint" /></p>

<h4 id="mower-deck">Mower Deck</h4>

<p>For this, I looked for the most basic mower I could find.  I figured this would make the conversion easier.  I ended up with a 21 inch basic mulching mower.  The original goal was to leverage the height adjustment levers and original axles.   However, the mower had a lot of plastic junk on both the front and back.  I removed the front, and found two metal tabs that were perfect to hang from.  The rear of the mower deck was not so easy.  I ended up cutting, glueing, and generally hacking the rear plastic section for hours.  The resulting rear was screwed closed, filled with expanding foam, and painted with undercoating.  Yeah, it was a mess.  Next time, I’ll find an all-metal mulching only deck.  The mower deck is suspended with adjustable turnbuckles.  They seem to work well.</p>

<p><img src="/assets/images/mowerdeck.jpg" alt="mower deck" /></p>

<p><a name="mowing"></a></p>
<h4 id="actual-mowing">Actual Mowing</h4>

<p>It works pretty well, I was surprised.  After playing with some of the control settings on the motor controller, I was able to pretty consistently pilot the mower.  I opted for a mulching-only mower, as I had no room for a bagging mechanism.  Overall, I think I’ll enjoy mowing with this contraption.</p>

<p>Example videos below:</p>

<iframe width="640" height="360" src="https://www.youtube.com/embed/5Z0A8KQb5hY" frameborder="0" allowfullscreen=""></iframe>
<iframe width="640" height="360" src="https://www.youtube.com/embed/L7QSVSLH_5k" frameborder="0" allowfullscreen=""></iframe>
<iframe width="640" height="360" src="https://www.youtube.com/embed/sAXZ2NYmdds" frameborder="0" allowfullscreen=""></iframe>

<p><a name="lessons"></a></p>
<h4 id="lessons-learned">Lessons Learned:</h4>

<ul>
  <li>It could be smaller.</li>
  <li>It could be a good bit lighter.</li>
  <li>Using an all-metal mower deck would have saved time.</li>
  <li>I would redesign the rear of the frame with fewer parts.</li>
  <li>The battery boxes do not need to be recessed INTO the frame.</li>
  <li>Chains for traction may help on hills, I have some wheelspin.</li>
  <li>Remote electric start? Might be fun.&lt;/li&gt;</li>
</ul>

<h4 id="update-512017---tire-upgrade">Update 5/1/2017 - Tire Upgrade</h4>

<p>The original ‘run flat’ wheelchair tires perform well on sidewalks and roads, but prove problematic on wet grass. They were standard rubber tires on the outside, with a foam core. These tires were rock hard, completely round, and would never go flat. I decided that knobby tires with tubes would be better, as I’d get more traction AND be able to lower the pressure within the tires, a good trick for driving a car in the snow. The Jet 3 Ultra scooter that provided the electric motors and axels did come with a pneumatic tire option, but wow, those rims were expensive, even second hand.  I eventually determined that I could drill through one of the split-rims and provide access for a tire inflation stalk. The rim modification took all of 20 minutes and isn’t pretty but works. The tires and tubes were purchased from Harbor Freight for $10 each on sale, and were leftover from one of my first attempts to match hubs to the motors. With this setup, I can try many different tire options in the future. <b>Update again:</b> Kenda makes knobby tires in the right size that work great.</p>

<p><img src="/assets/images/rims.jpg" alt="rims" />
<img src="/assets/images/tires.jpg" alt="tires" />
<!--<img src=pics/withnewtires.jpg width=35%>--></p>

<p><a name="mk2">mk2</a></p>

<h4 id="update-4222018---one-year-later-new-frame">Update 4/22/2018 - One year later, new frame</h4>

<p>After a summer of mowing, I came to a few conclusions. The mower could have benefitted from being shorter and lighter.  Having the wheels all the way in the back meant that more torque was needed to swing the frame around. Shifting all weight closer to the wheels helped quite a bit.  I suppose moving some of the weight behind the wheels would help even more, but this new design is a good balance of weight distribution and compactness.  Also, eliminating the recessed battery box shorted the frame quite a bit. Streamlining the electronics, putting them in a PVC enclosure and nestling them between the motors was a win on all fronts.
<img src="/assets/images/framecomparison.jpg" alt="frame comparison" />
<img src="/assets/images/mk2elec.jpg" alt="mk2 electrical" />
<img src="/assets/images/mk2grass.jpg" alt="mk2 grass" /></p>

<h4 id="update-712018---motor-controller-fire">Update 7/1/2018 - Motor Controller Fire</h4>
<p>While mowing grass, I noticed the controller seemed to be cutting out on a particularly hot July day. I powered down the mower, let it cool down, then tried to power it back on.  When it didn’t respond, I began fiddling with wires, checking things with a multimeter, etc.  It appeared that a lead on the motor controller itself was coming OFF of the printed circuit board.  I’m not sure if it vibrated loose or was melting off of the board.  I tried to reseat it, powered the unit back on for testing and poked at it.  <em>poof</em> I had a few sparks then an electrical fire. The fire extinguisher stored in the shed was finally called into action.</p>

<p>The next iteration, we’ll call it version 2.1, uses a Cytron SmartDriveDuo-60 (MDDS60). This unit seemed to have a few additional safety features, a design that fosters better airflow, and seem to be a a generation newer than the previous controller.  Between ordering the controller and re-wiring everything I was back up  and running in 12 days.</p>

<p><img src="/assets/images/controller.jpg" alt="controller" />
<img src="/assets/images/controlbox.jpg" alt="controlbox" /></p>

<p><a name="mk3">mk3</a></p>
<h4 id="update-732020---mk3">Update 7/3/2020 - Mk3</h4>

<p>Much lighter frame, rear wheels brought in to match the deck width, and batteries behind the rear axles. The mower now handles WAY better. This will be the last build for a while.
<img src="/assets/images//mk3.jpg" alt="mk3" /></p>

<p><strong>On second thought, don’t build one of these.</strong></p>

<p>If you have questions or comments, send them to ‘sclebo05’ -at- gmail</p>]]></content><author><name></name></author><category term="making" /><summary type="html"><![CDATA[Proceed with caution. I am not responsible for the destruction of property or wildlife. Use sound judgement.]]></summary></entry><entry><title type="html">Live Trap SMS Alerting Design</title><link href="http://www.joshlebo.com/making/2022/10/20/trapalert.html" rel="alternate" type="text/html" title="Live Trap SMS Alerting Design" /><published>2022-10-20T08:00:00-04:00</published><updated>2022-10-20T08:00:00-04:00</updated><id>http://www.joshlebo.com/making/2022/10/20/trapalert</id><content type="html" xml:base="http://www.joshlebo.com/making/2022/10/20/trapalert.html"><![CDATA[<font color="red">Proceed with caution.</font>
<p>I am not responsible for the destruction of property or wildlife. Know your local ordinances when it comes to the capture and release of animals. Use sound judgement.</p>

<p><strong>Table of Contents:</strong></p>

<p><a href="#parts">1 Parts List</a><br />
<a href="#wiring">2 Wiring</a><br />
<a href="#programming">3 Programming</a><br />
<a href="#setup">4 Setup</a><br />
<a href="#lessons">5 Lessons Learned</a><br /></p>

<p>The goal was to recieve an SMS notification the moment a live trap has success. This allowed immediate relocation of the animal without visually checking the trap at regular intervals. Picture of the final product below:<br />
<img src="/assets/images/trap.jpg" alt="trap" /></p>

<p><a name="parts"></a></p>
<h4 id="parts-list">Parts List:</h4>

<ul>
  <li>ESP32 microcontroller with wifi, I used a NodeMCU - $6 - $10</li>
  <li>Reed switch OR contact switch - $4</li>
  <li>USB Battery and cable to power the above</li>
  <li>PCB and wires to connect the above</li>
  <li>Some form of project box, I 3d printed one - $???</li>
  <li>Twilio Account for sending/recieving SMS messages - This costs pennies a month</li>
  <li>Standard live trap. Can be scaled up or down based on needs - $35</li>
  <li>Roasted peanuts, salt free - $3 a bag</li>
</ul>

<p>Always looking for a project, decided to build a simple notification system that can be used for many purposes. This particular build requires some electrical know-how, soldering, programming, and in my case, 3D printing.</p>

<p><a name="wiring"></a></p>
<h4 id="wiring">Wiring</h4>

<p>It doesn’t get any simpler than this. In essence, an ESP32 microcontroller watches for a reed switch to close via GPIO pins, and sends the text message alert via Twilio. I opted to 3D print an enclosure for the electronics.</p>

<p><img src="/assets/images/esp32circuitboard.jpg" alt="circuit" /></p>

<p>The magic comes from the reed switch. This is a simple device commonly used in home security systems.  One component has two small metal contacts that are naturally air-gapped.  The second has a simple magnet inside. When the magnet approaches the contacts, they bend and touch, completing a circuit. The reed switch was located on the door of the trap with double sided tape, creating a contact upon success.</p>

<p><img src="/assets/images/reedswitch.png" alt="reedswitch" /></p>

<p>For the enclosure I 3D printed a project box. Using a utility knife I scored and snapped a printed circuit board to fit inside. With a few soldered joints the ESP32 and jumper wires were securely in place.</p>

<p><a name="programming"></a></p>
<h4 id="programming">Programming</h4>

<p>The ESP32 supports CircuitPython as well as the Arduino IDE.  I chose the latter to quickly cobble together a few existing libraries and get the device deployed. The device connects to my home wifi and then calls Twilio for the alerting. Twilio is a service with callable programming interfaces that function as a cloud based texting service.  Call the APIs with the message and destination phone number, and they send the actual text. The main loop of my code watches for the reed switch to close, and then calls the Twilio library to send the text message. The wifi and library setup comprises the bulk of the code. The code is written in a manner that only sends the alert ONCE.</p>

<p><img src="/assets/images/squirreltrapcode.png" alt="code" /></p>

<p><strong>Sample code is: <a href="/assets/squirreltrap.txt">here</a></strong></p>

<p><a name="setup"></a></p>
<h4 id="setup">Setup</h4>

<p>Place peanuts at the BACK of the trap, with a trail running out the front. The squirrels will run off and bury the peanuts outside the trap, and become braver with subsequent trips.</p>

<p>Open the trap door and set the trap as normal. Plug the ESP32 into a standard USB power brick, and you’re set. The power draw is minimal, and even a cheap power brick lasts all day.</p>

<p><img src="/assets/images/culpritsmall.jpg" alt="culprit" /></p>

<p>Configuration of the Twilio account is beyond the scope of this article. The library within the Arduino IDE handles all of the heavy lifting, the user simply needs to register a Twilio account, select a source phone number and copy the account IDs to the code. Each text message costs something like $0.00001, making this service very affordable. Sample SMS message below:</p>

<p><img src="/assets/images/squirreltrapalert.png" alt="alert" /></p>

<p><a name="lessons"></a></p>
<h4 id="lessons-learned">Lessons Learned:</h4>
<ul>
  <li>The ESP32 is a nice balance between cost and power, occupying the space between an Arduino and Raspberry Pi</li>
  <li>Reed switches have countless uses for home security</li>
</ul>

<p><strong>No creatures were harmed during the completion of this project.</strong></p>

<p>If you have questions or comments, send them to ‘sclebo05’ -at- gmail</p>]]></content><author><name></name></author><category term="making" /><summary type="html"><![CDATA[Proceed with caution. I am not responsible for the destruction of property or wildlife. Know your local ordinances when it comes to the capture and release of animals. Use sound judgement.]]></summary></entry><entry><title type="html">Recover A Thecus N2100 from OpenBSD</title><link href="http://www.joshlebo.com/making/2019/02/17/thecusn2100debian.html" rel="alternate" type="text/html" title="Recover A Thecus N2100 from OpenBSD" /><published>2019-02-17T07:00:00-05:00</published><updated>2019-02-17T07:00:00-05:00</updated><id>http://www.joshlebo.com/making/2019/02/17/thecusn2100debian</id><content type="html" xml:base="http://www.joshlebo.com/making/2019/02/17/thecusn2100debian.html"><![CDATA[<p>Table of Contents:</p>

<p><a href="#background">0 Background</a><br />
<a href="#parts">1 Parts List</a><br />
<a href="#verification">2 Verification</a><br />
<a href="#export">3 Exporting Userland</a><br />
<a href="#import">4 Importing Userland to Flash</a><br />
<a href="#booting">5 Booting</a><br /> 
<a href="#info">6 Further Info</a><br /></p>

<font color="red">WARNING!!!</font>
<p>Do not try this unless you know what you are doing.  Clearly this could damage your equipment beyond repair.  Proceed at your own risk!</p>

<p><strong><a name="background">0 Background</a></strong></p>

<p>I purchased a used Thecus N2100 on ebay, that had been altered to run OpenBSD. I BELIEVE the previous owner used <a href="ftp://ftp.openbsd.org/pub/OpenBSD/5.1/armish/INSTALL.armish">this guide</a> to perform the installation. My intent was to install Debian linux to replace OpenBSD. Unfortunately, installing the OpenBSD bootloader required the deletion of userland tools from flash due to space constraints. This removes the ability to re-install the original factory firmware, and in turn, prevents the installation of Debian. Using these steps, I was able to restore the unit to original factory condition.  After this, installing Debian worked as expected.</p>

<p><strong><a name="parts">1 Parts List</a></strong></p>

<p>Still reading?  Anyway, I really didn’t use any tools for this project. The only required object is the Thecus N2100, and a second PC of some sort.  If you wish to open up the chassis to swap hard drives, etc, a #2 Philips screwdriver will work fine. To perform this recovery, I actually had a second working Thecus available, and was able to use its flash to recover the broken unit. I can provide memory dumps if this data if needed.</p>

<p><img src="/assets/images/thecusn2100.jpg" alt="Thecus N2100" />
<b><a name="verification">2 Verification</a></b></p>

<p>The box booted just fine into OpenBSD, but I can see how the following would help a box that can’t even do that. Most of the Thecus boxes that have been updated to a fairly recent flash will have Redboot, a bootloader/utility that provides basic functionality to booting and recovering the box. See <a href="http://www.cyrius.com/debian/iop/n2100/telnet.html"> this guide </a> for more details about accessing Redboot.</p>

<p>To access Redboot requires telnetting to port 9000 during the device’s boot process. The easiest way to do this is with the following:</p>
<pre>
arping -f 192.168.1.100 &amp;&amp; telnet 192.168.1.100 9000
WARNING: interface is ignored: Operation not permitted
ARPING 192.168.1.100 from 192.168.1.104 eth0
Unicast reply from 192.168.1.100 [00:14:FD:10:33:8E]  6.473ms
Sent 9 probes (9 broadcast(s))
Received 1 response(s)
Trying 192.168.1.100...
Connected to 192.168.1.100.
Escape character is '^]'.
== Executing boot script in 2.650 seconds - enter ^C to abort
^C
RedBoot&gt;
RedBoot&gt;
</pre>

<p>On my working Thecus, the following command showed the contents of the flash disk:</p>

<pre>
RedBoot&gt; fis list
Name              FLASH addr  Mem addr    Length      Entry point
RedBoot           0xF0000000  0xF0000000  0x00040000  0x00000000
RedBoot config    0xF0FC0000  0xF0FC0000  0x00001000  0x00000000
FIS directory     0xF0FE0000  0xF0FE0000  0x00020000  0x00000000
ramdisk           0xF0040000  0x00800000  0x00D00000  0x00800000
kernel            0xF0D40000  0x00200000  0x00160000  0x00200000
user              0xF0EA0000  0x00120000  0x00120000  0x00800000
</pre>

<p>Notice the ‘user’ directory. This is where the userland Linux tools are stored for the default Thecus firmware.</p>

<p>On the broken Thecus, I saw this in flash:</p>

<pre>
RedBoot&gt; fis list
Name              FLASH addr  Mem addr    Length      Entry point
RedBoot           0xF0000000  0xF0000000  0x00040000  0x00000000
RedBoot config    0xF0FC0000  0xF0FC0000  0x00001000  0x00000000
FIS directory     0xF0FE0000  0xF0FE0000  0x00020000  0x00000000
ramdisk           0xF0040000  0x00800000  0x00D00000  0x00800000
kernel            0xF0D40000  0x00200000  0x00160000  0x00200000
boot              0xF0EA0000  0x00100000  0x00020000  0x00100000
</pre>

<p>The ‘user’ directory had been replaced by a ‘boot’ image of a different length. When I tried to manually load and boot the kernel and ramdisk, they appeared to get started, but once the kernel booted, the lack of userland tools meant no web interface, no network settings, basically a dead system. How do we get this back?</p>

<p><strong><a name="exporting">3 Exporting Userland</a></strong></p>

<p>The working Thecus already had Debian installed on it, and provided all of the tools needed to extract the original Thecus firmware for the transplant. Looking at the forums, I determined that the flash was accessable under /dev/mtd*. To view which partitions housed the various flash images, simply view /proc/mtd. Observe:</p>

<pre>
debian:~# cat /proc/mtd
dev:    size   erasesize  name
mtd0: 00040000 00020000 "RedBoot"
mtd1: 00d00000 00020000 "ramdisk"
mtd2: 00160000 00020000 "kernel"
mtd3: 00120000 00020000 "user"
mtd4: 00001000 00020000 "RedBoot config"
mtd5: 00020000 00020000 "FIS directory"
</pre>

<p>This looked familiar.  I was able to mount these with mount -t jffs /dev/mtd3 /mnt/temp or something similar, but I wanted to extract the filesystem in its entirety.  After playing with dd, cat, and /dev/mtd3 and /dev/mtdblock3, I found that a simple</p>
<pre>
cat /dev/mtdblock3 &gt; user
</pre>
<p>appeared to do the trick. I now had a file called ‘user’ which had the contents of mtd3.</p>

<p><strong><a name="import">4 Importing Userland to Flash</a></strong></p>

<p>Importing the user image to flash proved to involve a bit of trial and error, and having made a few typos while I figured out which flags on the fis command did what, I was lucky to not blow away any other images ;)</p>

<p>From Redboot, I ran the following to erase the ‘boot’ image:</p>
<pre>
fis erase -f 0xF0EA0000 -l 0x00020000
</pre>

<p>Now load the ‘user’ image via tftp from the server 192.168.1.5 to the correct memory location:</p>
<pre>
ip -h 192.168.1.5

load -r user -b 0x00120000
</pre>

<p>Now the moment of truth, flashing the image from RAM to the onboard flash chip. No mistakes!</p>

<pre>
fis create -b 0x00120000 -l 0x00120000 -f 0xF0EA0000 -e 0x00800000 -r 0x00120000 user
</pre>

<p>Verify with fis list:</p>
<pre>
RedBoot&gt; fis list
Name              FLASH addr  Mem addr    Length      Entry point
RedBoot           0xF0000000  0xF0000000  0x00040000  0x00000000
RedBoot config    0xF0FC0000  0xF0FC0000  0x00001000  0x00000000
FIS directory     0xF0FE0000  0xF0FE0000  0x00020000  0x00000000
ramdisk           0xF0040000  0x00800000  0x00D00000  0x00800000
kernel            0xF0D40000  0x00200000  0x00160000  0x00200000
user              0xF0EA0000  0x00120000  0x00120000  0x00800000
</pre>

<p><strong><a name="booting">5 Booting</a></strong></p>

<p>RedBoot actually boots the system, so we have to set it to load the kernel and initrd into RAM, then run the userland tools that set the device IP and console access. Recreate the original boot script using fconfig in RedBoot:</p>
<pre>
RedBoot&gt; fconfig

...contents of the script below...

thecus_setip
fis load ramdisk
fis load kernel
exec -c "console=ttyS0,115200 root=/dev/ram0 initrd=0xa0800000,42M mem=128M@0xa0000000"
</pre>
<p>Set any IP or other settings that you like.  Reset with ‘reset’.</p>

<p>At this point, the unit booted into the original Thecus firmware! I upgraded to the Thecus firmware to 2.10, the latest version, then followed the Debian installation guide. The unit installed with no issues, and OpenBSD was gone forever. Eureka!</p>

<p><strong><a name="info">6 Further Info</a></strong></p>

<p>Below is a list of most of the articles I used to piece together this procedure. Thanks to the original authors, as without the background information, I would have never recovered this piece of hardware.</p>

<pre>
http://www.cyrius.com/debian/iop/n2100/
http://www.cyrius.com/debian/iop/n2100/telnet.html
http://www.cyrius.com/debian/iop/n2100/deinstall.html
http://foonas.org/index.php?title=Foonas-iscsi:Install-n2100
http://david.thg.se/n2100/
http://foonas.org/index.php/Platforms:n2100-notes
http://naswebsite.com/wiki/N2100_Recovering_from_a_bad_config_change
ftp://ftp.openbsd.org/pub/OpenBSD/5.1/armish/INSTALL.armish
</pre>

<p>That about wraps it up. This is a fairly straightforward hack that will allow you to run Debian in all of its glory on hardware that has a limited distro on it. If you have any thoughts/additions, email them to sclebo05 AAATTT gmail.com. Thanks for stopping by!</p>]]></content><author><name></name></author><category term="making" /><summary type="html"><![CDATA[Table of Contents:]]></summary></entry><entry><title type="html">Washing Machine Text Alerting</title><link href="http://www.joshlebo.com/making/2018/04/17/washeralerting.html" rel="alternate" type="text/html" title="Washing Machine Text Alerting" /><published>2018-04-17T08:00:00-04:00</published><updated>2018-04-17T08:00:00-04:00</updated><id>http://www.joshlebo.com/making/2018/04/17/washeralerting</id><content type="html" xml:base="http://www.joshlebo.com/making/2018/04/17/washeralerting.html"><![CDATA[<h4 id="article-originally-created-4172018">Article originally created 4/17/2018</h4>

<p>From time to time, when I’m out in the garage or off somewhere in the house, I forget about my laundry. Or worse, I check on my laundry and find that it’s not done.  While not the end of the world, it is inconvenient.  I saw that some modern washers have notification apps to solve this problem. Since the washing machine that came with our house still functions, I decided to retrofit a notification system to it.</p>

<p><img src="/assets/images/finishedproduct.png" alt="Finished Product" /></p>

<p><strong>Items Used and Cost:</strong></p>

<ul>
  <li>Raspberry Pi Zero W - $15</li>
  <li>A 3.3v or 5v Vibration sensor, for Raspberry Pi or Arduino - $4</li>
  <li>A piece of breadboard, a moment switch, a resistor, some wire, and solder - $5</li>
  <li>An old cell phone charger that I had a box of junk - FREE</li>
  <li>An old Roku 2 Case, or any enclosure - FREE</li>
  <li>Python Script to monitor the sensor and send text alerts - $$$ (Whatever you value your time at)</li>
  <li>Twilio.com Account - $0.0017 per text</li>
</ul>

<p>I really thought about using a Sardine can for this one.</p>

<p>The wiring schematic found on the site referenced below allowed me to put together a few circuits on breadboards for testing. The Roku 2 streaming device case had a perfect location for an LED indicator, which I incorporated into my programming as a status light. I then soldered everything together and superglued standoffs to the case to best position everything. Of note, nylon standoffs are my favorite thing ever.</p>

<p><img src="/assets/images/circuits.png" alt="Circuits" /></p>

<p>I spent most of my time merging together a few Python scripts into something I liked. Using callbacks as opposed to putting a button event in the center of the main loop seemed to make the most sense to me. When the sensor is motionless for 5 minutes, a text alert is sent. A link to the actual python app is also linked below.</p>

<p><img src="/assets/images/output.png" alt="Output" /></p>

<p>The alerting was the fun part.  I found that Twilio.com had a ready to go Python library, and rediculously inexpensive text plans for the hobbyist. The script logs to a file and outputs to standard out if debugging is needed.</p>

<p><img src="/assets/images/text.png" alt="Text Sample" /></p>

<p>Currently I have the device perched on the washer (or dryer). Seems to work pretty well so far.  <strong>Sample code is: <a href="/assets/washer.txt">here</a></strong></p>

<p><img src="/assets/images/washer.png" alt="Washer" /></p>

<p><strong>Links</strong></p>

<ul>
  <li>I heavily borrowed the circuit design from this page on Spiria: <a href="https://www.spiria.com/en/blog/iot-m2m-embedded-solutions/connected-washing-machine-raspberry-pi">https://www.spiria.com/en/blog/iot-m2m-embedded-solutions/connected-washing-machine-raspberry-pi</a></li>
  <li>Raspberry Pi Zero W: <a href="https://www.raspberrypi.org/products/raspberry-pi-zero-w/">https://www.raspberrypi.org/products/raspberry-pi-zero-w/</a></li>
  <li>Sample Vibration Sensor: <a href="https://www.banggood.com/SW-420-NC-Type-Vibration-Sensor-Module-Vibration-Switch-For-Arduino-p-916223.html?cur_warehouse=CN">https://www.banggood.com/SW-420-NC-Type-Vibration-Sensor-Module-Vibration-Switch-For-Arduino-p-916223.html?cur_warehouse=CN</a></li>
</ul>

<p>If you have questions about any specifics, email me at sclebo05 —AT— gmail</p>]]></content><author><name></name></author><category term="making" /><summary type="html"><![CDATA[Article originally created 4/17/2018]]></summary></entry><entry><title type="html">Installing Debian on a Thecus N5200</title><link href="http://www.joshlebo.com/making/2017/05/05/thecusdebian.html" rel="alternate" type="text/html" title="Installing Debian on a Thecus N5200" /><published>2017-05-05T08:00:00-04:00</published><updated>2017-05-05T08:00:00-04:00</updated><id>http://www.joshlebo.com/making/2017/05/05/thecusdebian</id><content type="html" xml:base="http://www.joshlebo.com/making/2017/05/05/thecusdebian.html"><![CDATA[<h3 id="how-to-install-debian-lenny-on-a-thecus-n5200-using-an-external-usb-cdrom">How to install Debian Lenny on a Thecus N5200, using an external USB CDROM</h3>

<p>Table of Contents:</p>

<p><a href="#parts">0 Parts List</a><br />
<a href="#dissassembly">1 Dissassembly</a><br />
<a href="#vga">2 VGA Hack</a><br />
<a href="#bios">3 BIOS Tweaks</a><br />
<a href="#flash">4 Flash Drive</a><br />
<a href="#install">5 Debian Install</a><br /> 
<a href="#tweaks">6 Tweaks</a><br />
<a href="#info">7 Further Info</a><br /></p>

<font color="red">WARNING!!!</font>
<p>Do not try this unless you know what you are doing.  Clearly this could damage your equipment beyond repair.  Proceed at your own risk!</p>

<p><strong><a name="parts">0 Parts List</a></strong></p>

<p>Still reading?  Anyway, not many tools are needed for this project.  We use a Thecus N5200 (obviously),
screwdrivers, pliers, Debian Lenny install disc, systemrescuecd.org disc,
External USB CDrom drive, an old VGA cable, and a USB keyboard.</p>

<p><img src="/assets/images/DSC07998.JPG" alt="picture" /></p>

<p><strong><a name="dissassembly">1 Dissassambly</a></strong></p>

<p>First, remove the rear panel of the case, being careful to unplug the fan as it is removed.
Remove the main housing of the Thecus.  Remove the two screws from the second gigabit network interface
riser card, and set it aside. Remove all SATA drives of course.</p>

<p><img src="/assets/images/DSC08007.JPG" alt="picture" />
<img src="/assets/images/DSC08014.JPG" alt="picture" />
<img src="/assets/images/DSC08016.JPG" alt="picture" /></p>

<p><strong><a name="vga">2 VGA Hack</a></strong></p>

<p>Beneath the gigabit riser card, you will find an array of leads at the edge of the board.</p>

<p>These leads would be where the VGA plug would be soldered into the board.  Using pliers and little bit
of patience, we were able to create a monitor cable with bare pins, that fit perfectly into the board,
giving us a VGA signal.  See the pictures below.  NOTE: We noticed that the monitor cable was getting 
close to touching various components on the board, so we created a little cardboard separator to place
between the cable and the board.</p>

<p><img src="/assets/images/DSC08021.JPG" alt="picture" />
<img src="/assets/images/DSC08002.JPG" alt="picture" />
<img src="/assets/images/DSC08029.JPG" alt="picture" /></p>

<p><strong><a name="bios">3 BIOS Tweaks</a></strong></p>

<p>At this point, we were able to boot the Thecus, press the Del key, and enter the bios.  Its a pretty standard bios.
We did adjust the boot devices order under the Advanced settings, adding our USB CDROM and USB Harddrive (for later).<br />
We left the internal IDE as a third option.  Save and exit.</p>

<p><img src="/assets/images/DSC08035.JPG" alt="picture" /></p>

<p><strong><a name="flash">4 Flash Drive, CDROM</a></strong></p>

<p>To prevent confusion, and to protect the original OS on the IDE flash memory, we removed it.  We found that wiggling it
up and down allowed it to be removed easily.  We were able to find a very small 8GB flash drive for very little cost,
and used that to serve as our hard disk.  Understanding the risk of failures, we will have images of the OS
drive and incremental config backups to help protect us.  Dumping images to pen drives is pretty easy ;)
We also cabled up an external USB CDROM drive at this point.  The adapter we found supports IDE, SATA, and laptop drives.
Very inexpensive also.</p>

<p><img src="/assets/images/DSC08018.JPG" alt="image" />
<img src="/assets/images/DSC08020.JPG" alt="image" />
<img src="/assets/images/DSC08039.JPG" alt="image" /></p>

<p><strong><a name="install">5 Debian Install</a></strong></p>

<p>We chose Debian Lenny as the OS, as we were familiar with it, and it is easy to maintain. We won’t go into the 
details of the install, but there are a few points to be aware of:</p>

<ul>
  <li>
    <p>You may have any partition scheme you want on the flash drive, but it is recommended that you do NOT use
a journaled filesystem, due to speed/repetitive journal issues with flash storage.  We chose a single root partition formatted with ext2</p>
  </li>
  <li>
    <p>create a label on the partitions.  This became VERY IMPORTANT, as we found out later that the flash drive appears 
as an sda device.  Things really got interesting once we started installing SATA drives and drive enumeration would jump around based on the number of drives.
When the install finishes, you should be able to boot to Lenny.  Everything seemed to work for us with no tweaks.
At that point, we immediately edited our /boot/grub/menu.lst and removed references to /dev/sda1 and replaced them with
root=LABEL=*labelname* .  Also, in our /etc/fstab we replaced any references to sda* partitions with LABEL=*labelname*.
Reboot, and ensure everything works.  If not, use your systemrescuecd to recover the box.</p>
  </li>
</ul>

<p>If you forget to create labels during install, its easy to do e2label *device* *labelname* on your partitions</p>

<p><img src="/assets/images/DSC08041.JPG" alt="image" /></p>

<p><strong><a name="tweaks">6 Tweaks</a></strong></p>

<p>The first tweak to perform is to add ‘noatime’ to the /etc/fstab line pertaining to the partitions on the flash drive.
This prevents the Thecus from updating the access time on files that it touches on the flash drive.  There are similar options
like relatime that help with apps like mutt that rely on atime.  See man mount for more info.</p>

<p>We plan to add other functionality, such as LCD control, apply the kernel patches we have found on the net, etc.
Check back to see our progress.</p>

<p>Oh, at this point you can re-add your SATA drives and build new partitions if you like.<br />
We were able to reassemble the ‘old’ Thecus drives/partitions with</p>
<pre>
vgscan -v
mount /dev/dm-1 /mnt/mount/point
</pre>

<p><strong><a name="info">7 Further Info</a></strong></p>

<p>That about wraps it up.  This is a fairly straightforward hack that will allow you to run Debian in all of its glory on hardware that has a limited distro on it. 
If you have any thoughts/additions, email them to sclebo05 AAATTT gmail.com.  Thanks for stopping by!</p>]]></content><author><name></name></author><category term="making" /><summary type="html"><![CDATA[How to install Debian Lenny on a Thecus N5200, using an external USB CDROM]]></summary></entry><entry><title type="html">Graphing Avaya IP500 PRI Usage</title><link href="http://www.joshlebo.com/making/2016/01/20/avayasnmp.html" rel="alternate" type="text/html" title="Graphing Avaya IP500 PRI Usage" /><published>2016-01-20T07:00:00-05:00</published><updated>2016-01-20T07:00:00-05:00</updated><id>http://www.joshlebo.com/making/2016/01/20/avayasnmp</id><content type="html" xml:base="http://www.joshlebo.com/making/2016/01/20/avayasnmp.html"><![CDATA[<p>The Avaya IP Office 500 PBX does not appear to have an easy way to graph PRI usage.</p>

<p>We discovered a status packet sent by the phone system to Xima that contains the number of current calls on the PRI trunks.   We need to convert a packet on the wire into a WhatsUp Gold Graph.
I have created a crude proof of concept using a physical server, tcpdump, perl, snmpd extensions, and WhatsUp Actionscript.  Any or all of these pieces could be replaced/refined if need be (for example, we could use a VM or sed instead).</p>

<p>I created a Cisco span port that replayed the traffic between the PBX and Xima, and attached a physical server to it.</p>

<p>Start with capturing the packet on the wire:
/usr/sbin/tcpdump -nn -v -i eth1 -s0 -A host <PBX IP=""> and host <XIMA IP=""> and udp</XIMA></PBX></p>

<p>In the below mess of a packet, you can see CALLS=2</p>

<pre>
17:37:41.828161 IP (tos 0x0, ttl 99, id 25899, offset 0, flags [none], proto UDP (17), length 303)
	172.27.105.5.50794 &gt; 172.27.105.6.60709: UDP, length 275
E../e+..c.Y^.........j.%.......f.........9 ...................L.A.W.=.U. .P.R.I.=.2.,. .B.R.I.=.0.,. .A.L.O.G.=.4.,. .V.C.O.M.P.=.7.4.,. .M.D.M.=.0.,. .W.A.N.=.0.,. .M.O.D.U.
..0. .L.A.N.M.=.0. .C.k.S.R.C.=.1. .V.M.A.I.L.=.1.(.V.E.R.=.3. .T.Y.P.=.1.). .1.-.X.=.1. .C.A.L.L.S.=.2.(.T.O.T.=.7.0.7.7.).
</pre>

<p>What a mess. Regex time!  So I put together the following Perl script, could be replaced with bash or another language</p>

<pre>
#!/usr/bin/perl -w
# by jlebo to capture trunk calls on PRIs from Avaya phone system

use strict;

my $callcount = '0';
my $outputfile = '/tmp/trunkcalls';

open(STDIN,"/usr/sbin/tcpdump -nn -v -i eth1 -s0 -A host 172.27.105.5 and host 172.27.105.6 and udp | " );

while ( &lt;&gt; ) {
    if ( $_ =~ /C.A.L.L./  ) {
        #print $_;
        $_ =~ s/\.//g; #remove periods
        $_ =~ /CALLS=(\d+)/ ;
        $callcount = $1;
        #print "So calls is $callcount\n";
        open(OUTFILE, "&gt;$outputfile") or die "Cant open file\n";
        print OUTFILE $callcount . "\n";
        close OUTFILE;
    }
}
exit 0;
</pre>

<p>The PBX sends these packets every minute. The above outputs the number of trunk calls to /tmp/trunkcalls as soon as they are recieved.</p>

<p>Now to configure the Linux SNMPD to display the contents of the above file. Created the below snmpd.conf file, which creates the custom OIDS</p>

<pre>
rocommunity snmpstring
trapcommunity snmpstring
syslocation Nowhere FL
syscontact nobody
proc snmpd
extend trunkcalls /bin/cat /tmp/trunkcalls
</pre>

<p>This OID contains our custom output: .1.3.6.1.4.1.8072.1.3</p>

<p>If I set the value of the above file to ‘50’ and query the new OID, I get this:</p>

<pre>
[root@netmon0 html]# snmpwalk -v1 -c tns-snmp 172.27.105.11 .1.3.6.1.4.1.8072.1.3.2.3.1
NET-SNMP-EXTEND-MIB::nsExtendOutput1Line."trunkcalls" = STRING: 50
NET-SNMP-EXTEND-MIB::nsExtendOutputFull."trunkcalls" = STRING: 50
NET-SNMP-EXTEND-MIB::nsExtendOutNumLines."trunkcalls" = INTEGER: 1
NET-SNMP-EXTEND-MIB::nsExtendResult."trunkcalls" = INTEGER: 0

Again, showing the full OID path:
[root@netmon0 html]# snmpwalk -On -v1 -c tns-snmp 172.27.105.11 .1.3.6.1.4.1.8072.1.3.2.3.1
.1.3.6.1.4.1.8072.1.3.2.3.1.1.10.116.114.117.110.107.99.97.108.108.115 = STRING: 50     &lt;--- Using this one
.1.3.6.1.4.1.8072.1.3.2.3.1.2.10.116.114.117.110.107.99.97.108.108.115 = STRING: 50
.1.3.6.1.4.1.8072.1.3.2.3.1.3.10.116.114.117.110.107.99.97.108.108.115 = INTEGER: 1
.1.3.6.1.4.1.8072.1.3.2.3.1.4.10.116.114.117.110.107.99.97.108.108.115 = INTEGER: 0
</pre>

<p>Note: 10.116.114.117.110.107.99.97.108.108.115 is an ascii representation of ‘trunkcalls’`</p>

<p>My initial thought was to use ‘ExtendOutput1Line’ as a simple SNMP monitor in WhatsUp.</p>

<p>Whatsup Monitors have 2 parts:</p>

<p>Object  .1.3.6.1.4.1.8072.1.3.2.3.1.1     Instance   10.116.114.117.110.107.99.97.108.108.115</p>

<p>Entered the info into an SNMP monitor and … FAIL.  WhatsUp complains that “The polled value was not numeric”.</p>

<p>Here’s where it gets fun.  Extending Linux SNMP OIDs in this manner ALWAYS returns a string. Most monitoring systems are smart enough to convert a 
string of numbers to an integer number - WhatsUp Gold does not do this.  Instead of a simple SNMP Performance Monitor, we have to create a Custom ActionScript Performance Monitor.<br />
In the Performance Monitor we first create a Reference Variable from the above 2 part OID while the below code converts the string to an integer.</p>

<pre>
TrunkCalls = Context.GetReferenceVariable("TrunkCalls") 'import variable
TrunkCalls = cInt(TrunkCalls) ' does the conversion
Context.SetValue TrunkCalls  'write it back
</pre>
<p>Now we simply add the Performance Monitor to the device in question.  Changing the frequency on the performance monitor to 1 minute gives good granularity.</p>

<p>Done [ x ]</p>]]></content><author><name></name></author><category term="making" /><summary type="html"><![CDATA[The Avaya IP Office 500 PBX does not appear to have an easy way to graph PRI usage.]]></summary></entry></feed>