Twitter is very famous website for short messaging. So many people tweeting and exchanging their idea's on twitter. So i made an small application for tweeting my current CPU temperature.
I am using the wheezy-raspbian OS in my raspberry pi and using the python language to write the code for tweeting the CPU temp.It is a very simple DIY project we just need to install Twython on the raspberry pi and small code for interfacing with twitter.
We also need to setup an twitter application to get an API so that we can talk to twitter server and make our application ready to talk with my status.
The raspbian is basically a LINUX based operating system. Most of the linux stuff worked on it.
Now some assumption
- You are having a raspbian installed on your SD card.(CLICK HERE IF NOT)
- You are connected with internet
Update the OS
Leave this step if you already updated with your OS.
**NOTE: sudo is used for root permession if You already login with root then there is no need of sudo
Type these commands in your terminal
sudo apt-get update
sudo apt-get upgrade
Update or Install the python dependencies or twython
These three commands below install the pip and twython in your raspbian.
sudo apt-get install python-setuptools
sudo easy_install pip
sudo pip install twython
Now register your Twitter App
For using the Twitter API to communicate our raspberry pi we need to register a new Twitter App on its site. CLICK HERE
After hitting the Click Here button you will be redirected to the developer zone of twitter.com
LOGIN with your twitter account in that website
Now click on the My Application
Now click on the create new application
And provide the details below
Now give Application name, Description, website url
Leave the Callbackurl
Hit the create button
Now go into the settings
Click on read and write and give organization name or website
and Update the settings
Now go into the details and Click on "create my access token"
Now the final result will look like the image below
Now copy the four thingson the image above anywhere in your computer.
1. CONSUMER_KEY
2. CONSUMER_SECRET
3. ACCESS_TOKEN (some times ACCESS_KEY)
4. ACCESS_TOKEN_SECRET
Creating A project in Python to update the status of twitter
Your project files should be saved in a one directory so create directory first,then create your python file in that directory.
mkdir twitter_project
cd twitter_project
sudo leafpad twitter_temp.py
Now "leafpad twitter_temp.py" command will open the text editor ("like notepad in windows") with the extension named .py for python type file.
Now copy the below code(red color code) in your text editor and save it.
##################################################
#!/usr/bin/env python
import sys
from twython import Twython
CONSUMER_KEY = '***************YOUR DATA*****************'
CONSUMER_SECRET = '***************YOUR DATA*****************'
ACCESS_KEY = '***************YOUR DATA*****************'
ACCESS_SECRET = '***************YOUR DATA*****************'
api = Twython(CONSUMER_KEY,CONSUMER_SECRET,ACCESS_KEY,ACCESS_SECRET)
api.update_status(status='My first status from raspberry pi')
##################################################
In the above code change your data with the data you get from the Twitter account.
The above code will update your twitter status as in the last line" My first status from the raspberry pi"
sudo chmod 777 twitter_temp.py
sudo ./twitter_temp.py --> This command will execute your projectNow the second part of the code is to get the Temperature of the CPU
Creating Python code for printing CPU temperature
Do the same procedure you do for twitter_temp.py #############################################
#!/usr/bin/env python
import sys
import os
cmd = '/opt/vc/bin/vcgencmd measure_temp'
line = os.popen(cmd).readline().strip()
temp = line.split('=')[1].split("'")[0]
print temp
#############################################
Creating Python code for CPU temperature on twitter
Finally add the above two program code and run the file will update your twitter status with the current CPU temperature as for twitter_temp.py
#############################################
#!/usr/bin/env python
import sys
import os
from twython import Twython
CONSUMER_KEY = '***************YOUR DATA*****************'
CONSUMER_SECRET = '***************YOUR DATA*****************'
ACCESS_KEY = '***************YOUR DATA*****************'
ACCESS_SECRET = '***************YOUR DATA*****************'
api = Twython(CONSUMER_KEY,CONSUMER_SECRET,ACCESS_KEY,ACCESS_SECRET)
while 1:
cmd = '/opt/vc/bin/vcgencmd measure_temp'
line = os.popen(cmd).readline().strip()
temp = line.split('=')[1].split("'")[0]
api.update_status(status='My current CPU temperature is '+temp+' C')
time.sleep(60)
sudo ./twitter_temp.py -->this command will run the twitter_temp.py and update the status
Running the application in background and starting at the time of boot
Your application is already ready to run and working
But some people wants their application run at the time of booting the window and run in background for making this you just need to do a very small change in the file named " rc.local" which is located in the " /etc ".
sudo leafpad /etc/rc.local
Now the command above will open the file in text editor.
Now write the line just after the " #rc.local"
sudo /path_of_your_project/file_name.py &
1.Here sudo is for doing the task with root
2.path_of_the_project will be path of your project file which you want to execute
3.file_name.py give your file name which you want to execute
4. '&' symbol is use to execute the file in back ground
And save the file.
This file will execute at the time of boot.
Now you are done.
#### BEST OF LUCK FOR YOUR APPLICATION ####
ReplyDeleteThanks for this selfless act. really feel very happy about sharing your useful update with us.
INFORMATICA Training in Chennai Guindy
your information is really good and it is nice and very well done, it is very much useful too. i got more information from your blog.
ReplyDeletecognos Training in Chennai
This post is really nice and informative. The explanation given is really comprehensive and informative..
ReplyDeletePHP Training in Chennai
Thanks for the good words! Really appreciated. Great post. I’ve been commenting a lot on a few blogs recently, but I hadn’t thought about my approach until you brought it up.
ReplyDeleteBest Dental Clinic In Tambaram
Learning new technolgy would help oneself at hard part of their career. And staying updated is the only way to survive in current position. Your content tells the same. Thanks for sharing this information in here. Keep blogging like this.
ReplyDeleteSmart Home in Chennai
Hey, that’s really a good post on Electronics Appliances Classifieds Help Adya, i really like your blog as the information is very useful if you are a pet lover. Well, there is one more site for the same service www.helpadya.com you should check it for more detail.
ReplyDeleteThe information you've provided in this blog is relevant and up to the mark, really such useful information on Best Sites For Posting Free Ads in Delhi websites India, liked the most. Well, there is one more classified website which will give you advance detail for this sort of topicswww.helpadya.com
ReplyDeleteReally a good stuff. You have shared an informative post.
ReplyDeleteKeep up the good thing.
Looking for your future posts.
Dentist in Bengaluru
Best Dental Clinic in Bengaluru
Dentist in Kalyan Nagar
Thank you for allowing me to read it, welcome to the next in a recent article. And thanks for sharing the nice article, keep posting or updating news article.
ReplyDeleteDevops training in Chennai
Devops training in Bangalore
Devops Online training
Devops training in Pune
I was recommended this web site by means of my cousin. I am now not certain whether this post is written through him as nobody else recognise such precise about my difficulty. You're amazing! Thank you!
ReplyDeletejava training in chennai | java training in bangalore
java online training | java training in pune
selenium training in chennai
selenium training in bangalore
The post is written in very a good manner and it entails many useful information for me. I am happy to find your distinguished way of writing the post. Now you make it easy for me to understand and implement the concept.
ReplyDeleteangularjs Training in chennai
angularjs Training in chennai
angularjs-Training in tambaram
angularjs-Training in sholinganallur
This story is very important. It is cool that you describe.
ReplyDeleteI was recommended this web site by means of my cousin. I am now not certain whether this post is written through him as nobody else recognise such precise about my difficulty. You're amazing! Thank you!
ReplyDeletepython training in chennai
python training in Bangalore
Python training institute in chennai
Thanks for splitting your comprehension with us. It’s really useful to me & I hope it helps the people who in need of this vital information.
ReplyDeleteangularjs-Training in sholinganallur
angularjs-Training in velachery
angularjs Training in bangalore
angularjs Training in bangalore
angularjs Training in btm
angularjs Training in electronic-city
Hey, Wow all the posts are very informative for the people who visit this site. Good work! We also have a Website. Please feel free to visit our site. Thank you for sharing.Well written article Thank You Sharing with Us pmp training in chennai | pmp training institute in chennai | pmp training centers in chennai| pmp training in velachery | pmp training near me | pmp training courses online
ReplyDeleteThank you for benefiting from time to focus on this kind of, I feel firmly about it and also really like comprehending far more with this particular subject matter. In case doable, when you get know-how, is it possible to thoughts modernizing your site together with far more details? It’s extremely useful to me.
ReplyDeletepython training Course in chennai
python training in Bangalore
Python training institute in bangalore
This blog is the general information for the feature. You got a good work for these blog.We have a developing our creative content of this mind.Thank you for this blog. This for very interesting and useful.
ReplyDeleteSelenium training in Pune | Selenium training institute in Pune | Selenium course in Pune
Selenium Online training | Selenium Certification Online course-Gangboard
Selenium interview questions and answers
Selenium interview questions and answers
Selenium Online training | Selenium Certification Online course
Great thoughts you got there, believe I may possibly try just some of it throughout my daily life.
ReplyDeleteData Science training in Chennai | Data Science Training Institute in Chennai | Data Science Course in Chennai
Data science training in Bangalore | Data Science Training institute in Bangalore
Data science training in pune | Data Science training institute in Pune
Data science online training | online Data Science certification Training-Gangboard
Data Science Interview questions and answers
Data Science Tutorial
Very nice post here and thanks for it .I always like and such a super contents of these post.Excellent and very cool idea and great content of different kinds of the valuable information's.
ReplyDeletebest rpa training in bangalore
rpa training in bangalore | rpa course in bangalore
RPA training in bangalore
rpa training in chennai
rpa online training
Your very own commitment to getting the message throughout came to be rather powerful and have consistently enabled employees just like me to arrive at their desired goals.
ReplyDeletepython Course in Pune
python Course institute in Chennai
python Training institute in Bangalore
Its really an Excellent post. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog. Thanks for sharing....
ReplyDeleteData Science Tutorial
Data Science training in anna nagar
Data science training in jaya nagar
Data science training in pune
Data Science Training in Marathahalli
Data science training in kalyan nagar
Excellent blog, I wish to share your post with my folks circle. It’s really helped me a lot, so keep sharing post like this
ReplyDeleteAWS Training in Bangalore
AWS Training in pune
This comment has been removed by the author.
ReplyDeleteFound your post on Google search.Interesting to read:-)
ReplyDeleteelection news live | election news 2019 | NetCab | election news 2019 | politics speech tamil |NetCab
ReplyDeleteNice article and thanks for sharing with us. Its very informative
Plots in PHARMA CITY
I would like to say that this blog really convinced me to do it! Thanks, very good post.
ReplyDeleteI like your post. It is good to see you verbalize from the heart and clarity on this important subject can be easily observed...
ReplyDelete