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 ? ?

2 Answers2

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 = 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

Mawg
  • 3,147
  • 1
  • 13
  • 35
1

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

mico
  • 4,351
  • 1
  • 18
  • 27