Value size limitation

Discussion about Z-Uno product. Visit http://z-uno.z-wave.me for more details.
Post Reply
dawiinci
Posts: 48
Joined: 14 Oct 2017 10:54

Value size limitation

Post 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.
petergebruers
Posts: 255
Joined: 26 Jul 2015 17:29

Re: Value size limitation

Post 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/
petergebruers
Posts: 255
Joined: 26 Jul 2015 17:29

Re: Value size limitation

Post 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...
dawiinci
Posts: 48
Joined: 14 Oct 2017 10:54

Re: Value size limitation

Post 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.
Post Reply