Insteegram Notification Gadget
In the movie "Middle Men", two guys decide to start an online porn subscription service (which is allegedly how online credit card transactions started). They built a gadget that either whistles, chimes, rings (along with other noises) every time there is a new incoming order. We don't do smut... but that movie inspired us to create our own similar gadget for Insteegram.com. With the recent Likeacoupon deal, Insteegram has been getting a lot more sales and visitors. So, we decided to rig up this gadget using: 1 arduino uno 1 breadboard 1 arduino ethernet shield 1 yellow LED 1 330ohm resistor 1 piezo transducer and some hook-up wires. It works like a charm: Everytime there's a new user, it plays a lower octave C note. Everytime there's a new incoming order, it plays a upper octave C note. Whenever there are unfulfilled orders, the yellow LED light stays on. This gadget is totally unnecessary and a little annoying, but it's definitely COOL! Almost forgot.... here's the crucial source code that makes this device run:
#include <SPI.h> #include <Ethernet.h> byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; IPAddress server(75,101,165,24); // Insteegram String readstring; String userstring; String orderstring; int ledPin = 8; int speakerPin = 9; int orders,users,temporders,tempusers = 0; EthernetClient client; void setup() { pinMode(speakerPin,OUTPUT); pinMode(ledPin,OUTPUT); //Serial.begin(9600); if (Ethernet.begin(mac) == 0) { //Serial.println("Failed to configure Ethernet using DHCP"); for(;;) ; } delay(1000); //Serial.println("connecting..."); } void connectToServerA() { if (client.connect(server, 80)) { //Serial.println("connected to orders"); client.println("GET /****REMOVED**** HTTP/1.0"); client.println(); } else { //Serial.println("connection failed"); } while (client.connected()){ while (client.available()) { char c = client.read(); //Serial.print(c); if(readstring.indexOf("orders:")>0){ if(c!='\n'){ //Serial.print('!'); orderstring += c; } } else{ readstring += c; } } if (!client.connected()) { Serial.println(); Serial.println("disconnecting."); client.stop(); int multiplier = 1; for(int i=orderstring.length()-1;i>=0;i--){ if(i < orderstring.length()-1){ multiplier *= 10; } temporders += (orderstring[i]-'0')*multiplier; } //Serial.print(orderstring); //Serial.println(temporders); if(temporders>orders){ // alert me; playTone(1915); } orders = temporders; temporders = 0; readstring = ""; orderstring = ""; } delay(1000); } } void connectToServerB() { tempusers = 0; readstring = ""; if (client.connect(server, 80)) { //Serial.println("connected to users"); client.println("GET /****REMOVED**** HTTP/1.0"); client.println(); } else { // kf you didn't get a connection to the server: //Serial.println("connection failed"); } while (client.connected()){ // if there are incoming bytes available // from the server, read them and print them: while (client.available()) { char c = client.read(); //Serial.print(c); if(readstring.indexOf("users:")>0){ if(c!='\n'){ //Serial.print('!'); userstring += c; } } else{ readstring += c; } } // if the server's disconnected, stop the client: if (!client.connected()) { //Serial.println(); //Serial.println("disconnecting."); client.stop(); int multiplier = 1; for(int i=userstring.length()-1;i>=0;i--){ if(i < userstring.length()-1){ multiplier *= 10; } tempusers += (userstring[i]-'0')*multiplier; } //Serial.print(orderstring); //Serial.println(tempusers); if(tempusers>users){ // alert me; playTone(956); } users = tempusers; tempusers = 0; readstring = ""; userstring = ""; } delay(1000); } } void loop() { connectToServerA(); connectToServerB(); if(orders>0){ digitalWrite(ledPin, HIGH); } else{ digitalWrite(ledPin, LOW); } delay(60000); } void playTone(int note) { for (int i=0; i<100; i++) { digitalWrite(speakerPin, HIGH); delayMicroseconds(note); digitalWrite(speakerPin, LOW); delayMicroseconds(note); } }








