Can't handle unsigend int or bigger types
manhalt opened this issue · 3 comments
Hi everyone,
I just noticed while transmitting some longer values from a node, that the gateway can't handle them. Emoncms is able to handle longer values then just signed integers.
I'm trying to get a working solution but any help is appreciated.
The problem seems to be in oemgatewaylistener.py at line 208 and following (?).
Anyway thanks for this nice script!
Cheers,
Mathias
The solution seems to be very simple:
comment out line 212 and 213 in oemgatewaylistener.py:
212: if value > 32768:
213: value -= 65536
Then the script can handle unsigned integers. Using longs seems to be a bit more complicated.
Hi.
Thanks for the feedback.
Thinking of it, I'm afraid this is actually a design choice. And not mine.
See here:
To keep the packet size down and so that it is easier to interpret the data in emonCMS, we have standardised on the data being signed integer type.
It has been standardized that data from emonTX is signed integer. It is then up to the rest of the chain to adapt to that.
This limitation has already been pointed in the forum. I added a post processing operation in emonCMS:
emoncms/emoncms#82
emoncms/emoncms#86
This allows to turn the variable back into an unsigned. I think it could be used to transmit even longer variables.
Example:
You want to send a long variable X.
X = 256 * A + B
Send A and B as integers (signed or not is just a matter of interpretation).
Then in emonCMS, X = sign2unsign(B) + 256 * sign2unsign(A)
Not sure I'm clear and not 100% certain it works. This is just the idea, I didn't test it and I had no feedback from Oscar here.
Anyway, I admit it looks twisted by design, doing the post-processing in emonCMS, but this is the way OEM was designed and it probably makes more sense when the base is more limited than the Raspberry Pi.
It can be frustrating sometimes. A high level reflexion on the code architecture could lead to an implementation of all or part of the post-processing in the Pi, where there is largely enough spare calculation power. Besides, doing the processing on the Pi would allow the use of any display (emonCMS, Pachube, ThingSpeak, whatever). But this is another story.
Does the signed2unsigned function in emonCMS solve your problem ?
Is the whole thing clear ? Feel free to ask for more precisions.
Bye.
Closing as wontfix, but please reopen if you think the answer is not satisfying.