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!