# Routing data from a field unique to just one device

**URL:** <https://discuss.blues.com/t/routing-data-from-a-field-unique-to-just-one-device/1638>\
**Category:** Notehub.io\
**Created:** [August 31, 2023, 4:29pm UTC](https://discuss.blues.com/t/routing-data-from-a-field-unique-to-just-one-device/1638 "2023-08-31T16:29:51Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![noforan](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.blues.com/noforan/32/618_2.png) [@noforan](https://discuss.blues.com/u/noforan)\
**Post date:** [August 31, 2023, 4:29pm UTC](https://discuss.blues.com/t/routing-data-from-a-field-unique-to-just-one-device/1638/1 "2023-08-31T16:29:51Z")

</div>

I have a number of remote devices all sending the same data to ThingSpeak. The single route works great. Now I have one device where I want just one of the fields to be different from all the rest. So instead of **Field 5** being “body.EC” I would like it to be “body.LUX” – but just for the one device.

I thought I could use the substitution feature as described in this post:

> [@ThingSpeak route(s) for multiple devices](https://discuss.blues.com/t/thingspeak-route-s-for-multiple-devices/1342):
>
> Hi all, I’m successfully using a Notehub route to send data from one device (Swan+n/c-F) to a ThingSpeak channel. Now I want to add multiple routes so each device sends its data to its own ThingSpeak channel. How would I implement that? Is it as simple as creating a separate route for each device and giving each JSONata expression its own API key? Or do you somehow use the HTTP headers to distinguish and route each event to the right channel using a single ThingSpeak route? I’ve read through …

So I changed this line in the route: “field5”: body.EC,  
To: “field5”: $field\_5\_data,

Then I added an environmental variable called **field\_5\_data** and set it to _body.lux_ for the one remote where I’d like Field 5 to send lux data, and set all the other device **field\_5\_data** env variables to _body.EC_ and as they will continue to send EC data.

I now see on Notehub that indeed, I’m getting either EC or Lux **values** according to the body / JSON tabs in the Event log. However, the route log response from ThingSpeak says it’s only receiving the variable name – body.EC or body.LUX – and not the actual value.

I have read through a number of forum posts and the docs, but still puzzled. Appreciate any suggestions as to what I’m missing. thanks!  
…Norm…

---

<div class="post-metadata">

**Author:** ![zfields](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.blues.com/zfields/32/29_2.png) [@zfields](https://discuss.blues.com/u/zfields)\
**Post date:** [August 31, 2023, 11:09pm UTC](https://discuss.blues.com/t/routing-data-from-a-field-unique-to-just-one-device/1638/2 "2023-08-31T23:09:46Z")

</div>

Hello @noforan ,

Are you familiar with [https://try.jsonata.org/](https://try.jsonata.org/)?

I used to struggle getting my data in the right shape, until I came across that website.

If you’re not familiar, you can grab the entire Note JSON and paste it on the left hand side of the screen, then you can paste your JSONata expression at the top. Finally you will see the result of the JSONata expression in the bottom panel.

Once you have that setup, can you grab a screenshot, so we can see what expression you are using to create the values you are expecting and how our implementation is different.

Thanks!  
Zak

---

<div class="post-metadata">

**Author:** ![noforan](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.blues.com/noforan/32/618_2.png) [@noforan](https://discuss.blues.com/u/noforan)\
**Post date:** [September 3, 2023, 1:44am UTC](https://discuss.blues.com/t/routing-data-from-a-field-unique-to-just-one-device/1638/3 "2023-09-03T01:44:51Z")

</div>

I am not familiar with that site, but I’ll give it go and report back.  
thanks!

---

<div class="post-metadata">

**Author:** ![noforan](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.blues.com/noforan/32/618_2.png) [@noforan](https://discuss.blues.com/u/noforan)\
**Post date:** [September 6, 2023, 10:19pm UTC](https://discuss.blues.com/t/routing-data-from-a-field-unique-to-just-one-device/1638/4 "2023-09-06T22:19:40Z")

</div>

I’ve spent some with JSONata Exerciser and see how it’s useful. The two things I’ve gleaned from it are that: (1) even though it works, it doesn’t like one of my variable names, so I will change it. And (2) I can tell that it doesn’t at all see the field I’m trying to substitute. Strangely, Notehub itself displays the correct result, for both variations, in the body tab of the Event.

So clearly I’m using the wrong expression to try to substitute variables. I’m guessing this is less a Blues Wireless question and more of a general JSON question, however not being all that familiar with JSON, I think I’m not asking the right question. I’ve searched “JSON variable substitution” in a variety of other forums but not finding anything that looks like the solution.

Any other suggestions or examples you could point me towards? Thanks!

---

<div class="post-metadata">

**Author:** ![noforan](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.blues.com/noforan/32/618_2.png) [@noforan](https://discuss.blues.com/u/noforan)\
**Post date:** [September 7, 2023, 1:16am UTC](https://discuss.blues.com/t/routing-data-from-a-field-unique-to-just-one-device/1638/5 "2023-09-07T01:16:18Z")

</div>

Stumbled upon the answer…

[Using Conditional Logic](https://dev.blues.io/guides-and-tutorials/notecard-guides/using-jsonata-to-transform-json/?_ga=2.104790464.1114979057.1693365186-339824259.1682517882&_gl=1*1unoo0n*_ga*MzM5ODI0MjU5LjE2ODI1MTc4ODI.*_ga_PJ7RGMWWBX*MTY5MzQ5NTI5Mi4xMDguMS4xNjkzNDk3MzAzLjcuMC4w#conditional-logic)

This is a kind of IF statement where you use one variable if it’s available, and if it’s not, then use another one.

In my case it looks like:

{  
“api\_key”: $device\_key,  
“field1”: body.airTmpC,  
“field2”: body.humid,  
“field3”: body.wTmpC@Sonde,  
“field4”: body.DO,  
**“field5”: body.EC ? body.EC : body.LUX,**  
“field6”: body.Salty,  
“field7”: body.cVoltge,  
“field8”: body.pH  
}

Which in words, to me, means – body.EC is available?  
If yes – use it : if not – use body.LUX

I tested it and it did route the proper data in both cases.

cheers!
