6

I am currently working on a wireless gardening project and quite new to this field.

My sht10 sensor is connected to Arduino Uno and GSM AT commands is used for wireless communication. I am using HTTP Get method to display sensor data on my web service.

The sensor value is stored using &temperature and &humidity.

soilSensor.measure(&temperature, &humidity, &dewpoint);// sensor value

To display sensor value on web service, I converted the value into string.

String stringOne = String(temperature)
String stringTwo = String(humidity)

But I am not able to display sensor data on web service using standard HTTP Get method because of '&' (pass by reference). I am getting T = 0.00 and H = 0.00

gprsSerial.println("AT+HTTPPARA=\"URL\",\"http://xyz.com/api.aspx?Device=sensor&DeviceData=T= " +stringOne+ " ,H= " +stringTwo+ " \"");

If I upload a code without '&' for storing the values, I get the data displayed properly.

So, what is wrong with my syntax for converting variable with values passed by reference and the is any difference in which they must be sent to the web service through HTTP Get ? ?

  • I do not like the look of those two = in DeviceData=T= ! Btw, this is the wrong site to ask this question. – Mawg Apr 24 '17 at 7:27
  • Did you rever get an answer? if so, please let others know – Mawg Jan 12 '18 at 11:06
6

Parameters to an HTTP GET request are key/value pairs, separated by an ampersand &

The key and value are separated by an equals sign.

Your use of DeviceData=T=<value> breaks this rule.

See this page, which explains that you need to use %3D for the equals which is part of the value.

I.e. DeviceData=T%3D<value>

But, ask yourself if you really need to pass that =. See this Wikipedia page for good info on HTTP query strings

  • Okay, but my error is not due to this though. Is there any difference in which values passed by reference are converted into strings or sent to web service by HTTP Get ? – knowledgeispower Apr 26 '17 at 5:03
  • 1
    Which programming language is that? With the edits, you might have been better asking on S.O But, please bear in mind that you will have problems if you try to pass an equals sign in the middle of a parameter without encoding it as %3D – Mawg Apr 26 '17 at 7:08
0

To get ampersand to work properly, it also needs to be url encoded. Try substituting it with %26 and you can have it in the url. Dot from float should be %2E to work properly.

Values can be checked from https://www.w3schools.com/tags/ref_urlencode.asp

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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