Temperature sensors - negative values

Hello!

I'm using the EmonTX with DS18B20 sensors and the emontx_temperature_power script. Everything is working fine, but I have problems with negative temperatures.

How do I convert the input to a correct value, the standard calculation generates a value of 651°C for example, that should be about -10,8°C. Positive temperature values work without problems.

Robert Wall's picture

Re: Temperature sensors - negative values

Try searching the forums - IIRC I've seen this question before, I think it's a matter of signed/unsigned integers.

http://openenergymonitor.org/emon/node/1074

 

jb79's picture

Re: Temperature sensors - negative values

Ok I've found a solution that is working for me.

First EmonTX has to check if the value is positive or negative. The maximum positive value is 125°C, the maximum negative value is -55°C.

If the value is negative the reading from the sensor will be higher than 500.00, that means an integer value of 50000. If this occurs I subtract the value from 65535. This is now the negative temperature but I can't add a minus to the integer. So the next step is to move the 0°C line up to +55°C, so th e value is subtracted from 5500. This value can now be transmitted to the receiver. To combine these steps simply subtract 60035 from the reading value and transmit it.

If the value is positiv then you have to add 5500 to the measurement (because 0 now means -55°C).

Code for EmonTX (inserted after reading of the temperature sensors):

if (emontx.T1 > 50000) emontx.T1=emontx.T1-60035;
else emontx.T1=emontx.T1+5500;
 

 

In EmonCms you simply subtract 5500 by adding -5500 to the received value and multiply it with 0.01 to get the real value because EmonCms can work with negative values.

 

Series530's picture

Re: Temperature sensors - negative values

With my fusion sketch, I read the results of the sensing  into a float variable first. Just before I want to transmit them I multiply them by 100 (so as to maintain two decimal places) and then cast them as integers just before the payload transmission. 

On the receiver (either the GLCD or emonCMS or, in my case both) upon receipt of the payload I divide the received numbers by 100 and can then work with them.

This works fine on emoncms but the GLCD struggles to print negative numbers so I need to do a check and if the value is less than zero I need to print a negative sign in front of the value on the display. Cms will give fractional readings but GLCD seems happier just printing integers.

jb79's picture

Re: Temperature sensors - negative values

After solving the biggest problem (no negative values possible) I want to find a solution for the problem when a sensor is disconnected. Then I get a value of 52836, I allready tried the following but something doesn't work.

if (emontx.T1>60035) emontx.T1=emontx.T1-60035; // negative value
  else emontx.T1=emontx.T1+5500; // positive value
  if (emontx.T1>18000) emontx.T1=5500; // Error: value should be 0°C

I want to send 0°C that would mean a value of 5500 when a sensor fails. On a graph It could be seen easily when the value drops to 0 (ok when the temperature is around 0 it can't be seen but normally temperatures move up and down permanently so if the value doesn't change for some time there should be an error.

Does anybody find an error in the short script?

MartinR's picture

Re: Temperature sensors - negative values

You don't need to do anything to the emonTx code, it behaves correctly and uses signed integers. If there is no sensor present it shows a value of -127 which is 52836 in unsigned form.

The latest version of emonCMS also handles signed integers correctly. The most likely cause of your problems is that you are running an old version of emonCMS. Have you checked?

jb79's picture

Re: Temperature sensors - negative values

Ok it seems the version of EmonCMS on my Raspberry wasn't the latest one. I did a complete new installation of EmonCMS (copy old database and directory done) and installed the standard temperature sensor example with the correct sensor adresses of cause.

Now I also get negative values, but is it possible to tell EmonCMS to convert a value of -127 to 0 because I don't want these "spikes" to -127 when a sensor failes. This completely destroys the readability of a temperature graph.

Any solution to get EmonCMS to convert -127 to a definded value (for example 0)?

Jérôme's picture

Re: Temperature sensors - negative values

Any solution to get EmonCMS to convert -127 to a definded value (for example 0)?

It would probably be better to just ignore that value, trash it, as if there had been no transmission at all.

jb79's picture

Re: Temperature sensors - negative values

Hello Jerome!

For me it's clear that -127 is a failure, but how to tell emoncms?

I think there should be a possibility in the input configuration to drop values if they have a certain value. (if value > x or if value < x then drop, else continue with the input processes) This would also reduce the space needed for the database if no false values are stored.

Jérôme's picture

Re: Temperature sensors - negative values

Hi.

> For me it's clear that -127 is a failure, but how to tell emoncms?

I don't know, I haven't looked into the code of emoncms (yet). I was replying to this specific sentence :

> Now I also get negative values, but is it possible to tell EmonCMS to convert a value of -127 to 0

If -127 values can be detected, I'd rather have them removed than converted to 0.

jb79's picture

Re: Temperature sensors - negative values

Removing would also be ok for me if possible.

It would be perfect if I can define in the inout configuration that if a value higher or lower than x is discarded and the handling of the input value is done with this step. Then it could be applied to all kind of inputs (power, temperature,...)

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.