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,553
  • 1
  • 12
  • 17
Anne Lingesh
  • 41
  • 1
  • 4

1 Answers1

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+"\"}"
Edgar Bonet
  • 39,449
  • 4
  • 36
  • 72
  • it displaying as +st+ in my application instead of value – Anne Lingesh Dec 24 '17 at 15:32
  • @AnneLingesh: That's what I wrote in my answer: you have **a literal “+st+”** in your string. – Edgar Bonet Dec 24 '17 at 16:04
  • I didn't understand @Edgar Bonet 2 – Anne Lingesh Dec 24 '17 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 – jsotola Dec 24 '17 at 20:13
  • Getting data but which I'm not expected, I want to display value in my application not st(text) – Anne Lingesh Dec 25 '17 at 04:47
  • @AnneLingesh: Please, read my answer again **slowly**, paying attention to each word and punctuation. If there is still something you do not understand, tell us what **exactly** you do not understand. – Edgar Bonet Dec 25 '17 at 08:52