Page 1 of 1

Value size limitation

Posted: 14 Oct 2017 17:24
by dawiinci
I I return values over 255 I get weird numbers on the ZWAVE controller.

Code: Select all

  ZUNO_SENSOR_MULTILEVEL(ZUNO_SENSOR_MULTILEVEL_TYPE_VELOCITY, SENSOR_MULTILEVEL_SCALE_METERS_PER_SECOND, SENSOR_MULTILEVEL_SIZE_FOUR_BYTES, SENSOR_MULTILEVEL_PRECISION_ONE_DECIMAL, getterWind),
Since I am using for bytes I expected to get larger values.

For 254 I get correctly 25.4 m/s, but with 354 I get 9.8 m/s.

Why is that and how can I get larger Values? My sensor goes up to 30 m/s and I want this data with .1 precision.

Re: Value size limitation

Posted: 14 Oct 2017 18:19
by petergebruers
I have not tried your setup, but I noticed something similar when I wrote my BH1750 sketch. Have a look at this piece of code:

Code: Select all

// petergebruers: Value returned by getter is signed. The Z-Uno reference says to use DWORD.
// I cannot make it work with DWORD, but type "long" is OK.
long GetterLightLux() {
  Clock10s = 0;
  LedBlip = true;
  PrevLightLux = Sensor.lightLux;
  return Sensor.lightLux;
}
And the definition of sensor.lightLux (in class Sensor):

// lightLux is luminance measured in Lux.
// Type long is 32-bit signed, which may seem odd for luminance, but
// Z-wave uses signed data for reporting, so that is what I use!
long lightLux;

So i specifically used "long" data type...

The full code is here:

https://github.com/petergebruers/Z-Uno-BH1750/

Re: Value size limitation

Posted: 14 Oct 2017 18:21
by petergebruers
BTW 354 overflowing a byte gives 354-256 = 98 so 9.8 on your controller. So please check if all your calculations use long data type...

Re: Value size limitation

Posted: 14 Oct 2017 20:41
by dawiinci
Interesting. I was using unsigned long for that reason but I missed the return of the function was still on byte. :oops:

Thanks for pointing me in the right direction.

Re: Value size limitation

Posted: 14 Oct 2017 20:55
by petergebruers
Glad I could help!