Pages: [1]   Go Down
Author Topic: GET - http request not working?  (Read 1107 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

i would like to send some temperature values to my home server. To send new values the server expects the following format:

/config/xmlapi/statechange.cgi?ise_id=xxxxx4&new_value=xx");

"ise_id=" is the ID of the variable and "new_value=" is the value - nothing special so far.
the code look like this (i enter a fixed value 1005 just for testing).

Code:
client.print("GET 192.168.178.21/config/xmlapi/statechange.cgi?ise_id=15324&new_value=1005 HTTP/1.0");

Sending the values through webbrowser is working perfect. If the code is send from Arduino it cut's off everything behind the ID. So the Arduino is sending the following request only:
"/config/xmlapi/statechange.cgi?ise_id=15324"  -  &new_value=...  is completely missing in the request! I don't know why. If i change the & character with any other it sends the complete request, only the & is not working. What's going on here? Do i miss something?

Any help is much appreciated.

Regards




Logged

Finland
Offline Offline
Sr. Member
****
Karma: 1
Posts: 270
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

How have you verified that the request is being cut? Did you check the server logs or did you use a network monitor/sniffer?

Anyway,  GET request you are trying to send looks invalid. Check this thread: http://arduino.cc/forum/index.php/topic,113010.msg851718.html#msg851718

Especially the post where I explain how you can test the request using telnet.  Testing with a browser is not the same thing.
Logged

Switzerland
Offline Offline
Faraday Member
**
Karma: 108
Posts: 5144
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Show us the whole code. Your request is wrong in any way but only if we see the rest of your code we can give you advise how to correct it.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

below is the complete code. I have made a new sketch with the air pressure value only - just to keep it simple. It's still not working.
I get the correct reading / values at the serial interface - only the GET request is not working.

Quote
How have you verified that the request is being cut? Did you check the server logs or did you use a network monitor/sniffer?
if you have this complete line in the code, it becomes a hyperlink and opens at the webbrowser but everything was cut off behind & - see my first post.
client.print("GET http://192.168.178.21/config/xmlapi/statechange.cgi?ise_id=15324&new_value=1005 HTTP/1.0");

Is there any way to monitor the GET Request in order to see what the arduino is send to the server?

Code:
#include <Wire.h>
#include <SPI.h>
#include <Ethernet.h>
#include <BMP085.h>

// I2C
BMP085 dps = BMP085();      // Digital Pressure Sensor
long Temperature = 0, Pressure = 0, Altitude = 58800;

// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = { 0x90, 0xA2, 0xDA, 0x0D, 0x2D, 0xF9 };
IPAddress server(192,168,178,21);

// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client;

void setup() {
 // Open serial communications and wait for port to open:
  Serial.begin(9600);
  // start the Ethernet connection:
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    // no point in carrying on, so do nothing forevermore:
    for(;;)
      ;
  }
  // give the Ethernet shield a second to initialize:
  delay(1000);
  Serial.println("connecting...");

  // if you get a connection, report back via serial:
  if (client.connect(server, 80)) {
    Serial.println("connected");
  }
  else {
    Serial.println("connection failed");
  }

// start I2C für BMP085
  Wire.begin();
  delay(1000);
  dps.init(MODE_ULTRA_HIGHRES, 58800, true);  // 588 meters, true = using meter units
 
}

void loop()
{
  // Get Altitude and air pressure
  dps.getPressure(&Pressure);
  dps.getAltitude(&Altitude);
  delay(2000);
 
  Serial.print("  Alt(cm):");
  Serial.print(Altitude);
  Serial.print("  Pressure(mbar):");
  Pressure = Pressure / 100;
  Serial.println(Pressure); 
   
  client.print("GET /config/xmlapi/statechange.cgi?ise_id=15324&new_value=");
  client.print(Pressure);
  client.println();

  }
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48556
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What goes in the GET request, and what you type in a browser window, are not the same thing.

The GET request implies an http protocol, so that does not belong in the request string. You have already connected to the server, so the server IP does not belong in the string.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi PaulS,

I think your post helps me to understand the problem. When i connect to this server with a webbrowser the address 192.168.178.21 will change into:

http://192.168.178.21/login.htm?sid=@OB0tsBSkxw@

And that's the problem, i guess. The request is added to this line. Is there any workaround for this problem?
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48556
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Is there any workaround for this problem?
It looks like a redirect to a login page is occurring. If that is indeed what is happening, then I don't know of a workaround.
Logged

Finland
Offline Offline
Sr. Member
****
Karma: 1
Posts: 270
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

below is the complete code. I have made a new sketch with the air pressure value only - just to keep it simple. It's still not working.
I get the correct reading / values at the serial interface - only the GET request is not working.

Quote
How have you verified that the request is being cut? Did you check the server logs or did you use a network monitor/sniffer?
if you have this complete line in the code, it becomes a hyperlink and opens at the webbrowser but everything was cut off behind & - see my first post.
client.print("GET http://192.168.178.21/config/xmlapi/statechange.cgi?ise_id=15324&new_value=1005 HTTP/1.0");

Is there any way to monitor the GET Request in order to see what the arduino is send to the server?

Yes, easiest is to check the server's access log. It should show the GET request that the Arduino has sent. Or if for some reason you can't read the access log, you can use a network monitor (i.e. a sniffer) such as wireshark. You can't run the network monitor on the Arduino but you may be able to run it on the web server (if you have required privileges) or on some other network element on the route (on a firewall, router etc).

But did you test the request using telnet as I suggested? Had you done that you would have immediately noticed that the server replies with redirect message (probably with http status code 302 or 303). As I said before and PaulS repeated, testing with the browsers is not the same as sending the request from the Arduino. The browser may do several things behind the curtain that you may not be aware of, such as handles the redirects.

« Last Edit: July 11, 2012, 04:35:48 pm by pekkaa » Logged

Pages: [1]   Go Up
Jump to: