diff --git a/Project/applications/smartcities/include/globals.h b/Project/applications/smartcities/include/globals.h new file mode 100644 index 0000000..b92ddd9 --- /dev/null +++ b/Project/applications/smartcities/include/globals.h @@ -0,0 +1,6 @@ +#ifndef GLOBALS_H +#define GLOBALS_H + +#define SERVER_IP "10.0.60.241" + +#endif \ No newline at end of file diff --git a/Project/applications/smartcities/include/json.h b/Project/applications/smartcities/include/json.h index afbf0fe..c797e89 100644 --- a/Project/applications/smartcities/include/json.h +++ b/Project/applications/smartcities/include/json.h @@ -3,7 +3,7 @@ #include #include -#include "http.h" +#include "httpClient.h" #include "libwismart.h" #include "ch.h" diff --git a/Project/applications/smartcities/include/module.h b/Project/applications/smartcities/include/module.h new file mode 100644 index 0000000..0323b3d --- /dev/null +++ b/Project/applications/smartcities/include/module.h @@ -0,0 +1,6 @@ +#ifndef MODULE_H +#define MODULE_H + +#define SERIAL_NUMBER 123456 + +#endif \ No newline at end of file diff --git a/Project/applications/smartcities/include/sensors.h b/Project/applications/smartcities/include/sensors.h new file mode 100644 index 0000000..59746a7 --- /dev/null +++ b/Project/applications/smartcities/include/sensors.h @@ -0,0 +1,5 @@ +#ifndef SENSORS_H +#define SENSORS_H + + +#endif diff --git a/Project/applications/smartcities/json.c b/Project/applications/smartcities/json.c index 5bffc35..2f67f87 100644 --- a/Project/applications/smartcities/json.c +++ b/Project/applications/smartcities/json.c @@ -21,7 +21,23 @@ char* prepare_json_observation_statement(char** data, uint32_t nObservations) char* prepare_json_register_statement(char* module_ID, uint8_t sensor_type) { - + char *json_data, *str_aux, *str_aux2; + int value_length = find_next_index(observation,length,','); //EXPECTS FORMATTING!!! + int timestamp_length = length - (value_length + 1); + char *value = (char*) chHeapAlloc(NULL,value_length+1); + char *timestamp = (char*) chHeapAlloc(NULL,timestamp_length+1); + strncpy(value,observation,value_length); + strncpy(timestamp,observation+(value_length+1),timestamp_length); + value[value_length] = '\0'; + timestamp[timestamp_length] = '\0'; + str_aux = join_strings("{\"value\":\"",value,10,value_length,JOIN_NO_FREE); + str_aux2 = join_strings(str_aux,"\",\"timestamp\":\"",10+value_length,15,JOIN_NO_FREE); + str_aux2 = join_strings(str_aux2,timestamp,25+value_length,timestamp_length,JOIN_FREE_MEM); + json_data = join_strings(str_aux2,"\"},",25+value_length+timestamp_length,3,JOIN_NO_FREE); + chHeapFree(str_aux); + chHeapFree(str_aux2); + chHeapFree(value); + return json_data; } char* prepare_observation(char* observation, uint32_t length)