2

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.

dda
1,5951 gold badge12 silver badges17 bronze badges
asked Dec 24, 2017 at 14:23
3
  • I take it, at some other point in your program, you are telling it where to post the data to? Commented Dec 24, 2017 at 16:36
  • To My Application Commented 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 statements Commented Dec 24, 2017 at 20:15

1 Answer 1

2

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+"\"}"
answered Dec 24, 2017 at 15:08
6
  • it displaying as +st+ in my application instead of value Commented Dec 24, 2017 at 15:32
  • @AnneLingesh: That's what I wrote in my answer: you have a literal "+st+" in your string. Commented Dec 24, 2017 at 16:04
  • I didn't understand @Edgar Bonet 2 Commented 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 getting invalid 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 information Commented 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) Commented Dec 25, 2017 at 4:47

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.