Process long variable

It seems as if the inputs in emoncms are always treated as ints? How do I handle an incoming long?

o_cee's picture

Re: Process long variable

This is for accumulated pulses, but I guess I could change it to int and handle the overflow in the emonTX.

Should add that this is sending data to a Raspberry Pi, so maybe it's the script that initialized the variables this way? Couldn't see anywhere to change the length though.

o_cee's picture

Re: Process long variable

For future reference, here's the code in raspberry_run.php which handles this:

$int16 = $values[$i] + $values[$i+1]*256;
if ($int16>32768) $int16 = -65536 + $int16;

It clearly only supports signed integers.

Jérôme's picture

Re: Process long variable

Hi.

I hope I'm not missing your point.

There's a short explanation about the integer choice in the RFM12b page, section "Scaling the data".

I guess you could send two ints, then do the maths in emoncms postprocessing :

feed = 65536 * input1 + input2

 

arwed's picture

Re: Process long variable

Hi Jérôme, I also had this problem, because I wanted to transfer unsigned long values. My first approach was to manipulate the inputs as you described. It worked well as long as the individual values (i.e. the low word and the high word) are less then 32768. But if not, the aggregated feed showed negative values. ;-(((

My current, second approach is to comment out the line in the file raspberrypi_run.php that was mentioned in a post above:

              if ($int16>32768) $int16 = -65536 + $int16;
By doinf this I immediately got al values correct as unsigend. Currently I do not have any values that could become negative. But winter will come and with it the outside temperatures will go down ... My idea is to add a separate sign value for temperatures (and other values that migth become negative).

Later I hope that there will somebody find a generic way to support both, signed and unsigend values. For now I'm happy.

Regards

Jérôme's picture

Re: Process long variable

I think I found a solution: I added a new input process to unsign an input.

I submitted a pull request here: https://github.com/emoncms/emoncms/pull/82

This allows for the unsigning of the least and/or most significant word before the addition.

Please tell us if it does the trick for you !

Comment viewing options

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