#include #include /* code ugly and many parts stolen/borrowed. redistribution is ok but will make people laugh at me, i should be cleaning this up at some point. some credits: samuel muller : href="http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1234028200/1 mats vaneslow : http://www.mats-vanselow.de/2009/02/08/arduino-lernt-twittern/ sorry if including your code i found on the internet makes you sad, guys. */ #define FLUSHPIN 7 byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; byte ip[] = { 192, 168, 111, 144 }; byte gateway[] = { 192, 168, 111, 1 }; byte subnet[] = { 255, 255, 255, 0 }; // Twitter Settings // byte server[] = { 128, 121, 146, 100 }; // IP von Twitter (default: 128.121.146.100) #define TWITTERURL "/statuses/update.xml" // URL zum Update Script #define TWITTERUSERNAMEPW "password goes here" // Base64 enkodet USERNAME:PASSWORT // freenode! byte freenode[] = { 130, 237, 188, 200 }; #define USER "USER hacklabtoilet - hacklab.to hacklabtoilet" #define NICK "NICK hacklabtoilet" #define JOIN "JOIN #hacklabto" #define PRIVMSG "PRIVMSG #hacklabto :" #define PART "PART #hacklabto" #define QUIT "QUIT" Client client(server, 80); Client irc(freenode, 6667); void setup() { pinMode(FLUSHPIN, INPUT); Ethernet.begin(mac, ip, gateway, subnet); Serial.begin(9600); delay(1000); randomSeed(analogRead(0)); Serial.println("initialized!"); } int f = 0; int prevflush = 0; long time = 0; #define DEBOUNCE 3000 #define NUMMSG 48 prog_char msg0[] PROGMEM = "toilet flushed!"; prog_char msg1[] PROGMEM = "flush flush flush"; prog_char msg2[] PROGMEM = "fluuuuuuuuuuuuuuuuuuush"; prog_char msg3[] PROGMEM = "swooooooooooooooosh"; prog_char msg4[] PROGMEM = "MISSION ACCOMPLISHED."; prog_char msg5[] PROGMEM = "bombs away!"; prog_char msg6[] PROGMEM = "plop"; prog_char msg7[] PROGMEM = "don't forget to wash your hands!"; prog_char msg8[] PROGMEM = "you sank my battleship"; prog_char msg9[] PROGMEM = "take that, admiral lord nelson!"; prog_char msg10[] PROGMEM = "blue?! WHAT were you eating?"; prog_char msg11[] PROGMEM = "plop plop fizz fizz"; prog_char msg12[] PROGMEM = "how many flushes does it take to get to the center of a tootsie roll pop?"; prog_char msg13[] PROGMEM = "WHOOP WHOOP WHOOP"; prog_char msg14[] PROGMEM = "down the hatch!"; prog_char msg15[] PROGMEM = "here we gooooooooooooooooo"; prog_char msg16[] PROGMEM = "i wonder if it really swirls in the other direction in the southern hemisphere"; prog_char msg17[] PROGMEM = "maybe you should have faced scylla instead"; prog_char msg18[] PROGMEM = "i sure am glad twitter is being put to good use!"; prog_char msg19[] PROGMEM = "i strongly support eating more fiber as part of a healthy diet"; prog_char msg20[] PROGMEM = "for your comfort and convenience, this toilet never rests"; prog_char msg21[] PROGMEM = "it's amazing what you can do with an arduino and a mercury switch these days"; prog_char msg22[] PROGMEM = "[insert joke about pull-down resistors here]"; prog_char msg23[] PROGMEM = "just wait until the rfid reader gets installed and i can call you by name"; prog_char msg24[] PROGMEM = "KHAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAANNNNNNNNNNNNNNNNNNNNNNNNNNNN"; prog_char msg25[] PROGMEM = "hey kid, i'm a toilet, stop with all the downloadin'"; prog_char msg26[] PROGMEM = "at least i'm not a lisp machine"; prog_char msg27[] PROGMEM = "anyone have a copy of 2600 magazine? i need some quality reading!"; prog_char msg28[] PROGMEM = "another day, another flush"; prog_char msg29[] PROGMEM = "why do i have so many followers?!"; prog_char msg30[] PROGMEM = "hey tweeps, i just wanted to share this awesome moment with you"; prog_char msg31[] PROGMEM = "http://penny-arcade.com/comic/2008/4/23/"; prog_char msg32[] PROGMEM = "conserve water, use the toilet with a fr... nevermind"; prog_char msg33[] PROGMEM = "well that was satisfying"; prog_char msg34[] PROGMEM = "this flush announcement brought to you by @thirdson, blame him"; prog_char msg35[] PROGMEM = "just dropping the kids off at the pool"; prog_char msg36[] PROGMEM = "HI VICKI! :D :D :D"; prog_char msg37[] PROGMEM = "does anyone know a good plumber?"; prog_char msg38[] PROGMEM = "i sure am glad we have a lot of tubes at the lab"; prog_char msg39[] PROGMEM = "high bandwidth mode enabled"; prog_char msg40[] PROGMEM = "it's that time again"; prog_char msg41[] PROGMEM = "twitter is so awesome, i'm so happy i can tweet about this!"; prog_char msg42[] PROGMEM = "arduinos are SO COOL."; prog_char msg43[] PROGMEM = "i hope i get slashdotted! this definitely qualifies as \"news for nerds, stuff that matters.\""; prog_char msg44[] PROGMEM = "can i trade jobs with someone for the day?"; prog_char msg45[] PROGMEM = "i hope nobody runs solitaire on me, that would be very rude and disrespectful"; prog_char msg46[] PROGMEM = "this toilet is now IP enabled!"; prog_char msg47[] PROGMEM = "SIGSEGV detected, dumping core"; PROGMEM const char *messages[] = { msg0, msg1, msg2, msg3, msg4, msg5, msg6, msg7, msg8, msg9, msg10, msg11, msg12, msg13, msg14, msg15, msg16, msg17, msg18, msg19, msg20, msg21, msg22, msg23, msg24, msg25, msg26, msg27, msg28, msg29, msg30, msg31, msg32, msg33, msg34, msg35, msg36, msg37, msg38, msg39, msg40, msg41, msg42, msg43, msg44, msg45, msg46, msg47 }; int msg; char buffer[141]; void loop() { fetchTwitterUpdate(); f = digitalRead(FLUSHPIN); if( (prevflush == 0) && (f == 1) && (millis() - time > DEBOUNCE) ) { time = millis(); msg = random(NUMMSG); strcpy_P(buffer, (const char*)pgm_read_word(&(messages[msg]))); sendTwitterUpdate(buffer); sendIRCUpdate(buffer); } prevflush = f; } /// Functions //// void sendTwitterUpdate(char* tweet) // Nachricht an Twitter übermitteln { Serial.print(tweet); Serial.print(" - "); Serial.print("connecting... "); if (client.connect()) { client.print("POST "); client.print(TWITTERURL); client.println(" HTTP/1.1"); client.println("Host: twitter.com"); client.print("Authorization: Basic "); client.println(TWITTERUSERNAMEPW); client.print("Content-Length: "); client.println(9+strlen(tweet)); client.println(""); client.println("status="); client.println(tweet); Serial.println("twitter message sent!"); } else { Serial.println("connection failed."); } } void sendIRCUpdate(char *tweet) { Serial.print(tweet); Serial.print(" - "); Serial.print("connecting (IRC)... "); if (irc.connect()) { irc.println(USER); delay(5000); irc.println(NICK); irc.println(JOIN); irc.print(PRIVMSG); irc.println(tweet); irc.println(PART); irc.println(QUIT); Serial.println("irc message sent!"); } else { Serial.println("connection failed."); } } void fetchTwitterUpdate() // Rückmeldung von Twitter auslesen { if (client.available()) { char c = client.read(); // Serial.print(c); } while(!client.connected()) { client.stop(); } if( irc.available()) { char c = irc.read(); } while(!irc.connected()) { irc.stop(); } }