Friday, July 14, 2017

2 - Raspberry Pi and ThingSpeak (I): sending notifications with ThingTweet


- Layout for this exercise:

1 - ThingSpeak

- ThingSpeak is an open source Internet of Things (IoT) platform and API to store and retrieve data from things using the HTTP protocol over the Internet or via a Local Area Network.

- An introduction to ThingSpeak:

- ThingSpeak enables the creation of sensor logging applications, location tracking applications, and a social network of things with status updates.

- ThingSpeak has integrated support from the numerical computing software Matlab from MathWorks, allowing ThingSpeak users to analyze and visualize uploaded data using Matlab without requiring the purchase of a Matlab license from Mathworks.

- ThingSpeak has a close relationship with Mathworks, Inc. In fact, all of the ThingSpeak documentation is incorporated into the Mathworks' Matlab documentation site and even enabling registered Mathworks user accounts as valid login credentials on the ThingSpeak website.

- Before signing up for ThinSpeak a MarthWorks account must be created:

- After providing some required information the profile of the MathWorks account is verified:

2 - ThingTweet 

- ThingTweet is a web services wrapper around Twitter provided by ThingSpeak. 

- ThingTweet allows to connect an IoT device (for instance a Raspberry Pi module) and send notifications to Twitter about different events.

- Once signed up to ThingSpeak the ThingTweet action must be selected:

- The ThingTweet application will be linked to a preexisting Tweeter account:

- Once the requested information is provided the Twitter account is linked to ThingSpeak:

- An API Key is automatically generated, what must be written down carefully for further usage:

3 - Sending notifications to Twitter about the Raspberry Pi CPU temperature

- The next Python program has been adapted from here:

- The program sends web requests to ThingSpeak (using the ThingTweet action) to publish messages on Twitter every time a notification about the CPU temperature is made.

- Notice that the API key obtained before is introduced as a constant into the program:

- Giving permissions to the program to be run:

- Executing the program, every 1 minute a notification about the CPU Temperature is published:

 - As a consequence of running the program, and due to the link between ThingSpeak and Twitter, a corresponding tweet is published: