Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TCM 218943 weather station: support negative temperature #309

Merged
merged 1 commit into from Dec 1, 2016

Conversation

puuu
Copy link
Contributor

@puuu puuu commented Nov 30, 2016

The temperature is a signed integer, so we have to handle the negative case.

@CurlyMoo
Copy link
Contributor

Has this been tested?

@dc6jn
Copy link

dc6jn commented Dec 1, 2016

Just came across this topic. i found 2 weeks ago a bug that might be related.
In the driver protocols/433.92/alecto_wx500.c there is also a bug connected with negative temperature values. The problem was solved by me with the following patch:

json_append_member(alecto_wx500->message, "data", json_mknumber(data,12));
switch(type) {
	case 1:
		id = binToDec(binary, 0, 7);
		long x=binToDec(binary, 12, 23);
                    //the value is a  temperature 
                    //This 12 bits wide 2's complement signed binary number represents the actual temperature value in 0.1 °C units.
                    // so we have to adjust x for this :
		x = (x >> 11) == 0 ? x : -1 ^ 0xFFF | x;
		temperature = (double)x/10.0;
		humidity = (binToDec(binary, 28, 31) * 10) + binToDec(binary, 24,27);

Hope this helps

@puuu
Copy link
Contributor Author

puuu commented Dec 1, 2016

@CurlyMoo: Yes, I have three of these transmitter. One of them is outdoor and measured last night down to -3°C. With this patch, the displayed temperature (Display of the transmitter) and the parsed value are the same, for all of the three transmitter. Before the patch, the received and decoded value was about 407°C at negative temperatures.

@puuu
Copy link
Contributor Author

puuu commented Dec 1, 2016

@dc6jn I think this was fixed in #234.

@CurlyMoo It seems, there are many device/protocols that use signed integer (e.g. #234, #221). IMHO we should consider to introduce a function to convert binary to signed integer.

e.g:

int binToSigned(const int *binary, int s, int e) { //  0<=s<=e, binary[s(lsb) .. e(msb)]
	int result;
	result = binToDec(binary, s, e);
	if(binary[s]) {
		result -= 1<<(e-s+1);
	}
	return result;
}

@CurlyMoo
Copy link
Contributor

CurlyMoo commented Dec 1, 2016

IMHO we should consider to introduce a function to convert binary to signed integer.

Good idea (in a new PR).

@CurlyMoo CurlyMoo merged commit 44205c9 into pilight:development Dec 1, 2016
@puuu puuu deleted the tcm branch December 2, 2016 14:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants