Skip to content

developing a version of spacebrew and Hiroki Ohtani's websocket lib that can run on the Arduino Yun.

Notifications You must be signed in to change notification settings

julioterra/yunSpacebrew

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

57 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Spacebrew for the Arduino Yun

The Spacebrew Yun library features two main components - a set of python scripts that run on the linino, and a library that runs on the atmel chip. Below is an overview of how to install both of these components so that you can connect to Spacebrew from an Arduino sketch.

@date: July 16, 2013

Installing Linino Python and Shell Scripts:

There are two python scripts that you need to copy into the python library folder on the arduino. These file are spacebrew.py and getprocpid.py, and they both reside in the spacebrew folder on the linino directory of this project. Here is how to copy them over:

  1. Navigate to the linino folder in the yunSpacebrew directories
  2. Run following commands:
scp -r ./spacebrew [email protected]:/usr/lib/python2.7

There is one shell script that you need to copy into the user bin folder on the arduino. This files is called run-spacebrew. It resides in the shell folder on the linino directory of this project. Here is how to copy them over and then configure them to be executable files:

  1. Navigate to the linino/shell folder in the yunSpacebrew directories
  2. Copy files over to linino with scp commands:
scp ./run-spacebrew [email protected]:/usr/bin
  1. SSH into the linino using the following command, input the password when prompted:
  1. Make the files executable by running chmod commands:
chmod 0755 /usr/bin/run-spacebrew

Important: replace juliyun.local with the name or IP of your yun

Installing Arduino Library:

To install the Arduino Library just copy the folder titled spacebrewYun into the libraries folder in your Arduino sketch book. Then run the example sketch to try it out.

Trying it Out with the Sample Sketch:

Here is how you can test out the library with the sample sketch:

Understanding the Example Sketch:

Here is how the example sketch works. At the top of the sketch we create an instance of the SpacebrewYun class using the constructor. The constructor accepts two values: a name and a description.

SpacebrewYun sb = SpacebrewYun("aYun", "Arduino Yun spacebrew test");

In the setup function we configure our Spacebrew client as follows.

First, we call the verbose() method with the argument true to tell the sb object to print status messages to serial. If we didn't call this method, or if we called it and passed it a false argument instead, then the sb object would not print status messages.

sb.verbose(true);

Next, we register the subscribers and publishers for our app using the addSubscribe and addPublish methods. These are the incoming and outgoing data channels that will enable us to send and receive data from Spacebrew. Each publisher and subscriber needs to have a unique name, and a data type.

sb.addPublish("string test", "string");
sb.addPublish("range test", "range");
sb.addPublish("boolean test", "boolean");
sb.addPublish("custom test", "crazy");  
sb.addSubscribe("string test", "string");
sb.addSubscribe("range test", "range");
sb.addSubscribe("boolean test", "boolean");
sb.addSubscribe("custom test", "crazy");

Then, we register the callback method that will handle different types of data. Spacebrew supports three different standard data types - range, string, and boolean. If you created a subscriber with any other data type, those messages will be routed to the callback function registered with onCustomMessage method.

sb.onRangeMessage(handleRange);
sb.onStringMessage(handleString);
sb.onBooleanMessage(handleBoolean);
sb.onCustomMessage(handleCustom);

The handler functions that are registered in the setup are defined at the end of the example sketch. When creating your own sketch make sure that your functions support the appropriate types and numbers of arguments.
Once the sb object has been configured we are ready to connect to the Spacebrew server. To do so we call the sb.connect() method and pass it the server ip address or hostname, and optionally, the port number.

sb.connect("sandbox.spacebrew.cc"); 

Once connected to Spacebrew, we send messages to all publishers using the sb.send() method. This method accepts two arguments, the first argument is the name and the second argument is the value.

sb.send("string test", test_str_msg);
sb.send("range test", 500);
sb.send("boolean test", true);
sb.send("custom test", "youre loco");

It automatically publishes information on the outgoing routes every 2 seconds. Data received via the subscriber routes is printed to the serial monitor. is set-up to connect your yun directly to the cloud instance of Spacebrew. Here is how to test out the library with the example.

Websocket for the Arduino Yun

The Websockets for Arduino script is also included in this repo. That said, this script is already included in the Arduino Yun distribution.

About

developing a version of spacebrew and Hiroki Ohtani's websocket lib that can run on the Arduino Yun.

Resources

Stars

Watchers

Forks

Packages

No packages published