How to Sending Tweets Using ThingSpeak with Raspberry Pi

The ThingTweet action

You need to automatically send tweets from your Raspberry Pi. Today I show you, How to Sending Tweets Using ThingSpeak with Raspberry Pi. for example, to irritate people by telling them the temperature of your CPU.

≡ Components Required  :

Here is a list of the hardware we suggest for this tutorial on ThingSpeak Tweets Raspberry Pi

  1. Raspberry pi
  2.  Micro SD Card
  3. Ethernet cable
  4. Power Supply

This book will help you to gain more knowledge of Raspberry pi  Software and Hardware Problems and Solutions

Raspberry Pi Cookbook

≡ Create  ThingSpek Account :

ThingSpeak is similar to Raspberry Pi Email send with IFTTT but is pointed squarely at IoT projects. It allows you to create channels that can store and retrieve data using web requests, and also contains a number of activitiesincluding ThingTweet, which provides web services wrapper around Twitter. This is often less demanding to utilize than the Twitter API, which needs you to register your application with Twitter. Start by going by and signing up.

 At that point select the ThingTweet actionYou’ll be provoked to log in to Twitter.

The ThingTweet action

Now you have to time link your twitter account screenshot below.

The ThingTweet action

The ThingTweet action

You can see Your API key On this page, copy down the API key  and past on your python Program 

The ThingTweet action

≡ Preparing your Raspberry Pi for this project:

In this sectionwe’ll be showing you how to  Raspberry Pi for this project. if you First-time run project you have to need to update your raspberry pi You’ll do this by running the following commands.
sudo apt update
sudo apt upgrade

Now you have to need library install for this project You’ll do this by running the following commands. 

pip install urllib3

sudo apt-get install urllib2

≡ Code ThingSpeak Tweets Raspberry Pi:

The Python program to ThingSpeak Tweets Raspberry Pi

import time, os, urllib, urllib2

MAX_TEMP = 37.0


def send_notification(temp):
    status = 'Hello Raspberry Pi getting hot. CPU temp=' + temp
    data = urllib.urlencode({'api_key' : KEY, 'status': status})
    response = urllib2.urlopen(url=BASE_URL, data=data)

def cpu_temp():
    dev = os.popen('/opt/vc/bin/vcgencmd measure_temp')
    cpu_temp =[5:-3]
    return cpu_temp
while True:
    temp = cpu_temp()
    print("CPU Temp (C): " + str(temp))
    if temp > MAX_TEMP:
        print("CPU TOO HOT!")
        print("No more notifications for: " + str(MIN_T_BETWEEN_WARNINGS) + 
" mins")
        time.sleep(MIN_T_BETWEEN_WARNINGS * 60)

Before running the program, you’ll have to get an get to the key for the Maker Action channel by selecting Channels, and after that searching for Maker. Paste the key into on the line that begins KEY= and then run the program using the screenshot below:

The ThingTweet action

Notice how the values have been substituted into the Tweeter screenshot below 

The ThingTweet action

If you want to know more about raspberry pi then click on the link below


 953 total views,  1 views today