loading

In this Instructable, we are going to build something that is going to bring together social networking and data analytics. We are going to build a TwitterBot that tweets plots of temperature (or any user defined data).

This bot will create the plots using the "gnuplot" program and uses Twython Python library to tweet the generated plots.

This bot can log data and tweet plots at configurable intervals. The data that has to be logged and subsequently plotted is user configurable and hence you can log any data that you wish to record and plot.

Also it is possible to plot multiple data sources.

Step 1: Craeting the Twitter Account

Follow these steps to create a Twitter application for your TwitterBot

Create a Twitter account:

  • Create an email account for your twitter bot and then head onto www.twitter.com.
  • In "sign up" section, enter the details.
  • Enter a name for your Twitter bot
  • Go ahead and complete rest of the account creation process

Once the account is created, find your actual Twitter account and follow your account from the TwitterBot's account and vice versa. That is, your actual Twitter account should follow your Twitter bot and your Twitter bot should be following your account.

Create the Twitter application:

You need to create an Twitter application to create the Twitter bot.

Follow these steps to create a Twitter bot:

  • While still logged into you Twitterbot's application, click on this link.
  • Enter the mandatory details for your Twitter application
  • Accept the terms and click on "Create your Twitter Application"
  • In the next page, click on "permissions" and select "Read, Write and Access direct messages"
  • Click on "update settings"
  • Click on "Keys and Access tokens"
  • Click on "Create access token" and note down the keys that appears

We will use these keys later, hence keep this tab open

Step 2: Preparing the Galileo

For using this application we will need the "Linux IoT" image for the Galileo.

Click on this link if you need help with setting up your Galileo and booting into the Linux image.

For the application to work, You need to set the proper time on your Galileo.

google "UTC time" to know the current UTC time.

Then using the date command, set the date in following format:

date -s "5 AUG 3:45:00 PM"

In the above command, the date is set in accordance to the attached screen shot.

Step 3: Installing the TwitterPlotBot

Connect your Galileo to the Internet.

Type the following command onto your Galileo's Linux console:

git clone
cd TwitterPlotBot
cd install
sh install_packages_on_Galileo.sh

The last command will download and install all the required packages this command will take few minutes to complete.

Step 4: Configuring the System

All the configuration information is stored in the "config.py" file within the project folder.

Open the config.py with the following command

vi config.py

and hit 'i' key to start editing.

The first thing that you need to configure is the consumer/api and access keys.

Refer to the attached mails where you need to paste the information.

Remove the user information fillers (such as 'consumer key here', excluding quotes) and copy paste the keys.

If you are using "putty" as your serial console, place the cursor between quotes and right click to paste the copied key.

If you are using "screen" then use "ctrl+shift+v" to paste the text.

You also need to insert your twitter screen name in place of "your screen name" with your Twitter account.

Other things that you might want to configure are "Tweet Interval" and "Log Interval" which control the the time interval between Tweeting the plot and logging the data respectively in terms of seconds.

The "stop plot cmd" and "resume plot cmd" string values control the strings that you can direct message to your bot to stop and start the tweets.

Step 5: Using the Application

Connect the temperature sensor to "A1" pin header on the Grove shield.

On command line, type the following command to start the application

python TwitterBot.py

This should start tweeting the plots.

Any time you need to stop the plot you have to direct message the TwitterBot with the "stop command" as specified in the config.py similarly, you can resume tweeting by sending the "resume command"

If all you need is temperature plots being tweeted by the TwitterBot then this Instructable, for you, ends here.

If you want to configure the bot to plot other data or temperature sensor connected to different pin then head over to the next step.

Step 6: Adding Custom Data Logging (optional)

All the data collection functions can be found in the "CallBacks.py" file.

Let us take an example of adding the plot of voltage across the "A0" pin on the Galileo.

The first thing to do is define a function that will set up the analog pin and will read the voltage at that pin and returns the voltage.

def getPotVltg():   
    reading = mraa.Aio(0)
    vltg = (reading.read()/1024.0)*5  # switch is towards 5v
    return vltg

Then add this function to the list called "callbacks" (after the comma). Here you need to specify a string that will be displayed to identify the plot, next comes the call back function that you have defined and the last parameter is the color of the plot in hexadecimal format starting with #

callbacks = [
    # The data item name   The callback func    The color in the plot for this item
    [   'Temperature',      getTemperature,                "#FF2050"],
    [   'Pot vltg',         getPotVltg,                    "#2F3055"],
    
    ]

You need to restart the application for these changes to take effect.

If you need instructions on using the Python to program the Edison/Galileo, you can refer to this tutorial.

About This Instructable

246views

2favorites

License:

More by NavinB:Random news reader on the Linkit smart 7688 Effecter: A simple guitar effects processor Guitar Tuner 
Add instructable to: