HackSpace_-_October_2019

(Rick Simeone) #1
FORGE

shunts the data to the right place, and the output.
We’ll use the IFTTT app on a phone as the output –
this lets us send notifications to our phone from a
web-connected CircuitPython device.


GETTING INPUT
Let’s start at the beginning of our data flow – the
CircuitPython device that will send the data to IFTTT.
We’ll detect this based on a touch – press the
touchscreen, and it will send data to IFTTT. This could
easily be used to create a notifier where people can tap
a button on a touchpad to get your attention. It could
also be used with other sensors to alert you to a
particular condition, such as using a soil moisture
sensor to let you know when your plants are running
dry. The important bit in all of this is the link to your
phone via IFTTT, so let’s focus on that.
The main loop that does the work is as follows:
while True:
p=ts.touch_point
if p:
print(“touched”)
ifttt.send_message(wifi, secrets,
“circuitpylink”, debug=True, value1=”touchy touchy


Right
It’s well worth
searching through
the different services
to IFTTT, as there are
many that you might
not suspect, and
there are some great
examples to whet
your appetite

Above
You can link lots of
different events to
the phone app, so it
makes a great
source for all
your notifications

SENDING EVENTS


We’ve used the IFTTT library in this tutorial to make
it easy to send events via webhooks, but it’s actually
fairly easy to send webhooks directly. To understand
what we’re doing, you need to understand that there
are different types of requests that you can send
to a web server. Probably the two most popular
are GET and POST. The former is what you send
when requesting a normal webpage; the latter is
usually what happens when submitting a form on a
webpage. We can use either in our webhooks, but
in order to send data, we have to use a POST.

updated”)
time.sleep(10)
This requires a few bits set up in order to work. The
ts object is the touch sensor for the screen – it’s set
up with the following line:
ts = adafruit_touchscreen.Touchscreen(board.TOUCH_
XL, board.TOUCH_XR,
board.TOUCH_YD, board.TOUCH_YU,
Free download pdf