Little break

I took a little break last week. There was no real reason other than I was busy coding! There are times when I really get involved in something and I can’t stop coding. This was one of those times! Working from home and a little side project has been keeping me busy, but there is another project I’ve been working on for fun.

Story

A bit ago, I wrote about our building maintenance worker shutting off our AC unit and the servers were about to melt down when my boss went in to clean. We haven’t had an incident sense, but there is no one in the office to keep an eye on the server. How would we know if the server was melting down? …Hmm. I decided to try and build a temperature sensor for the server room.

The Project

I am a huge fan of the Raspberry PI and have done several projects. The Parking Lot Project is one of them. This time, I took a Raspberry PI and a USB Temperature Sensor and hooked them up into a makeshift temperature monitor for our server room. The system will send out an email when the temperature reaches “warning” temperature and an “emergency” temperature. Let me tell you about the setup. I’m not going to tell you everything I’ve done and show code. If you want that, I can share it.

  • Raspberry PI 3
  • Case – This is probably my favorite case that I’ve used so far.
  • Raspbian OS
  • USB Temperature Sensor
  • NodeJS
  • Python & Pyteams – Used to post the current IP Address to Microsoft Teams when the system boots up, so I can find the IP address. Very important
  • Temper-Python – Used to read the sensor.
  • Smart Plug – This is also key when the server stops working and you have to reboot it from home.
  • Sqlite – I’m currently just writing the logs to a local DB. I really want to change this
Before placing it in the server

Grabbing the temperature

I wrote a little tool, in Node, that calls “temper-poll” every 15 minutes to read the temperature with a cron job. This is a super simple script that grabs the temperature and inserts it into the DB along with the time. I really want to change this and sync the dates with a server. What if the server shuts down? If I can see the temperature trend, it may give me an idea of why the server is down. (Was it climbing to it’s death?)

Web View

The next piece was the fun part. I am not a UI guy, but I like to play one sometimes. In recent interviews at the HackerX events, they are always looking for a Full Stack individual. (see “Out of My Shell” post) I think that is where I had the most fun on this. I decided to deviate from what i’m use to,Bootstrap, and go with Semantic-UI and Jade. It’s been a bit of a learning curve.

What you see in the image is a week of tweaking. I’m still not happy with what I have but it is ok. I’m sure I break a lot of UI rules, but it is functional.

Last week I decided to add an “Average” temperature line that, I was hoping would tell me how the current temperature relates to the average. The average is hard to show when the air conditioning is kicking on at random times and the heat outside, etc. (that’s my guess) As of this writing, the temperature has been the same for 7 hours. It is making me nervous. It’s hard to see but the temperature is 65.9 for the last several hours.

What is next?

This has been a fun little project that has kept me a little busy. It’s a super simple concept, but it’s a bit hard to debug remote and keep it up. The smart plug helps. I’m sure I’ll be tweaking this a bit here and there. A few things I want to do.

  • Figure out why the temperature has been the same.
  • Sync the temperatures to an offsite DB

This has been pretty fun. I hope it doesn’t fail me when the air conditioner goes out.

Playing with technology.

Image by Mike Sweeney from Pixabay

The Problem

I wanted to talk about something I’ve been playing with at work (not for work..just at work). Before I start, I want to say that I’m not trying to do a full review or guide on how to set this up. It is just a little story about what was built.. 🙂

We have two entrances to our work. We have the main entrance and then a second door most of us use to go to the bathroom. No one is monitoring the main door, so if a package is delivered, it would sit there until someone happened to go to the bathroom or you go looking for it. If someone came to the office to meet with us, they never knew where to go. Most of the time the visitor would sit up there waiting for someone to greet them. A coworker mentioned that it would be nice to have a webcam to view people coming and going. This is how this little project was born.

The solution. Version 1

My nephew is always up on cool tech toys and had recently built a Raspberry PI garage monitor system. I took that idea and built one for the office. The following items were used:

  • A Raspberry Pi 3 – Raspberry Pi 3
  • Web Cam 1080p – I can’t remember what type this is
  • Raspbian – UI for Raspberry Pi
  • MotionEye – Software used to manage the camera and motion, etc.

Setup

I didn’t want to have a monitor plugged into the Pi all the time, even though I was using a GUI OS (Raspbian), so I setup all the stuff at home. MotionEye has a pretty good page that describes how to install the software, and that was pretty easy. The following script (very simple) was used to post a message to a Microsoft Teams server indicating what the IP Address of the Pi. This would allow me to make a change to the WiFi settings to connect to the WiFi when it booted up. Everything should have been taken care of after that, because I can use putty to connect to the machine.

import teams
import tools, os
import pymsteams

def teamMsg(ip):
    ips = ip.split(' ')

    myTeamsMessage = pymsteams.connectorcard("<secret>")
    myMessageSection = pymsteams.cardsection()
    # Section Title
    myMessageSection.title("Pi Boot")
    # Activity Elements
    myip = ips[0]
    myMessageSection.activityTitle("Here is my IP(s) - %s " % (ip))
    myMessageSection.text("Here is a link to come watch Watch. [Watch here](http://%s:8765) - username: 'user' -- blank password " % (myip))
    # Add your section to the connector card object before sending
    myTeamsMessage.addSection(myMessageSection)
    myTeamsMessage.summary("Camera booted.  Connected to network.")
    myTeamsMessage.send()

import teams
import tools, os

ipaddress = os.getenv("_IP")
print ipaddress
teams.teamMsg(ipaddress)

This code hasn’t been cleaned up.

Motion Detection

One feature of motionEye is to detect motion, so I created some scripts to post messages to Teams when motion was triggered. This was a great idea in theory, but it would never work. MotionEye wouldn’t fire these scripts for some reason, and I haven’t been able to fix it..yet

Plugging it in

I took the Pi to work and plugged it into the network and fired it up. It didn’t go so smooth, but I was able to work it out and get it going. We had fun with it. Unfortunately, it wasn’t doing what we wanted, since it wouldn’t run the scripts during a motion event. We had more fun watching the videos of coworkers going to the bathroom, coming to work, or going home.

Boredom

We eventually grew bored of this setup and thought it would be a better idea to monitor the parking lot. Specifically Nefarious Corner mentioned in The Parking Lot post. It was nice to view this area, because it was more interesting than watching the co-workers go to the bathroom. We found a few problems with this setup and the raspberry pi.

Problem 1

The Pi didn’t have enough processing power to handle the video processing. We were getting pretty low refresh rates, so the videos were very choppy and provided little value.

Problem 2

The machine would crash often, and the only thing we could figure out is that it may be overheating. I have the Pi in a Retro Nintendo case, which is super cool when you are building a gaming machine. The case comes with a fan, but it wasn’t installed…woops!

Problem 3

There wasn’t enough space on the memory card, so it would fill up fast and then freeze up. When this thing freezes up it was difficult to get in without having a monitor plugged in.

Version 2

After the incident mentioned in The Parking Lot and the camera crashing. I wanted to get MotionEye working on a new machine that can hopefully handle the image processing and have more space.

I located an old machine that we haven’t used since 2010 and repurposed it. The new machine was constructed using Ubuntu Server 19.10. It didn’t go as smooth as the Pi due to some mistakes on my part, but I got it running. Things are running and we haven’t seen much action on the camera though.

ParkingLot

I’ve had fun setting this up, but I’m pretty sure it can do a lot more. I have several ideas on how to extend this. One would be to integrate this with the software/service by Sigthound, which is a service that can recognize cars, license plates, people, etc. Go check it out if you haven’t seen it before. I would suggest looking at the Cloud API. I’m going to apologize now, because after you go to the site, your FB wall will be riddled with ads from Sighthound. 🙂

Conclusion

I love exploring and playing with technology and this system is perfect for watching people, especially those misbehaving in your parking lot. I say bring on the summer and the crazy meth-heads.