From 3baadec22ceb664726d2b3c2cc756d96c808f42b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?King=20K=C3=A9vin?= Date: Wed, 11 Nov 2015 01:36:45 +0100 Subject: [PATCH] database, username, and password must now be provided to spark_angel_receiver --- rpi/spark_counter_receiver.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/rpi/spark_counter_receiver.cpp b/rpi/spark_counter_receiver.cpp index 2ff4a6a..7c6939b 100644 --- a/rpi/spark_counter_receiver.cpp +++ b/rpi/spark_counter_receiver.cpp @@ -47,10 +47,24 @@ uint8_t iv[16] = {0xff,0xee,0xdd,0xcc,0xbb,0xaa,0x99,0x88,0x77,0x66,0x55,0x44,0x int main(int argc, char** argv){ + if (argc!=4) { + fprintf(stderr, "provide database name, username, and password as argument (spaces, ':', special characters, or very long arguments not supported)\n"); + return 1; + } + // configure influxdb connection curl = curl_easy_init(); - if(curl) { - curl_easy_setopt(curl, CURLOPT_URL, "http://localhost:8086/write?db=electricity"); + if (curl) { + char url[256]; + snprintf(url, sizeof(url), "http://localhost:8086/write?db=%s", argv[1]); + curl_easy_setopt(curl, CURLOPT_URL, url); + char auth[256]; + snprintf(auth, sizeof(auth), "%s:%s", argv[2], argv[3]); + curl_easy_setopt(curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); + curl_easy_setopt(curl, CURLOPT_USERPWD, auth); + } else { + fprintf(stderr, "could not initialize curl\n"); + return 1; } // configure nRF24L01+ radio