# Buienradar - windrichting

**URL:** <https://discourse.nodered.org/t/buienradar-windrichting/49841>\
**Category:** Dashboard\
**Created:** [17 August 2021 12:35 UTC](https://discourse.nodered.org/t/buienradar-windrichting/49841 "2021-08-17T12:35:46Z")\
**Posts on this page:** 5\
**Page:** 2

<div class="post-metadata">

**Author:** ![Gunner](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gunner/32/43582_2.png) [@Gunner](https://discourse.nodered.org/u/Gunner)\
**Post date:** [25 August 2021 20:18 UTC](https://discourse.nodered.org/t/buienradar-windrichting/49841/21 "2021-08-25T20:18:09Z")

</div>

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/9/5972373f8ecd8979200146f0d4c0d8d0081f2723.png)

Good catch @guidoleijten ... Yep... a closer look at the function shows _greater than_ `num.dec` and _less than_ `num.dec` which leaves all _exact_ `num.dec` to fall through as N

This explains the occasional glitch I have been seeing... one I had attributed to browser refresh or something interrupting the 10 minute update cycle I use.

A simple tweak changing the rest of the `<` symbols to `<=` corrected that.

As was in the initial beginning of the function

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/0/c0571d4b8ff7409e10e8f08d4115e3eb0c759af7.png)

_ **"New and Improved... Now with 99% more = "** _ 😛

```auto
let degreesToCardinal = function(deg){
  if (deg>11.25 && deg<=33.75){return "NNE";}
  else if (deg>33.75 && deg<=56.25){return "NE";}
  else if (deg>56.25 && deg<=78.75){return "ENE";}
  else if (deg>78.75 && deg<=101.25){return "E";}
  else if (deg>101.25 && deg<=123.75){return "ESE";}
  else if (deg>123.75 && deg<=146.25){return "SE";}
  else if (deg>146.25 && deg<=168.75){return "SSE";}
  else if (deg>168.75 && deg<=191.25){return "S";}
  else if (deg>191.25 && deg<=213.75){return "SSW";}
  else if (deg>213.75 && deg<=236.25){return "SW";}
  else if (deg>236.25 && deg<=258.75){return "WSW";}
  else if (deg>258.75 && deg<=281.25){return "W";}
  else if (deg>281.25 && deg<=303.75){return "WNW";}
  else if (deg>303.75 && deg<=326.25){return "NW";}
  else if (deg>326.25 && deg<=348.75){return "NNW";}
  else {return "N";}
}

```

---

<div class="post-metadata">

**Author:** ![hotNipi](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hotnipi/32/383_2.png) [@hotNipi](https://discourse.nodered.org/u/hotNipi)\
**Post date:** [25 August 2021 20:32 UTC](https://discourse.nodered.org/t/buienradar-windrichting/49841/22 "2021-08-25T20:32:44Z")

</div>

With a bit Math may be simpler

```auto
function degToCompass(num) {
    var val = Math.floor((num / 22.5) + 0.5);
    var arr = ["N", "NNE", "NE", "ENE", "E", "ESE", "SE", "SSE", "S", "SSW", "SW", "WSW", "W", "WNW", "NW", "NNW"];
    return arr[(val % 16)];
}

```

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [25 August 2021 20:43 UTC](https://discourse.nodered.org/t/buienradar-windrichting/49841/23 "2021-08-25T20:43:24Z")

</div>

Great minds think alike..

> [@Steve-Mcl](#):
>
> Or a simple function node containing...
> 
> ```auto
> const dir = ["N", "NNE", "NE", "ENE", "E", "ESE", "SE", "SSE", "S", "SSW", "SW", "WSW", "W", "WNW", "NW", "NNW", "N"]
> msg.payload = dir[Math.round((msg.payload % 360) / 22.5)];
> return msg;
> 
> ```
> 
> ![2HvUjtUC7E](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/8/2833f53306d763d823766b2f1c10dfa6dada7baa.gif)

---

<div class="post-metadata">

**Author:** ![Gunner](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gunner/32/43582_2.png) [@Gunner](https://discourse.nodered.org/u/Gunner)\
**Post date:** [25 August 2021 21:09 UTC](https://discourse.nodered.org/t/buienradar-windrichting/49841/24 "2021-08-25T21:09:26Z")

</div>

> [@hotNipi](#):
>
> With a bit Math may be simpler

Yes, unfortunately Math and I do not compute 😛 So I tend to just grab what I can find and shoehorn it into my code 😇

Eventually I tweak my stuff as I get a better understanding of the improvements offered. Thanks 😃

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [24 September 2021 21:09 UTC](https://discourse.nodered.org/t/buienradar-windrichting/49841/25 "2021-09-24T21:09:34Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.

[Previous page](https://discourse.nodered.org/t/buienradar-windrichting/49841.md?page=1)
