Showing posts with label Security. Show all posts
Showing posts with label Security. Show all posts

Wednesday, October 9, 2013

Video feed from the Pi(es)

I know I went silent for awhile.  New job and more.  Tons more.  I'm getting back to some of the projects, but I'm also taking on a new one.  I need to install some basic security cameras at a facility.  I'd prefer that they work using the network infrastructure (It's not a computing intensive location).  Really cheap IP cameras run around $70, and I'm not looking to pick up another maintenance hobby.

A Raspberry Pi runs $35, and the camera runs $25.  That's essentially an HD IP camera for $60 (I've got an insane number of power supplies lying around the house).  I also already own a Pi and camera to play with.

I bounced over to the Raspberry Pi foundation's website to see what they had to say about the camera.  They have some good tips on getting the camera installed.  However, I hit a couple of snags and couldn't get videos to stream over the network.  It was dinner time and I had to bounce out to have dinner with friends.

A couple of days later, I'm back, and searching around the internet.  I stumbled across Miguel's great post, and started learning a couple of things.  After a little bit of reading, I came across his updated post, which had EVERYTHING I needed to get the little computer streaming over the network.  I needed to do some apt-get update/upgrade between steps 6 and 7.  I also wrote a quick script to start the camera up:

mkdir /tmp/stream
raspistill --nopreview -w 960 -h 540 -q 80 -o /tmp/stream/pic.jpg -tl 10 -t 9999999 -th 0:0:0 &
LD_LIBRARY_PATH=/usr/local/lib mjpg_streamer -i "input_file.so -f /tmp/stream -n pic.jpg" -o "output_http.so -w /usr/local/www"

All this does is make sure the directory exists, then it creates a series of 960x540 JPEG's of quality 80 every 10 milliseconds for 9999999 seconds (I think it's seconds).  The "-th" is a thumbnail configuration, and the "&" tells this script to run in the background (I think).
The next part of the script is one that I'm not sure about.  It streams the JPEG, but I'm not completely sure I understand everything, yet.

I did mess around with the JPEG settings.  I selected the 960x540 image size because all of my monitors are 1080p, at least.  This way I can easily accommodate multiple streams on the same monitor.  I set the time lapse down to 10 milliseconds, but it didn't seem to increase the streamed frame rate.  I put quality at 80 because it was where I could read some text from across the room in my test image.  I finally messed around with all three of these settings to try to improve the frame rate, but with no real success.  It also appears that frame rate is impacted by the amount of light in the image (In theory this makes sense, but we should still be able to get decent lighting/shutter speed without sacrificing frame rates).

Great work, Miguel.  Thanks!

Monday, December 3, 2012

GPIO Pins on the Adafruit Pi Cobbler

I posted the code for the program I used over in the Adafruit Forums:  Raspberry Pi Home Datalogger (new window)

I'm cleaning the project up a little bit.  I'm trying to make the code "nicer" and easier to follow (I should comment my code.... one of these days).  I switched the code that runs the programs over time to a system that checks the time every second, executing specified code at the top of the minute (Poll the temperature and pressure sensors), and at the top of the hour.  It works, but my system utilization never drops below 60%, and is frequently at 97%.  I may have to go back to having the system "sleep" in between sensor checks.  I think that's a bad way to do it, but I'd like to look at having these little nodes be battery and/or solar powered.

I messed around with the RPIO program I was screwing around with.  I wanted to see which RPIO reported pins correlated with which pins labeled on the Cobbler T-Plate.
The chart is repeated over on the Adafruit forums, in the comments section of the code.
Cobbler RPIO
#4------ 7
#17----- 11
#18 -----12
#21 -----V1 13
#22 -----15
#23 -----16
#24 -----18
#25 -----22
#27 -----V2 13

Monday, November 19, 2012

Raspberry Pi Home Datalogger

I've wanted to do something like this since I first started playing with microprocessors.  The idea of an inexpensive, distributed sensor network throughout the house is really cool.  In Hollywood we always see someone sitting at their computer console accessing their security system.  It's typically a wire-frame display with sensors all over the place.  They're getting all kinds of data, and even providing the occasional remote output (displays, lights or sirens, etc).

The $35 Raspberry Pi is almost the ideal basis for this kind of sensor network.  It runs a (relatively) well developed Linux distribution.  It has two USB ports, runs on 5v, sports an ethernet port, and will support almost any video display out there.  More importantly, it has several exposed general purpose I/O pins and supports I2C.

I'm using Lady Ada's Occidentalis distro.  So far it has been incredibly stable (though it swaps between video outputs if I cut power to the system).  I'm using this distro because there are examples using Python to access the various GPIO's and the I2C.

My previous post detailed some of my earlier experiments with the system.  Since then, I have worked on building a series of programs to access a BMP085 board attached to the I2C bus.  I haven't done much with Python in quite awhile, so I'm fairly rusty and lacking a definite style.

I finished a series of programs last night that check the sensor, log the sensor data to a logfile and update a webpage, and a simple program to automate the whole process.  Currently I've got the sensor being checked and logged every minute.  The logger program is using the Python Logging module.  I'm recording the event level (I'm generating a warning if the temperature reaches 30c), the epoch time (to facilitate graphing later), and the temperature and pressure (I don't care about the altitude).  Using epoch time versus Python's asctime also saves some memory.  The log files are between 1.8 and 18 megabytes per day (one measurement per minute).  This yields recordings between 50-500 days per gigabyte.  I'm not sure why there is such an insane difference between "Total Size of Files" and "Size on Disk".  Given that it's close to an order of magnitude, I need to address that at some point.

I'm looking to increase the number of sensors on the board.  I'm playing around with a GY-80 board that I got off of eBay some time ago.  It includes the BMP085 sensor, plus an IMU/Gyro component with a compass.  It was about $20.  I'm wondering if the resolution is tight enough to work as a seismograph, though I'll have to increase the polling rate to something much higher than once a minute.  Luckily, with the processing power of the Raspberry Pi, I could poll the sensor very quickly, analyze the data locally, and only report data that was relevant.  This idea is going to be an add on after some of the other to-do list is achieved.

A big thank you to the write of the Giuseppe Urso Blog.  He's found the datasheets for all of the components on this board (I think).  The ebay seller has not been able to provide good information for me.

Things to do:
I want to improve the webpage.  Right now it's a simple Apache text page that shows the temperature and pressure, along with the system time of the latest measurement (actual time, not epoch time).

I want more sensors.  I'd like a light and motion sensor (again, we're trying to get close to that Hollywood sensor system).  It would be great to incorporate a smoke/carbon monoxide/gas sensor into this build.  A networked, web-enabled hazard detector would be incredible.  I've already got a couple of sensors for this. To get them to work, I need to grab something that will let me add analog to digital feeds to the board (perhaps this?).

I really think I'd like to incorporate a second temperature sensor.  I'd like my first sensor node to be located just inside the front door.  Running a cable outside to a sensor (MPL115A2) would be pretty easy, and would give me the ability to log the weather outside compared to the environment inside.  The capability would also be nice if Angel decides to start working with herps again.  This would allow us to monitor the inside and outside of the tank.

The webpage needs serious work.  I'd like to be able to generate graphs of the data, on the fly (click on the parameter, and it brings up a graph of the last hour.  Click on that graph it shows the last 12 hours.  Click on that, it shows the last day.  Week, month, year, etc).  My skills with Python are not up to the task yet.  Hell, my skills with HTML are essentially non-existent (My webpages in the past have all used Dreamweaver).  I need to see if I can merge the two, and someone get the Python code to play nicely with a Dreamweaver generated page.

Automated alerts.  We'll go back to the Hollywood example for this one:  When the bad guys are breaking in, I need the network to tell my cellphone (or bring up an alert on my computer).  A more practical concept:  When the house gets too hot, I need to be told.  When the house is on fire, I need to be screamed at.

I want to keep the cost down.  The average cost, per node, should be less than $100.  At this price point, folks can afford to pick up a couple of nodes to watch their doors.  As they like it more, they could grab additional nodes for other rooms in the house (I want to be able to control my small home theater system using my cellphone and an IR equipped node).

Webcam support.  The Pi has two USB ports.  Once the node is developed, there is no reason to have the USB ports in use.  A web cam is a cheap (I saw a couple for under $10 the other day) way to gain tremendous amounts of information about a locale.  Even if the camera is only used to snap stills to send to a remote site (or just log locally) the idea has tremendous value.  As it stands, I haven't even tried hooking up a camera to the USB ports.

Free and open code.  An idea like this is only as usable as the guy making everything.  I'm not an engineer or computer scientist.  If I could get a couple of those guys interested in the project, they'd be able to do incredible things with it.  More to the point, they'd see ideas that I'd never even consider.  This project, as an open source project, has real potential.  I'm going to work on setting up a GitHub account, and making my code public (I'll warn you, it's ugly code).

I'll post up more as I get it.

Late edit:  I'm starting to look at Lady Ada's Raspberry Pi WebIDE.  I spent the afternoon/evening learning BitBucket, and now I've got a BitBucket account with the code on it (PiLog).  I may not be doing things correctly, so the repository may be a little bizarre over the next couple of days.  The code that was loaded tonight was tested to work, though your mileage may vary.




Thursday, February 25, 2010

Your personal security

OK, another tangential post. Well, not even tangential, but completely off topic.

http://www.huffingtonpost.com/2010/02/18/harriton-high-school-spie_n_467491.html

Harriton High School required all students to use school designated Macbooks (I'm wondering who picked up the cost for these items). Students noticed several bizarre glitches, occasionally the webcam light would flicker. The students were told that this was a glitch with the computer, and there was no problem with it.

It turns out that the school system had installed, what they call, remote management/administration software on the computer. They claim that this was designed to allow the school system to track the computers. In reality, it allowed the school system to remotely access the computers, including the web cam.

The question now, is when was this web cam activation used? Well, that's the question that the FBI wants to have answered.

My question is how did this ever happen in the first place? This is an invasion of privacy of an incredibly high degree. The fact that incredible measures were taken to conceal the invasion, and that it was repeatedly lied about, just makes it more insidious. The crime happened when the software was installed. It became a major issue when the school system lied about it.

Imagine you're a teenager. You already have trust issues (I did). You're in an incredible transition. You're not a child. You want to be treated like an adult. People continually expect more from you. Then the school district pulls this crap on you.

Good job.

If you're interested in the technical aspects of this piece of software, here's a great blog. Some of it is really technical, but the guy does a good job of explaining the meat of the matter.



We need to take responsibility for our own security. No where is this more important than in the security of our privacy. No one is going to tell you when they're nefariously invading your privacy.

I'm just incredibly struck by this incident at the high school. The students were forced to use the computers. If they attempted to bypass the monitoring features, they were threatened with expulsion. Even if they had the knowledge and ability to take control of their privacy (something we should be advocating), they weren't allowed to.

OK, 'nuff said.