Library for receiving data from fake inverter.

Revision:
0:e2b263279a61
Child:
1:1b1e78592710
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Inverter.cpp	Wed Mar 17 16:13:45 2021 +0000
@@ -0,0 +1,34 @@
+#include "Inverter.h"
+
+Inverter::Inverter(char* url, int port, EthernetInterface* ethIn)
+{
+    eth = ethIn;
+    eth->gethostbyname(url, &a);
+    a.set_port(port);
+}
+
+int Inverter::getPower()
+{
+    socket.open(eth);
+    socket.connect(a);
+
+    char sbuffer[] = "GET /solar_api/v1/GetInverterRealtimeData.cgi HTTP/1.1\r\nHost: int-sol-ref.herokuapp.com\r\n\r\n";
+    int scount = socket.send(sbuffer, sizeof sbuffer);
+
+    char rbuffer[500];
+    int rcount = socket.recv(rbuffer, sizeof rbuffer);
+
+    char *data = strstr(rbuffer, "{\"Body");
+    
+    StaticJsonDocument<128> doc;
+    DeserializationError error = deserializeJson(doc, data);
+
+    if (error) {
+        printf("deserializeJson() failed.\r\n");
+        return 0;
+    }
+
+    int power = doc["Body"]["Data"]["PAC"]["Value"];
+    socket.close();
+    return power;
+}
\ No newline at end of file