ARduino / Homeseer / tenHsServer

All about Arduino, Jeenode and other Clones (hardware & Software)

Moderator: Mdamen

Post Reply
Francois
Member
Member
Posts: 255
Joined: Mon Apr 21, 2008 3:16 pm
Location: Netherlands

ARduino / Homeseer / tenHsServer

Post by Francois »

I have the following setup:

- Arduino + Ethernet Shield
- Homeseer 2 + tenHsServer installed

and like to use the Arduino to control devices in Homeseer by sending HTTP requests from the arduino to Homeseer in a format like http://192.168.1.140/tenHsServer/tenHsS ... vice&d=v90

For some reason I cannot get this to work from the arduino, Homeseer does not understand the GET I am sending and does not reply.

Code: Select all

[i]Serial.print   ("Connecting to Homeseer on ");  // if you get a connection, report back via serial:
  Serial.println (HSserver);
  if (client.connect(HSserver, HSport)) {
    Serial.print   ("Succesfully connected to Homeseer on port ");
    Serial.println (HSport);

     // send the HTTP request:
     client.println("GET /tenHsServer/tenHsServer.aspx?t=ab&f=toggleDevice&d=v90 HTTP/1.1");
     client.println("Host: 192.168.1.140");
     client.println("Connection: close");
     client.println();[/i]
I am able to establish a connection from the arduino to homeseer (confirmed in WireShark traces), the payload looks the same but for some reason when using a normal browser the URL works but from the arduino it doesn't. The device status is not changed and no feedback from tenHsServer is provided

The above sketch is part of an example provided on the arduino website and originally points to http://www.google.com. When using it in it original format it works and returns content from the google website.

Has anybody done this before? If so can you point me in the right direction?

Can someone confirm this (using aspx) should work?

Your help is much appreciated!
Francois
Digit
Global Moderator
Global Moderator
Posts: 3388
Joined: Sat Mar 25, 2006 10:23 am
Location: Netherlands
Contact:

Re: ARduino / Homeseer / tenHsServer

Post by Digit »

Check the headers the browser is sending and add those too, like Accept, Referer, User-Agent.
When it doesn't work, I always start with a 'full copy' of the headers sent by the browser, make it work and then strip the headers until it stops working.
That might help.

BTW, Fiddler is a great tool for analyzing this kind of stuff.
Francois
Member
Member
Posts: 255
Joined: Mon Apr 21, 2008 3:16 pm
Location: Netherlands

Re: ARduino / Homeseer / tenHsServer

Post by Francois »

Robert,

I have checked the headers and actually have recreated the headers like the ones that are generated by Internet Explorer. No luck there. I am using wireshark to trace the traffic from and to the webserver, if remember correctly fiddler will not show this kind of traffic. (or am I mistaken?)

Did some more trouble shooting this evening and had some positive results. It looks like the problem is related to an existing connecting to Homeseer.

Code: Select all

[u]If the log shows a message about the existing connection, the GET will fail:[/u]
 [size=85]2014-4-8_06:55:21:2179: Web Server ex0 Exception: An existing connection was forcibly closed by the remote host"
2014-4-8_06:55:31:3968:   
2014-4-8_06:55:31:3968: =========================================================
2014-4-8_06:55:31:3968: Read Start: Data Arrival #53
2014-4-8_06:55:31:3968: Read Start: From IP=192.168.1.15
2014-4-8_06:55:31:3968: Read Start: Data Length=1
2014-4-8_06:55:31:3968: Read Start: Data (Up to 50)=
2014-4-8_06:55:31:3968: =========================================================
2014-4-8_06:55:31:3968: Read: Getting headers.
2014-4-8_06:55:31:3968: Read_Headers: Getting Headers
2014-4-8_06:55:31:3968: ------------------
2014-4-8_06:55:31:3968:   Read: EXIT (1)
2014-4-8_06:55:31:3968: ------------------[/size]

[u]A successful attempt will not start with the connection error:[/u]
[size=85]2014-4-8_06:55:31:4124:   
2014-4-8_06:55:31:4124: =========================================================
2014-4-8_06:55:31:4124: Read Start: Data Arrival #53
2014-4-8_06:55:31:4124: Read Start: From IP=192.168.1.15
2014-4-8_06:55:31:4124: Read Start: Data Length=75
2014-4-8_06:55:31:4124: Read Start: Data (Up to 50)=
GET /tenHsServer/tenHsServer.aspx?t=ab&f=toggleDe
2014-4-8_06:55:31:4124: =========================================================
2014-4-8_06:55:31:4124: Read: Getting headers.
2014-4-8_06:55:31:4124: Read_Headers: Getting Headers
2014-4-8_06:55:31:4124: Read_Headers: Processing...|||
GET /tenHsServer/tenHsServer.aspx?t=ab&f=toggleDevice&d=v90 HTTP/1.1|||
2014-4-8_06:55:31:4124: Read_Headers: Processing...||||||
2014-4-8_06:55:31:4124: Read_Headers: No Data[/size]
I will try to change the sketch in a way so it will first close the connection and then reopen it. Hope that works.

Will post the results
Francois
Digit
Global Moderator
Global Moderator
Posts: 3388
Joined: Sat Mar 25, 2006 10:23 am
Location: Netherlands
Contact:

Re: ARduino / Homeseer / tenHsServer

Post by Digit »

Fiddler is great for this! Try it, I'm sure you'll love it.
All kinds of views (text, hex, raw, whatever), tools, statistics, etc.
Should be in anyone's toolbox if you ask me :lol:
fiddler.PNG
fiddler.PNG (146.89 KiB) Viewed 23395 times
Digit
Global Moderator
Global Moderator
Posts: 3388
Joined: Sat Mar 25, 2006 10:23 am
Location: Netherlands
Contact:

Re: ARduino / Homeseer / tenHsServer

Post by Digit »

BTW,
I saw the exception and maybe this is an idea:
your Ethernet client in the sketch should connect to the server just before it needs to start sending, not earlier. (as in: probably not in the setup() routine)

I know the Ethernet example does that, but that's just a single call and game over - not what you want I guess
Last edited by Digit on Tue Apr 08, 2014 10:03 pm, edited 1 time in total.
Reason: Added additional remark
Francois
Member
Member
Posts: 255
Joined: Mon Apr 21, 2008 3:16 pm
Location: Netherlands

Re: ARduino / Homeseer / tenHsServer

Post by Francois »

Well, I noticed something really funny. My sketch is working and returns the webpage from tenHsServer, but ONLY if Homeseer debugging is switched on.

Situation is 100% repeatable, debug on = working, debug off = no reply

Code: Select all

void httpRequest()  {
  Serial.print   ("Connecting to Homeseer on ");  // if you get a connection, report back via serial:
  Serial.println (HSserver);
  if (client.connect(HSserver,HSport)) {
    Serial.print   ("Succesfully connected to Homeseer on port ");
    Serial.println (HSport);
    client.flush();
    client.println();
    client.println("GET /tenHsServer/tenHsServer.aspx?t=ab&f=toggleDevice&d=v90 HTTP/1.1");
    client.println();
    client.println();
    client.println("Connection: close");
  } 
  else {                            // you didn't get a connection to the server:
    Serial.println("Connection to Homeseer failed");
  }
  while (!client.available()) {
//    Serial.print (".");
  }
  while (client.available()) {
     char c = client.read();
     Serial.print(c);
   }
}
I tried to introduce some delays before I send the GET, but no luck.
Francois
Francois
Member
Member
Posts: 255
Joined: Mon Apr 21, 2008 3:16 pm
Location: Netherlands

Re: ARduino / Homeseer / tenHsServer

Post by Francois »

Tried to insert delays , used a different board+ethernet shield. Situation remains the same. It only works if Debug is set to Server_Activity (512) for Homeseer

I am lost :)
Francois
Digit
Global Moderator
Global Moderator
Posts: 3388
Joined: Sat Mar 25, 2006 10:23 am
Location: Netherlands
Contact:

Re: ARduino / Homeseer / tenHsServer

Post by Digit »

You're not lost, this is the point where things become interesting! :wink:
BTW, did you test your sketch with something else than tenHsServer, e.g. just a simple hello world html file?
mhn
Member
Member
Posts: 399
Joined: Tue Jul 21, 2009 9:27 pm
Location: Denmark

Re: ARduino / Homeseer / tenHsServer

Post by mhn »

I remember having some very strang behavior when playing with Arduino and http. I think I used Rover on Homeseer.

The first packages always went to the gateway hence I had to setup the server IP as gateway to make it work.

Regards
Morten
Francois
Member
Member
Posts: 255
Joined: Mon Apr 21, 2008 3:16 pm
Location: Netherlands

Re: ARduino / Homeseer / tenHsServer

Post by Francois »

Robert, I did not yet. But will certainly try that tonight. Like to understand if debug changes the behavior or maybe affects timing of things. BTW. I am still trying to figure out how to use Fiddler in this case. I have Fiddler installed on the homeseer server and it see all outgoing connections to for example a webcam. How do I get it to monitor incoming requests to the HS webserver? (Installing fiddler on the arduino unfortunately is no option :( )

Morten, unfortunately changing the gateway is not really an option, the interface is provisioned through DHCP (reservation) and the GW is assigned automatically. Looking at the behavior (works when debug is on, stops when debug is off) I do not expect this to be related.
Francois
Digit
Global Moderator
Global Moderator
Posts: 3388
Joined: Sat Mar 25, 2006 10:23 am
Location: Netherlands
Contact:

Re: ARduino / Homeseer / tenHsServer

Post by Digit »

All kinds of filters available:
fiddler2.PNG
fiddler2.PNG (34.97 KiB) Viewed 23305 times
Digit
Global Moderator
Global Moderator
Posts: 3388
Joined: Sat Mar 25, 2006 10:23 am
Location: Netherlands
Contact:

Re: ARduino / Homeseer / tenHsServer

Post by Digit »

Fixed.

Francois sent me a sketch this evening and I tried to get it running on a spare Arduino Ethernet.
No luck.
Sending all the headers that a browser would send didn't help either.
Switched web-server to one of my internal ones, instant success.
Everything looked great in Fiddler though.. ?

OK, lets dig some deeper with Wireshark.
Ah, Arduino's "client.println()" uses 3 TCP packets to send a header line: one for the header text, one for the carriage return (0x0d) and one for the line feed (0x0a).
That's a bit odd... although it should not matter actually. But maybe it does, I mean, it's Homeseer we're talking to... :lol:

So I changed the sketch and used

Code: Select all

client.print("blabla\r\n");
instead of

Code: Select all

client.println("blabla");
The result was now that just 1 single packet was sent instead of 3.
Bingo, HTTP/1.1 200 OK

Working example attached which GETs the test.aspx that can be found in the C:\Program Files (x86)\HomeSeer HS2\html\ directory.
IP's and port need to be adjusted to your setup.
Attachments
HS_Web_Client.zip
(994 Bytes) Downloaded 778 times
Francois
Member
Member
Posts: 255
Joined: Mon Apr 21, 2008 3:16 pm
Location: Netherlands

Re: ARduino / Homeseer / tenHsServer

Post by Francois »

Robert,

very very nice! Yes it works. I was working on an alternative using Gerard's code for an HSTouch based interface and noticed he used:

client.print(HsCommand);
client.write(0x02);

And I was wondering why. I have not done a full trace but could this in anyway be related?

Again, KUDOS to Robert!!
Francois
Digit
Global Moderator
Global Moderator
Posts: 3388
Joined: Sat Mar 25, 2006 10:23 am
Location: Netherlands
Contact:

Re: ARduino / Homeseer / tenHsServer

Post by Digit »

Fixing things that don't work as expected is a hobby of mine, I just can't resist finding out what's going wrong :)
I think it's done that way because the HsCommand is a string and the 2nd value isn't, so this is easier to do I guess?
Have fun with your Arduino Webclient!
Post Reply

Return to “Raspberry, Arduino, Cubietruck and other clones Forum”