Http get request with D1

Dear members,

I need to get information from energy monitoring system and use the data for export/import of power. This will help me limit the energy I am exporting to the grid.
The meter is 3 phase, I need the power import and export from one of the phases.
I want to use this and calculate how many solar panels to include in the house, without exporting to the grid. Electrical part is my stuff, but with the http get - I am lost.
I am trying about 2 days to get the data from the server, and I am just not good enough to do it.
I need some help.
First I had huge problems with the libraries, finally everything is working, simple examples are working. I don't know where I am wrong.
This is example in Python, of what it should be (from the producer of the energy meter):

import requests
 
url = "http://ip/monitorjson" 
 
headers={'Authorization':'Basic YWRtaW46YWRtaW4='}
 
response = requests.request("get", url, headers=headers)
 
print(response.text)

this should be the reply:

{"status":"succeed","data":[234.00,6.235,1423,1222.67,0.00]}
voltage:234 V
current:6.25 A
active power:1433 W
import energy:1222.67 Kwh
export energy:0 Kwh

and this is what I am trying to run:

#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h>

#include <ESP8266HTTPClient.h>
#include <WiFiClient.h>
ESP8266WiFiMulti WiFiMulti;

void setup() {

  Serial.begin(115200);
  // Serial.setDebugOutput(true);
 Serial.println();
  Serial.println();
  Serial.println();

  for (uint8_t t = 4; t > 0; t--) {
    Serial.printf("[SETUP] WAIT %d...\n", t);
    Serial.flush();
    delay(1000);
  }

  WiFi.mode(WIFI_STA);
  WiFiMulti.addAP("My network", "My Password");

}

void loop() {
  // wait for WiFi connection
  if ((WiFiMulti.run() == WL_CONNECTED)) {

    WiFiClient client;

    HTTPClient http;

    Serial.print("[HTTP] begin...\n");
    // configure traged server and url


    
    http.begin(client, "https://192.168.1.8/monitorjson");
    http.setAuthorization ("My Username","My password for this website");



    Serial.print("[HTTP] GET...\n");
    // start connection and send HTTP header
    int httpCode = http.GET();

    // httpCode will be negative on error
    if (httpCode > 0) {
      // HTTP header has been send and Server response header has been handled
      Serial.printf("[HTTP] GET... code: %d\n", httpCode);

      // file found at server
      if (httpCode == HTTP_CODE_OK) {
        String payload = http.getString();
        Serial.println(payload);
      }
    } else {
      Serial.print (httpCode);// I put this one just to see what I have in return
      Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
    }

    http.end();
  }

  delay(10000);
}

I read so many threads, finally they start to confuse me more than helping.

I hope someone here have time to explain me my mistake.

Thanks!

what do you see in the Serial monitor?

This is what I see. -1 is what I add,as I had no idea for the answer of the server.

Thank you

Your python is using http, but your Arduino code has https - is that correct?

First I try with http, no difference. I change it recently, trying to see if it helps, but it doesn't

I don't see anything in your arduino code to replace the above. Unless it's this line?

Honestly I have never used Python in my life. I am not sure, but I think Authorization in my code replaces only the first part of what is inside the brackets, but for the second part, I don't know how to implement in Arduino.

The python version does not seem to include a user name and password, only some authorisation token. So what user name and password are you giving in the Arduino version (I mean don't give them away, just tell us what the are the user name and password from?)

Maybe try

http.setAuthorization ("YWRtaW46YWRtaW4=");

Do you have a link to the manufacturer's site?

Wildbill: This is link from the site and their representation.

PaulRB: What I am posting for authorization are my credentials for login the website. I don't know if this is right.

But those credentials don't seem to be used in the python example, only that token YWRtaW46YWRtaW4=. Is that the same as your password? (I suspect not.)

Did you try my suggestion from post #8 yet?

I just tried both ways:

Basic YWRtaW46YWRtaW4=

and also just with : ```
YWRtaW46YWRtaW4=

Same result


This is interesting. If I paste the http and try to load, it does not work.
But It should,right?

When you did the step to connect to wifi, what IP address did the meter get - I think you're using the one from their example code, which is probably not correct.

Dang! Should have seen this immediately:

You are using an HTTPS URL but you are not using an HTTPS client, only an HTTP client.

Have a look at this example.

I just tested it with all dynamic IP adresses on my network.
Didn't help

The URL in the example of the supplier is not HTTPS, It is HTTP, I tested it both ways

Did you do the initial step to connect it to your wifi?

Can you see the meter in your router's admin page list of IPs?

I tested all IP's on my network.
Also I found on the customer's side of the webpage some kind of token. I think this is unique for the users and the one in the Python example is not for all users.
However no success yet