diff --git a/Project/applications/smartcities/include/json.h b/Project/applications/smartcities/include/json.h index f225f57..22d78b9 100644 --- a/Project/applications/smartcities/include/json.h +++ b/Project/applications/smartcities/include/json.h @@ -18,6 +18,7 @@ #define JOIN_NO_FREE 0 #define JOIN_FREE_MEM 1 +uint8_t register_sensor(sensor sens); char* prepare_json_observation_statement(char** data, uint32_t nObservations); char* prepare_json_register_statement(module mod, sensor sens); char* prepare_observation(char* observation, uint32_t length); @@ -25,4 +26,4 @@ uint8_t send_json(char* statement, uint32_t length, char* provider_ID, char* sen uint32_t find_next_index(char* string, uint32_t length, char delimiter); char* join_strings(char* str1, char* str2, uint32_t len1, uint32_t len2, uint8_t free_mem); -#endif \ No newline at end of file +#endif diff --git a/Project/applications/smartcities/include/sensors.h b/Project/applications/smartcities/include/sensors.h index 25b8771..6f09c80 100644 --- a/Project/applications/smartcities/include/sensors.h +++ b/Project/applications/smartcities/include/sensors.h @@ -6,7 +6,7 @@ #include "i2c.h" #include "libwismart.h" #include "module.h" -#include "json.h" +//#include "json.h" #define LIGHT_ADDR 0x39 #define DISTANCE_ADDR 0x01 @@ -17,7 +17,7 @@ typedef struct { char* description; char* type; char* unit; - char* additional_data; + char* additional_info; } sensor; uint8_t register_sensor(sensor sens); @@ -56,8 +56,8 @@ typedef struct { } bmp085_callibration; uint16_t get_pressure_data(void); -bmp085_callibration get_callibration_data(void); -char* callibration_data_csv(bmp085_callibration parameters); +bmp085_callibration get_pressure_callibration_data(void); +char* callibration_pressure_data_csv(bmp085_callibration parameters); void init_pressure(void); -#endif \ No newline at end of file +#endif diff --git a/Project/applications/smartcities/json.c b/Project/applications/smartcities/json.c index bac3d42..b2fc32f 100644 --- a/Project/applications/smartcities/json.c +++ b/Project/applications/smartcities/json.c @@ -1,5 +1,22 @@ #include "json.h" +uint8_t register_sensor(sensor sens) +{ + uint8_t result; + if(sens.ID == PRESSURE_ADDR) + { + sens.additional_info = callibration_pressure_data_csv(get_pressure_callibration_data()); + } + char *statement = prepare_json_register_statement(mod,sens); + chHeapFree(sens.additional_info); + sens.additional_info = NULL; + char sensor_ID[3]; + sprintf(sensor_ID,"%d",sens.ID); + result = send_json(statement,strlen(statement),mod.ID,sensor_ID); + chHeapFree(statement); + return result; +} + char* prepare_json_observation_statement(char** data, uint32_t nObservations) { unsigned int i, length, observation_length; @@ -163,4 +180,4 @@ char* join_strings(char* str1, char* str2, uint32_t len1, uint32_t len2, uint8_t chHeapFree(str2); } return str; -} \ No newline at end of file +} diff --git a/Project/applications/smartcities/ntp.c b/Project/applications/smartcities/ntp.c index 9819c15..e3e3f77 100644 --- a/Project/applications/smartcities/ntp.c +++ b/Project/applications/smartcities/ntp.c @@ -3,7 +3,6 @@ #include #include #include -#include #include #include diff --git a/Project/applications/smartcities/sensors.c b/Project/applications/smartcities/sensors.c index 749b44a..dca6d0e 100644 --- a/Project/applications/smartcities/sensors.c +++ b/Project/applications/smartcities/sensors.c @@ -4,21 +4,6 @@ sensor light_sensor = {LIGHT_ADDR, "Light sensor", "illumination", "lux",NULL}; sensor ultrasound_sensor = {DISTANCE_ADDR, "Ultrasound sensor", "distance", "cm",NULL}; sensor pressure_sensor = {PRESSURE_ADDR, "Pressure sensor", "pressure", "kPa",NULL}; -uint8_t register_sensor(sensor sens) -{ - uint8_t result; - if(sens.ID == PRESSURE_ADDR) - { - sens.additional_data = callibration_pressure_data_csv(get_pressure_callibration_data()); - } - char *statement = prepare_json_register_statement(mod,sens); - chHeapFree(sens.additional_data); - sens.additional_data = NULL; - result = send_json(statement,strlen(statement),mod.ID,sens.ID); - chHeapFree(statement); - return result; -} - uint32_t get_light_data(void) { uint32_t data = 0; @@ -220,7 +205,6 @@ bmp085_callibration get_pressure_callibration_data(void) } char* callibration_pressure_data_csv(bmp085_callibration parameters) { - uint8_t i; char *str = chHeapAlloc(NULL,sizeof(char)*(4*11-1)); memset(str,0x00,sizeof(char)*(4*11-1)); sprintf(str + strlen(str),"%d,",parameters.AC1);