Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 21 Next »

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.  

https://shiftr.io/get-started

Additionally, download and install the desktop app.

https://desktop.shiftr.io/

Step 2 – Set up Processing

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.

To verify that everything worked as expected, go to Files > Examples and open the MQTT > PublishSubscribe example. This example sketch will connect to the try namespace and send a hello world message on every keypress.

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:
In this example, we're using an iPhone hotspot, so you can be more flexible and don't have to stay within the reach of the router. Use the name and password of your wifi (for the routers it's BRIDGE / internet). Don't forget to press Configure.

MQTT:

Normally:

When you're connected to the internet, use the domain name of Shiftr.io in the Host field: broker.shiftr.io. The is MQTT Port is 1883 and the Client ID is 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.


When using Lokal Broker:

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. In the 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. Usually it's the same as your Client ID.

Parameters:
Here you can choose which sensors should be activated. Remember that having multiple sensors active can make your battery unload faster.

Step XX – Store data (draft)

Once you've managed to have the sensor sending data, you can use the following Processing script to store the received data in an .csv file.

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).

Please note: The script overwrites the current .csv file, if you don't change the file name (to f.e. "new-2.csv") 

import mqtt.*;

MQTTClient client;

Table table;

void setup() {
  client = new MQTTClient(this);
  client.connect("mqtt://67edd5ec:ca0473914fbded6b@broker.shiftr.io", "processing");
  client.subscribe("p7/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");
}