metbosch / homebridge-http-temperature

HomeBridge HomeKit Plugin for HTTP temperature endpoints
https://www.npmjs.com/package/homebridge-http-temperature
Apache License 2.0
33 stars 18 forks source link

HTTP bad response ECONNREFUSED #17

Closed silversurfer147 closed 5 years ago

silversurfer147 commented 6 years ago

Hi, I have a problem to get data to homebridge. I still get messages HTTP bad response. I don't know where is a problem, could somene help me? I tried everything. Here is part of my code from arduino (which works without problem)

EthernetClient client = server.available();
  if(client){
    Serial.println("new client");
    boolean currentLineIsBlank = true;
    while(client.connected()){
      if(client.available()){
        char c = client.read();
        Serial.write(c);

        if(c == '\n' && currentLineIsBlank){
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: application/json");
          client.println("Connection: close");  
          client.println("Refresh: 5");  // refresh the page automatically every 5 sec
          client.println();
          client.println(F("{"));
          client.print(F("\t\"temperature\": "));
          client.println(temperature);
          client.println(F("}"));

          break;
        }
        if (c == '\n') {
          // you're starting a new line
          currentLineIsBlank = true;
        } else if (c != '\r') {
          // you've gotten a character on the current line
          currentLineIsBlank = false;
        }
      }
    }
     delay(1);
    // close the connection:
    client.stop();
"accessory": "HttpTemperature",
        "name": "Outside Temperature",
        "url": "http://192.168.1.170",
        "http_method": "GET",
        "field_name": "temperature"
metbosch commented 6 years ago

Can you try to upload the following code into your Ardunio?

  if(client){
    Serial.println("new client");
    boolean currentLineIsBlank = true;
    while(client.connected()){
      if(client.available()){
        char c = client.read();
        Serial.write(c);

        if(c == '\n' && currentLineIsBlank){
          client.print("{\"temperature\": ");
          client.print(temperature);
          client.println("}");
          break;
        }
        if (c == '\n') {
          // you're starting a new line
          currentLineIsBlank = true;
        } else if (c != '\r') {
          // you've gotten a character on the current line
          currentLineIsBlank = false;
        }
      }
    }
     delay(1);
    // close the connection:
    client.stop();

Also, can you connect to the arduino with your browser and check the response?

metbosch commented 6 years ago

@silversurfer147 Is it working?

metbosch commented 5 years ago

Closing the issue because it seems a problem related to the end-point, not the plugin.