0
Beantwoord

Taking parsed JSON and putting it into a Project Variable

Iain Brew 5 jaar geleden bijgewerkt door Vladimir Ovchinnikov (expert) 4 jaar geleden 11

With thanks to this forum, I have been able to solve many issues with my current project. I have everything working perfectly now (using Philips Hue Dimmer switches to trigger various events/drivers etc in my system) however the only thing left which is stumping me is the ability to take a requested and parsed JSON value and have it written to a Server Channel/Tag:

//Get "temperature" number from motion sensor
            // SENSOR 2 TEMPERATURE
            var getTemperature = sensor2.state["temperature"];
            var tempreadout2 = getTemperature.toString();
            tempreadout2 = tempreadout2.slice(0,2) + "." + tempreadout2.charAt(2) + " ºC";
            IR.SetVariable("Server.Tags.Lab1_Temperature", "tempreadout2");

Here I request the temperature from a Philips Motion Sensor. When testing this on a panel project, I was able to send 'tempreadout2' to a text field and it worked. Instead, I want to send this to a Server Tag (named Lab1_Temperature) so that it can appear on any control panel subscribed to that feedback channel. 

What is the best way to 'insert' that text?

+1
Under review
Hello.

To solve your problem with JSON, you may find these projects useful as an example.

JSON_.sirpz

JSON_.irpz

Hello

I am revisiting this project and still having issues. I am able to write the temperature value to a panel project text item, but I want to have this written to the server token I've created. I have been reading about IR.Log i.e. send the temperature to an IR.Log, then send that IR.Log to the server variable/token. How should I code that using the code above as an example? (tempreadout2 = the actual human readable temperature as 25.6ºC for example. 

Hello.

There are no Project Tokens in the server project. Instead, virtual feedbacks are used. Specify, do you want to write a string or number in a virtual feedback? Do you need to write from a panel project?

Hi Vladimir

What is happening is that every 200ms I am requesting data from a Philips Hue Bridge 2.0. One of the items I am requesting is the temperature from a sensor. I want to be able to write that value into a Server Virtual Feedback which multiple Panel projects can then refer to for the sensor temperature. 

From the panel, you can write to the virtual server feedback only through the "iRidium Server" driver. Do you need an example of how this can be done?

The requests to the Hue Bridge are being conducted from the server. As it polls the bridge, I want it to put the returned value into a Server Tag/Variable which I can then display as text on a connected panel project. Would something like the following be more suitable?

//Get "temperature" number from motion sensor
// SENSOR 2 TEMPERATURE
var getTemperature = sensor2.state["temperature"];
var tempreadout2 = getTemperature.toString();
tempreadout2 = tempreadout2.slice(0,2) + "." + tempreadout2.charAt(2) + " ºC";
IR.SetVariable("ServerName.Tags.Lab1_Temperature", JSON.Stringify(tempreadout2));

+1

Yes, it should work. Just make sure you have JSON.Stringify (tempreadout2) is really a string (output to the log).

Thanks for the response! It's after midnight in Sydney now so will try this when I get into work tomorrow.

This worked beautifully - all my temperature values are updating across my panel projects when referencing the server token now - YAY!