Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

This is a step by step manual for getting started with shiftr.io (desktop application), shiftr.io pocket and Processing. The goal is to collect data via shiftr.io Pocket and to store this in an .csv file.

Step 1 – Set up shiftr.io

Create an acount on shiftr.io, and follow the instructions on the getting started page to create a new namespace and a new token.  

...

Also you need to make sure that you're running the latest version of Processing. If you have an old version or haven’t Processing installed at all, get it from their website.

Afterwards, download the processing-mqtt library from the GitHub repository. When the download has finished, move the library to your sketch folders libraries directory. More information about installing a library can be found here.

...

Run the example and check the console for the following line: [MQTT] connected to: broker.shiftr.io. If you see the connected client and the messages flowing in the real-time graph, you are ready to go!

Step 3 – Shiftr.io Desktop

Please choose your device by clicking on the Shiftr.io icon in your menu bar. In this example it's pocket (p11). Make sure your Bluetooth is switched on.

...

Wifi:
Of course, you need to be connected to a network to use Shiftr.io. We can f.e. use an iPhone hotspot, so you can be more flexible and don't have to stay within the reach of the local router. Or we simply connect to the Bridge routers (SSID: BRIDGE / Password: internet). Don't forget to press Configure.

...

As soon as you're connected to the network of your choice, use the domain name of Shiftr.io in the Host field: broker.shiftr.io. The MQTT Port is 1883 and the Client ID is the name of your connected device. Because we're using the try namespace, the Username and Password is both «try». Of course, you can use your own namespace here.

...

The Host field needs your IP-adress. Check with «alt» + click on the wifi icon in your Menu Bar. You need to have a router although it has no internet connection. (Later in the Processing script, don't forget to change the address from borker.shiftr.io to your IP address.)

Device:
Make sure you've got the right Device Name and Base Topic. Here, it's the same as your Client ID.

...

Please note: Change the URI (here: "mqtt://67edd5ec:ca0473914fbded6b@broker.shiftr.io") to the one you are connected to. And don't forget to subscribe to the right device (here: p7) with the activated sensor (here: dst).

...

Code Block
languagejava
import mqtt.*;

MQTTClient client;

Table table;

void setup() {
  client = new MQTTClient(this);
  client.connect("mqtt://67edd5ectry:ca0473914fbded6b@brokertry@broker.shiftr.io", "processing");
  client.subscribe("p7p11/dst");

  table = new Table();
  table.addColumn("time");
  table.addColumn("dst");
}

void draw() {
}

void keyPressed() {
  client.publish("/hello", "world");
}

void messageReceived(String topic, byte[] payload) {
  println("new message: " + topic + " - " + new String(payload));

  String str = new String(payload);
  int dst = Integer.parseInt(str);

  TableRow newRow = table.addRow();
  newRow.setInt("time", millis());
  newRow.setInt("dst", dst);
  
  saveTable(table, "data/new.csv");
}

...