After having published my tutorial about sending SMS with the ESP32, I received some comments via the contact form of my website asking a way to send notifications for free. Today I’ll show you a way to do it; it will be also the occasion to write about IFTTT service and about developing custom components for the esp-idf framework.
IFTTT
IFTTT (IF This Then That) it’s a web service that allows to create applets connecting different services with the pattern if this happens, then do that action.
To better understand what you can do with IFTTT, here are some pre-built applets:
- send me an email if rain is expected tomorrow
- automatically post on Facebook the photos I share on Instagram
- turn on silence mode on my smartphone when I arrive at work
The main advantage of using IFTTT is indeed the availability of many services ready to use: starting from the ones which query weather forecast providers, to services which connect to famous social networks and even including services that can talk to smart devices like FitBit bracelets or Nest thermostats.
Besides the website, IFTTT is also available on Android and iOS smartphones; for this tutorial I’m going to use indeed a feature of this app, the notifications.
Maker Webhooks
Among the many services IFTTT offers, one is very handy to integrate IFTTT with IoT devices: the Maker Webhooks service. As the name suggests, this service allows applets to interface with the Web. If you add it as a This service (trigger, source of the event that activates the applet) Maker Webhooks allows to send an event to the applet using a web request (GET or POST), while if you add it as a That service (action that the applet performs), Maker Webhooks allows the applet to make a web call:
The Maker Webhooks service is the first element of our applet: thanks to it we’ll be able to activate the applet with a web request performed by the ESP32 chip and we’ll be also able to pass optional values to the applet itself.
Notifications
The second service we’ll be using is called Notifications: using this service the applet can send notifications to our smartphone. The only requirement is that our smartphone is running the IFTTT app and that we log in with the same account used to create the applet.
Applet
Let’s see how to build the applet. After having registered to the website, click on New Applet.
First click on this:
Type some letters of “Maker Webhooks” to search the service, then click on its icon:
Select the only trigger the service offers:
Type the name of the event that will activate the applet. You can choose the name we prefer; the same name will be used when making the web request:
Now click on that:
Search and select the Notifications service:
Click on the only action the service offers:
Customize the message that will be displayed as notification. You can also include some custom values that will be received by the applet via the web call, together with the event name:
Complete the wizard with a click on Finish:
Personal key
To be able to send a request to the Maker Webhooks service, you must specify your personal key. Connect to the service’s homepage and click on Settings:
Copy the key, that is the string after /use/ in the service URL:
esp32_ifttt_maker component
To simplify the interaction with the Maker Webhooks service, I developed a component that is ready to use with the esp-idf framework. You can compare components to libraries, reusable code elements for your programs. You only need to copy the component’s folder within the components folder of your project to be able to use it:
My esp32_ifttt_maker component is available in a dedicated Github repository and I explained how to use it in details in a dedicated webpage of my website.
Demo
I prepared a demo program that sends notifications using IFTTT applets; its source code is on Github.
Here’s a video that shows how it works (italian subtitles are available):
Ciao Luca, ho provato questo esempio, all’inizio funziona correttamente ma dopo il quinto evento inviato mi da errore 4 per 10 invii e poi sempre errore 2.
questo è l’output:
Button pressed, sending events…
Sending HELLO event without values… success 🙂
Sending ALARM event with a value… success 🙂
Button pressed, sending events…
Sending HELLO event without values… success 🙂
Button pressed, sending events….. success 🙂
Sending HELLO event without values… success 🙂
Sending ALARM event with a value… error (4) 🙁
Button pressed, sending events…
Sending HELLO event without values… error (4) 🙁
Sending ALARM event with a value… error (4) 🙁
Button pressed, sending events…
Sending HELLO event without values… error (4) 🙁
Sending ALARM event with a value… error (4) 🙁
Button pressed, sending events…
Sending HELLO event without values… error (4) 🙁
Sending ALARM event with a value… error (4) 🙁
Button pressed, sending events…
Sending HELLO event without values… error (4) 🙁
Sending ALARM event with a value… error (4) 🙁
Button pressed, sending events…
Sending HELLO event without values… error (4) 🙁
Sending ALARM event with a value… error (2) 🙁
Ho abilitato il debug, l’errore 4 è MBEDTLS_ERR_SSL_BAD_INPUT_DATA -0x7100 , ma la request mi sembra corretta, mentre l’errore 2 è MBEDTLS_SSL_ALERT_MSG_BAD_CERT .
Sai dove potrebbe essere il problema? Grazie Andrea