Going forward in this tutorial we'll be assuming two or three things.
- You are connecting to Adafruit IO's MQTT server (a.k.a broker) - you could use another broker and as long as it fits the MQTT 3 or 3.1.1 specs, it ought to work.
- You are connecting via the Internet - WiFi, Ethernet, and cellular are king here. Other transports would need a gateway
- You are using an Arduino or compatible - Our code is fairly portable, but it order to keep the examples concrete, we'll be focusing on the Arduino library
- You have already signed up for Adafruit IO and logged in
Honestly, if this is your first time using MQTT, the above is a pretty safe way to get started!
Step #0 - adafruit.io key and feeds
Before you can go crazy with Internetting your Things, you will need to do a little light config work to get adafruit.io ready for you.
To do this we'll introduce three new terms
- Account username - This is the name of your account, which you set when creating your adafruit account.
- Key - this is a long, unique identifier that you use to authenticate any devices using your account. This is your password! Keep it safe! You get one key per account, but you can, at any time revoke and regenerate your key.
- Feed - this is basically a set of data that you can read or write from like a sequential file. There is some history stored with feeds, with MQTT you cannot access historical data (REST does support it) but you can add data and you can receive the latest added data.
You can find your username by visiting https://accounts.adafruit.com/ and logging in. Your username is right there!
Where to find your adafruit.io key
Visit https://io.adafruit.com and look in the top left. You will see a little navbar with a yellow key
Click it to see your key. If you regenerate your key, your old key will no longer be valid and you'll need to update all your projects!
(The key above is just me bashing on the keyboard, don't use that number. Use only the key that is created for your account!)
Create your first two feeds
You can read up on how to do this here
https://learn.adafruit.com/adafruit-io-basics-feeds
Once you've read that. Go to your feeds page and create two feeds
- photocell - this feed will store light data from your device to adafruit.io
- onoff - this feed will act as an on/off switch, sending data to your device from adafruit.io
Create a dashboard
Like feeds, this has its very own, excellent tutorial. Read all about it here
https://learn.adafruit.com/create-an-internet-of-things-dashboard-with-adafruit-dot-io
Once you've read it, create a dashboard with a gauge connected to photocell
Use a thin type gauge with min value 0 and max value 1024 (this could store a 10 bit value)
the block is now added to the dashboard
Next up, make another block, this time an on-off toggle switch. Tie it to the onoff feed
Use the defaults for the 'on' and 'off' texts
OK now you have two blocks! You are ready to rock.
Continue on to the next step!
Page last edited October 22, 2015
Text editor powered by tinymce.