Setup camera and such
From Kandos Digital Embassy
Revision as of 10:38, 10 April 2015 by 120.151.60.174 (Talk)
Contents
Connect to server
= Set up general
- change host name = basestation-01, edit in /etc/hosts, and /etc/hostname then "sudo /etc/init.d/hostname.sh"
- eth0 connect inet DHCP
= Temp/Humidity Sensor + dust
- do with arduino. following sketch with DHT11 library:
#include <dht.h> /* Standalone Sketch to use with a Arduino UNO and a Sharp Optical Dust Sensor GP2Y1010AU0F */ // // FILE: dht11_test.ino // AUTHOR: Rob Tillaart // VERSION: 0.1.01 // PURPOSE: DHT library test sketch for DHT11 && Arduino // URL: // // Released to the public domain // dht DHT; #define DHT11_PIN 4 int measurePin = 6; //Connect dust sensor to Arduino A0 pin int ledPower = 12; //Connect 3 led driver pins of dust sensor to Arduino D2 int samplingTime = 280; int deltaTime = 40; int sleepTime = 9680; float voMeasured = 0; float calcVoltage = 0; float dustDensity = 0; void setup(){ Serial.begin(9600); pinMode(ledPower,OUTPUT); // for dust sensor } void loop(){ if (Serial.available() > 0) { delay(1000); sendData(); // clear buffer while(Serial.available()) { char t= Serial.read(); } } } float getFiltered() { getDustLevel(); delay(200); float d = getDustLevel(); delay(200); d += getDustLevel(); delay(200); d += getDustLevel(); delay(200); d += getDustLevel(); return d/4; } float getDustLevel() { digitalWrite(ledPower,LOW); // power on the LED delayMicroseconds(samplingTime); voMeasured = analogRead(measurePin); // read the dust value delayMicroseconds(deltaTime); digitalWrite(ledPower,HIGH); // turn the LED off delayMicroseconds(sleepTime); // 0 - 5V mapped to 0 - 1023 integer values // recover voltage calcVoltage = voMeasured * (5.0 / 1024.0); // linear eqaution taken from http://www.howmuchsnow.com/arduino/airquality/ // Chris Nafis (c) 2012 dustDensity = 0.17 * calcVoltage - 0.1; return dustDensity; // unit: mg/m3 } void sendData() { float dust = getFiltered(); // READ DATA float temp = -100; float humidity = -100; int chk = DHT.read11(DHT11_PIN); if (chk == DHTLIB_OK) { humidity = DHT.humidity; temp = DHT.temperature; } /*switch (chk) { case DHTLIB_OK: Serial.print("OK,\t"); break; case DHTLIB_ERROR_CHECKSUM: Serial.print("Checksum error,\t"); break; case DHTLIB_ERROR_TIMEOUT: Serial.print("Time out error,\t"); break; case DHTLIB_ERROR_CONNECT: Serial.print("Connect error,\t"); break; case DHTLIB_ERROR_ACK_L: Serial.print("Ack Low error,\t"); break; case DHTLIB_ERROR_ACK_H: Serial.print("Ack High error,\t"); break; default: Serial.print("Unknown error,\t"); break; }*/ // DISPLAY DATA Serial.print("dust="); Serial.print(dust); Serial.print(","); Serial.print("humidity="); Serial.print(humidity); Serial.print(","); Serial.print("temp="); Serial.println(temp); }
pi
- make sensor script senddata.py and change chmod 755 for executable
- set up crontab -e
crontab -e * * * * * /home/pi/senddata.py 1 >> /home/pi/cron_out.log sudo service cron restart
Camera sending image to Server
- install sshpass
sudo apt-get install sshpass
- make sendimage in /home/pi, with chmod 755
#!/bin/bash raspistill -vf -hf -o /home/pi/image.jpg sshpass -p '<password>' scp /home/pi/image.jpg pi@digitalembassy.mesh:/var/www/data/sensors/images/1.jpg sshpass -p '<password>' scp /home/pi/image.jpg pi@digitalembassy.mesh:/var/www/data/sensors/images/1-$(date +%F-%H:%M).jpg
- add cron command to take image and upload to server
- /5 * * * * /home/pi/sendimage
- restart cron "sudo service cron restart"