I want to post data that I'm getting from the sensor every 5 seconds to my application in JSON format. Initially, I'm getting data as int and converting into String.
For example:
if data=15, it is converting into string.
String st=String(data);
Now I want to post st
every 5 seconds.
int S2 = http.sendRequest("PUT", "{\"itemId\":\"64006A962B71A1E7B3A0428637DA997C.327681\",\"item\":{\"Properties\":{\"AssetSensorDistance\":\"+st+\"}},\"operationType\":\"Update\",\"originalItem\":{\"Work_Order\":{\"ItemId\":\"64006A962B71A1E7B3A0428637DA997C.327681\"},\"Properties\":{\"AssetSensorDistance\":\"+st1+\"}}}");
Serial.print("Sensor Status: ");
Serial.println(S2);
st1 is the previous value, it is printing httpcode -2(invalid Syntax).
Can anyone help me with this issue?
Thanks in advance.
-
I take it, at some other point in your program, you are telling it where to post the data to?Majenko– Majenko2017年12月24日 16:36:18 +00:00Commented Dec 24, 2017 at 16:36
-
To My ApplicationAnne Lingesh– Anne Lingesh2017年12月24日 17:14:11 +00:00Commented Dec 24, 2017 at 17:14
-
please provide detailed information in your question about what you are observing. ... there appears to be a contradiction in your statementsjsotola– jsotola2017年12月24日 20:15:33 +00:00Commented Dec 24, 2017 at 20:15
1 Answer 1
The string
"{\"AssetSensorDistance\":\"+st+\"}"
contains a literal "+st+". If you want to do string concatenation, you should terminate the string with a double quote character, then add st, then use another double quote to start the second part of the string:
"{\"AssetSensorDistance\":\""+st+"\"}"
-
it displaying as +st+ in my application instead of valueAnne Lingesh– Anne Lingesh2017年12月24日 15:32:06 +00:00Commented Dec 24, 2017 at 15:32
-
@AnneLingesh: That's what I wrote in my answer: you have a literal "+st+" in your string.Edgar Bonet– Edgar Bonet2017年12月24日 16:04:19 +00:00Commented Dec 24, 2017 at 16:04
-
I didn't understand @Edgar Bonet 2Anne Lingesh– Anne Lingesh2017年12月24日 18:37:34 +00:00Commented Dec 24, 2017 at 18:37
-
1
it displaying as +st+ in my application instead of value
... your post says that it does not work, that you are gettinginvalid Syntax
... which is it? you are either getting some data to your application, or you are not getting data to your application. .... update your question with more informationjsotola– jsotola2017年12月24日 20:13:47 +00:00Commented Dec 24, 2017 at 20:13 -
Getting data but which I'm not expected, I want to display value in my application not st(text)Anne Lingesh– Anne Lingesh2017年12月25日 04:47:53 +00:00Commented Dec 25, 2017 at 4:47
Explore related questions
See similar questions with these tags.