HackSpace_-_October_2019

(Rick Simeone) #1
FORGE

Notification From the IFTTT App’. Here you can enter
the text that you want to appear in your notification.
As well as plain text, you can add ‘ingredients’ which
are tags that will be replaced by data that’s sent. IFTTT
lets you send three values names: Value1, Value2, and
Value3 – we’ll only use the first.
The message for our notification is then:
Message from CircuitPython: “{{Value1}}”

That’s the glue for our system completed. The only
thing left is the final part – we need to set up our
phone to receive and display the notification.
Fortunately, this is easy. Just install IFTTT from your
phone’s app store and log into it.

KEYS TO SUCCESS
We’re almost all the way there now. The only thing left
is the IFTTT key that we need in order to authenticate
our requests. This lives in the secrets.py file. We’ve
left it until now because we need to get it from the
IFTTT app. We don’t know why you have to get it from
the app rather than the webpage – it’s possible that
this is a bug and will change by the time you read this
as the online help suggests that you should be able to
get it from the webpage.
Go into the app and select Webhooks, then click on
the cog in the top left. You should see your account
info here which includes a user_url which will be in the
format: maker.ifttt.com/use/<thisisyourkey>.

Copy the text that’s in the place of <thisisyourkey> into
the appropriate place in your secrets.py file. Every time
you make changes to your webhooks setup, your key
changes, so if you stop getting messages through, it’s
worth checking that your key hasn’t changed.
Once that’s in place, everything is set up. Touch the
screen of your PyPortal (or do whatever you’ve set up
to trigger the message), and after a few seconds, you
should see a notification appear on your phone. If it
doesn’t, check that both devices have internet access,
and the IFTTT key is correct.
While we’ve covered a very trivial use in this article,
this method of sending data to IFTTT from
CircuitPython devices gives you a powerful way of
linking builds together across the internet and
monitoring them in real time.

OTHER IFTTT INPUTS


There are other ways of getting data into an IFTTT applet.
You can scroll through the huge list when you press the
‘Plus’ button, but here are a few of our favourites:

Adafruit – this links your IFTTT applet to an Adafruit.io
feed. This way, you can feed data into your trigger while
still retaining a copy to use elsewhere.
Button Widget – this works the opposite way to our
applet, in that data goes from the IFTTT app to where
ever you want it to.
GitHub – start applets when events happen to your
source code.
Twitter – tweet your applets into life.

You can also send data to a wide variety of sources
including:

Android SMS – this uses your phone to text details to
whoever you like. It uses your SMS plan, so this may
cost you money, and it’ll only work if your phone has
an internet connection.
Email – send a message to anywhere in the world.
littleBits – control your littleBits hardware.
Google Sheets – save your data in an online
spreadsheet.

WEB OF THINGS
We’re almost there with the CircuitPython board, so
let’s turn our attention to the setup on IFTTT. First, go
to ifttt.com and create a free account.
Scripts in IFTTT are known as applets. You can
create many of them in your account and have them
running concurrently. To create a new applet, click on
your profile in the top-right, then select Create. In the
new screen, you should see, in big letters, If This Then
That. Clicking on ‘This’ will let you select the action that
you want to trigger your applet. Select ‘Webhooks’ and
then ‘Receive a web request’. Web requests are
‘events’ in IFTTT lingo. You can have as many different
event types as you like associated with your account,
each triggering a different applet. However, so that
IFTTT can tell which is which, each needs a name.
We called ours ‘circuitpylink’ (you might recognise this
from the code above), however, you can use any text
string you like (we had difficulties with strings with
spaces in, so we’d recommend avoiding these).
You should then be taken back to the If This Then
That screen, and you can click on ‘That’ to select the
action to perform. Select Notifications, then ‘Send a


AND OUTPUTS


After a few seconds, you
should see a notification
appear on your phone


Free download pdf