Tuesday, December 24, 2019

ESP8266 DHT Temperature Sensor

My cube mate seems to think that hanging NASA Space Blankets on the glass cube block windows drastically changes the temperature in our cube. It does nothing to class the place up but does seem to offer some heat savings on hot days. The blocks get up over 100 degrees on sunny days so I am sure it helps some.

Anyway, I have a thermometer at my desk and thought it would be fun to create a real time monitor for the temperature near the space blanket to compare. I threw together a ESP8266, DHT, and a small LCD that I recently ordered and wanted to test.

I plugged the LCD up as follows:
GND - GND
VCC - VIN pin
SDA - D2
SCL - D1

I plugged the DHT data connection into D2 and ground and power.

Here is the code.


I am using the LCD library from here: https://github.com/johnrickman/LiquidCrystal_I2C. Just download the zip and then in the Arduino IDE add the zip file as a library. You will also see that I have the code needed to connect to wifi and then post the data to a web service. I was using this to get some temperature trends in the office, and may turn that back on later so I just left it in there.

I then found a bunch of local weather buzz words and made a little border using an index card. The temperature is gathered every 30 seconds. I would get a NAN reading from the sensor often so I changed it so if NAN was the read it would just display the last good value.




Monday, October 21, 2019

MQTT Python Save to SQL Server Database using OwnTracks Data

Started playing around with MQTT this week. Figured out how to save MQTT messages directly to a SQL Server database so I thought I would share how here.

Owntracks

Owntracks is an application that allows you to post your location from your phone to an MQTT broker. You can read about it here: https://owntracks.org/ and download the app. I am using Android.

Mosquitto

Mosquitto is an open source MQTT broker that has clients for Windows and Linux. I am using a Windows broker here in this example but it was easy to install this on a Raspberry Pi with the Linux version. https://mosquitto.org

The Windows install was easy, just next next finish through the setup and then make sure the Windows Service Mosquitto Broker is running



Python 

You will need to install the paho python module using pip. pip -install paho-mqtt should do the trick. Once you get in installed you can create a simple script like so. This is using pyodbc to insert data into SQL Server



Some comments. 
  • This creates a subscriber to whatever mqtt message you want to post. You configure the publisher on your smartphone application.
  • Notice I have a your server ip in the script. You will need to figure out what your external facing ip address is (just google what is my ip). Then you will need add a port forward to your router config for port 1883 or whatever port you are going to use.
  • Create a simple table in SQL Server called mqtt and create two columns
  • I am using the replace function here because the message payload was almost in JSON format but had some extract characters. The payload started with a b' and ended with a ' so I just remove that out.
Configure OwnTracks
As I mentioned I am using the Android App. Here are some screen shots on how I configured it.






SQL Server

Once data starts flowing into the database you can start querying it or doing whatever you want with it. Earlier I mentioned that I removed some characters off the payload so the resulting data would be in JSON format. Since we did that work here we can use the JSON_VALUE function to extract data out of the payload column.


This SELECT will give you the most recent payload captured and will return it back in some nice useable columns.

Google Maps

Then from there if you want to get real creepy you can select the lat/lon values from your db and display them on a Google Map using the JavaScript Maps API (requires an API key).


I zoomed in so you couldn't really see where I am sitting but that is my most recent position with other information displayed. Internet Type indicates I am on wifi. Pretty cool.

Tuesday, September 17, 2019

Chiefs Tomahawk Chop with Raspberry Pi

Wanted to cook up a quick and nerdy way to support the Chiefs this year. So I came up with a Raspberry Pi Tomahawk Chop Button using a servo and an arcade button I had laying around.

Code here.



Had to figure out how to slow the servo down a bit. You can see I went the low tech way. Essentially I am rolling through 3 chops to play with the music. I call the music first using another python script so I can return back to the code to run the chop will the song plays. Here is the song script.

See video below for the chop in action. Let's go CHIEFS!!!!!!


Thursday, May 16, 2019

Python NEOPIXEL Google Traffic and Weather LED Strip

Started playing around with the Neopixel library and python on the Raspberry Pi. I usually take a run over lunch break so I wanted a way to get a quick view of the current weather conditions. I have a 60 LED WS2812 strip so I divided the strip up into 15 LED sections.

  • Section 1 - Temperature. Depending on the temperature I wanted to color the 15 LEDs a specific color.
    • temp > 44 and < 80 = Green
    • temp > 79 and < 90 = Yellow
    • temp > 90 = Red
    • temp > 34 and < 45 = Yellow
    • temp < 34 = Red
  • Section 2 - Wind. 
    • wind < 5 = green
    • wind = 5 and < 16 = Yellow
    • wind > 15 = Red
  • Section 3 - Humidity
    • Humidity < 61 = Green
    • humidity > 61 and < 80 = Yellow
    • humidity > 80 = Red
  • Section 4 - Condition
    • If it is not raining - Green
    • If it is raining - Red
I am using the Open Weather Map API. You can sign up for a free account here: https://openweathermap.org/. I setup an infinite while loop that will sleep for 10 minutes between each iteration. I also set it up to only turn the LEDs on between 10AM and 2PM. The API will only be called during these times. I typically take a run around lunch time so no need to keep it on after this. 



Next steps is to add a Traffic API call. I will light the led up based upon my commute time home.




Monday, March 25, 2019

PowerShell Folder Sizes

More of just a place holder for me because I am tired of searching for this everytime I need it. The following powershell will list out all the subfolders for a given root folder with Sizes and last date modified.


The script will dump the data to CSV so you can do whatever you need from there.