Hi
I have a Problem with my Arduino Project.
I am using an Arduino uno with a ethernet shield 2 attached to it.
My Goal is to do a Get Request to get the Powerdata from a Shelly Pro 3 EM (Energy Meter) and to do a Post Request for a Shelly Pro 3 («Contactor ») via LAN connection.
The IP of the Shelly devices are fixed (192.168.0.180/181).
In my Code i get the Data in a json string in return, if i want to print certain Data specifically it dosent work.
In my Code i have a static string to test that the json string to show that it works.
CODE :
#include <ArduinoJson.h>
#include <ArduinoJson.hpp>
#include <SPI.h>
#include <Ethernet.h>
//Gib deine MAC-Adresse deines Ethernetshield ein
byte mac[] = { 0xA8, 0x61, 0x0A, 0xAE, 0xF6, 0x68 };
EthernetClient client;
void setup() {
Ethernet.begin(mac);
Serial.begin(9600);
}
void loop() {
while (!Serial) {
// Warte auf Öffnung des Serial Monitors
}
if (client.connect("192.168.0.180", 80)) {
client.println("GET /rpc/EM.GetStatus?id=0 HTTP/1.1");
client.println("Host: 192.168.0.180");
client.println("Connection: close");
client.println();
} else {
Serial.println("Connection failed");
}
while (client.connected())
{
if (client.available())
{
DynamicJsonDocument doc(200);
String response = client.readStringUntil('\n');
char Leistung[] =
"{\"a_act_power\":-0.0,\"c_act_power\":100.9}";
DeserializationError error = deserializeJson(doc, Leistung);
double a_act_power = doc["a_act_power"];
double b_act_power = doc["b_act_power"];
double c_act_power = doc["c_act_power"];
double total_act_power = a_act_power + c_act_power;
Serial.println(c_act_power);
Serial.println(a_act_power);
Serial.println (response);
delay (5000);
}
}
client.stop();
}
REPONSE Serial Monitor
100.90
0.00
{"id":0,"a_current":0.041,"a_voltage":0.1,"a_act_power":-0.0,"a_aprt_power":0.0,"a_pf":1.00,"b_current":0.027,"b_voltage":0.1,"b_act_power":0.0,"b_aprt_power":0.0,"b_pf":1.00,"c_current":0.026,"c_voltage":233.5,"c_act_power":0.1,"c_aprt_power":6.1,"c_pf":1.00,"n_current":null,"total_current":0.094,"total_act_power":0.067,"total_aprt_power":6.140, "user_calibrated_phase":[],"errors": ["no_load"]}
100.90
0.00
HTTP/1.1 200 OK
100.90
0.00
Server: Mongoose/6.18
100.90
0.00
Content-Type: application/json
100.90
0.00
Access-Control-Allow-Origin: *
100.90
0.00
Access-Control-Allow-Headers: *
100.90
0.00
Content-Length: 400
100.90
0.00
Connection: close
100.90
0.00
100.90
0.00
Any Help ?