This page last changed on Nov 30, 2014 by agarcia.

I am having an issue with the HTTP Command GET using a JSON data string. I get the entire string in the label. Any help would be greatly appreciated. It is very simple, I have a command, a sensor and a label. The JSON is very simple "LED"= 0 or "LED"= 1. Once I have this working I will continue adding more stuff.

Adrian

_____________________COMMAND:__________________________________

Name: GET_LED_State
Protocol: HTTP

HTTP attributes
URL: http://192.168.2.2/
HTTP Method: GET
Workload:
Username:
Password:
XPath Expression:
RegularExpression:
Polling interval: 3s
JSONPath Expression: $.LED

______________________SENSOR:____________________________________

Name: LED_Sensor
Command: GET_LED_Sate

Type: Custom
Not sure which values I need to put/select in Name and Value fields

______________________label:____________________________________
Then I add a label and select the sensor and all a get is the entire string "LED"= 1 or "LED"= 0

Thanks in advance
Adrian


http://www.openremote.org/display/docs/Designer+2.0+-+Create+Custom+Sensor

Posted by pz1 at Nov 30, 2014 21:32

Hi PZ1,

Thank you very much for your reply. Yes, I haven seen this link already but it is not very clear to me to be honest. It didnt help me so that is why I asked in this forum for more help.

What shall I put in Name: and Value: if I need to use my settings of "LED"=1?

Many thanks,
Adrian

Posted by agarcia at Dec 01, 2014 11:40

As in the last image of the link I gave you.

on   "LED"= 1
off  "LED"= 0
Posted by pz1 at Dec 01, 2014 11:58

It still displays the JSON string in the label app instead of the value: "LED": 1

The arduino code which generate the HTTP response code is:

// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: application/json");
client.println();

// output the value of each analog input pin as a json-p object
client.print("{");
client.print("\"LED");
client.print("\": ");
int sw1 = digitalRead(2);
if (sw1 == HIGH)

Unknown macro: { client.print("1"); }

if (sw1 == LOW)
Unknown macro: { client.print("0"); }

//client.print(",");
client.println("}");

Below, are also the three elements that I am working with. Also, when adding the label in the UI Designer, there is the Sensor State which displays Off: On: . See last picture. I guess this is the actual label you want to display in the app, is that correct?

Command

Sensor

Label

Thank you so much

Posted by agarcia at Dec 01, 2014 18:46

Please
1) Show the json as you receive it from the Arduino
2) Include your code and logs {code}...{code} tags for better readability

Posted by pz1 at Dec 01, 2014 18:56

Text displays in the label is:

Posted by agarcia at Dec 01, 2014 19:36

OK, then in the custom sensor definition use 1 and 0 instead of the full strings including LED that you use now.
I only tested with a online JSONPath expression tester (http://jsonpath.curiousconcept.com/) on your data.

Posted by pz1 at Dec 02, 2014 08:17
Document generated by Confluence on Jun 05, 2016 09:35