Archive for the ‘Computers/Internet’ Category

Bitten by the Home Automation Bug

Not quite two years ago, I wrote about a little timer I made using an Arduino microcontroller and a simple relay. The purpose was to turn a couple lamps on in my living room automatically at sunset, and off around 11:00pm. An old-fashioned timer doesn’t work so well because sunset changes every day, and the timer needed to be reprogrammed every couple of weeks.

That little project was fun, and the timer was quite useful for awhile. However, a few weeks ago, the relay burned out or something went wonky and the project died. I needed a replacement, and didn’t want to take time to rebuild my original timer.

Then I discovered the Belkin Wemo line. There are a few products in the Wemo line, but the one I was most interested in was a simple switched outlet. The advantage is that they are web connected, and can be turned on and off with an app from anywhere you have an internet connection. Among the simple programs is switching relative to sunrise and sunset. It would work nicely. However, I discovered something in the process that would work even better.

Smartthings!
Read the rest of this entry »

Securing Asterisk with IPTables

I’ve been running my phone system through Asterisk on Debian (Linux) for a number of years. I’d consider myself a novice to intermediate user of Linux, even though I’ve been tinkering with it for over a decade. I also don’t play with Asterisk very often, but like to get things set up comfortably from time to time so I can leave it alone for awhile.

I recently upgraded from Asterisk 1.6 to 11. In the move, I also spent some time taking a close look at the CLI, which caused me to notice a lot of attempts to either call extensions on my system that didn’t exist, or log in to extensions that didn’t exist. It was apparent that there were attempts being made to hack my system. It was time to dig deeper into security before someone succeeded.

In the past, by happenstance, I tended to avoid some practices that make it easier to hack an Asterisk system. The primary one being I didn’t put any extensions in the default context. Hackers seem to like to focus on that one, and with nothing there, there really is nothing to hack.

That wasn’t enough though. I really wanted to lock things down and prevent the attempts themselves. The best way, I found, was to bone up on IPTables, the most common firewall on Linux.

I took inventory of what I was doing with my system, and realized that there is only one outside account/system that I use that should need to connect to my system. I have a few phone numbers at IPKall.com, and need their server to be able to reach me if anyone should call one of my numbers. Everything else is internal to my home network.

Below is a set of rules that I put into my IPTables to allow in traffic from IPKall, but block anything else that is attempting to connect to this particular machine.

I should note that SIP is the only service that is open to the internet on this machine. Should I ever need to log in to it via SSH, I would do so by way of another machine on the internal network, either directly or by proxy.

The following is in a shell script. I know very little about IPTables, and learned quickly that the best way to ensure the rules behave as expected is to always start from scratch. If I need to change my rules, I’d do so in this script, and run it again once I’ve made my changes.

!/bin/bash

# First, I flush out the existing rules
iptables -F

# Next, allow all traffic on the localhost loopback interface
iptables -A INPUT -i lo -j ACCEPT

# Allow already established connections
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT

# Allow tcp and udp traffic from IPKall and all traffic from the local network
iptables -A INPUT -p tcp -s 66.54.140.46 -j ACCEPT
iptables -A INPUT -p udp -s 66.54.140.46 -j ACCEPT
iptables -A INPUT -p all -s 192.168.1.0/24 -j ACCEPT

# Allow voice streaming for SIP from IPKall - Note I use a much more limited port range than the default
iptables -A INPUT -p all --destination-port 21000:21030 -s 66.54.140.46 -j ACCEPT

# Set default policies for everyone else (not IPKall or local)
# Disallow any connections on port 5060 (SIP), but allow all outgoing traffic
# Note that 5060 is the only port that forwards to this machine from outside the network,
# so any traffic on any other port would be blocked at the NAT router itself,
# never bothering this machine in the first place
iptables -A INPUT -p tcp --destination-port 5060 -j DROP
iptables -A INPUT -p udp --destination-port 5060 -j DROP
iptables -P OUTPUT ACCEPT

So there you go. This post is really for the benefit of people doing searches for Asterisk and IPTables, and I hope someone finds this useful.

HTPC: Revisited

Almost two years ago, I posted of my transition away from cable/satellite TV to using only internet & over-the-air and a Home Theater PC. Since it has been almost two years, I thought it a good time to update how things are going.

We’re still every bit the “cord cutters” we were back then. We haven’t missed satellite tv, and haven’t looked back. There have been some minor changes to our setup, as I’ve learned more and found different things to enhance the experience.
Read the rest of this entry »

Programming the ChronoDot DS3231 Real Time Clock

In my last post, I introduced my new hobby tinkering with the Arduino microcontroller. I also mentioned a timer that I’m building to power some lamps in my living room.

Since the Arduino doesn’t have a clock built into it, there is an interesting problem wherein there is no way to ensure that the Arduino will turn the relays on and off when I want it to. Enter the Real Time Clock (RTC). It’s a small clock chip with a battery. You program it once to set the time, and from then on it will keep time rather well. The one I have will keep time within a minute or two per year, which is plenty accurate enough for turning on lamps.

The biggest issue I’ve run into is that it has been hard to figure out how to program it with the right time. There are example sketches (program code) out there that will do it, but not exactly as I need it.

The code I got from Jack Christensen over at Adventures in Arduinoland assumes that the clock is set to UTC time, not local time, and the examples that I have found all set the clock to local time. Setting to UTC is important because it automatically adjusts for daylight savings time. It’s also easier to program the code for use anywhere in the world (share it with others) when it is based on UTC time.

So because I had such a hard time, I modified the example that is found here to set the clock to UTC, and figured out how I needed to modify it here. All you need to do is paste this into the Arduino programmer, modify the variable for the UTC offset to fit your timezone, and upload it. (I’m in UTC – 5, so mine is set to float UTCOffset = -5.0; It is set as a float for those locations that may be offset by an amount that is not a whole hour (for example, Nepal is UTC +5.75). If you’re powering the RTC from the pins, you’ll have to uncomment those and modify them to fit your configuration.

// Date and time functions using a DS1307 RTC connected via I2C and Wire lib

#include <Wire.h>
#include "RTClib.h"

RTC_DS1307 RTC;

float UTCOffset = -5.0;    // Your timezone relative to UTC



void setup () {
    Serial.begin(9600);
        
    
    // Uncomment the following lines to use pins 4 & 5 as power and ground for the RTC
    
    // pinMode(4, OUTPUT);
    // digitalWrite(4, HIGH);  // HIGH for power
    // pinMode(5, OUTPUT);
    // digitalWrite(5, LOW);   // LOW for ground
        
    Wire.begin();
    RTC.begin();
    
    RTC.adjust(DateTime(__DATE__, __TIME__));  // sets the clock to the time when this sketch is compiled
    delay(1000);
    DateTime now = RTC.now();
    DateTime UTCTime(now.unixtime() - 3600 * UTCOffset);   // Adjust the time from local to UTC
    RTC.adjust(UTCTime);
    
}

void loop () {
    DateTime now = RTC.now();
    
    Serial.print(now.year(), DEC);
    Serial.print('/');
    Serial.print(now.month(), DEC);
    Serial.print('/');
    Serial.print(now.day(), DEC);
    Serial.print(' ');
    Serial.print(now.hour(), DEC);
    Serial.print(':');
    Serial.print(now.minute(), DEC);
    Serial.print(':');
    Serial.print(now.second(), DEC);
    Serial.println();
    
    Serial.print(" since midnight 1/1/1970 = ");
    Serial.print(now.unixtime());
    Serial.print("s = ");
    Serial.print(now.unixtime() / 86400L);
    Serial.println("d");
    
    // calculate a date which is 7 days and 30 seconds into the future
    DateTime future (now.unixtime() + 7 * 86400L + 30);
    
    Serial.print(" now + 7d + 30s: ");
    Serial.print(future.year(), DEC);
    Serial.print('/');
    Serial.print(future.month(), DEC);
    Serial.print('/');
    Serial.print(future.day(), DEC);
    Serial.print(' ');
    Serial.print(future.hour(), DEC);
    Serial.print(':');
    Serial.print(future.minute(), DEC);
    Serial.print(':');
    Serial.print(future.second(), DEC);
    Serial.println();
    
    Serial.println();
    delay(3000);
}

Learning Programming with the Arduino Microcontroller

A few weeks ago, I got my hands on an Arduino starter kit. The Arduino is a microcontroller that is capable of doing a lot of really cool things. The starter kit included the Arduino board, a collection of electronic parts (LEDs, a breadboard, wiring, resistors, potentiometers, an LCD screen, and some other things), and a book to start learning the programming. The Arduino is programmed using a modified version of C++, so learning to program it means that your programming skills can be easily transfered elsewhere.

Learning to program the Arduino is not hard, and it’s a lot of fun. The first thing you’ll learn is how to make the LED on the board blink. It’s very simple, but seeing it do what you tell it to do is exciting.

I’ve gone about half way through the book, putting together example projects. Once I got half way through, I started having my own ideas that I wanted to try. The projects I’ve done include: A “Spaceship interface”, “Love-o-meter”, Color mixing lamp, Mood Cue, Light Theremin, and a Crystal Ball. The Spaceship interface is the first project, to give you the basics of hooking up buttons, LEDs, resistors, and working with inputs & outputs in the code. It’s very simple, just a couple lights that change when you push the button. When you’re done, it looks like something you’d see in an old sci-fi movie.

The Love-o-meter is simply a temperature sensor connected to some lights. The warmer it gets, the more lights turn on.

The color mixing lamp is really cool. It’s an LED with red, green, and blue elements in it. You can make any color you want by mixing the light from the elements.

The mood cue uses a stepper motor to point an indicator. The purpose is to learn the use of the stepper motor.

The light theremin is interesting. It uses a light sensor, and outputs a varied pitch tone based on the amount of light it sees.

I modified the code for the Crystal Ball. It’s supposed to be like a “magic 8 ball”. You program it with 8 possible answers and have a switch that’s activated by turning the board over. I never got the switch to attach to the breadboard because the pins are too short, so I just wired in a pushbutton switch instead. Instead of 8 random answers, I put in 8 random trivia facts. It was a fun project to learn how to get an LCD screen working.

Beyond that, I’ve been working on a few other projects that came to mind. One of them is a timer to control two lamps in my living room. Right now those lamps are on timers and come on in the evening, and turn off around 10:30. However, I have to adjust the timers every few weeks to follow the changing sunset time. My new timer will have a clock built in, and be able to calculate when sunset is, so I won’t have to adjust for it any more.

While contemplating that project, I found this. It’s a goofy little project, but it does almost exactly what I want my timer to do. The only difference is that I will drive a relay instead of an LED.

I emailed the guy who made that and asked if he could point me in the right direction for tracking sunrise/sunset times, since that is still a bit beyond my current abilities. He gladly shared his code with me, and has been very helpful in getting it modified to suit my needs. He also pointed me to the Arduino forums, where there is a wealth of knowledge to help figure this interesting little board out.

The other project I’m working on is a simple one to understand and build. I bought an old stoplight at a surplus store, and am fixing it up for my rec room. It will be driving by relays that are controlled by an Arduino when I’m done with it. The programming is super simple, not much more complicated than the “blink” program that is the first thing you learn with the Arduino, it will just have three lights instead of one, and the “blinks” will be very slow, and never on at the same time. I may get fancy and figure out how to connect a motion sensor to it so it only runs while we are in the room (no point in powering lights when there’s no on there to see them).

I have been having a great time, and look forward to a lot of fun projects in the future. Not only that, but I’m getting things figured out now, so when my kids get a little older, I can help them learn to program and make neat little projects too!

My Twitter Philosophy

I’ve been on twitter for a while, two years as a regular user, almost six since I first created my account.

I think I tend to be a typical user as far as who I follow and what I tweet. Some are very topical, they may be tech celebs, so they only tweet tech-related stuff, just as an example.

I have two main subjects I tweet on: faith and politics. When it comes to politics, I have found no better way to keep up with state and local stuff than twitter. I just don’t have the time with three kids to follow the blogs or local media to keep up. Outside of faith and politics, I’m not afraid to tweet on whatever subject is on my mind, but other topics are less commonly found in my stream.

As for who I follow, as with most people, I follow those whom I find interesting. I also do follow-backs, but not automatically. Twitter can be a cesspool of attention-seeking glory-hounds and wanna-be self-made millionaires that will follow people by the thousands just to get follow-backs. That defeats the purpose of twitter as I see it; a community of people who have similar interests. Thus, if you follow me, and show me that you actually read my tweets (like a simple reply that is relevant to what I’ve tweeted), I’ll most likely follow you back.

However, my feed sometimes gets a little out of control, and it gets hard for me to keep up, so I sometimes feel the need to trim the list of people I follow. Usually first on the list is those who I don’t know that don’t follow me back. It’s usually an indication that someone met the criteria I illustrated above to get a follow-back, and then unfollowed me.

My Evolution of Media Consumption

I’m a media junkie. Whether it’s music, TV shows, or movies, I like it. I’m especially fond of podcasting. Not only do I produce a podcast, I love listening to them.

Several years ago, I bought an Apple TV. I loved it. It was a great way to serve up my iTunes library to my TVs and stereo systems. I especially liked that I could play audio from my computer using iTunes and have it come out of the speakers hooked up to my Apple TVs (I have two). If I was moving around the house, I could have the music or podcasts I was listening to played in several rooms at the same time.

I’ve been using my Apple TVs less and less though. I still like them, but I’ve come to like something else better.

It all started last winter when I built my first Home Theater PC. As I was moving away from DirecTV and toward a life as a cord-cutter (someone who gives up cable and satellite TV), I quickly came to like using Windows Media Center as a DVR for over-the-air television. For the shows I used to watch on cable/satellite, Amazon Instant Video was an excellent substitute. Paying $3 per episode ($2 if you don’t mind standard definition, lower resolution) is much cheaper for my family than the $100/month we were paying for DirecTV.

In addition to my new DVR functionality, I quickly came to like another program: Plex. Plex is a derivative of XBMC, a media player that was originally built to play audio and video files on the first XBox, but was ported over to the PC. Plex is a little different in that it requires that one computer on your network act as a server. If you only have one computer, that’s no problem, it can serve to itself (it just requires two programs: the server and the client). The server is nice because it keeps track of everything. If you start watching a show or movie on one machine, stop part way through it, and continue in another room, it will remember where you left off.

What I love about Plex so much is that it is much more flexible than iTunes. It will handle many more file formats, and you can create your own sections. For example, instead of just having one section for TV shows, we have two. One of them is the standard TV show section, and another is for German language shows, since our kids watch all of their shows in German (which we get from save.tv, an online DVR service from Germany).

One feature that I mentioned loving about iTunes was one I missed with the HTPC: the ability to play audio to multiple places. This is a feature that Apple calles “Airplay”. However, I’ve been discovering other ways to use Airplay than just using Apple hardware. I won’t get into any real depth here, but Lifehacker has an article on how to send audio to a whole host of different places, from your phone to your HTPC and others. I can now send my podcasts from my Mac running iTunes to all of my HTPCs, as well as my Android phone, as well as my old Android phone that is hooked up to a radio in my kitchen. I’m now at a point where I can have a player set up in every area of my house (though not quite every room, so the volume needs to be turned up a bit and bedroom doors left open.)

My Apple TVs are first-generation. I haven’t used any of the newer ones (they are currently on the third generation), but I’ve come to use mine so little I don’t foresee updating to newer models. There is nothing more flexible than a computer. The newer Apple TVs have app support, but Apple has had a history of limiting what apps it will allow on their hardware. Not so with a computer.

Since building that HTPC, I set up an old laptop to act as an HTPC (mentioned in the post in March), but now have also added an old Mac Mini. For the time being, the Mac Mini mostly runs Plex, but the plan is to get a copy of Windows 7 to load on it via Boot Camp for a full-fledged HTPC for my bedroom.

If you’re going to record TV to an HTPC, DVR style, it’s good to have a current-generation machine with the power to handle several video streams simultaneously. However, older machines work great for clients. The old laptop, which works just fine as a client, is a Pentium Dual Core (the hardware that is between the Pentium 4 and the Core Duo). The Mac Mini is a Core Duo. If you’ve got an old machine that you’re looking for a use for, try hooking it up to your TV and using it as a media center.

HTPC: The Software

Just a few days ago, I published a post about my family’s new Home Theater PC. That post focussed on the hardware I used to put together the machine. Today I’ll discuss the software.

First and foremost is Windows 7. I use Windows Media Center (WMC) as my DVR software, and WMC is built into most versions of Windows 7, and has been in Windows since the latter days of XP. WMC is a great DVR package that works very well. I’ve read articles that put it on par with Tivo for the best DVR interfaces. I think that’s not an exaggeration, it is a good interface. This isn’t meant to be a detailed “how-to”, but rather will describe how I went about setting up my system. I tend to learn best by doing, and don’t read through manuals before I start, so this is meant to help give pointers on things that aren’t obvious to a first-time user. It’s also meant to give an idea how easy (or hard, depending on your perspective) WMC is to configure and use.
Read the rest of this entry »

Raspberry Pi

I’m very excited about the Raspberry Pi, a small computer, about the size of a credit card, that sells for just $35 and has a lot of power. It has an ARM processor running at 700MHz, 256MB RAM, runs off of an SD Card, has a pair of USB ports, an Ethernet (network) port, an HDMI port for video, an RCA port (also for video), an audio jack, and is powered from a micro-USB port. In other words, you power this thing off the same cable you probably use to charge your cell phone. The hardware is comparable to a mid-range Android phone, it’s only drawback is it doesn’t have enough RAM to actually run the Android OS.

Raspberry Pi was developed by a UK based non-profit and is intended to provide a very cheap, but powerful platform, not only for enthusiasts, but for educational uses as well. The $35 model is their ‘B’ model. The ‘A’ model will be $25, and will come with similar specs, but lack the Ethernet port and have only one USB port.

The Raspberry Pi was first released last week, and sold out their first lot of 10,000 units rather quickly. I just placed a pre-order for a unit from their next lot, and look forward to getting mine in the coming weeks.

What Does it Do?

The possible uses for this capable little machine are endless. I have plans for several already, and haven’t even gotten my first one yet, so I expect more ideas to come to me. The first one will probably get an installation of Debian, which is already available for download (and installing to an SD card on another machine as I type this). My plan is to connect a rather large hard drive to it, probably either 1.5TB or 2TB, and leave it at my parents’ house so that I can back up files to it that I want preserved should disaster strike at home and everything in the house be destroyed. The idea is to connect via the internet and back up automatically. I already do this with my brother-in-law in North Dakota, but need something a little closer to home so I can access it more easily when things go wrong and need my attention.

Another use I have plans for is to load up OpenELEC, which is XBMC (which originally was an acronym for ‘XBox Media Center’, but now is just XBMC since the XBox was replaced with the XBox 360 and became obsolete). OpenELEC is a minimal operating system designed just to get XBMC running and nothing else. The idea with this machine is to hook it up to an older TV via the RCA port for a cheap & easy media center.

Some day I also hope to find time to start learning some serious programming skills as well. I can foresee using a Raspberry Pi as a platform for programming some home automation projects. One idea I would love to pursue, but have no concrete plans to work on yet, is a controller for my home irrigation system. The one I have now, made by Rain Bird, turns my sprinklers on and off at set times, and has a rain sensor to prevent it from coming on if it has rained recently. It would be nice to have a predictive system that could watch the weather forecast and not turn on if, say, there is a 60% or more chance of rain later in the day. My system costs about $5 to run every time it’s turned on, and runs every-other day, for a cost of about $75/month on my water bill from May to mid-October. In addition, it would be nice to be able to control it remotely with a smart-phone app, or maybe even email or SMS message.

I’m excited about the possibilities. I can foresee having these little wonders scattered all over my house, running various tasks, automating things, and just making life fun.

HTPC: The Build

I’m currently in the latter stages of transitioning my family away from cable/satellite for our TV service toward just using over-the-air, along with the internet. I’ve been a DirecTV customer since the summer of 2001, and the service, along with the bill, has been a part of life for over a decade for me. Our family income has remained steady through the economic downturn, and we are fairing well. However, we don’t take that for granted, and still take a look at our expenses from time to time and look for ways of cutting unnecessary expenses. It has come time that we are not only comfortable with losing our satellite service, we look forward to it. Our service costs about $100/month, which gets us: the “Choice Xtra” package, HD service, an HD-DVR, equipment protection, and a second receiver (a first-generation Tivo I bought shortly after getting DirecTV service back in 2001). That $100/month does NOT get us any movie channels, sports packages, or receivers beyond the two mentioned. We have two HDTVs, and I hooked them both up to the same receiver about two years ago. The one where the receiver is located is hooked up via HDMI, and the one upstairs in the family room is hooked up via Component cables that I ran through the ceiling and walls (five coax cables with RCA connections on each end). We control it through RF remote controls.

No more, we’re moving away from that and towards an extra $100 in our pockets every month.

This first post on our setup is dedicated to sharing the hardware that I used to build our system. We currently have a brand-new HTPC that I build in recent weeks hooked up in our entertainment room to the same TV that has the DirecTV receiver. We also have an older laptop hooked up to the other HDTV. The laptop is a Dual-Core Pentium machine running Windows 7 Pro – 32-bit. This machine acts only as a viewer, the new HTPC is doing the work of recording. We also have an X-Box 360 that can work as an extender, but it is hooked up to the same TV as the laptop, so it doesn’t get used much for watching TV (for reasons I may get into later).

Here is the hardware that makes up my HTPC:

The case

Some time ago, when the idea of an HTPC was first born, I found the nMEDIAPC Red Wood case at Newegg. It is simply a beautiful case. It looks like an old radio, and looks great on the shelf nest to the TV. I could have gone with a simple black box meant to go in an entertainment center with the audio receiver, DVD/Blu-Ray player, and other equipment, but the price on this one was similar to those simpler cases and was too cool to pass up. It’s slightly more complicated than your average case, since it’s made mostly from wood, but nothing too complicated.

I also sprang for the LCD display, a $40 add-on. The cool-factor is really there, though I can’t say it’s perfect. The driver on it often locks up, causing it to display a blue bar across the top row of the display, and the blue color of the display makes it difficult to read from more than 4-5 feet away. I have 20/20 vision and have a hard time reading it from the couch, about 8-10 feet away. That said, it is cool enough that I would spring for it again if I were to start over knowing what I know now.

The case was $90, and the LCD panel added an additional $40 for a total of $130.
Read the rest of this entry »