Timeout when requesting data with GET request from Homewizard

Hi All,

I'm trying to get data from the HomeWizard P1 monitor. I'm able to read the data by visiting
http://{IP_ADDRESS}/api/v1/data as noted in the documentation of HomeWizard (Getting Started — HomeWizard Energy API documentation)

So i'm connecting to HomeWizard using the following code;

if (!HTTPclient.connect("192.168.10.208", 80)) {
        Serial.println(F("Connection failed"));
        return;
      }
      Serial.println(F("Connected!"));

HTTPclient.println(F("GET /api/v1/data HTTP/1.1"));
      HTTPclient.println(F("Host: 192.168.10.208"));
      HTTPclient.println(F("Connection: keep-alive"));
      delay(1000);
      if (HTTPclient.println() == 0) {
        Serial.println(HTTPclient.println());
        Serial.println(F("Failed to send request"));
        HTTPclient.stop();
        return;
      }

      // Check HTTP response
      char status[32] = {0};
      HTTPclient.readBytesUntil('\r', status, sizeof(status));
      if (strcmp(status + 9, "200 OK") != 0) {
        Serial.print(F("Unexpected response: "));
        Serial.println(status);
        HTTPclient.stop();
        return;
      }

      // Skip HTTP headers
      char endOfHeaders[] = "\r\n\r\n";
      if (!HTTPclient.find(endOfHeaders)) {
        Serial.println(F("Invalid response"));
        HTTPclient.stop();
        return;
      }


      DynamicJsonDocument doc(2048);

      // Parse JSON object
      DeserializationError error = deserializeJson(doc, HTTPclient);
      if (error) {
        Serial.print(F("deserializeJson() failed: "));
        Serial.println(error.f_str());
        HTTPclient.stop();
        return;
      }
      HTTPclient.stop();

Then i'm able to retrieve data. BUT mostly only once or twice, then my HomeWizard is unreachable. (pinging to the device stops working, and even the ring on the HomeWizard P1 monitor turns from green to red)
Sometimes i'm briefly getting a 408 timeout, and then it keeps saying "Connection failed" (because the device is offline)

After reconnecting it to my netwerk, or reconnecting it to my P1 port is directly starts working again. Until i request data with my Arduino Mega again over HTTP GET.

However when i request data with HTTP GET using postman, or just by loading the webpage itself it remains online, and there is no problem.

Then i build a PHP script to retrieve the JSON data from that page at a face pace to check for stability. This also works like a charm.

So it seems that something on the Arduino is causing the HomeWizard to crash.

Can someone please assist me in this?

Why "keep-alive"? You'll close the connection after every request so you should tell the server.

I'm sure this delay() doesn't help.

This means that your HomeWizard isn't very resilient. Of course you can fix your code not to do the most obvious errors but the software of your HomeWizard should be fixed too.

Because your browser does HTTP correctly, I guess.

That probably means PHP does HTTP correctly too.

Yes, your code. As you're hiding most of it we're not able to help you further. Post your complete code if you want us to help.

You should also tell us what board you're using as it's obviously no UNO (which we always expect if a poster forgets to mention the board).

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.