@mwittig
Thanks for your help, in the meantime i did some “development”.
Your code looks more professional than mine.
I found an issue with negative temperature, here is the code that worked for me:
if (helper.binaryToNumber(binary, 24, 27)==15){ //negativ
temperature = (helper.binaryToNumber(binary, 28, 35)-255)/10;
} else { //positive
temperature = helper.binaryToNumber(binary, 28, 35)/10;
}
Maybe this can be implemented before releasing “weather21” to master.
See my development attached (still little buggy and no clean code)
module.exports = function(helper) {
var protocolInfo, pulsesToBinaryMapping;
pulsesToBinaryMapping = {
/*'12': '0',
'22': '1',
'20': '1',
'23': ''*/
/*
'12': '0',
'13': '',
'20': '1',
'22': '1'
*/
//bessere Erkennung?
/*
'01': '0',//der Block geht nicht (sollte aber???)
'12': '1',
'111111': '111',//nach 01 und 12 setzen? (da sonst nicht eindeutig)
'13': '1'
*/
/*
'12': '0',//ab hier läufts stabil
'222222': '111',
'20': '1',
'13': '1'
*/
'12': '0',//ab hier läufts stabil - andere Reihenfolge
'20': '1',
'222222': '111',
'13': '1',
'03': '1',//wenn schlechte Übertragung
'21': '1',//wenn schlechte Übertragung
'02': '0',
'23': '1'//wenn schlechte Übertragung
};
return protocolInfo = {
name: 'weather97',
type: 'weather',
values: {
id: {
type: "number"
},
channel: {
type: "number"
},
temperature: {
type: "number"
},
humidity: {
type: "number"
},
/*debug: {
type: "string"
},*/
lowBattery: {
type: "boolean"
}
},
brands: ["Auriol"],
/*
Data layout:
X II HH F TTT CC
- X: preamble, sync
- I: id, 8 bit
- H: humidity, 8 bit
- F: flags, 4 bit (Batt, TX-Button, Chan, Chan)
- T: temperature, 12 bit, deg. C scale 10
- C: checksum, 8 bit
Pulse: 1222222220122012121212201212202012201220121212121212121220202012122012202020201212201213
mapped: 0111 1010 0001 0010 1110 0000 0000 1100 1110 0010 0001
XXXX IIII IIII HHHH HHHH FFFF TTTT TTTT TTTT CCCC CCCC
*/
//pulseLengths: [180, 308, 640, 60904],
//pulseLengths: [176, 308, 628, 60904],
pulseLengths: [192, 252, 640, 61372],
pulseCount: 88,
decodePulses: function(pulses) {
//var binary, h0, h1, humidity, lowBattery, result, t0, temperature;
var binary, temperature, lowBattery;
binary = helper.map(pulses, pulsesToBinaryMapping);
if (helper.binaryToNumber(binary, 8, 8)==0) {
lowBattery = false;
} else {
lowBattery = true;
}
//Formular for negative temperature
if (helper.binaryToNumber(binary, 24, 27)==15){ //negativ
temperature = (helper.binaryToNumber(binary, 28, 35)-255)/10;
} else { //positive
temperature = helper.binaryToNumber(binary, 28, 35)/10;
}
return result = {
id: helper.binaryToNumber(binary, 4, 11),
channel: helper.binaryToNumber(binary, 22, 23)+1,
//temperature: helper.binaryToNumber(binary, 28, 35)/10, //onlx last 8 bits because of negative value
temperature: temperature,
//debug: helper.binaryToNumber(binary, 24, 27),
//debug: debug,
humidity: helper.binaryToNumber(binary, 12, 19),
lowBattery: lowBattery
};
}
};
};
Is there something you need (further sample datas, etc)?
Thanks
AxLED