▒█▀▀█ █▀▀ █░░█ ▒█▀▀█ █░░█ ░▀░ █▀▀█
▒█▄▄█ ▀▀█ █▄▄█ ▒█░░░ █▀▀█ ▀█▀ █░░█
▒█░░░ ▀▀▀ ▄▄▄█ ▒█▄▄█ ▀░░▀ ▀▀▀ █▀▀▀
A reliable & multitasked sensory station, optimized for quick response to movement detection#include #include #include #include #include IPAddress ip(192, 168, 1, 245); byte subnet[] = { 255, 255, 255, 0 }; byte gateway[] = { 192, 168, 1, 1 }; byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; const char uniqid[] = "kitchen-001"; IPAddress serveraddr(192,168,1,25); int serverport = 2424; int TMP = 2; int PIR = 3; int LDR = A0; unsigned long lastreading = 0; const int readinterval = 3000; EthernetClient client; unsigned long pirtimer; OneWire ds(TMP); int pircycle; float temperature; int light; boolean pirtrigger; int pirstate; int lastpirstate = LOW; long lastDebounceTime = 0; long debounceDelay = 10; unsigned long lastsend,lastpir; unsigned long pirinterval = 100; unsigned long tempinterval = 6000; void setup(void) { Serial.begin(9600); Ethernet.begin(mac, ip, gateway, subnet); delay(1000); Serial.print("Device IP: "); Serial.println(Ethernet.localIP()); Serial.println("Ready"); pinMode(PIR,INPUT_PULLUP); } void checkpir() { int reading = digitalRead(PIR); if (reading != lastpirstate) { lastDebounceTime = millis(); } if ((millis() - lastDebounceTime) > debounceDelay) { if (reading != pirstate) { pirstate = reading; if (pirstate == HIGH) { pirtimer=millis(); pirtrigger=true; } } } lastpirstate = reading; } void pumpdata(boolean pironly) { if(((millis()-lastreading)>readinterval) && !pironly) { temperature = getTemp(); light = analogRead(LDR); lastreading=millis(); } if (client.connect(serveraddr, serverport)) { Serial.println("Pushing variables to server.."); client.print("GET /c/pushdata/"); client.print("id="); client.print(uniqid); client.print("|"); client.print("uptime="); client.print((long)millis()); client.print("|"); client.print("temp="); client.print(temperature); client.print("|"); client.print("light="); client.print(light); client.print("|"); client.print("pir="); client.print((long)pirtimer); client.println(" HTTP/1.1"); client.print("Host: "); client.println(serveraddr); client.println("Connection: close"); client.println(); delay(50); client.flush(); client.stop(); } else { Serial.print("Connection failed to: "); Serial.println(serveraddr); } } void loop(void) { pircycle=0; while(pircycle < 5048){ checkpir(); pircycle++; } if(pirtrigger && (millis()-lastpir)>pirinterval) { pumpdata(true); lastpir=millis(); pirtrigger=false; } else { if((millis()-lastsend)>tempinterval) { pumpdata(false); lastsend = millis(); } } } float getTemp(){ byte data[12]; byte addr[8]; if ( !ds.search(addr)) { ds.reset_search(); return -1000; } if ( OneWire::crc8( addr, 7) != addr[7]) { Serial.println("CRC is not valid!"); return -1000; } if ( addr[0] != 0x10 && addr[0] != 0x28) { Serial.print("Device is not recognized"); return -1000; } ds.reset(); ds.select(addr); ds.write(0x44,1); // start conversion, with parasite power on at the end byte present = ds.reset(); ds.select(addr); ds.write(0xBE); // Read Scratchpad for (int i = 0; i < 9; i++) { // we need 9 bytes data[i] = ds.read(); } ds.reset_search(); byte MSB = data[1]; byte LSB = data[0]; float tempRead = ((MSB << 8) | LSB); //using two's compliment float TemperatureSum = tempRead / 16; return TemperatureSum; }
libraspi.js
2 Year, 11 Month ago
wifi_sensor_station.ino
serialrelay.ino
sensorstation.ino
class.dbipc.php