Home Automation with the Raspberry Pi is a book that will teach you how to use your Raspberry Pi for home automation projects.

The book follows a logical progression and starts with simple projects using the Raspberry Pi as a single board computer. Then, you will start to build more complex function on your Raspberry Pi using Node.js. After that, you will learn how to make the Raspberry Pi the 'hub' of a more complex home automation system. At the end of the book, you will also learn how to connect your Raspberry Pi hub to web services, to integrate it into an Internet of Things framework.

#!/usr/bin/python
import io
import socket
import struct
import time
import picamera
# Connect a client socket to my_server:8000 (change my_server to the
# hostname of your server)
client_socket = socket.socket()
client_socket.connect(('192.168.1.111', 8000))
# Make a file-like object out of the connection
connection = client_socket.makefile('wb')
try:
with picamera.PiCamera() as camera:
camera.resolution = (640, 480)
# Start a preview and let the camera warm up for 2 seconds
camera.start_preview()
time.sleep(2)
# Note the start time and construct a stream to hold image data
# temporarily (we could write it directly to connection but in this
# case we want to find out the size of each capture first to keep
# our protocol simple)
start = time.time()
stream = io.BytesIO()
for foo in camera.capture_continuous(stream, 'jpeg'):
# Write the length of the capture to the stream and flush to
# ensure it actually gets sent
connection.write(struct.pack('<L', stream.tell()))
connection.flush()
# Rewind the stream and send the image data over the wire
stream.seek(0)
connection.write(stream.read())
# If we've been capturing for more than 30 seconds, quit
if time.time() - start > 30:
break
# Reset the stream for the next capture
stream.seek(0)
stream.truncate()
# Write a length of zero to the stream to signal we're done
connection.write(struct.pack('<L', 0))
finally:
connection.close()
client_socket.close()

Tuesday, May 5, 2015

Here show how to stream video from Raspberry Pi Camera Module to network using raspivid and vlc.

Run on Raspberry Pi 2/Raspbian

View on desktop Ubuntu with VLC Media Player

- for sure, you have to enable camera module in your Raspberry Pi/Raspbian setup.

- install vlc:
$ sudo apt-get install vlc

- Run the command in Terminal, or you can make a sh file (remember to make it runnable):
$ raspivid -o - -t 99999 -w 640 -h 360 -fps 25|cvlc stream:///dev/stdin --sout '#standard{access=http,mux=ts,dst=:8090}' :demux=h264

Where 99999 is the length of the video, 99.999 seconds. You can change that to whatever you like. If you change it to 0 (zero) it will carry on indefinitely. (And CTRL+C to kill it at any time).

In my case, report error of "Invalid PCR value in ES_OUT_SET_(GROUP_)PCR !" Just ignore it, the stream video is playing, and show on RPi main monitor.

Tested on desktop Ubuntu, it can be played with VLC Media Player. On Android devices, Nexus 7 (2012) running Android 5.1, and Samsung Galaxy S3 running Android 4.3, it can be played using MX Player, but not VLC Player (black screen).

Go to http://www.windowsondevices.com to learn more and join the community of developers building an internet of your things.Featured Board: Raspberry Pi 2Frame Design: Paweł Szymczykowski @makenaiWooden Parts: http://ponoko.comElectronics: http://pololu.comSubscribe to our channel for more lessons and demos.We can’t wait to see what you make!Narated and directed by @IoTDanVideo and music produced by @IoTMikeT