The system is now finished. The full version displayed above, and the twitter stream is available at NephthysCat. Of course she's not wearing the harness all the time so don't expect constant updates. The battery life is longer than the calculated 7.1 hours, which was to be expected because I didn't expect the components to run at their maximum rating the whole time.
I solved the charging of the LiPoly battery by cutting a USB cable in half and using that power for the input of the charger circuit. On the Playstation 2 I have the cu command (cu -s 9600 -l /dev/ttyUSB0 dir >entry) run in a local terminal. This will cause all the incoming messages to appear in the file "entry":
4F0088E27B5E
4F00889B0F53
4F00890403C1
4F00890403C1
4F00889BD78B
4F0088DC2932
4F0088DC2932
4F0088DC2932
4F0088DC2932
4F0088DC2932
4F0088DC2932
4F0088DC2932
4F0088DC2932
4F0088DC2932
4F0088DC2932
4F0088DC2932
4F0088DC2932
4F0088DC2932
4F0088EE88A1
4F0088EE88A1
4F0088EE88A1
A simple pike program keeps track of which line we are in this file, and continues from there. If an entry gets added beyond that, it will a message read from a file called "tweets". Here is the code:
/* NEPH.PIKE - Allow Nephthys to tweet */
/* 110812: Started programming */
#pike 7.0
#include
mapping(string:string) tweets = ([]);
int main() {
string data = Stdio.read_file("tweets");
string *lines = data/"\n";
for(int i=0;i
tweets["0"+lines[i]]=lines[i+1];
tweets["1"+lines[i]]=lines[i+2];
}
string current = Stdio.read_file("current");
int where = (int)current;
write("Last index: " + where + "\n");
int count = 0;
while(1) {
string entries = Stdio.read_file("entry");
lines = entries/"\n";
if((sizeof(lines)-1)>where) {
tweet(lines[where++]);
Stdio.write_file("current", "" + where);
write("New index: " + where + "\n");
count = 0;
} else {
if (count++ > 60) {
//tweet("Purr!");
}
}
write("Sleeping...\n");
sleep(60);
}
}
void tweet(string text) {
text-="\r";
text-="\n";
string last = text[(sizeof(text)-2)..(sizeof(text)-1)];
string code = "" + random(2) + last;
string message = tweets[code];
if (!message) {
message = "Cat error " + code;
}
write("Tweeting: " + message + "\n");
system("/usr/local/bin/ttyter -keyf=nephthys -status='" + message + "'");
}
The code doesn't filter out duplicates, but fortunately twitter does this for you. It uses the ttyter command line to send the tweets. The tweets file contains the last two digits of the tag, followed by two possible tweet lines which it can choose from at random. For example:
32
Nom, nom, nom!
Oops, I dropped a piece of food. No worries, Miuty will get it.
A1
This is smelly tasty food from the top shelf.
This food is better because it is higher.
The tags are placed at crucial positions in the house, for example near the cat toy.
There are obviously many improvements that can be added, and more tags that can be spread around the house.