Go to content Go to menu

Playing around with Zinc’s streaming entities I looked for a source of streaming data. A never ending streaming source are video streams. So I implemented a very simple Motion JPEG reader using Pharo Smalltalk. It does not use any plugins. Just plain smalltalk and a stock pharo image.

Use your pharos monticello browser to add the following repository and open it.

MCHttpRepository
   location: 'http://www.min.at/prinz/repo/mjpeg'
   user: ''
   password: ''

Update:
Some people have reported hat they cannot load the package into their image. Opening a monticello browser, adding a new http repository with +Repository and pasting the code snippet above and then opening the repository works as expected. Alternatively you can download the package using this link and open it from a local directory repository.

Update 2:
As noted by Sven Van Caekenberghe the mime type for .mcz monticello archives is now set to application/x-monticello in the webserver response. So now there should not be any format errors. Thanks for this hint.

Update 3:
Cédrick Béler modified the source to work under Pharo 7. Thanks for that. The new version can be found in the repo.

It consists of just one class Mjpeg.

| cam |
" Create a new MJPEG stream from a given url "
cam := Mjpeg 
   fromUrl: 'http://218.219.210.174:86/mjpg/video.mjpg?camera=1'.
" Start reading the stream and displaying it in a window "
cam start. 
" Start capturing the stream frame by frame to disk "
cam startCapture: 'c:/temp/test'.
" Returns true if the stream is started (reading or "
" capturing), false otherwise "
cam isRunning.
" Stop reading the stream and close the camera window "
cam stop.
" Stop capturing "
cam stopCapture.

There are two example class methods availabe.

" Sample of a webcam stream from Tokyo "
Mjpeg exampleTokyo.
" Webcam from Vienna "
Mjpeg exampleVienna.

Performance of this simple implementation is quite good. The Tokyo example used the stream available at http://218.219.210.174:86/mjpg/video.mjpg?camera=1. Playing this stream with Pharo has no impact on CPU usage whereas playing the same stream with Chrome has a noticeable effect on CPU usage.



This post describes the Cosm smalltalk package which allows it to send sensor measurements to a cosm.com stream using either Pharo or Squeak Smalltalk.

It’s also possible to use this package with squeak on your Raspberry PI so you can create a data logger with Smalltalk instead of Python or shell scripts as described here.

Use your smalltalks monticello browser to add the following repository and open the repository.

MCHttpRepository
	location: 'http://www.min.at/prinz/repo/cosm'
	user: ''
	password: ''

Inside you will find two packages. One for Squeak (4.x) and one for Pharo (1.4; 2.x).

First you should already have a cosm.com registration. If not register it’s easy and free. Cosm.com allows you to create so called feeds. A feed represents a collection of one or more streams. Streams are used to store values which can be charted on your cosm.com dashboard. So for example you can register a feed MyFeed and inside this feed a stream called Temperature. Now using the Cosm Smalltalk package you are able to send temperature measurements to your Temperature stream.

| client stream result ]
" Create a client instance with your cosm.com API key "
" and feed id "
client := CosmClient 
     newApiKey: 'this should be your API key' 
     feedID: 12345.
" Specify to which stream you want to send data and "
" in which format. Available formats are #JSON, #CSV "
" and #XML "
stream := client 
     openStream: 'my stream name' 
     withFormat: #JSON.
" Send a value (42) to the stream once "
result := stream put: 42.
" Take a block, execute it every x seconds (10) and send "
" the result of it to a cosm.com stream. This represents "
" an automatic stream "
stream put: [ 255 atRandom ] every: 10 
	align: false.
 
" Check if a stream is running automatically "
stream isRunning.
" Stop an automatic running stream "
stream stop.

When using automatic stream mode the time window can be controlled by every: which controls how often data is sent in seconds and align: which specifies if the time window should be time aligned. If set to false the time window starts after the block is evaluated. If set to true the time window is aligned based on how long the block took to evaluate. For example:

Aligned StartAt TimeWindow Block evaluation Next run
true 21:10:10 10 sec. 5 sec. 21:10:25
false 21:10:10 10 sec. 5 sec. 21:10:20
true 21:10:10 10 sec. 13 sec. 21:10:30
false 21:10:10 10 sec. 13 sec. 21:10:33

 
Running the following code

stream put: [ 255 atRandom ] every: 10 
	align: false.

produces random results between 0 and 255 sent to a stream resulting in a simmilar graphs like this:


cosm-stream.png

So now you can send your measurements into the cloud.

After building the Raspberry PI extension board it’s time to do some useful things with it.

The board contains an I2C temperature sensor and you can also connect external sensors so how can you use it to monitor temperatures over a long time range and store and visualize the measurements?

This post describes a very simple way to do this as well as how to store the measurement data local as well as in the cloud.
[Read more…]

Making a mobile phone or tablet holder out of Lego bricks is not only very easy but also
fun to do.

[Read more…]

So you have just bought your new very fancy quadcopter? Fine! But I’m pretty sure (unless you are
very talented) after some flights somehow the idea will arise to have the oportunity to train your
flying skills without some (maybee more) hard landings or (worse) crashes.

Here I describe a way to connect nearly every R/C transmitter to your PC using an Arduino UNO
board. Why? Because I bought a quadcopter and hat some hard landings and crashes so I started
training on the PC using a flight simulator controlled by my R/C transmitter.
[Read more…]