Announcement

Collapse
No announcement yet.

Arduino / Homeseer / tenHsServer

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Arduino / Homeseer / tenHsServer

    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 <!-- m -->http://192.168.1.140/tenHsServer/tenHsS ... vice&d=v90<!-- m -->

    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.

    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 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 <!-- m -->http://www.google.com<!-- m -->. 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

    #2
    I have done some further troubleshooting and found some strange behavior.

    My Sketch is working and returns the expected HTML page but ONLY if Homeseer debug is set to 512 ???

    I tried to introduce delays but no luck what so ever. Behavior is 100% reproducible.

    Here's the sketch I built, it straight forward and will do a GET every time the arduino starts.

    Any suggestion are welcome!

    Code:
     
    #include <SPI.H>
    #include <ETHERNET.H>
    //Ethernet shield
        // Enter a MAC address for your controller below.
        byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
        // Set the static IP address to use if the DHCP fails to assign
        IPAddress ip(192,168,1,14);
        // the DNS server:
        IPAddress dnServer(192,168,1,1);
        // the router's gateway address:
        IPAddress gateway(192,168,1,1);
        // the subnet:
        IPAddress subnet(255,255,255,0);
        // Initialize the Ethernet client library
        EthernetClient client;
    // Homeseer 
        //IPAddress HSserver(192,168,1,140);
        char HSserver[] ="HS-1000";
        int HSport = 80;
    void setup() {
      // Open serial communications and wait for port to open:
        Serial.begin(9600);
      // start the Ethernet connection:
        Serial.println("Initializing Ethernet Shield");
        if (Ethernet.begin(mac) == 0) {
          Serial.println("Failed to configure Ethernet using DHCP, will use static IP instead");
          // If DHCP fails use static config
          Ethernet.begin(mac, ip, dnServer, gateway, subnet);
          }
        Serial.print ("Initialized using IP address ");
        Serial.println(Ethernet.localIP());
        // give the Ethernet shield a second to initialize:
        delay(1000);
        httpRequest();
    }
     
    void loop(){
    }
     
    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.println();      // if removed communication will fail ???
        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);
       }
    }

    Comment


      #3
      Doesn't sound like it (since you say it works in debug mode), but is it possible your firewall is somehow getting in the way?

      Comment


        #4
        Nope, had that turned off for development, seen that, been there, forgot about it once to often

        Comment


          #5
          SOLVED

          Thanks to a fellow board member (Robert Hekkers) at http://www.domoticaforum.eu the problem has been identified and solved.

          Short version of his findings:
          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). This seems to not work well with Homeseer.
          When using :
          Code:
          client.print("blabla\r\n");
          instead of:
          Code:
          client.println("blabla");
          it works as a charm.

          Full details can be found here : http://www.domoticaforum.eu/viewtopic.php?f=63&t=9603

          Thanks for all the help, kudos to Robert.

          Francois

          Comment

          Working...
          X