add influx driver

This commit is contained in:
Wolfgang Hottgenroth 2019-10-05 23:49:06 +02:00
parent 4b5ba236c5
commit 15e2f831b8
Signed by: wn
GPG Key ID: 6C1E5E531E0D5D7F
3 changed files with 34 additions and 2 deletions

View File

@ -1,9 +1,9 @@
CC=gcc
CFLAGS=-Wall
LDFLAGS=-lwiringPi
LDFLAGS=-lwiringPi -lcurl
counter: counter.o LS7366R.o
counter: counter.o LS7366R.o influx.o
$(CC) -o $@ $(LDFLAGS) $^
.c.o:

25
src/influx.c Normal file
View File

@ -0,0 +1,25 @@
#include <stdint.h>
#include <stdio.h>
#include <curl/curl.h>
const char INFLUXURL[] = "http://172.16.3.15:8086/write?db=smarthome2&precision=ms";
void influxSendFrequency(double f) {
char buffer[256];
sprintf(buffer, "mainsfrequency freq=%f", f);
CURL *curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, INFLUXURL);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, buffer);
CURLcode res = curl_easy_perform(curl);
if(res != CURLE_OK) {
fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
} else {
printf("inserted into database\n");
}
curl_easy_cleanup(curl);
}
}

7
src/influx.h Normal file
View File

@ -0,0 +1,7 @@
#ifndef _INFLUX_H_
#define _INFLUX_H_
void influxSendFrequency(double f);
#endif // _INFLUX_H_