@@ -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);
|
||||
|
Reference in New Issue
Block a user