How to Sending Tweets Using ThingSpeak with Raspberry Pi
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
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 activities, including 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 https://thingspeak.com and signing up.
At that point select the ThingTweet action. You'll be provoked to log in to Twitter.
Now you have to time link your twitter account screenshot below.
You can see Your API key On this page, copy down the API key and past on your python Program
≡ Preparing your Raspberry Pi for this project:
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
Or
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
MIN_T_BETWEEN_WARNINGS = 60 # Minutes
BASE_URL = 'https://api.thingspeak.com/apps/thingtweet/1/statuses/update/'
KEY = '68LZC4LBMMMO6YDY'
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)
print(response.read())
def cpu_temp():
dev = os.popen('/opt/vc/bin/vcgencmd measure_temp')
cpu_temp = dev.read()[5:-3]
return cpu_temp
while True:
temp = cpu_temp()
print("CPU Temp (C): " + str(temp))
if temp > MAX_TEMP:
print("CPU TOO HOT!")
send_notification(temp)
print("No more notifications for: " + str(MIN_T_BETWEEN_WARNINGS) +
" mins")
time.sleep(MIN_T_BETWEEN_WARNINGS * 60)
time.sleep(1)
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 thingtweetl.py on the line that begins KEY= and then run the program using the screenshot below:
No comments