# UDP JSON numbers type

**URL:** <https://community.tempest.earth/t/udp-json-numbers-type/9422>\
**Category:** Developers\
**Tags:** udp, tempest\
**Created:** [September 20, 2020, 11:13pm UTC](https://community.tempest.earth/t/udp-json-numbers-type/9422 "2020-09-20T23:13:57Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![mircolino](https://sea2.discourse-cdn.com/flex020/user_avatar/community.tempest.earth/mircolino/32/9837_2.png) [@mircolino](https://community.tempest.earth/u/mircolino)\
**Post date:** [September 20, 2020, 11:13pm UTC](https://community.tempest.earth/t/udp-json-numbers-type/9422/1 "2020-09-20T23:13:57Z")

</div>

Relatively new here, just got my Tempest (which I love) last week and I’m now trying to write a simple Linux UDP relay daemon in C/C++.

Given the nature of the language I’m using, I’m trying to determine if it’s possible to “typify” the various numbers or should I just consider everything as `"double"`?

For instance, in the UDP documentation, is the presence of a decimal point and subsequent decimals an indication that the number is to be considered a float with that max number of decimal digits? And conversely, if a number doesn’t have decimals, can it always be considered an integer?

For example I always considered the UV index to be an integer scale from 0 to 11+. However I see that `"obs_sky"` has an UV index of `"10"` while `"obs_st"` is reporting `"0.03"` and my Android Tempest app is reporting UV index as `"6.7"`.

---

<div class="post-metadata">

**Author:** ![sunny](https://sea2.discourse-cdn.com/flex020/user_avatar/community.tempest.earth/sunny/32/16368_2.png) [@sunny](https://community.tempest.earth/u/sunny)\
**Post date:** [September 21, 2020, 8:13am UTC](https://community.tempest.earth/t/udp-json-numbers-type/9422/2 "2020-09-21T08:13:46Z")

</div>

I’m not sure if it is relevant, but winddirection can be NULL, when there is no wind at all.

---

<div class="post-metadata">

**Author:** ![peter](https://sea2.discourse-cdn.com/flex020/user_avatar/community.tempest.earth/peter/32/1365_2.png) [@peter](https://community.tempest.earth/u/peter)\
**Post date:** [September 21, 2020, 8:50am UTC](https://community.tempest.earth/t/udp-json-numbers-type/9422/3 "2020-09-21T08:50:04Z")

</div>

If the amount of memory your script will use isn’t a constraint, I would just consider everything as `double` to be on the safe side. Otherwise based on my experience the following fields will probably always by of type integer:

Time Epoch, Wind Direction, Wind Sample Interval, Illuminance, Precipitation Type, Lightning Strike Count, Report Interval

Everything else (except perhaps Solar Radiation and Lightning Strike Avg Distance - I’m not certain if these are always integer) will have some number of decimal places.

---

<div class="post-metadata">

**Author:** ![jkf](https://sea2.discourse-cdn.com/flex020/user_avatar/community.tempest.earth/jkf/32/7855_2.png) [@jkf](https://community.tempest.earth/u/jkf)\
**Post date:** [September 21, 2020, 7:08pm UTC](https://community.tempest.earth/t/udp-json-numbers-type/9422/4 "2020-09-21T19:08:40Z")

</div>

For parsing JSON, using a parsing library is the right way to go, and from the results you can usually detect the type of number that was parsed, integer vs float.

On a more fun note are the inconsistencies with some numbers like the firmware\_revision field. In the device\_status and obs\_st messages I see, firmware\_revision is a proper integer. In the hub\_status messages, firmware\_revision is a string of the integer instead. Keeps you on your toes while writing code. 🙂

---

<div class="post-metadata">

**Author:** ![mircolino](https://sea2.discourse-cdn.com/flex020/user_avatar/community.tempest.earth/mircolino/32/9837_2.png) [@mircolino](https://community.tempest.earth/u/mircolino)\
**Post date:** [September 21, 2020, 8:12pm UTC](https://community.tempest.earth/t/udp-json-numbers-type/9422/5 "2020-09-21T20:12:36Z")

</div>

Yes of course I’m using a [parser](https://github.com/nlohmann/json).  
But if a number like the UV shows up in `"obs_st"` as `"0.03"`, and in `"obs_sky"` as `"10"`, what can even the library do?

I’ll probably get a `double` in `"obs_st"` and an `int` in `"obs_sky"`, which is kind of confusing.

---

<div class="post-metadata">

**Author:** ![vinceskahan](https://sea2.discourse-cdn.com/flex020/user_avatar/community.tempest.earth/vinceskahan/32/2785_2.png) [@vinceskahan](https://community.tempest.earth/u/vinceskahan)\
**Post date:** [September 21, 2020, 8:15pm UTC](https://community.tempest.earth/t/udp-json-numbers-type/9422/6 "2020-09-21T20:15:24Z")

</div>

> [@mircolino](#):
>
> For example I always considered the UV index to be an integer scale from 0 to 11+. However I see that `"obs_sky"` has an UV index of `"10"` while `"obs_st"` is reporting `"0.03"` and my Android Tempest app is reporting UV index as `"6.7"` .

If you’re writing a relay daemon, I’d think you want to relay whatever the hub reports verbatim.

I would not presume absence of a decimal point in the documentation means anything either way, unless the docs say something specific.

---

<div class="post-metadata">

**Author:** ![mircolino](https://sea2.discourse-cdn.com/flex020/user_avatar/community.tempest.earth/mircolino/32/9837_2.png) [@mircolino](https://community.tempest.earth/u/mircolino)\
**Post date:** [September 21, 2020, 8:19pm UTC](https://community.tempest.earth/t/udp-json-numbers-type/9422/7 "2020-09-21T20:19:48Z")

</div>

> [@vinceskahan](#):
>
> If you’re writing a relay daemon, I’d think you want to relay whatever the hub reports verbatim.

Well, passthrough relay is one of the options, in which case I 100% agree with you.  
But I’d eventually also like to do some preprocessing and possibly repackage the data in a different format.

---

<div class="post-metadata">

**Author:** ![mircolino](https://sea2.discourse-cdn.com/flex020/user_avatar/community.tempest.earth/mircolino/32/9837_2.png) [@mircolino](https://community.tempest.earth/u/mircolino)\
**Post date:** [September 21, 2020, 8:22pm UTC](https://community.tempest.earth/t/udp-json-numbers-type/9422/8 "2020-09-21T20:22:09Z")

</div>

Could a staff member explain to me why the UV index shows up in `"obs_st"` as `"0.03"` , and in `"obs_sky"` as `"10"`?

Is it just a typo? Should I read `"obs_sky"` as `"10.0"` and use `"double"` everywhere?

---

<div class="post-metadata">

**Author:** ![jkf](https://sea2.discourse-cdn.com/flex020/user_avatar/community.tempest.earth/jkf/32/7855_2.png) [@jkf](https://community.tempest.earth/u/jkf)\
**Post date:** [September 21, 2020, 8:54pm UTC](https://community.tempest.earth/t/udp-json-numbers-type/9422/9 "2020-09-21T20:54:20Z")

</div>

> [@mircolino](#):
>
> Yes of course I’m using a [parser](https://github.com/nlohmann/json).  
> But if a number like the UV shows up in `"obs_st"` as `"0.03"` , and in `"obs_sky"` as `"10"` , what can even the library do?
> 
> I’ll probably get a `double` in `"obs_st"` and an `int` in `"obs_sky"` , which is kind of confusing.

Fair enough, I’ve seen people try to parse JSON manually and in really strange ways. I just wanted to be sure that you weren’t on that path. Nice choice with C++. 🙂

As for the different types, I’m writing a collector for this data as well, and I’ll be massaging inconsistencies into more consistent types for consumption by other systems via mqtt topics. I’ve noticed slight changed between the same UDP message when echoed back via the WebSocket channel. I’m not sure if WF plans on correcting some of the inconsistencies, but until they do, we’re going to have to deal with them.

Example UDP and WS values from my Tempest

```auto
udp - [1600721177,0.45,1.82,2.86,89,3,996.13,23.86,41.79,71865,5.11,599,0.000000,0,0,0,2.790,1]
ws - [1600721177,0.45,1.82,2.86,89,3,996.1, 23.9, 42, 71865,5.11,599,0.0, 0,0,0,2.79, 1,0.0,null,null,0]

```

---

<div class="post-metadata">

**Author:** ![jkf](https://sea2.discourse-cdn.com/flex020/user_avatar/community.tempest.earth/jkf/32/7855_2.png) [@jkf](https://community.tempest.earth/u/jkf)\
**Post date:** [September 21, 2020, 8:56pm UTC](https://community.tempest.earth/t/udp-json-numbers-type/9422/10 "2020-09-21T20:56:23Z")

</div>

> [@mircolino](#):
>
> Should I read `"obs_sky"` as `"10.0"` and use `"double"` everywhere?

That’s the route I’m planning on taking. To keep the precision of the existing floats, promote the ints to floats where needed.

---

<div class="post-metadata">

**Author:** ![GaryFunk](https://sea2.discourse-cdn.com/flex020/user_avatar/community.tempest.earth/garyfunk/32/5729_2.png) [@GaryFunk](https://community.tempest.earth/u/GaryFunk)\
**Post date:** [September 22, 2020, 1:48am UTC](https://community.tempest.earth/t/udp-json-numbers-type/9422/11 "2020-09-22T01:48:26Z")

</div>

I get UV as a decimal on Sky and Tempest.

---

<div class="post-metadata">

**Author:** ![gizmoev](https://sea2.discourse-cdn.com/flex020/user_avatar/community.tempest.earth/gizmoev/32/941_2.png) [@gizmoev](https://community.tempest.earth/u/gizmoev)\
**Post date:** [September 22, 2020, 1:55am UTC](https://community.tempest.earth/t/udp-json-numbers-type/9422/12 "2020-09-22T01:55:51Z")

</div>

> [@GaryFunk](#):
>
> on Skype and

Did Microsoft hack your autocorrect. 🤣

---

<div class="post-metadata">

**Author:** ![GaryFunk](https://sea2.discourse-cdn.com/flex020/user_avatar/community.tempest.earth/garyfunk/32/5729_2.png) [@GaryFunk](https://community.tempest.earth/u/GaryFunk)\
**Post date:** [September 22, 2020, 2:15am UTC](https://community.tempest.earth/t/udp-json-numbers-type/9422/13 "2020-09-22T02:15:56Z")

</div>

![20200921_200125](https://us1.discourse-cdn.com/flex020/uploads/sws/original/2X/f/f420366bff8ccc145ee754305385fe422b22e883.jpeg)

---

<div class="post-metadata">

**Author:** ![vinceskahan](https://sea2.discourse-cdn.com/flex020/user_avatar/community.tempest.earth/vinceskahan/32/2785_2.png) [@vinceskahan](https://community.tempest.earth/u/vinceskahan)\
**Post date:** [September 22, 2020, 4:27pm UTC](https://community.tempest.earth/t/udp-json-numbers-type/9422/14 "2020-09-22T16:27:24Z")

</div>

> [@jkf](#):
>
> I’m not sure if WF plans on correcting some of the inconsistencies

When in doubt just follow the respective API and deal with any inconsistencies you find there.

They haven’t really changed anything in the public interface in a long time. You might see ‘internal use only’ things changing a bit, but they’ve been pretty good about mentioning them in release note-like info (after a number of us raised a ruckus for many months long ago).
