#!/usr/bin/python

import sys
import Adafruit_DHT

# Parse command line parameters.
sensor_args = { '11': Adafruit_DHT.DHT11,
		'22': Adafruit_DHT.DHT22,
		'2302': Adafruit_DHT.AM2302 }
samples = 1
if len(sys.argv) >= 2:
	pin = sys.argv[1]
	if len(sys.argv) == 3:
		samples = int(sys.argv[2])
else:
	sys.exit(1)

humiditySum = 0
tempSum = 0
samplesDone = 0

while samplesDone < samples:
  humidity, temperature = Adafruit_DHT.read_retry(Adafruit_DHT.DHT22, pin)
  if humidity is not None and temperature is not None:
    humiditySum += humidity
    tempSum += temperature
    samplesDone += 1
  else:
    print >> sys.stderr, 'Failed to get reading. Try again'

humidity = humiditySum / samplesDone
temperature = tempSum / samplesDone  
print '{1:0.1f},{0:0.1f}'.format(temperature, humidity)

sys.exit(0)

@@ -317,28 +317,27 @@
 idit
-ySum = 0
+ies = %5B%5D
 %0Atemp
-Sum = 0
+s = %5B%5D
 %0Asam
@@ -524,15 +524,16 @@
 idit
-ySum
+ies
  +=
+ %5B
  hum
@@ -537,16 +537,18 @@
 humidity
+ %5D
 %0A    tem
@@ -552,14 +552,14 @@
 temp
-Sum
+s
  +=
+ %5B
  tem
@@ -566,16 +566,18 @@
 perature
+ %5D
 %0A    sam
@@ -681,26 +681,26 @@
 idit
-ySum / 
+ies%5B(
 samples
-Done
+ / 2)%5D
 %0Atem
@@ -718,25 +718,27 @@
 temp
-Sum / 
+s%5Bint(
 samples
-Done
+ / 2)%5D
   %0Ap

use median