Skip to main content

Building a Twitterbot with Nordic and IFTTT

IoT devices are becoming a ubiquitous part of living in the age of technology. The applications of low-power, long-range wireless protocols are many and have fuelled a demand for connected infrastructure like 5G. The prominence of exciting frameworks like Nods.JS, Azure and AWS have also helped bridge the gap between the edge and the cloud thanks to their flexible functionality and developer accessibility.

More specific services like IFTTT (If This Then That) have also allowed users to link a huge array of different web services together using simple conditional statements. These links can be referred to as webhooks and are extremely useful for connecting low-level IoT hardware events with high-level web functions. This article aims to explore the growing interoperability of the IoT infrastructure using the IFTTT webhook service.

Screenshot_%2811%291_76fea1cb300fe61cde79cc11cc439ca7f67a14f4.png

The Nordic Thingy:52 is a palm sized IoT powerhouse.

For this project we will be using the Thingy:52 IoT development kit from Nordic Semiconductor to establish a connection to the IFTTT service. To do this, we can use the dedicated Nordic Thingy app to interface with the device over Bluetooth and connect it to the internet via our phone. Once we have turned the device on and connected to Bluetooth, we will start to see the available data events being logged through the app.

1_-_Copy_25d45d22af67b55321ea2e021f03922c9f00c3c9.jpg

The Nordic Thingy app makes it very easy to access hardware functions and the cloud.

The Thingy:52 has an impressive amount of environmental, motion and audio sensing capabilities that can be accessed through the app side bar. However, our interest for this project is the cloud tab that displays the web functions available to the device. By default, the app assigns three sensor outputs as webhook event triggers and underneath each sensor name is an event name which is used as an identifier by the IFTTT service.

Screenshot_20210203-201340_Nordic_Thingy_706c98bb30c08eef147c346c537cdd10f70f97bc.jpg

The cloud tab controls the link between Bluetooth and the internet.

Before we activate the event triggers though we need to log in to our account on the IFTTT website, or through the app and select the services we would like to use. Registration is free and allows up to three services to be allocated, which is more than enough for a few test projects. For this project we will be using the Webhooks and Twitter services to record any Thingy:52 hardware events as a feed on social media.

Screenshot_%2854%29_1df10861d9d8d499ac8d903e4ca054a5445b0c5a.png

First step in creating an IFTTT applet.

By selecting create at the top of the homepage, we can begin designing our first IFTTT applet. This process is very simple where the designer uses conditional blocks to create relationships between different web services. We can add our first service at the top of the hierarchy by clicking “add”.

Screenshot_%2855%29_f729f2acece6fff2c7eac2c0fa2f4142bbd776e1.png

Use the search box to find the desired web service.

Our applet will be using webhook events triggered by the Thingy:52 hardware so we need to select webhooks from the list of services and configure it for the incoming data sent by the Nordic Thingy app.

Screenshot_%2859%29_bdc4bb1188d8f6f0561d2d1fef798d34061fb3c1.png

The event name is displayed in the cloud tab of the Nordic Thingy app.

Next the webhook service needs to know the name of the incoming event triggered by our hardware to correctly identify the incoming message and parse any attached data to the next service. As previously stated, the event name is clearly displayed in the Nordic Thingy app in the cloud tab.

Screenshot_%2861%29_222b3daf61ff519f9efa1908a2366e97d13bb7f9.png

IFTTT makes linking web services very simple.

Once our webhook event handler has been created we can now look to configure a dependent web service that responds to our low-level hardware events. Just like before we can click “add” to select the service we want to be controlled by our webhook event.

Screenshot_%2864%29_070a61c9b285941f7c575f11c925da2e9dfeec33.png

Enter a test message to view on your Twitter feed.

Similar to the webhook service, we can select Twitter from the list of available services and link it to an account. For this example, I will be testing the webhook using my personal handle and posting a simple message to my feed.

Screenshot_%2865%29_cbc7cbe094c2c79c561e0f71970859f799cf06fd.png

The finished IFTTT applet.

Once both parts of the applet have been configured, we are ready to test this new web relationship by setting up events in the Nordic Thingy app.

double_phone_cdbf156e71610cd9e0d0b5b1faff9d7b66f674fa.jpg

Activate the webhook in the app to start sending messages to the IFTTT service.

For this example, we will use the “Button state” event in the Nordic Thingy app to send a message to the IFTTT service when the Thingy:52 hardware button is pressed. Activate the radio button at the right of the screen and tap the triple dots above it to add the IFTTT token.

In order to establish a link to the IFTTT service, a cloud token is required to tell the app where to send the data. This comes in a URL format that can be found in our IFTTT account. Go to my services > webhooks > settings in the web browser to find a reference to the URL and copy the cloud token at the end of the URL string into the Nordic Thingy app when prompted. Our Thingy:52 should then be ready to send automated tweets.

tweetss_c88be660ddfb9090331bfb8c9b2379112263ece9.png

It begins...

Ensuring our phone is connected to both Bluetooth and Wi-Fi, sending a tweet can now literally be done at the push of a button!

Obviously, this is a very basic application of the IFTTT service but is an excellent way to establish very simple cloud functions. This simplicity does also highlight a growing problem with social media, where webhooks and bots can be used to create fake accounts and data aggregators often with nefarious intentions. However, the scope for altruistic applications on this platform are also huge and would be just as easy to establish applications for personal safety, home automation and environmental monitoring.

Thanks for reading, follow my more human tweets here: @ElectricJoshy

A keen maker and electronic engineer with a passion for the environment, renewables, alternative transport and anything off-grid. Man with a van and founder of the Kickstart Kamper sustainable campervan project. Grassroots Education Sustainability Ambassador. BrightSpark 2017. BEng. KickstartKamper.co.uk