Page 1 of 1

Send {"status" : "OK"} response on HTTP request

Posted: Tuesday 17 January 2017 19:23
by pit34
Hello everybody,

I have a problem to understand how to send response to when Domoticz send order to my ESP8266.
Wiki is not very precise about this point and i need more details : https://www.domoticz.com/wiki/Domoticz_ ... s#Response

Situation :
I have installed an ESP12F in my bathroom's radiator. Firmware is entirely custom and written with Arduino IDE. All is working pretty well : I can control On/Off with a local switch (that send update state to Domoticz), control On/Off remotely with Domoticz, and send temperature value to Domoticz.

My problem is when Domoticz send On or Off command to my module, few second later i have an error "Error: Error opening url: http://***.***.***.***/On" on Domoticz log. I think there is a problem of response. My module must send response {"status" : "OK"} but i don't know how and in which format.

My code to receive Domoticz command (in which i want to include response function) :

Code: Select all

  WiFiClient client = server.available();
  if (client) {
      String req = client.readStringUntil('\r');      // Read the first line of the request
      if (req.indexOf("On") >=0) {      // If "On" is send by Domoticz in request, activate Pin_relay
          digitalWrite(Pin_relay, LOW);
          statut_radiateur = 1;
      }  
      if (req.indexOf("Off") >=0) {     // If "Off" is send by Domoticz in request, desactivate Pin_relay
          digitalWrite(Pin_relay, HIGH);
          statut_radiateur = 0;
      }
      client.flush();
  }
My code to send temperature and humidity data :

Code: Select all

  if (client.connect(domoticz_server,port)) {
    client.print("GET /json.htm?type=command&param=udevice&idx=5");
    client.print("&nvalue=0&svalue=");
    client.print(String(temperature));
    client.print(";");
    client.print(String(humidity));
    client.print(";0");
    client.println(" HTTP/1.1");
    client.print("Host: ");
    client.print(domoticz_server);
    client.print(":");
    client.println(port);
    client.println("User-Agent: Arduino-ethernet");
    client.println("Connection: close");
    client.println();
    client.stop();
  }
My code to send state On or Off when switched locally :

Code: Select all

  if (client.connect(domoticz_server,port)) {
    client.print("GET /json.htm?type=command&param=udevice&idx=3");
    client.print("&nvalue=1");
    client.println(" HTTP/1.1");
    client.print("Host: ");
    client.print(domoticz_server);
    client.print(":");
    client.println(port);
    client.println("User-Agent: Arduino-ethernet");
    client.println("Connection: close");
    client.println();
    client.stop();
  }
I don't know if i should use function like the 2 last, with HTTP/1.1 and other elements, or other form. I have tried lot of things but can't send response to Domoticz, and always have error "Error opening url: http://***.***.***.***/On" in Domoticz's log.

Thanks for your help and explanation ;), i really want to understand this point.

Re: Send {"status" : "OK"} response on HTTP request

Posted: Wednesday 26 April 2017 22:31
by keko37un
Hi Pit
a I have the same problem
do you resove it ?
thanks
peter