i getdanjperron wrote: ↑Fri Jan 16, 2015 4:41 amThere is a small differences between the DHT11 and the DHT22
The DHT11 is way less precise and don't go below 0 Celsius.
The data stream output of the DHT22 is 16 bit big endian with the bit 15 for negative indicator.
The DHT11 is 16 bit little endian and both MSB byte are set to zero.
This is a problem when you decode the data.
On the DHT22 the formula is ( (MSB * 256) + LSB) /10
On the DHT11 it is simply the LSB data which is in a swapped position from the DHT22
To have Joan code behave correctly , I just modify it by adding a variable to check if the sensor is a DHT11.
Then If you want to use Joan method with PIGPIO use this step by step method,
1 - update2 - Get pigpioCode: Select all
sudo apt-get update
3 - Create pigpio service. This way we don’t need to start it all the timesCode: Select all
cd ~ wget abyz.co.uk/rpi/pigpio/pigpio.zip unzip pigpio.zip cd PIGPIO make sudo make install
let’s load my pigpio script version
ref: http://blog.scphillips.com/2013/07/gett ... e-on-boot/Code: Select all
cd /etc/init.d sudo wget -O pigpiod \ https://googledrive.com/host/0B9H9nJFy3HJcWVhsY2xUel9uUk0 sudo chmod 755 /etc/init.d/pigpiod sudo update-rc.d pigpiod defaults 9 complete -W "$(ls /etc/init.d/)" service sudo service pigpiod start
4 - Let’s download my modified version of Joan’s DHT22 code
Code: Select all
cd ~ wget https://www.dropbox.com/s/326si04qiheqfw1/DHT22.py
Be sure that you are using GPIO22 (pin 15) otherwise you will have to change the pin information in the code.
if everything is ok just typeand it should returnsCode: Select all
sudo python DHT22.py
Temperature 23 Celsius humidity 34%Code: Select all
pi@raspberrypi ~ $ sudo python DHT22.py 1 33 23 0.19 0 0 0 0 2 34 23 0.19 0 0 0 0 3 34 23 0.19 0 0 0 0
I will continue tomorrow with the script to store into rrdtool
Daniel
@devtapra Yes I do have a big crystal ball but I only see some strutures magnification of the table.can you help me
Code: Select all
function computeSunrise(day, sunrise) {
/*Sunrise/Sunset Algorithm taken from
http://williams.best.vwh.net/sunrise_sunset_algorithm.htm
inputs:
day = day of the year
sunrise = true for sunrise, false for sunset
output:
time of sunrise/sunset in hours */
//lat, lon for Gold Coast, Qld, Australia
var longitude = 153.423471;
var latitude = -27.990119;
var zenith = 90.83333333333333;
var D2R = Math.PI / 180;
var R2D = 180 / Math.PI;
// convert the longitude to hour value and calculate an approximate time
var lnHour = longitude / 15;
var t;
if (sunrise) {
t = day + ((6 - lnHour) / 24);
} else {
t = day + ((18 - lnHour) / 24);
}
//calculate the Sun's mean anomaly
var M = (0.9856 * t) - 3.289;
//calculate the Sun's true longitude
var L = M + (1.916 * Math.sin(M * D2R)) + (0.020 * Math.sin(2 * M * D2R)) + 282.634;
if (L > 360) {
L = L - 360;
} else if (L < 0) {
L = L + 360;
}
//calculate the Sun's right ascension
var RA = R2D * Math.atan(0.91764 * Math.tan(L * D2R));
if (RA > 360) {
RA = RA - 360;
} else if (RA < 0) {
RA = RA + 360;
}
//right ascension value needs to be in the same qua
var Lquadrant = (Math.floor(L / (90))) * 90;
var RAquadrant = (Math.floor(RA / 90)) * 90;
RA = RA + (Lquadrant - RAquadrant);
//right ascension value needs to be converted into hours
RA = RA / 15;
//calculate the Sun's declination
var sinDec = 0.39782 * Math.sin(L * D2R);
var cosDec = Math.cos(Math.asin(sinDec));
//calculate the Sun's local hour angle
var cosH = (Math.cos(zenith * D2R) - (sinDec * Math.sin(latitude * D2R))) / (cosDec * Math.cos(latitude * D2R));
var H;
if (sunrise) {
H = 360 - R2D * Math.acos(cosH)
} else {
H = R2D * Math.acos(cosH)
}
H = H / 15;
//calculate local mean time of rising/setting
var T = H + RA - (0.06571 * t) - 6.622;
//adjust back to UTC
var UT = T - lnHour;
if (UT > 24) {
UT = UT - 24;
} else if (UT < 0) {
UT = UT + 24;
}
//convert UT value to local time zone of latitude/longitude
var localT = UT + 10;
//convert to Milliseconds
return localT * 3600 * 1000;
}
Code: Select all
Highcharts.setOptions({
global: {
useUTC: false
}
});
options = {
chart: {
renderTo: 'content',
type: 'spline'
},
title: {
text: 'Temperatures of the last 24h'
},
subtitle: {
text: ''
},
colors: ['#4572A7', '#AA4643', '#89A54E', '#80699B', '#3D96AE', '#DB843D', '#92A8CD', '#A47D7C', '#B5CA92'],
xAxis: {
type: 'datetime',
dateTimeLabelFormats: {
hour: '%H. %M',
}
},
yAxis: {
title: {
text: 'Temperature'
},
labels: {
formatter: function () {
return this.value + '°';
}
}
},
tooltip: {
crosshairs: true,
shared: true,
valueDecimals: 1,
useHTML: true,
headerFormat: '<small>{point.key}</small><table>',
pointFormat: '<tr><td style="color: {series.color}">{series.name}: </td>' + '<td style="text-align: right"><b>{point.y}</b></td></tr>',
footerFormat: '</table>',
valueSuffix: ' °C',
},
plotOptions: {
spline: {
marker: {
radius: 0,
lineColor: '#666666',
lineWidth: 1
}
}
},
legend: {
layout: 'vertical',
align: 'left',
x: 80,
verticalAlign: 'top',
y: 55,
floating: true,
backgroundColor: (Highcharts.theme && Highcharts.theme.legendBackgroundColor) || '#FFFFFF'
},
lineWidth: 1,
name: GetSerieName($(this).text()),
series: []
}
function computeSunrise(day, sunrise) {
/*Sunrise/Sunset Algorithm taken from
http://williams.best.vwh.net/sunrise_sunset_algorithm.htm
inputs:
day = day of the year
sunrise = true for sunrise, false for sunset
output:
time of sunrise/sunset in hours */
//lat, lon for Gold Coast, Qld, Australia
var longitude = 153.423471;
// var longitude = 0;
var latitude = -27.990119;
var zenith = 90.83333333333333;
var D2R = Math.PI / 180;
var R2D = 180 / Math.PI;
// convert the longitude to hour value and calculate an approximate time
var lnHour = longitude / 15;
var t;
if (sunrise) {
t = day + ((6 - lnHour) / 24);
} else {
t = day + ((18 - lnHour) / 24);
}
//calculate the Sun's mean anomaly
var M = (0.9856 * t) - 3.289;
//calculate the Sun's true longitude
var L = M + (1.916 * Math.sin(M * D2R)) + (0.020 * Math.sin(2 * M * D2R)) + 282.634;
if (L > 360) {
L = L - 360;
} else if (L < 0) {
L = L + 360;
}
//calculate the Sun's right ascension
var RA = R2D * Math.atan(0.91764 * Math.tan(L * D2R));
if (RA > 360) {
RA = RA - 360;
} else if (RA < 0) {
RA = RA + 360;
}
//right ascension value needs to be in the same qua
var Lquadrant = (Math.floor(L / (90))) * 90;
var RAquadrant = (Math.floor(RA / 90)) * 90;
RA = RA + (Lquadrant - RAquadrant);
//right ascension value needs to be converted into hours
RA = RA / 15;
//calculate the Sun's declination
var sinDec = 0.39782 * Math.sin(L * D2R);
var cosDec = Math.cos(Math.asin(sinDec));
//calculate the Sun's local hour angle
var cosH = (Math.cos(zenith * D2R) - (sinDec * Math.sin(latitude * D2R))) / (cosDec * Math.cos(latitude * D2R));
var H;
if (sunrise) {
H = 360 - R2D * Math.acos(cosH)
} else {
H = R2D * Math.acos(cosH)
}
H = H / 15;
//calculate local mean time of rising/setting
var T = H + RA - (0.06571 * t) - 6.622;
//adjust back to UTC
var UT = T - lnHour;
if (UT > 24) {
UT = UT - 24;
} else if (UT < 0) {
UT = UT + 24;
}
//convert UT value to local time zone of latitude/longitude
var localT = UT + 10;
//convert to Milliseconds
return localT * 3600 * 1000;
}
function dayOfYear() {
var yearFirstDay = Math.floor(new Date().setFullYear(new Date().getFullYear(), 0, 1) / 86400000);
var today = Math.ceil((new Date().getTime()) / 86400000);
return today - yearFirstDay;
Code: Select all
texte = "rrdtool xport -t -s {0} -e now --step {1} ".format(start, step)
Users browsing this forum: No registered users and 16 guests