Monday, January 4, 2021

AUTOTRON 1700 - Teensy Shortcut Buttons

Wanted to cook up a shortcut button thing for common work tasks. Had some 30mm arcade buttons laying around. Man I searched and searched for a 3d printable box to house 30mm buttons in. I could not find anything, most boxes use the 24mm arcade buttons. Me updating a CAD drawing is a no go so I was able to find the top plate with 30mm holes and used it. Had a cardboard box laying around and threw some stickers on that bad boi, there ya go the AUTOTRON1700



So I used a Teensy cause it shows up as a Keyboard. I was currently using Auto Hot Key (https://www.autohotkey.com/) for keyboard macros. This allows me to use some key strokes to launch something. For example CRTL+SHIFT+1 will copy a SQL Script I use often to the clipboard so I can paste it and run it. CRTL+SHIFT+2 will launch our team wiki web site. Stuff I use often at work. 

You can use this to launch anything really. Anyway so I used Auto Hot Key to setup the macros I wanted and then programmed the Teensy to send the Keystrokes needed to launch the macro.


Works pretty well. As mentioned I wasn't able to find a printable box but I think the sweet cardboard gives it a better feel anyway. It's a little to large but plenty of room for wiring and stuff.



Monday, December 28, 2020

ESP8266 Magnetic Switch Deep Freezer Monitor

Setup an ESP8266 as a Deep Freezer Monitor using a magnetic switch. The ESP8266 will start sending me emails and text messages if the Deep Freezer has been open for more than 1 minute. I also wanted to log when the Deep Freezer was open. So a web service is called to log the data to a database.


If the Deep Freezer has been opened for over a minute I get a text and an email. Then the counter resets. If if is still open after another minute I get another text and email. In version 2 I am planning to add a temperature probe I can place in the deep freeze. Then I will take some random temp samples to monitor the temperature.





Monday, November 16, 2020

PowerShell Delete files by Modified Date

 Simple script to delete files based on modified date. 



Wednesday, October 28, 2020

Microsoft Teams PowerShell Bot Example

Microsoft Teams has a lot of cool features. This article will show you how to write a simple PowerShell bot that will post messages to a Teams channel.

Configure the WebHook in MS Teams

  1. Open the MS Teams Channel you want to add the bot to
  2. Click Connectors


  3. Click the Configure button by the Incoming WebHook option


  4. Give your WebHook a name...such and such Bot and you can upload an image if you want. Scroll down and click Create
  5. On the create screen you will see a URL. Copy this URL and save it somewhere you will need it in your PowerShell Script.


PowerShell Script


Sample PowerShell Script Below.


The script will run a simple SELECT statement on a DB and will Send a WebRequest to the URL you setup in Teams. The Bot will post a message to the channel you configured for the Incoming WebHook above.













If you do not want to mess with the Card Format then you can just post a simple message like this.

You can update the SQL Statement to pull data and display it in whatever channel. 

Wednesday, October 14, 2020

AC Notification with DHT22 and ESP8266

The building installed new AC units in the building. On the new units you can actually crank up the fan and turn the unit off completely. Last summer the building would routinely heat up to over 80 degrees. We are on the west side of the building so in the afternoon it gets stuffy.

So we can control fan speed and power, but we cannot control the temperature. I wanted a solution where I could quickly determine if the AC was blowing hot or cold air. First attempt is documented here. I took a DHT22 and hooked it up to an ESP82666.

The ESP8266 takes a temperature reading every few seconds and displays the temp and humidity on a little TM1637 Display.

Here is the code


Here is a pic



Friday, September 25, 2020

Alpaca Paper Trading Bot Test

Alpaca is a cool little site that allows you to test various stock trading strategies using their free fake money account (paper account) with a powerful free API. 

Head on over to the site and sign up for a free account. You will see a link on the left side menu that takes you to the paper trading account


On the right side of the paper account you should see a link to View your API keys. You will need these keys to plug into your Python Script. They have tons of documentation on the API but I will list out a few samples below. You will see a Buy, Sell, Lookup Order, and a very basic Trade Bot.

Buy Sample

Sell Sample

Lookup order Sample

Basic Trade Bot


This is a very very very basic Trading bot for a paper money account (fake money). Please don't use this and expect big GAINS. The bot will buy shares and then hold them until a specified profit threshold or loss threshold has been hit. You can tweak the thresholds to see how the strategy works. At the bottom of the script you'll see the startBot('WDC') command. This is where you insert the stock you want to work with.

Of course this can be improved upon, this is just a sample to get the bot up and rolling quickly. The bot can be configured to work with multiple stocks, etc.

So there you have it. Run wild, make a fancy new trading strategy and reap all the GAINS.



SQL Server Read/Write Percentage and Index Usage Script

Thursday, September 24, 2020

Air Quality Calculation Purple Air API and Python

Stumbled on an article about the Purple Air Air Quality API. This thing has a wealth of knowledge. Had no clue how Air Quality numbers were calculated. The API provides several different metrics for those folks that purchase the Purple Air monitoring sensors. The sensor feed data into the Purple Air network of sensors and display the data on a nice handy map: https://www.purpleair.com/map?mylocation

You can easily hit the Purple Air api when you find a sensor in your location. Just click on the sensor you want and inspect the URL. Here is an example of the sensor near Vinita Oklahoma: https://www.purpleair.com/map?opt=1/mHUMIDEX_F/a10/cC0&select=35895#12.99/36.63253/-95.14012

That Select = in the Address is what you want to key on. Now that you have the sensor ID you can just plug that in to the URL to get the JSON feed for that sensor: http://www.purpleair.com/json?show=11668


You will get back some neat looking JSON. Now all you need to do is parse it. See below for sample code. This is using Python to parse out the JSON return value and then doing some fancy math to calculate air quality index based on the value returned for PM2.5 Particulate < 2.5 microns pollutant. You can read up more about the Air Quality Index here: https://www.airnow.gov/aqi/aqi-basics/#:~:text=Think%20of%20the%20AQI%20as,300%20represents%20hazardous%20air%20quality.



You can then capture this data in a DB or display it however you want.

Wednesday, April 29, 2020

Wednesday, February 12, 2020

Run MSC using RunAs

At times you need to run MSC as a different user. Specifically for active directory users and computers when managing AD objects. I have to run this app as an elevated admin to make changes. Finally made a shortcut and documenting it here for the future.

C:\Windows\System32\runas.exe /user:DOMAIN\user /savecred "cmd /c start /b mmc %SystemRoot%\system32\dsa.msc"