Page 1 of 1

ESP8266 does not upate Air Quality device

Posted: Saturday 15 April 2023 1:39
by peterbos
Hi all,

I made a virtual Air Quality device with index 120. I try to update it with a value from an ESP8266 but it does not update the device. I don't even know what Domoticz does with the data at all...

Code: Select all

#include <ESP8266WiFi.h>
#include "Types.h"

//=============================================================================

// SSID
const char* ssid = "*******************";

// wifi-password
const char* password = "************";

// Domoticz-server
const char* dzAddress = "192.168.1.162";
const int dzPort = 8080;

// index of sensor
const int dzIdx = 120;

//=============================================================================

WiFiClient client;
long lastMsg = 0;

void setup() {
  // Wifi instellen
  WiFi.mode(WIFI_STA);
  delay(10);
  WiFi.hostname("Vindriktning");
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
}

void loop() {
  long now = millis();
  if ((now - lastMsg > 10000) or (now < lastMsg)) {
    lastMsg = now;
    if (client.connect(dzAddress, dzPort)) {
      client.print(String("GET "));
      client.print("/json.htm?type=command&param=udevice&idx=120&nvalue=220");
      client.println(" HTTP/1.1");
      client.print("Host: ");
      client.print(dzAddress);
      client.print(":");
      client.println(dzPort);
      client.println("User-Agent: Arduino-ethernet");
      client.println("Connection: close");
      client.println();
      client.stop();
    }
  }
}
The ESP8266 gets IP number 192.168.1.158 when connected. On the security page I enabled 'Allow Basic-Auth authentication over plain HTTP (API only)' and set '192.168.1.*' as a trusted network. I also tried with a text device but that doesn't work also.

What am I missing?

Peter

Re: ESP8266 does not upate Air Quality device

Posted: Saturday 15 April 2023 13:57
by waltervl
If you send the same api call as an URL in a browser from a system in your network, does it work?

Re: ESP8266 does not upate Air Quality device

Posted: Saturday 15 April 2023 22:12
by peterbos
Hi Walter,

If I do an http API call it says the connection is reinitialized. With an https call the secured connection fails with fault PR_END_OF_FILE_ERROR. I did not do exact the same command, but used "http://192.168.1.162:8080/json.htm?type ... &range=day" which should normally work - and did work before I upgraded. This was the first time since the update I tried to use an ESP8266.

Peter

Re: ESP8266 does not upate Air Quality device

Posted: Saturday 15 April 2023 22:52
by waltervl
I meant if you send the following api call (as in your esp program) will it update the device?

Code: Select all

http://192.168.1.162:8080/json.htm?type=command&param=udevice&idx=120&nvalue=220
If not you should check the trusted network settings, or check the nvalue if it has the correct range.

Re: ESP8266 does not upate Air Quality device

Posted: Sunday 16 April 2023 10:07
by waltervl
Perhaps you need to change your HTTP message in the code from GET to POST...

Re: ESP8266 does not upate Air Quality device

Posted: Sunday 16 April 2023 22:39
by peterbos
waltervl wrote: Saturday 15 April 2023 22:52 I meant if you send the following api call (as in your esp program) will it update the device?

Code: Select all

http://192.168.1.162:8080/json.htm?type=command&param=udevice&idx=120&nvalue=220
If not you should check the trusted network settings, or check the nvalue if it has the correct range.
Hi Walter,

That doesn't work but it works if I use port number 443 and https instead of port number 8080 and http. That's weird because I have allowed Basic Authentication over plain HTTP. The ESP8266 has address 192.168.1.158 and the trusted network range is '192.168.1.*;127.0.0.*;localhost'. I do remember in my old setup I also had a IPv6 address in this range but I can't find how to specify that. May that be the problem?

Peter

Re: ESP8266 does not upate Air Quality device

Posted: Monday 17 April 2023 0:47
by waltervl
I think in latest 2023 beta there were some changes to loosen up some security rules. But I have not enough knowledge to understand if it would help in your case.

With the HTTP authorization setting in my opinion it should indeed behave the same has with HTTPS.

Re: ESP8266 does not upate Air Quality device

Posted: Monday 17 April 2023 9:53
by jvdz
peterbos wrote: Sunday 16 April 2023 22:39 That's weird because I have allowed Basic Authentication over plain HTTP.
Don't you require the userid:passord in the url when you need basic authentication?
something like:

Code: Select all

http://userid:[email protected]:8080/json.htm?type=command&param=udevice&idx=120&nvalue=220
Jos

Re: ESP8266 does not upate Air Quality device

Posted: Monday 17 April 2023 12:22
by thomasbaetge
Why not simply use MQTT for this?
The ESP8266 is well capable of that and this way you have a protokoll standard, instead of writing scripts for every device.

I have around 10 ESP devices in my network and they all operate on MQTT. No issues at all.

Re: ESP8266 does not upate Air Quality device

Posted: Monday 17 April 2023 23:36
by peterbos
I changed to MQTT yesterday. I now have a working Ikea Vindriktning device in Domoticz. But it still annoys me that it doesn't work like it used to ...

Peter

Re: ESP8266 does not upate Air Quality device

Posted: Tuesday 18 April 2023 10:41
by thomasbaetge
Great,

you may still look into your previous issue for sure, but I always find it a good idea, to use standard protocols.
Errorhandling and a possible later migration are so much easier.

I write a lot of different integrations and I never even consider using anything else but MQTT.

Re: ESP8266 does not upate Air Quality device

Posted: Tuesday 18 April 2023 13:40
by waltervl
waltervl wrote: Monday 17 April 2023 0:47 I think in latest 2023 beta there were some changes to loosen up some security rules. But I have not enough knowledge to understand if it would help in your case.

With the HTTP authorization setting in my opinion it should indeed behave the same has with HTTPS.
Could be fixed in latest beta already with PR https://github.com/domoticz/domoticz/pull/5625