diff --git a/main.c b/main.c index 961097b..5968e2e 100644 --- a/main.c +++ b/main.c @@ -78,6 +78,16 @@ volatile bool rtc_internal_tick_flag = false; /**< flag set when internal RTC ti volatile uint32_t ddm100tc_interval = 0; /**< last time interval between pulses **/ /** @} */ +/** @defgroup main_database influxDB information to submit measurements + * @{ + */ +#define DATABASE_HOST "opi" /**< influxDB host (or IP) */ +#define DATABASE_PORT 8086 /**< influxDB port for HTTP API */ +#define DATABASE_USER "meter" /**< name of user with permission to write to database */ +#define DATABASE_PASSWORD "password" /**< password of user with permission to write to database */ +#define DATABASE_NAME "spark_abacus" /**< name of database where to write the measurement values to */ +/** @} */ + int _write(int file, char *ptr, int len) { int i; // how much data has been sent @@ -218,9 +228,13 @@ static bool http_post_header(char* host, uint16_t port, size_t length) fprintf(stderr,"TCP connection failed\n"); return false; } - if (!http_send((uint8_t*)"POST /write?db=spark_abacus HTTP/1.1\r\n", 0)) { // send data + if (snprintf(http_line, LENGTH(http_line), "POST /write?db=%s&u=%s&p=%s HTTP/1.1\r\n", DATABASE_NAME, DATABASE_USER, DATABASE_PASSWORD)<=0) { + fprintf(stderr,"could not create POST line\n"); return false; } + if (!http_send((uint8_t*)http_line, 0)) { + fprintf(stderr,"could not send POST line\n"); + } if (snprintf(http_line, LENGTH(http_line), "Content-Length: %u\r\n", length)<0) { // set content length (for measurements) fprintf(stderr,"could not create line\n"); return false; @@ -614,7 +628,7 @@ void main(void) 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 + if (!http_post_header(DATABASE_HOST, DATABASE_PORT, data_length)) { // send header fprintf(stderr,"could not sent HTTP POST header\n"); } else { // send PZEM-004T values