User:Tom/Arduino Project
Overpeinzingen
Te meten
Digitaal
- Voordeur, deur meterkast, deur cvkast, deur garage-woonkamer, deur garage-achter, deur garage-voor-links-rechts.
- Brievenbus
- Bel
- Uitlezen elektriciteitsmeter, gasmeter, watermeter.
- PIR hal beneden, hal boven, woonkamer, garage.
Analoog
- Temperatuur hal, hal radiator,woonkamer, geluidsinstallatie, meterkast, cvkast, garage, garage radiator. buiten voor, buiten achter, onder de vloer
- Weerstation buiten (wind, temperatuur, zonlicht, CO2, luchtdruk).
Plaatsen voor Arduino
- meterkast
- garage
- hobbykamer
- houthok in tuin
- boom bij cirkel in tuin
Over naar raspberry pi's.
Onderhoud/configuratie met ansible en monitoring met Icinga/Nagios.
Raspberrys verzamelen gegevens en sturen deze iedere minuut naar Atlas. Bewaar de samples als het versturen mislukt en stuur de vorige samples opnieuw. Stuur naar Atlas wanneer samples niet lukte en hoeveel samples er niet en later wel verstuurd zijn.
Naamgeving records Carbon
roggedomo.boilerroom.humidity roggedomo.boilerroom.temperature roggedomo.boilerroom.cvin.temperature roggedomo.boilerroom.cvout.temperature roggedomo.crawlspace.humidity roggedomo.crawlspace.temperature roggedomo.crawlspace.ground.temperature roggedomo.garage.door.rear roggedomo.garage.door.front.left roggedomo.garage.door.front.right roggedomo.garage.door.side roggedomo.garage.humidity roggedomo.garage.temperature roggedomo.garage.radiator.temperature roggedomo.garden.humidity roggedomo.garden.temperature.ground-40 roggedomo.garden.temperature.ground+10 roggedomo.garden.temperature.ground+80 roggedomo.garden.temperature.ground+120 roggedomo.garden.movement roggedomo.hall.door roggedomo.hall.doorbell roggedomo.hall.mailbox roggedomo.hall.humidity roggedomo.hall.temperature roggedomo.livingroom.temperature roggedomo.livingroom.humidity roggedomo.study. roggedomo.bedroom. roggedomo.hobby.
roggedomo.solar.totalwattstoday roggedomo.solar.wattsnow roggedomo.solar.temperature roggedomo.solar.pv1voltagedc roggedomo.solar.pv2voltagedc roggedomo.solar.pv1currentdc roggedomo.solar.pv2currentdc roggedomo.solar.voltageac roggedomo.solar.currentac roggedomo.solar.frequency roggedomo.solar.totalwattstoday roggedomo.solar.totalkWhsincereset
Sensoren
DHT22 Temperature/humidity
DS18B20 Temperature
Bij verlengen aansluitkabel met cat-5 kabel dient de data en ground aansluiting in hetzelfde twisted pair te zitten. Laat de overige aansluitingen ongemoeid, verbind deze niet met massa.
DS18B20 serienummers:
- A24340
- A2535A
- A2566A
- A29539
- A29A8B
- A2C311
- A2F0D9
- A3BB16
- A3E76A
En waar zijn de reeds aangesloten sensoren
- DE70FF
- E252FF
RTC DS1307
Real Time Clock module met CR1220 knoopcel.
HC-SR501 Bewegingsensor
Gevoeligheid: Je kunt de afstand waarover de sensor werkt aanpassen (3m tot 7m).
Output timing: Deze instelling regelt hoe lang de uitgang hoog wordt gehouden na de sensor wordt geactiveerd (5 seconden tot 300 seconden).
Jumper Auto reset: De sensor blijft geactiveerd totdat de beweging stopt.
Jumper Geen reset: De sensor blijft de ingestelde ‘Output timing' periode geactiveerd bij de detectie van een beweging.
YF-S201 Waterflow Sensor
Er is ook een groter model (YF-G1 DN25 1inch Water Flow Sensor) max 100L/min.
Aansluitdraden:
- Zwart - Ground
- Rood - Vcc 5V
- Geel - Signal / Data
Sample code:
#!/usr/bin/env python
import RPi.GPIO as GPIO
import time, sys
FLOW_SENSOR = 23
GPIO.setmode(GPIO.BCM)
GPIO.setup(FLOW_SENSOR, GPIO.IN, pull_up_down = GPIO.PUD_UP)
global count
count = 0
def countPulse(channel):
global count
count = count+1
print count
GPIO.add_event_detect(FLOW_SENSOR, GPIO.FALLING, callback=countPulse)
while True:
try:
time.sleep(1)
except KeyboardInterrupt:
print '\ncaught keyboard interrupt!, bye'
GPIO.cleanup()
sys.exit()
Debounce code:
#initialise a previous input variable to 0 (assume button not pressed last)
prev_input = 0
while True:
#take a reading
input = GPIO.input(17)
#if the last reading was low and this one high, print
if ((not prev_input) and input):
print("Button pressed")
#update previous input
prev_input = input
#slight pause to debounce
time.sleep(0.05)
Samples queuen
Pseudo code
If Sample Ok
Then
Send Sample to server
If Send Ok
Then
If sample files found
Then
Do while sample files available
send sample to server
if Send Ok
then
Remove sample file
else
Log error retry sample failed
Fi
Done
Else
nop
Fi
Else
Store sample as a file in directory
Fi
Else
Tell Sample failed
Fi
Pseudo code variant eerst schrijven naar file in directory
Uitbreiden met nagios monitoring en retries inzichtelijk maken.
If Sample Ok
Then
write sample to file
If write-ok
Then
Do while sample files available
send sample to server
if Send Ok
then
Remove sample file
else
Log error retry sample failed
Fi
Done
Else
tell write failed
Fi
Else
Tell Sample failed
Fi
Aap
pi@roggeberry1:~ $ cat /home/pi/sample/sample.py
#!/usr/bin/python2
import sys
import time
import os
import platform
import subprocess
from socket import socket
import Adafruit_DHT
CARBON_SERVER = '192.168.2.100'
CARBON_PORT = 2003
sock = socket()
try:
sock.connect( (CARBON_SERVER,CARBON_PORT) )
except:
print "Couldn't connect to %(server)s on port %(port)d, is carbon-agent.py running?" % { 'server':CARBON_SERVER, 'port':CARBON_PORT }
sys.exit(1)
def gettemp(id):
try:
mytemp=
filename = 'w1_slave'
f = open('/sys/bus/w1/devices/' + id + '/' + filename, 'r')
line = f.readline()
crc = line.rsplit(' ',1)
crc = crc[1].replace('\n',)
if crc=='YES':
line = f.readline()
mytemp = line.rsplit('t=',1)
else:
mytemp = 0
f.close()
return int(mytemp[1])
except:
return 0
humidity, temperature = Adafruit_DHT.read_retry(Adafruit_DHT.DHT22, 4)
humidity = round(humidity, 2)
temperature = round(temperature, 2)
if humidity is not None and temperature is not None:
now = int( time.time() )
lines = []
#We're gonna report all three loadavg values
lines.append("roggedomo.livingroom.temperature %s %d" % (temperature,now))
lines.append("roggedomo.livingroom.humidity %s %d" % (humidity,now))
lines.append("roggedomo.livingroom.ground.temperature %s %d" % (gettemp('28-051691de70ff')/float(1000),now))
lines.append("roggedomo.livingroom.floor.temperature %s %d" % (gettemp('28-051691e252ff')/float(1000),now))
message = '\n'.join(lines) + '\n' #all lines must end in a newline
print "sending message\n"
print '-' * 80
print message
print
sock.sendall(message)
else
print 'No data from DHT22'
pi@roggeberry1:~ $
ADC
MCP3008
8 analoge input channels met 10-bit resolutie.
ADS1x15
4 input channels met 12/16-bit precisie en instelbare gevoeligheid/versterking. ADS1015 12 bits precisie en ADS1115 met 16-bit precisie.
Raspberries
Meterkast
Host roggeberry1.
DHT22 pin 1 5V (3.3?)
pin 2 Data
pin 3 Not connected
pin 4 Ground
Pullup 10k resistor between pin 1 and 2
DS18B20 rood 3.3v
groen Ground
geel Data
UTP kabel DS18B20 oranje --> connector rood (onder) wit --> connector geel (links) Kijkend naar voorzijde wcd) groen --> connector groen (rechts)
HP206C
zwart Ground
rood +5V
wit SDA
geel SCL
HC SR-501
zwart GND
geel Output
rood VCC +5V
Sensoren
Roggeberry1
--------- Carbon resource name --------- Sensor - ID - ------- GPIO pins ------ - Junction - - Connector -
Data + Ground - box - -- pins --
roggedomo.boilerroom.humidity DHT22 DHT22-1 32 GPIO 12 17 39 1.1.1 4
roggedomo.boilerroom.temperature DHT22 1.1.1
roggedomo.boilerroom.temperature.cvin DS18B20 A2C311 37 GPIO 26 17 39 1.1.2
roggedomo.boilerroom.temperature.cvout DS18B20 A2F0D9 37 GPIO 26 17 39 1.1.3
roggedomo.crawlspace.humidity DHT22 DHT22-2 36 GPIO 16 17 39 1.2.1 4 roggedomo.crawlspace.temperature DHT22 1.2.1 roggedomo.crawlspace.temperature.ground DS18B20 111111 37 GPIO 26 17 39 1.2.2
roggedomo.hall.barometer HP206C BARO-1 1.3.1 9 roggedomo.hall.door Reed REED-1 29 GPIO 5 39 1.3.2 roggedomo.hall.doorbell Reed REED-2 31 GPIO 6 39 1.3.3 roggedomo.hall.mailbox Reed REED-3 33 GPIO 13 39 1.3.4 roggedomo.hall.humidity DHT22 DHT22-3 38 GPIO 20 17 39 1.3.5 roggedomo.hall.temperature DHT22 1.3.5 roggedomo.hall.movement HC-SR501 PIR-1 13 GPIO 27 17 02 1.3.6 roggedomo.hall.lamp SRD-05VDC RELA-1 11 GPIO 17 17 02 1.3.7
roggedomo.livingroom.humidity DHT22 DHT22-4 40 GPIO 21 17 39 1.4.1 4 roggedomo.livingroom.temperature.ground DHT22 1.4.1 roggedomo.livingroom.temperature.ground+200 DS18B20 111111 37 GPIO 26 17 39 1.4.2 roggedomo.livingroom.temperature.ground+80 DS18B20 111111 37 GPIO 26 17 39 1.4.3 roggedomo.livingroom.temperature.tuner DS18B20 111111 37 GPIO 26 17 39 1.4.4 roggedomo.livingroom.temperature.amplifier DS18B20 111111 37 GPIO 26 17 39 1.4.5 roggedomo.livingroom.temperature.cd DS18B20 111111 37 GPIO 26 17 39 1.4.6 roggedomo.livingroom.temperature.tape DS18B20 111111 37 GPIO 26 17 39 1.4.7 roggedomo.livingroom.lamp.audio SRD-05VDC RELA-2 GPIO 17 39
Roggeberry2
------------ Carbon resource name ------------- Sensor - ID - ------- GPIO pins ------
Data + Ground
roggedomo.garage.humidity.binnen DHT22 DHT22-1 32 GPIO 12 17 39
roggedomo.garage.temperature.binnen DHT22
roggedomo.garage.humidity.buiten DHT22 DHT22-1 32 GPIO 12 17 39
roggedomo.garage.temperature.buiten DHT22
roggedomo.garage.crawlspace.humidity DHT22 DHT22-1 32 GPIO 12 17 39
roggedomo.garage.crawlspace.temperature DHT22
roggedomo.garage.crawlspace.temperature.ground-20 DS18B20 A2C311 37 GPIO 26 17 39
roggedomo.garage.temperature.radiator DS18B20 A2F0D9 37 GPIO 26 17 39
roggedomo.garage.event.zijdeur roggedomo.garage.event.achterdeur roggedomo.garage.event.voordeur.links roggedomo.garage.event.voordeur.rechts roggedomo.garage.verlichting.tuin roggedomo.garage.verlichting.algemeen roggedomo.garage.verlichting.werkbank roggedomo.garage.sensor roggedomo.regen.buffer.hoog roggedomo.regen.buffer.laag roggedomo.regen.buffer.druk roggedomo.regen.flow.hemelwater (in) roggedomo.regen.flow.overloop (spill) roggedomo.regen.flow.pomp (uit)
Roggeberry3
Camera V2.1
--------- Carbon resource name --------- Sensor - ID - ------- GPIO pins ------ Connector
Data + Ground
roggedomo.garden.humidity DHT22 DHT22-5 40 GPIO 21 17 39 1
roggedomo.garden.temperature.ground+120 DHT22
roggedomo.garden.temperature.ground-40 DS18B20 A2F0D9? 36 GPIO 16 17 34 2
roggedomo.garden.temperature.ground+10 DS18B20 A29539? ' ' ' '
roggedomo.garden.temperature.ground+80 DS18B20 A2C311? ' ' ' '
roggedomo.garden.movement HC-SR501 PIR-2 08 GPIO 14 04 06