Skip to content

Commit 92c8a3b

Browse files
committed
updates
1 parent 3f7de36 commit 92c8a3b

File tree

4 files changed

+87
-5
lines changed

4 files changed

+87
-5
lines changed

ArduinoEnergyLogger.ino

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ uint16_t post_error = 0;
107107
uint16_t http_error = 0;
108108
int http_code = 0;
109109

110+
uint16_t run_time = 0;
111+
110112
// timing
111113
uint8_t second = 0;
112114
//uint8_t minute;
@@ -222,6 +224,7 @@ void execEverySecond() {
222224
if (post_enable == 1) postCsv();
223225
else if (post_enable == 2) postInflux();
224226
second = 0;
227+
run_time++;
225228
}
226229
else {
227230
second++;

ct.ino

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ void extractCT() {
2424
}
2525
double I_RATIO = ct_calibration * ((SupplyVoltage / 1000.0) / (ADC_COUNTS));
2626
ct_current = I_RATIO * sqrt(sumI / Number_of_Samples);
27-
sumI = 0;
28-
27+
2928
ct_power = (ct_current * ct_voltage * ct_pf); // watts / power apparent
3029
}

post.ino

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ int postInflux() {
116116
postStr += ",inv_in_frequency=" + String(inv_in_frequency);
117117
postStr += ",inv_cell_voltage=" + String(inv_cell_voltage);
118118
postStr += ",inv_temperature=" + String(inv_temperature);
119-
//postStr += ",inv_flags=" + String(inv_flags);
119+
postStr += ",inv_flags=" + String(inv_flags);
120120

121121
postStr += "\n\n";
122122
int httpCode = http.POST(postStr);
@@ -149,3 +149,79 @@ int postInflux() {
149149
}
150150
return ret;
151151
}
152+
153+
int postJson() {
154+
int ret = 0;
155+
// http
156+
WiFiClient client;
157+
HTTPClient http;
158+
159+
if (WiFi.status() == WL_CONNECTED) {
160+
// https insecure
161+
//client.setFingerprint(fingerprint);
162+
//client.setInsecure();
163+
164+
// http://localhost:8086/write?db=home_energy
165+
166+
if (http_timeout > 0) http.setTimeout(http_timeout); // ms
167+
if (http.begin(client, api_url)) {
168+
http.addHeader("Content-Type", "application/json");
169+
170+
// home_energy,api_key=NIJCG7UI28O9CAYD ct_voltage=$P1,ct_power=$P2,pv_voltage=$P3,pv_power=$P4,battery_voltage=$P5,battery_charge=$P6,mppt_voltage=$P7,mppt_power=$P8,battery_temperature=$P9,mppt_temperature=$P10,dc_voltage=$P11,dc_power=$P12,input_voltage=$P13,input_fault_voltage=$P14,inv_voltage=$P15,inv_power=$P16,input_frequency=$P17,cell_voltage=$P18,inv_temperature=$P19" -database="home_energy"
171+
String postStr = "{api_key:" + String(api_key);
172+
173+
// json
174+
postStr += ",ct_voltage:" + String(ct_voltage);
175+
postStr += ",ct_power:" + String(ct_power);
176+
177+
postStr += ",pv_voltage:" + String(pv_voltage);
178+
postStr += ",pv_voltage:" + String(pv_power);
179+
postStr += ",battery_voltage:" + String(battery_voltage);
180+
postStr += ",battery_charge:" + String(battery_charge);
181+
postStr += ",mppt_voltage:" + String(mppt_voltage);
182+
postStr += ",mppt_power:" + String(mppt_power);
183+
postStr += ",battery_temperature:" + String(battery_temperature);
184+
postStr += ",mppt_temperature:" + String(mppt_temperature);
185+
postStr += ",dc_voltage:" + String(dc_voltage);
186+
postStr += ",dc_power:" + String(dc_power);
187+
188+
postStr += ",inv_in_voltage:" + String(inv_in_voltage);
189+
postStr += ",inv_in_fault_voltage:" + String(inv_in_fault_voltage);
190+
postStr += ",inv_out_voltage:" + String(inv_out_voltage);
191+
postStr += ",inv_out_power:" + String(inv_out_power); // watts
192+
postStr += ",inv_in_frequency:" + String(inv_in_frequency);
193+
postStr += ",inv_cell_voltage:" + String(inv_cell_voltage);
194+
postStr += ",inv_temperature:" + String(inv_temperature);
195+
postStr += ",inv_flags:" + String(inv_flags);
196+
197+
postStr += "}\n\n";
198+
int httpCode = http.POST(postStr);
199+
200+
if (httpCode == HTTP_CODE_OK) {
201+
//Serial.printf("[HTTP] POST... code: %d\n", httpCode);
202+
String payload = http.getString();
203+
//Serial.println("received payload:\n<<");
204+
//Serial.println(payload);
205+
//Serial.println(">>");
206+
207+
if (payload == "") {
208+
post_error++;
209+
ret = -1;
210+
}
211+
//Serial.print("error: ");
212+
//Serial.println(error);
213+
} else {
214+
//Serial.printf("[HTTP] POST... failed, error: %s\n", http.errorToString(httpCode).c_str());
215+
http_error++;
216+
http_code=httpCode;
217+
ret = -1;
218+
}
219+
http.end();
220+
}
221+
}
222+
else {
223+
wifi_error++;
224+
ret = -1;
225+
}
226+
return ret;
227+
}

webserver.ino

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,8 @@ void handleInfo() {
166166
body += F(" amps</td></tr><tr><td>CT Voltage</td><td>");
167167
body += String(ct_voltage);
168168
body += F(" volts</td></tr><tr><td>CT Power</td><td>");
169-
body += String(ct_power);
170-
body += F(" watts</td></tr><tr><td>CT Pf</td><td>");
169+
body += String(ct_power / 1000.0, 3);
170+
body += F(" kW</td></tr><tr><td>CT Pf</td><td>");
171171
body += String(ct_pf);
172172
body += F("</td></tr></tbody></table><br>");
173173

@@ -224,6 +224,8 @@ void handleInfo() {
224224
body += String(http_error);
225225
body += F("</td></tr><tr><td>Http Code</td><td>");
226226
body += String(http_code);
227+
body += F("</td></tr><tr><td>Run Time (minutes)</td><td>");
228+
body += String(run_time);
227229
body += F("</td></tr></tbody></table><br><br>");
228230

229231
body += F( "<a class=\"btn\" href=\"/reset\">Reset</a><br>" );
@@ -389,6 +391,8 @@ void handleReset() {
389391
modbus_error = 0;
390392
megatec_error = 0;
391393

394+
run_time = 0;
395+
392396
webServer.sendHeader("Location", "/", true);
393397
webServer.sendHeader("Cache-Control", "no-cache, no-store, must-revalidate");
394398
webServer.sendHeader("Pragma", "no-cache");

0 commit comments

Comments
 (0)