Project 9: Tweet Logger

Twitter is a handy way to exchange messages with friends. But Twitter can also be used in conjunction with a data logger to keep you informed on the readings taken by your data logging system.

This project will show how to create a 3-channel data logger that records temperature readings every 5 minutes.  The program also sends a tweet to your Twitter account every 15 minutes with the latest readings of PC case temperature, CPU temperature and ambient air temperature.

Twitter Account:
 The first thing you need, if you don’t already have one, is a Twitter account.  These are very easy to set up – simply go to and follow the sign-up instructions.  You will have a user name and password that will let you log into your Twitter account to send messages and receive “tweets”.

Getting and Installing Curl:
It is one thing to use your Twitter account from your browser, but how can a program be made to send updates directly to Twitter? To accomplish this we will use a free program called Curl. You can download Curl at

Installing Curl is extremely simple: create a folder called curl on the c: drive and unzip the contents of the download file. Curl may want to extract itself into a sub-folder, but it will simplify things if you move curl.exe program and its associated files into c:\curl.

Curl is a command line program that interfaces with various Internet protocols so that batch files can be used to do things automatically on the Internet. In this project we will create a batch file that will send a text file to Twitter as a message tweet. The logging program will have written the tweeted file and it will contain the temperature readings with a time and date stamp.

Creating a Batch File:
Open the Windows Notebook utility and create a batch file that looks like this:

Project 9 - Tweet Batchfile

Note: There should be just two lines in this file.

The second line wraps around so it fits on the Notepad screen, but be sure to backspace this out so you have only two lines in the batch file.

Next, change the word documatrix  to the user name of your Twitter account.  Similarly, edit password so that it is your Twitter account password. 

Finally, save the file as sendtweet.bat in the c:\curl folder.  Be sure Notepad is in the All Files mode in the Save box. 

The Tweet File:
The message you want to send to your Twitter account is contained in a file named tweetlog.txt. You might want to create one in Notepad that looks like the one shown below.

Project 9 - tweelog.txt file

Save this as a text file to c:\curl\tweetlog.txt

Testing the Curl Twitter Update:
When the batch file and the sample tweetlog.txt file are in place, you can try uploading the tweet to twitter.  To do this open a DOS box window and go to the Curl folder: cd \curl. 

Next, simply type: sendtweet.bat  After a second or so the screen will fill up with strange looking characters – this is simply Twitter confirming that it has received the tweet file.  The sequence should look like that below:

Project 9 - sendtweet.bat stuff

Now log into your Twitter account and you should be able to view the contents of the tweelog.txt file in your Home page.

Creating a Twitter Logging Program:
Now that we have a way to send the contents of a text file up to our Twitter account without using a browser, all we have to do is write a ThinBasic program to place temperature readings into the tweetlog.txt file, and execute the sendtweet.bat file. 

To do this we will modify the Project 8 code so that the PC case temperature, CPU temperature and ambient air temperature acquired by the Simplex 101 interface will all be written to c:\curl\tweetlog.txt.  Every 15 minutes the program will send the data to Twitter by executing the sendtweet.bat file.

Because this program will not create a webpage or graph, all of this code must be removed from the Project 8 source file.  The program will record all the temperature readings every 5 minutes to a file called alltemps.txt, as before.  And we will add code that will send the tweetlog.txt file up to Twitter every 15 minutes.  The source code is here. You can copy and paste this into a blank ThinBasic project, but be sure to adjust those lines of code that wrap over to a new line.

Running the Tweet Logger:
Running the tweet logger means starting the Motherboard temperature program and the Fixed program for the Simplex 101.  When these are running, start the Project 9 program.  You can open  the alltemps.txt file with Notepad after 5 minutes to verify everything is weorking OK.  In 15 minutes the Program 9 DOS box screen will fill with the Twitter response to the Curl sendtwee.bat file.

Now log into your Twitter account and look for the tweet from the logger.  The screen below shows what mine looked like after 45 minutes.

Project 9 - Twitter Home Page screenshot

Going Further:
This logger sends a tweet on a fixed interval of 15 minutes. You could add code that sends a tweet when a certain temperature has been exceeded. Or you could combine the tweet function with any of the other loggers so that you also have a real-time update available by web page.

%d bloggers like this: