Bringinh all the pieces together. #2 #7

This commit is contained in:
2017-08-27 16:31:46 +02:00
parent 98a0e3ff5f
commit eca544a421
6 changed files with 72 additions and 6 deletions

View File

@@ -1,5 +1,6 @@
#include "restcurl.h"
#include <curl/curl.h>
#include <string.h>
static struct url_data {
size_t size;
@@ -64,13 +65,18 @@ static char *handle_url(char *url) {
}
int getRestSensor(sensor *sensor) {
char *data = handle_url(sensor->ip);
char url[25];
url = "http://";
strcat(url, sensor->ip);
char *data = handle_url(url);
if (data) {
cJSON *jsondata = cJSON_Parse(data);
cJSON *temperature = cJSON_GetObjectItemCaseSensitive(jsondata, "temperature");
cJSON *humidity = cJSON_GetObjectItemCaseSensitive(jsondata, "humidity");
cJSON *id = cJSON_GetObjectItemCaseSensitive(jsondata, "id");
sensor->temperature = (float)temperature->valuedouble;
sensor->humidity = (float)humidity->valuedouble;
sensor->node_id = id->valueint;
//free
cJSON_Delete(jsondata);