Commit f198e1db authored by Gebhardt, Albrecht's avatar Gebhardt, Albrecht

use libcurl for https upload

parent c02512ac
all: frewe-client
frewe-client: frewe-client.c http_fetcher.c http_error_codes.c
gcc frewe-client.c http_fetcher.c http_error_codes.c -o frewe-client -lusb -lm -lcrypto
gcc frewe-client.c http_fetcher.c http_error_codes.c -o frewe-client -lusb -lm -lcrypto -lcurl
install: frewe-client
cp rc.frewe-client /etc/init.d/frewe-client
......@@ -63,6 +63,7 @@
* 2015-04-24 Handle lasttime as UTC
* 2015-08-20 Don't write fhem.txt for older records
* 2016-01-16 Separate read interval for fhem.txt, run each 48 seconds for FHEM
* 2018-11-10 switch to libcurl
* TODO: Handle rain counter overflow
......@@ -81,6 +82,7 @@
#include <elf.h>
#include <openssl/md5.h>
#include "http_fetcher.h"
#include <curl/curl.h>
#define PROGRAM_VERSION "1.19"
......@@ -250,6 +252,8 @@ int main(int argc, char **argv)
for (i=0;i<MAX_ADD_URLS;i++) add_url[i]=NULL;
// Parse options
while (rv==0 && (c=getopt(argc,argv,"hH?vxf:d:a:A:p:e:t:s:c:u:r:t:k:"))!=-1)
......@@ -1547,6 +1551,7 @@ int ws_parse(uint8_t *buffer, uint8_t *buffer60, uint8_t *buffer0h, time_t curti
if (w.rainhour<0)
{ logger(LOG_ERROR,"ws_parse","Rainhour is negative, will set it to 0, rain=%f, lastrain=%f",w.rain,lastrain);
w.rainhour = 0;
if (w.rainhour>150)
{ logger(LOG_ERROR,"ws_parse","Rainhour is out of range, rain=%f, lastrain=%f",w.rain,lastrain);
......@@ -1637,6 +1642,31 @@ static size_t write_callback(char *buffer, size_t size,size_t nitems,void *outpu
return size*nitems;
size_t write_data(void *ptr, size_t size, size_t nmemb, char **filebuf){
logger(LOG_DEBUG,"write_data"," %i times %i bytes", nmemb, size);
char *pagebuf = (char*)malloc(nmemb*size);
logger(LOG_ERROR,"write_data","malloc failed");
return 1;
logger(LOG_DEBUG,"write_data","malloc success: %i", nmemb*size);
char *cptr=(char*)ptr;
size_t written=0;
int pos=0;
while(((char*)ptr)[pos]!='\0' && pos<nmemb*size){
logger(LOG_DEBUG,"write_data","transfer byte %i", pos);
//logger(LOG_DEBUG,"write_data","read byte: %s", cptr[pos]);
logger(LOG_DEBUG,"write_data","read byte: %s", pagebuf[pos]);
//size_t written = fwrite(ptr, size, nmemb, pagebuf);
logger(LOG_DEBUG,"write_data","content: %s", pagebuf);
return written;
int ws_submit(char *server_url, char** filebuf)
......@@ -1644,16 +1674,38 @@ int ws_submit(char *server_url, char** filebuf)
{ free(*filebuf);
// init CURL
CURL *curl;
CURLcode res;
int l=http_fetch(server_url, filebuf);
if (l>=0)
{ logger(LOG_DEBUG,"ws_submit","http_fetcher performed OK content: %s", *filebuf);
/* int l=http_fetch(server_url, filebuf);*/
curl = curl_easy_init();
logger(LOG_ERROR,"ws_submit","curl init failed");
return 1;
curl_easy_setopt(curl, CURLOPT_URL, server_url);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, *filebuf);
int l=curl_easy_perform(curl);
/*if (l>=0)*/
if (l == CURLE_OK)
/* { logger(LOG_DEBUG,"ws_submit","http_fetcher performed OK content: %s", *filebuf);*/
{ logger(LOG_DEBUG,"ws_submit","curl performed OK content: %s", *filebuf);
return 0;
{ logger(LOG_WARNING,"ws_submit","http_fetcher failed with message \"%s\"", http_strerror());
/*{ logger(LOG_WARNING,"ws_submit","http_fetcher failed with message \"%s\"", http_strerror());*/
{ logger(LOG_WARNING,"ws_submit","curl failed with message \"%s\"", curl_easy_strerror(l));
return 1;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment