Author Topic: Storing Negative Numbers  (Read 1933 times)

rubberchicken

  • NewMember
  • *
  • Posts: 13
Storing Negative Numbers
« on: September 07, 2015, 07:57:50 PM »
Hi,

I am using the latest gateway image to log a pressure sensor that indicates both positive and negative numbers.

It appears that the new storage engine can only handle unsigned numbers, ie. buff.writeUInt32BE(value,5);

What would be the best way to work around this?

[08-09-15_09:34:51.458] [LOG] >: [31] V:3.42v TC:1260 P:-78 [RSSI:-91]                 
[08-09-15_09:34:51.462] [LOG] post: /home/pi/moteino/db/0031_V.bin[1441668891,3.42]
[08-09-15_09:34:51.465] [LOG] post: /home/pi/moteino/db/0031_C.bin[1441668891,1260]
[08-09-15_09:34:51.467] [LOG] post: /home/pi/moteino/db/0031_P.bin[1441668891,-78]
[08-09-15_09:34:51.469] [LOG]     POST ERROR: value is out of bounds

Cheers,
RC

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6866
  • Country: us
    • LowPowerLab
Re: Storing Negative Numbers
« Reply #1 on: September 07, 2015, 10:03:31 PM »
Good catch, negatives have to be supported. I will look at this soon. That should perhaps be a buff.writeInt32BE(value,5);

rubberchicken

  • NewMember
  • *
  • Posts: 13
Re: Storing Negative Numbers
« Reply #2 on: September 07, 2015, 10:46:48 PM »
Thanks Felix

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6866
  • Country: us
    • LowPowerLab
Re: Storing Negative Numbers
« Reply #3 on: September 22, 2015, 03:48:31 PM »
Ok so the problem is one line in logUtil.js, in function post():

buff.writeUInt32BE(value,5);     //value 4 bytes

needs to be:

buff.writeInt32BE(value,5);     //value 4 bytes

This will be fixed with a new release.

rubberchicken

  • NewMember
  • *
  • Posts: 13
Re: Storing Negative Numbers
« Reply #4 on: September 22, 2015, 07:16:39 PM »
Thanks Felix