submit DDM100TC measurements

This commit is contained in:
King Kévin 2017-01-20 14:12:44 +01:00
parent 881fcc6061
commit 301ccbb72d
1 changed files with 14 additions and 0 deletions

14
main.c
View File

@ -566,7 +566,12 @@ void main(void)
"energy,meter=SDM120,phase=%u,type=active,direction=total value=%.3f\n",
"energy,meter=SDM120,phase=%u,type=reactive,direction=total value=%.3f\n"
};
uint32_t ddm100tc_value_energy = (uint32_t)((ddm100tc_pulses*(uint64_t)1000)/1600); // the meter has 1600 impulses/kWh (use 64-bit calculation to not overflow after 2684354 Wh)
const char* ddm100tc_string_energy = "energy,meter=DDM100TC value=%lu\n";
uint32_t ddm100tc_value_power = (uint32_t)(((rcc_ahb_frequency*(double)1.0)/((uint32_t)TIM_PSC(TIM(DDM100TC_TIMER))+1))*(3600*1000/1600)/ddm100tc_interval); // calculate with floating point for precision
const char* ddm100tc_string_power = "power,meter=DDM100TC value=%lu\n";
// calculate length for text to POST
char line[256] = {0}; // measurement line to send
size_t data_length = 0; /**< length of the data string to send */
for (pzem_meter = 0; pzem_meter<LENGTH(pzem_measurements); pzem_meter++) {
@ -601,6 +606,9 @@ void main(void)
}
}
}
data_length += snprintf(line, LENGTH(line), ddm100tc_string_energy, ddm100tc_value_energy); // get the size (hope no error is occurring)
data_length += snprintf(line, LENGTH(line), ddm100tc_string_power, ddm100tc_value_power); // get the size (hope no error is occurring)
// send HTTP POST request
if (!http_post_header("192.168.42.2", 8086, data_length)) { // send header
fprintf(stderr,"could not sent HTTP POST header\n");
@ -644,6 +652,12 @@ void main(void)
}
}
}
if (snprintf(line, LENGTH(line), ddm100tc_string_energy, ddm100tc_value_energy)>0) {
http_send((uint8_t*)line, 0); // don't care about the result
}
if (snprintf(line, LENGTH(line), ddm100tc_string_power, ddm100tc_value_power)>0) {
http_send((uint8_t*)line, 0); // don't care about the result
}
http_end(); // end HTTP request (don't care about the result)
gpio_set(GPIO(LED_SUBMIT_PORT), GPIO(LED_SUBMIT_PIN)); // switch off submit LED
printf("OK\n");