/* Tweeting Coffeemaker script Commands found on: http://protocol-jura.do.am/ */ #include #include EthernetServer server(80); void setup() { // initialize digital pin 13 as an output. pinMode(8, OUTPUT); //LED Indicator pinMode(10,INPUT_PULLUP); //Button to make the coffee //Begin the serial connection with baud 9600 Serial1.begin(9600); //Start ethernet Server server.begin(); } // the loop function runs over and over again forever void loop() { serveWebsite(); //Check if Button is pressed if so make coffee while(digitalRead(10) == 0) { digitalWrite(8, HIGH); makerMakeCoffee(); } digitalWrite(8, LOW); } /** * Serves a website to make coffee. This is mainly the arduino example for a webserver */ void serveWebsite() { EthernetClient client = server.available(); if (client) { // an http request ends with a blank line boolean currentLineIsBlank = true; String line = ""; while (client.connected()) { if (client.available()) { //Buffer request lines to determine which was called char c = client.read(); line = line + c; // if you've gotten to the end of the line (received a newline // character) and the line is blank, the http request has ended, // so you can send a reply if (c == '\n' && currentLineIsBlank) { // send a standard http response header client.println("HTTP/1.1 200 OK"); client.println("Content-Type: text/html"); client.println("Connection: close"); // the connection will be closed after completion of the response client.println(); //Output HTML - in one line - not nice but lazy client.println("

The Tweeting Coffee Maker

Here you're able to remotely order your coffe! Enjoy!

"); client.println("

Make me some Coffee!

Background-Image: Creative Commons Creative Commons Attribution-Noncommercial 2.0 Generic License    by  Zach Inglis 
"); break; } if (c == '\n') { // you're starting a new line currentLineIsBlank = true; line = ""; } else if (c != '\r') { // you've gotten a character on the current line currentLineIsBlank = false; //Check for commands if(line == "GET /makeCoffee") { makerMakeCoffee(); } } } } // give the web browser time to receive the data delay(1); // close the connection: client.stop(); } } void tweet() { system("python /home/root/tweeter.py"); } /**################### Commands to send to the coffeemachine ##########################*/ void makerTurnOn() { toCoffeemaker("AN:01\r\n"); } void makerTurnOff() { toCoffeemaker("AN:02\r\n"); } void makerMakeCoffee() { toCoffeemaker("FA:06\r\n"); //This could be another code for your coffee maker please check http://protocol-jura.do.am/ //Its time to tweet that we made a coffee tweet(); } /** * Converts the commad string in to 4 bits blocks and sends the data over the serial connection to the coffeemaker * Function from: https://github.com/oliverk71/Coffeemaker-Payment-System thanks! */ void toCoffeemaker(String outputString) { for (byte a = 0; a < outputString.length(); a++){ byte d0 = 255; byte d1 = 255; byte d2 = 255; byte d3 = 255; bitWrite(d0, 2, bitRead(outputString.charAt(a),0)); bitWrite(d0, 5, bitRead(outputString.charAt(a),1)); bitWrite(d1, 2, bitRead(outputString.charAt(a),2)); bitWrite(d1, 5, bitRead(outputString.charAt(a),3)); bitWrite(d2, 2, bitRead(outputString.charAt(a),4)); bitWrite(d2, 5, bitRead(outputString.charAt(a),5)); bitWrite(d3, 2, bitRead(outputString.charAt(a),6)); bitWrite(d3, 5, bitRead(outputString.charAt(a),7)); Serial1.write(d0); delay(1); Serial1.write(d1); delay(1); Serial1.write(d2); delay(1); Serial1.write(d3); delay(7); } }