Introduction to shiftr.io

shiftr is an MQTT broker that offers public, free and paid services. It has a great interface for visualizing device connections and message pathways. It is popular in the maker community ensuring you will find many examples online.

Instances and Tokens

In shiftr parlance one uses an MQTT broker instance. Access to an instance is regulated through a token.

Tokens include user and password (key) information as well as a URL. You should always take steps to keep the password (key) out of public repositories.

In general tokens take the form:

protocol :// user : password @ URL

where the URL is a combination of instance name and the shiftr cloud server.

[instance].cloud.shiftr.io

You will need all of these pieces of information to successfully connect to a shiftr instance.

PUBLIC Instance (broker)

When just starting with shiftr (and MQTT), a typical point of departure is the shiftr public instance. Many online examples use this broker as they don’t need to worry about user names and passwords. You can find it at:

https://www.shiftr.io/try

The token for this service is:

 mqtt://public:public@public.cloud.shiftr.io

Where :

user == public

password == public

instance == public.

I found code samples using this instance and token confusing as public was showing up everywhere and I wasn’t sure in which context.

Following the pattern of usr:pw@url and reading variable names carefully can help clarify how each occurrence of the variable public is being used.

Custom Instance (broker)

shiftr makes it easy to set up a custom broker. You should all take the time to set one up and try it out. In the following demo and video I show the steps needed to create instances and tokens. These instances were terminated after this tutorial was completed — you can’t use these, but they will guide you in setting up your own.

Video :: shiftr instance creation

Step-by-step :: Create an Instance

You will need to sign into shiftr. Create an account if you don’t have one (free, requires email) and click on Deploy in the upper right or in the Setup/Dashboard welcome box.

If this is your first instance you will be asked to create a Group before proceeding. With your group setup, choose Deploy.

Now there are several simple steps:

Choose a plan — in this case I am choosing Basic. A basic plan can only run for 6 hours a day. More than enough for testing and prototyping, but not ideal for a project needing continuous connections. Plus plans or your own broker will make more sense for longer installations / projects and cost 7$ per month (at time of writing).

Scroll down to Settings and name your instance. I chose tester123 — try to keep it meaningful. Your instance name will be automatically converted to lowercase and copied as the prefix to the URL. You can pick a unique URL (assuming its available) — but i have not had a need to play with this.

Billing should match your test group. You will not be billed for basic instances.

Click Deploy at bottom.

You will now be automatically take to your Instances list. it will include the instance you just created.

IN each instance listed, if you click the white bold link (white arrow above) you will be taken to the instance Overview. This view has basic info about the instance. In the upper right there is a Configuration tab that allows some modification to settings you selected at setup.

If you click the instance green bold link (green arrow above) you will be taken to your broker view which should be familiar from class.

Configure a token

From the green broker view, open Settings in the bottom right — it’s the little GEAR ICON in the bottom right (red box) in the image above.

A token popup will now dominate the screen. In General tab select public or private. You will need shiftr passwords to see/share the instance if you keep this private.

Now, in Tokens tab –click CreateToken (upper right). Enter a Description – keep it simple (eg. Project Token). I usually keep the default Secret — but you can change it if you like. Under Permissions, choose Full Access if you want others to be able to publish and subscribe. Select Read Only if you want to create an interface in which others can only pull (subscribe) data.

Finally, click Create Token — and your now token will display.

For this demo, I created a Read Only token:

mqtt://tester123:DrB0qlfo4EHJGT7W@tester123.cloud.shiftr.io

Where:

user name AND instance name == tester123

key or password == DrB0qlfo4EHJGT7W

URL for viewing the instance == tester123.cloud.shiftr.io

Remember, because this is a Basic token it can only run 6 hours a day. If you return to your instance view you will see that the instance is either hibernating or running and that it uses a Basic plan.

Bottom line of each instance view indicates instance status and type.

NOTE:: As mentioned above, the token used here is for demo only. It was revoked and disabled before this post went live. You will need to follow this method to create your own tokens and use them in your own projects. The video offers another walk through of the process.

Class token

The token we are using is class is attached to a shiftr Plus instance. This means that is usable by students 24/7 — not just for 6 hours a day. The token and key can be found in D2L. Please do not make that info public. The token will change from time to time.

The class instance was setup following the above instructions, with Plus being selected for the plan at time of instance creation.