poprawka do odczytywania z orno

This commit is contained in:
ms
2026-02-15 23:08:33 +01:00
parent 7220d3e750
commit 3078bbcf3f

View File

@@ -348,17 +348,58 @@ int influx_send_orno_batch(s_voltage *v, int v_ok, s_current *i, int i_ok,
char batch[1024]; char batch[1024];
int offset = 0; int offset = 0;
/* Line protocol format: measurement,tag=value field=value ... */ /* New format: group by phase with U, I, P, W fields */
/* New format groups data by phase with U, I, P, W fields */ /* For each phase, build field list based on available data */
// Phase L1
if (v_ok || i_ok || p_ok || w_ok) {
char fields[256] = "";
int foff = 0;
if (v_ok) foff += snprintf(fields + foff, sizeof(fields) - foff, "U=%.2f,", v->U1);
if (i_ok) foff += snprintf(fields + foff, sizeof(fields) - foff, "I=%.2f,", i->I1);
if (p_ok) foff += snprintf(fields + foff, sizeof(fields) - foff, "P=%.2f,", p->P1);
if (w_ok) foff += snprintf(fields + foff, sizeof(fields) - foff, "W=%.2f,", w->W1);
if (foff > 0) fields[foff - 1] = '\0'; // remove trailing comma
offset += snprintf(batch + offset, sizeof(batch) - offset, offset += snprintf(batch + offset, sizeof(batch) - offset,
"energydb,device=orno,phase=L1 U=%.2f,I=%.2f,P=%.2f,W=%.2f\n" "energydb,device=orno,phase=L1 %s\n", fields);
"energydb,device=orno,phase=L2 U=%.2f,I=%.2f,P=%.2f,W=%.2f\n" }
"energydb,device=orno,phase=L3 U=%.2f,I=%.2f,P=%.2f,W=%.2f\n"
"energydb,device=orno,phase=total P=%.2f,W=%.2f\n", // Phase L2
v->U1, i->I1, p->P1, w->W1, if (v_ok || i_ok || p_ok || w_ok) {
v->U2, i->I2, p->P2, w->W2, char fields[256] = "";
v->U3, i->I3, p->P3, w->W3, int foff = 0;
p->P_Tot, w->W_Tot); if (v_ok) foff += snprintf(fields + foff, sizeof(fields) - foff, "U=%.2f,", v->U2);
if (i_ok) foff += snprintf(fields + foff, sizeof(fields) - foff, "I=%.2f,", i->I2);
if (p_ok) foff += snprintf(fields + foff, sizeof(fields) - foff, "P=%.2f,", p->P2);
if (w_ok) foff += snprintf(fields + foff, sizeof(fields) - foff, "W=%.2f,", w->W2);
if (foff > 0) fields[foff - 1] = '\0';
offset += snprintf(batch + offset, sizeof(batch) - offset,
"energydb,device=orno,phase=L2 %s\n", fields);
}
// Phase L3
if (v_ok || i_ok || p_ok || w_ok) {
char fields[256] = "";
int foff = 0;
if (v_ok) foff += snprintf(fields + foff, sizeof(fields) - foff, "U=%.2f,", v->U3);
if (i_ok) foff += snprintf(fields + foff, sizeof(fields) - foff, "I=%.2f,", i->I3);
if (p_ok) foff += snprintf(fields + foff, sizeof(fields) - foff, "P=%.2f,", p->P3);
if (w_ok) foff += snprintf(fields + foff, sizeof(fields) - foff, "W=%.2f,", w->W3);
if (foff > 0) fields[foff - 1] = '\0';
offset += snprintf(batch + offset, sizeof(batch) - offset,
"energydb,device=orno,phase=L3 %s\n", fields);
}
// Phase total
if (p_ok || w_ok) {
char fields[256] = "";
int foff = 0;
if (p_ok) foff += snprintf(fields + foff, sizeof(fields) - foff, "P=%.2f,", p->P_Tot);
if (w_ok) foff += snprintf(fields + foff, sizeof(fields) - foff, "W=%.2f,", w->W_Tot);
if (foff > 0) fields[foff - 1] = '\0';
offset += snprintf(batch + offset, sizeof(batch) - offset,
"energydb,device=orno,phase=total %s\n", fields);
}
if (f_ok) { if (f_ok) {
offset += snprintf(batch + offset, sizeof(batch) - offset, offset += snprintf(batch + offset, sizeof(batch) - offset,