#include static byte mymac[] = {0x24,0x99,0x46,0xAD,0x30,0x31}; // Be sure this address is unique in your network //Your secret DevID from PushingBox.com. You can use multiple DevID on multiple Pin if you want char DEVID1[] = "vCE5B71364F0C2A0"; //Scenario : "The mailbox is open" //Numeric Pin where you connect your switch uint8_t pinDevid1 = 3; // Example : the mailbox switch is connect to the Pin 3 // Debug mode boolean DEBUG = true; /////// //End// /////// const char website[] PROGMEM = "api.pushingbox.com"; byte Ethernet::buffer[700]; Stash stash; boolean pinDevid1State = false; // Save the last state of the Pin for DEVID1 int PIRsensor = 6; // the pin that the sensor is atteched to int PIRstate = LOW; // by default, no motion detected int PIRval = 0; // variable to store the sensor status (value) bool resultAllDevices = false; int HALLsensor = 7; int HALLstate = HIGH; int HALval = 0; int SOUNDsensor = 9; int SOUNDstate = LOW; int SOUNDval = 0; void setup () { pinMode(PIRsensor, INPUT); // initialize sensor as an input Serial.begin(9600); pinMode(pinDevid1, INPUT); if(DEBUG){Serial.println("\n[getDHCPandDNS]");} // //***Depending of your Shield, you may have to try this line instead of the second***// //if(ether.begin(sizeof Ethernet::buffer, mymac) == 0) if(ether.begin(sizeof Ethernet::buffer, mymac, 10) == 0) if(DEBUG){Serial.println( "Failed to access Ethernet controller");} else Serial.println("1"); // Wait until we have an IP from the DHCP while(!ether.dhcpSetup()){ if(DEBUG){Serial.println("Error: DHCP failed. Can't get an IP address, let's retry...");} } if(DEBUG){ ether.printIp("My IP: ", ether.myip); ether.printIp("Netmask: ", ether.netmask); ether.printIp("GW IP: ", ether.gwip); ether.printIp("DNS IP: ", ether.dnsip); } if (!ether.dnsLookup(website)) if(DEBUG){Serial.println("DNS failed");} if(DEBUG){ether.printIp("Server: ", ether.hisip);} } void loop () { ether.packetLoop(ether.packetReceive()); if (resultAllDevices) // switch on pinDevid1 is ON { //ether.browseUrl(PSTR("/pushingbox?devid="), DEVID1, website, my_callback); send_push(); delay(500); } } // called when the client request is complete static void my_callback (byte status, word off, word len) { Serial.println(">>>"); Ethernet::buffer[off+300] = 0; Serial.print((const char*) Ethernet::buffer + off); Serial.println("..."); } void send_push() { ether.browseUrl(PSTR("/pushingbox?devid="), DEVID1, website, my_callback); delay(500); resultAllDevices = false; } void control_devices() { check_motion(); check_hall(); check_sound(); } void check_motion() { PIRval = digitalRead(PIRsensor); // read sensor value if (PIRval == HIGH) { // check if the sensor is HIGH delay(100); // delay 100 milliseconds if (PIRstate == LOW) { //Hareket algılandı resultAllDevices = true; Serial.print("PIR SENSOR ACTIVATED"); PIRstate = HIGH; // update variable state to HIGH } } else { delay(200); if (PIRstate == HIGH){ PIRstate = LOW; resultAllDevices = false; } } } void check_hall() { HALval = digitalRead(HALLsensor); // read sensor value if (HALval == LOW) { delay(100); if (HALLstate == HIGH) { Serial.print("HALL SENSOR ACTIVATED"); resultAllDevices = true; HALLstate = LOW; // update variable state to HIGH } } else { delay(200); if (HALLstate == LOW) { HALLstate = HIGH; resultAllDevices = false; } } } void check_sound() { SOUNDval = digitalRead(SOUNDsensor); // read sensor value if (SOUNDval == HIGH) { // check if the sensor is HIGH delay(100); // delay 100 milliseconds if (SOUNDstate == LOW) { //Hareket algılandı resultAllDevices = true; Serial.print("SOUND SENSOR ACTIVATED"); SOUNDstate = HIGH; // update variable state to HIGH } } else { delay(200); if (SOUNDstate == HIGH){ SOUNDstate = LOW; resultAllDevices = false; } } }