After working with the Arduino IDE for some time, I decided it is time to write some convenient libraries that will help me quickly do some of the tasks that occur often and could do with a convenient wrapper.
Let’s look at the functions:
String ifttt (String event, String value1, String value2, String value3)
If This Than That, IFTTT, is a very extensive online tool that allows you to act on an event. The concept is based on channels that can send and receive data. A specific combination of channels and actions is called an applet.
There is also a channel called Maker which you can use for your own IoT devices. This is what this library is for. You get your own Maker key which you should put in the library PAM_Defines.h which is nothing more than a way for you to select which APIs are compiled in. If you don’t use IFTTT for example, you should also not have to overhead when compiling so if you do not define a key, the functions will be excluded from the library which should save memroy. I will not go into detail on IFTTT usage just now. Suffice it to say you need a key which you define in PAM_Defines.h:
#ifndef PAM_Defines_H #define PAM_Defines_H // // This is where you define your own IFTTT.com key // #define IFTTTKEY "YOUR-KEY-HERE" #endif
and you need an event type which defines what kind of trigger you want to send. I have also defined these in my PAM_Defines.h:
#define IFTTT_BOOT "PAM_BOOT" #define IFTTT_HTTP "PAM_HTTP" #define IFTTT_MSG "PAM_MSG"
There are multiple instances of the same function created in the library so you can call it with no values, one, two or all three.
As an example, I use the event IFTTT_BOOT to send me a message if an IoT device boots where I send it’s IP as value 1. If it also contains a webserver I use the event IFTTT_HTTP along with it’s IP as value 1 so the message can actually contain a link to the IP.
I use IFTTT_MSG to send a message, for example if my plant needs watering.
void thingspeak (String api, String field1, String field2, String field3, String field4)
void thingspeak (String api, float field1, float field2, float field3, float field4)
The next API included is that for ThingSpeak. ThingSpeak call themselves an open data platform for the Internet of Things. In order to work with ThingSpeak, you need to set up an account and than set up a channel. Unlike IFTTT, you need a different API key per channel so in the library I choose to have one define to say you want to use the library. I use seperate defines for each of my channels:
#define THINGSPEAK #define TS_TEST "MY-API-KEY"
The #define THINGSPEAK is needed to compile this part of the library. Like IFTTT there are multiple instances of the library. You can call the function with just one parameter or up to four parameters (ThingSpeak actually allows eight but I have not set up for that yet. If it is needed, let me know). The API key is mandator as well as the first field. The API of ThingSpeak allows you to set a date time for the event and if you don’t current date time is used. Since I wanted to keep the library small, I did not implement the seperate date time parameter.
You can use String for the values or int/float.