Starting HAP-NodeJS on Boot

I have been following QuickPi’s tutorials on getting a USB Camera working with HomeKit. One thing that recently came up was getting HAP-NodeJS to load on boot. CameraCore.js is required and getting it to load on boot was key. Here are the steps and a mention of what was throwing me off.

This method uses rc.local and forever. You can learn more about forever here.

Make sure you have your Raspberry set to wait for the network on boot.  You can do the in rapsi-config under the boot options.  Ocne you do this then  follow along with the rest of this tutorial.

Make sure you are in the home directory. Then install forever with the global.  This can take 5 minutes to install so be patient.

cd ~
sudo npm install forever -g
sudo nano /etc/rc.local

Now, using nano to edit  rc.local we want to add a line of code before the “exit 0” line at the bottom of the file.   We want forever to start up the CameraCore.js file.

sudo forever start /home/pi/HAP-NodeJS/CameraCore.js

NOTE: You can do the same thing with BridgedCore.js or Core.js if you are using them for any reason.

Save (Ctrl+O) and exit(Ctrl+W) the rc.local file once you are done.  Don’t forget to reboot.

sudo reboot

That is pretty much the extent of getting HAP-NodeJS to load on boot.

Unfortunately for me, even after this I could’t get CameraCore.js to load on boot.  Or that is what I thought.  My mistake was not checking if it was running as sudo.

You can  use ‘forever list’ to tell you what processes are running.  But as you see below nothing is running even after a reboot.

pi@TheaterCam:~ $ forever list
info:    No forever processes running

After pulling my hair out I figured out that since the rc.local command was run as sudo I had to use ‘forever list’ also as sudo.

pi@TheaterCam:~ $ sudo forever list 

info: Forever processes running data: uid command script forever pid id logfile uptime data: [0] j-_g /usr/local/bin/node /home/pi/HAP-NodeJS/CameraCore.js 1041 1138 /root/.forever/j-_g.log 0:0:13:3.917

As sudo I can see that in fact the CameraCore process is running.

One more bit of code that might help those of you to test and debug is running the rc.local from the terminal. If it is not working from the rc.local this is a nice option. You can do this by entering the following.

sudo sh /etc/rc.local

This was actually how I found out that the CameraCore process was already running. I got errors and the Raspberry Pi CPU resource meter was pinged out at 100%.

A final note, you can kill all forever process with the following.

sudo forever stopall

SunFounder DS18B20 Temperature Module for Raspberry Pi – Part 2

Here is some python code from the SunFounder site that is part of their sensor kit install.

Let’s get back to our Raspberry home directory if you are not already. You can technically out the python script anyplace you like but I prefer the pi user home directory. Type the following if needed in Terminal.

cd /home/pi/

Now let’s create a python script. Copy the following code below then type the following again in Terminal.

sudo nano getTemp.py

Past the text below into the file.  This will get the temp from the sensors that start with “28”

#!/usr/bin/env python
import os
import time

#---------------------------------------------------
#	Note:
#		ds18b20's data pin must be connected to pin7.
#---------------------------------------------------

# Reads temperature from sensor and prints to stdout
# id is the id of the sensor
def readSensor(id):
	tfile = open("/sys/bus/w1/devices/"+id+"/w1_slave")
	text = tfile.read()
	tfile.close()
	secondline = text.split("\n")[1]
	temperaturedata = secondline.split(" ")[9]
	temperature = float(temperaturedata[2:])
	temperature = temperature / 1000
	print "Sensor: " + id  + " - Current temperature : %0.3f C" % temperature


# Reads temperature from all sensors found in /sys/bus/w1/devices/
# starting with "28-...
def readSensors():
	count = 0
	sensor = ""
	for file in os.listdir("/sys/bus/w1/devices/"):
		if (file.startswith("28-")):
			readSensor(file)
			count+=1
	if (count == 0):
		print "No sensor found! Check connection"

# read temperature every second for all connected sensors
def loop():
	while True:
		readSensors()
		time.sleep(1)

# Nothing to cleanup
def destroy():
	pass

# Main starts here
if __name__ == "__main__":
	try:
		loop()
	except KeyboardInterrupt:
		destroy()

 

ds18b20 = '28-051684d013ff'

Now we can save and exit the nano editor.  Ctrl+o to save the file and Ctrl+x to exit.

Now we can run the python script to see the results.

python getTemp.py 

You should see something like the following start to display.

Sensor: 28-051684d013ff - Current temperature : 21.437 C
Sensor: 28-051684d013ff - Current temperature : 21.500 C
Sensor: 28-051684d013ff - Current temperature : 21.500 C
Sensor: 28-051684d013ff - Current temperature : 21.500 C
Sensor: 28-051684d013ff - Current temperature : 21.500 C
Sensor: 28-051684d013ff - Current temperature : 21.500 C

You can stop the script from running with a Ctrl+z.

In part 3 of this tutorial I will show you how to get the temp sensor results showing up in Homebridge for your home automation.

Google Glass Explorer Program

I was invited to join the Google Glass Explorer Program yesterday. I have been following Glass since the beginning but have never had the chance to play with it. I’m on the fence about the opportunity but I can’t wait very long to make a decision.

20140403-095812.jpg

I’m most interested in the photo and video opportunities since you can shoot and capture both hands free. Biking with Glass is something I’d love to try. Photo, video, and navigation all without using my hands or fumbling for my iPhone. Concert video would be pretty interesting. I also have a few ideas for children’s educational games and a fitness app.

I’ve never seen anyone in Des Moines with Glass so I might be the first. Or maybe just the first to be seen wearing them? But it might come down to the price tag. 1500 to get into the program. That’s a lot of cash and I’m sure I could spend the money on other gadgets. Still, I’m a big enough geek that it might be hard to pass this opportunity up.

RPi Arcade Project Update: 12/2/13

A long weekend gave me time to work on the Raspberry Pi powered arcade system. For starters I used an old marquee that I had from my last arcade. It is not a perfect fit since it is smaller by about 2 inches all the way around. I’d really like to use the full marquee area with a custom marquee. This one one I downloaded from the web and added a bit to it. I have a very talented comic book artist friend so I might commission his to create me something custom.

Temporary arcade marguee in place Side shot of the marquee

My game pads arrived. I have read decent review of these retro style version on Amazon so I decided to pick them up. These are USB so they should be plug and plan. When I add these two additional USB slots will being filled and I am starting to wonder if I am going to be using all 7 USB ports on my powered USB hub in the very near future. My goal is to use the game pads for any Nintendo emulated games. I prefer the traditional arcade joysticks and arcade buttons for NeoGeo and MAME games but would like to have these as an additional option.

Classic game pads arrived.

Below you can see the cabinet in use. The control panel still doesn’t have a protective plexiglass cover on it yet. But, the panel is metal and not wood. I kind of like it without  the plexiglass at the moments. I sprayed about 4 coats of the white so I am hoping that is enough to protect it without the normal plexiglass on top of the metal control panel.  I would also like to add some vinyl graphics to it. I will reevaluate the plexiglass when I start to work on adding the vinyl. You can also see the game pads in the photos below.  The only thing I am missing is beverage holders on the sides of the control panel. I did notice this weekend that I have put place my adult beverage on the pool table that is with in an arms stretch behind the cabinet.

System in action Donkey Kong FTW

Here is a close up of the control panel in action. Now that I have NeoGeo games working I am thinking of adding 4 more buttons to each players already 6 button layout. I currently have the traditional 4 NeoGeo button mapped to each player more like a game pad with two buttons on top and two on the bottom. So that means buttons A and B are mapped to buttons 1 and 2. Then I have buttons C and D mapped to buttons 4 and 5. If I add the extra buttons I will have to drill into the metal again and maybe put another coat of white on it. More work so I am not rushing to make this update. I also need to make sure that I have the room for the extra buttons with the track ball in place.

Lots of room for more buttons.

Speaking of trackball I don’t have this working yet for any games. I also need to power a light below the trackball so that it lights up. The trackball works on operating system GUI so I’m not sure what I need to do to enable this yet fro games. My spinner is also USB so as soon as I figure out the trackball I should have the spinner working as well. There are a handful of classic game I really like to use a track ball for like Centipede, Missile Command, and World Class Bowling. For the spinner Tempest is must. I am pretty sure that the Raspberry Pi has no chance of planing any of the Golden Tee Golf games but those also use a trackball.

I hope my next post covers the trials and tribulations of getting the front end working to the different emulators. This is where I spent most of my time this last weekend. It has been a struggle to get that part of the project working.

RPi Arcade Project Update: 11/24/13

I was back on the control panel again today. I decided to paint the panel white. Before I was able to paint I had to drill two holes and test the trackball mounting. I might have to order special carriage bolts but I’m going with what I was able to find at Home Depot. They seem to work.

I planned to use the original plexiglass cover despite having some carvings in it. After painting the panel white using the original panel was not going to work. Scratches really stand out. I am going to have to get a plexiglass cover professionally cut. Not sure what that is going to cost me.

Here is the sexy new look to the control panel.

20131124-180725.jpg

20131124-180745.jpg

20131124-180759.jpg

20131124-180811.jpg

20131124-180828.jpg

20131124-180838.jpg

RPi Arcade Build Update: 11/23/13

I tackled the control panel today. I have 8 hours easy into cutting, stripping, cleaning, and cutting the panel some more. I am wore out to be honest.

I was able to use the original metal panel. This is a nice plus since the panel has the bolts for the joysticks already. I had planned to only use wood but I managed to cut the trackball hole without too much trouble into the metal control panel. A 3” hole saw did the work and it was a clean cut. It was a little cold outside but with my son’s help and we made steady progress. After cutting the trackball hole I used my Dremel to clean up the tough edges.

20131124-012517.jpg

Next I planned to strip off the original sticker on the control panel. I bet it took me 2 hours to get the sticker off and the surface cleaned up. The sticker came off using a razor blade easily enough but the sticker left behind the sticky part. I scrapped, and scrapped, and scrapped some more. Then I sanded it and scrapped even more. Finally it was free of the tacky mess.

20131124-013141.jpg

20131124-013155.jpg

I ran into my first issue when I realized I cut the trackball hole too far down on the control panel. This mistake prevented the control panel from fully closing. I ended up having to trim out the particle board to get the control panel to fully close. Again the Dremel to the rescue.

20131124-013525.jpg

Now it was time to cut some holes. I have added a total of 13 holes to the control panel. I bought what is called a step drill bit and it worked out great.

I added 8 button holes across the top. 1 and 2 player buttons will be centered with 3 buttons on each side. These were super hard to cut since I had to go through metal and wood.

20131124-013917.jpg

20131124-014221.jpg

20131124-014246.jpg

20131124-014253.jpg

The last button I added was for a spinner. This hole is placed right above the trackball. Since Tempest was one of my favorite games as a child I had to have the spinner.

Tomorrow I plan to paint the control panel white and try to cut some new plexiglass to cover it. I also need to find the right sized carriage bolts to mount the trackball.

RPi Arcade Build Update: 11/20/13

I have some new equipment added to the arcade cabinet tonight. To get the sound working (louder) I installed a LP-2020A+ Lepai Tripath Class-T hi-Fi Audio Mini Amplifier. This meant I needed a USB sound card as well. I went with a 7.1 Channel USB External Sound Card Adapter. Finally a 7 port USB hub was added. Total price for this was about $40.

After getting the sound card configured and working with the Raspberry Pi it is loud. Really loud. I am using the cabinet speaker from the original Tekken 2 cabinet and it sounds incredible!

20131120-235847.jpg

20131121-000743.jpg

The rest of my efforts tonight surrounded figuring out how I’m going to work the control panel. I think I have a sold plan now so keep your fingers crossed it all works out.

Wonder Woman’s RPi Case

If Wonder Woman needed a case for her Raspberry Pi she would want this case. It would match her invisible plane. This is the same paper case I designed but I cut it from an over head projector plastic sheet.

The entire time I was folding it I kept say it was not going to work. When I finished it was better than I could have imagined. Check out the photos.

20131119-232018.jpg

20131119-232031.jpg

20131119-232042.jpg

20131119-232104.jpg

20131119-232119.jpg

Here is the paper version next to the invisible Wonder Woman version.

20131119-232131.jpg

RPi Arcade Build Update: 11/18/13

Lots of work tonight on the cabinet. Clean, clean, clean. I removed the coin doors and scrubbed them. They are fully in tacked. I removed all the wires from the Tekken 2 games that I won’t be using.

Coin door before Coin door removed Cleaned up now Cool control All back together

I stripped the control panel down but couldn’t get the plastic cover off it since it has security screws in it. Really?

Control panel guts Stripped down Security screw, ugh

Here is a photo of my old control panel and the Tekken panel. I hope to get most the buttons, the spinner, and the trackball on the new one. Space might be an issue so we will see.

20131119-230024.jpg

The bezel on the cabinet can be switched from portrait to landscape. I have been running portrait for a few days but I just switched it back to landscape. The viewing angle was terrible in portrait.

Portrait mode Landscape is better Ms. Pac-Man anyone?

Last, a power supply came with the cabinet so I managed to hook up the light. Happy that it works! Now I’m wondering if I can power the RPi off the power supply?

Lights off the power supply Power supply details

I do have PiMAME up and running as well. Without the control panel working it it just not much fun. I’ll plan out the panel tomorrow. That’s all for now.