Scott Vincent / Inverter
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Inverter.cpp Source File

Inverter.cpp

00001 #include "Inverter.h"
00002 
00003 Inverter::Inverter(char* url, int port, EthernetInterface* ethIn)
00004 {
00005     eth = ethIn;
00006     connect(url,port);
00007 }
00008 
00009 void Inverter::connect(char* url, int port){
00010     eth->gethostbyname(url, &a);
00011     a.set_port(port);
00012 }
00013 
00014 int Inverter::getPower()
00015 {
00016     socket.open(eth);
00017     socket.connect(a);
00018 
00019     char sbuffer[] = "GET /solar_api/v1/GetInverterRealtimeData.cgi HTTP/1.1\r\nHost: int-sol-ref.herokuapp.com\r\n\r\n";
00020     int scount = socket.send(sbuffer, sizeof sbuffer);
00021 
00022     char rbuffer[500];
00023     int rcount = socket.recv(rbuffer, sizeof rbuffer);
00024 
00025     char *data = strstr(rbuffer, "{\"Body");
00026     
00027     StaticJsonDocument<128> doc;
00028     DeserializationError error = deserializeJson(doc, data);
00029 
00030     if (error) {
00031         printf("deserializeJson() failed.\r\n");
00032         return 0;
00033     }
00034 
00035     int power = doc["Body"]["Data"]["PAC"]["Value"];
00036     socket.close();
00037     return power;
00038 }