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.

  • I take it, at some other point in your program, you are telling it where to post the data to? – Majenko Dec 24 '17 at 16:36
  • To My Application – Anne Lingesh Dec 24 '17 at 17:14
  • please provide detailed information in your question about what you are observing. ... there appears to be a contradiction in your statements – jsotola Dec 24 '17 at 20:15
3

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 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 4:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.