Commit 26c6a495a3894ad9d811d8bf4ff926136378db20
1 parent
ce796b71
--no commit message
Showing
5 changed files
with
25 additions
and
24 deletions
Project/applications/smartcities/include/json.h
@@ -18,6 +18,7 @@ | @@ -18,6 +18,7 @@ | ||
18 | #define JOIN_NO_FREE 0 | 18 | #define JOIN_NO_FREE 0 |
19 | #define JOIN_FREE_MEM 1 | 19 | #define JOIN_FREE_MEM 1 |
20 | 20 | ||
21 | +uint8_t register_sensor(sensor sens); | ||
21 | char* prepare_json_observation_statement(char** data, uint32_t nObservations); | 22 | char* prepare_json_observation_statement(char** data, uint32_t nObservations); |
22 | char* prepare_json_register_statement(module mod, sensor sens); | 23 | char* prepare_json_register_statement(module mod, sensor sens); |
23 | char* prepare_observation(char* observation, uint32_t length); | 24 | 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 | @@ -25,4 +26,4 @@ uint8_t send_json(char* statement, uint32_t length, char* provider_ID, char* sen | ||
25 | uint32_t find_next_index(char* string, uint32_t length, char delimiter); | 26 | uint32_t find_next_index(char* string, uint32_t length, char delimiter); |
26 | char* join_strings(char* str1, char* str2, uint32_t len1, uint32_t len2, uint8_t free_mem); | 27 | char* join_strings(char* str1, char* str2, uint32_t len1, uint32_t len2, uint8_t free_mem); |
27 | 28 | ||
28 | -#endif | ||
29 | \ No newline at end of file | 29 | \ No newline at end of file |
30 | +#endif |
Project/applications/smartcities/include/sensors.h
@@ -6,7 +6,7 @@ | @@ -6,7 +6,7 @@ | ||
6 | #include "i2c.h" | 6 | #include "i2c.h" |
7 | #include "libwismart.h" | 7 | #include "libwismart.h" |
8 | #include "module.h" | 8 | #include "module.h" |
9 | -#include "json.h" | 9 | +//#include "json.h" |
10 | 10 | ||
11 | #define LIGHT_ADDR 0x39 | 11 | #define LIGHT_ADDR 0x39 |
12 | #define DISTANCE_ADDR 0x01 | 12 | #define DISTANCE_ADDR 0x01 |
@@ -17,7 +17,7 @@ typedef struct { | @@ -17,7 +17,7 @@ typedef struct { | ||
17 | char* description; | 17 | char* description; |
18 | char* type; | 18 | char* type; |
19 | char* unit; | 19 | char* unit; |
20 | - char* additional_data; | 20 | + char* additional_info; |
21 | } sensor; | 21 | } sensor; |
22 | 22 | ||
23 | uint8_t register_sensor(sensor sens); | 23 | uint8_t register_sensor(sensor sens); |
@@ -56,8 +56,8 @@ typedef struct { | @@ -56,8 +56,8 @@ typedef struct { | ||
56 | } bmp085_callibration; | 56 | } bmp085_callibration; |
57 | 57 | ||
58 | uint16_t get_pressure_data(void); | 58 | uint16_t get_pressure_data(void); |
59 | -bmp085_callibration get_callibration_data(void); | ||
60 | -char* callibration_data_csv(bmp085_callibration parameters); | 59 | +bmp085_callibration get_pressure_callibration_data(void); |
60 | +char* callibration_pressure_data_csv(bmp085_callibration parameters); | ||
61 | void init_pressure(void); | 61 | void init_pressure(void); |
62 | 62 | ||
63 | -#endif | ||
64 | \ No newline at end of file | 63 | \ No newline at end of file |
64 | +#endif |
Project/applications/smartcities/json.c
1 | #include "json.h" | 1 | #include "json.h" |
2 | 2 | ||
3 | +uint8_t register_sensor(sensor sens) | ||
4 | +{ | ||
5 | + uint8_t result; | ||
6 | + if(sens.ID == PRESSURE_ADDR) | ||
7 | + { | ||
8 | + sens.additional_info = callibration_pressure_data_csv(get_pressure_callibration_data()); | ||
9 | + } | ||
10 | + char *statement = prepare_json_register_statement(mod,sens); | ||
11 | + chHeapFree(sens.additional_info); | ||
12 | + sens.additional_info = NULL; | ||
13 | + char sensor_ID[3]; | ||
14 | + sprintf(sensor_ID,"%d",sens.ID); | ||
15 | + result = send_json(statement,strlen(statement),mod.ID,sensor_ID); | ||
16 | + chHeapFree(statement); | ||
17 | + return result; | ||
18 | +} | ||
19 | + | ||
3 | char* prepare_json_observation_statement(char** data, uint32_t nObservations) | 20 | char* prepare_json_observation_statement(char** data, uint32_t nObservations) |
4 | { | 21 | { |
5 | unsigned int i, length, observation_length; | 22 | 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 | @@ -163,4 +180,4 @@ char* join_strings(char* str1, char* str2, uint32_t len1, uint32_t len2, uint8_t | ||
163 | chHeapFree(str2); | 180 | chHeapFree(str2); |
164 | } | 181 | } |
165 | return str; | 182 | return str; |
166 | -} | ||
167 | \ No newline at end of file | 183 | \ No newline at end of file |
184 | +} |
Project/applications/smartcities/ntp.c
Project/applications/smartcities/sensors.c
@@ -4,21 +4,6 @@ sensor light_sensor = {LIGHT_ADDR, "Light sensor", "illumination", "lux",NULL}; | @@ -4,21 +4,6 @@ sensor light_sensor = {LIGHT_ADDR, "Light sensor", "illumination", "lux",NULL}; | ||
4 | sensor ultrasound_sensor = {DISTANCE_ADDR, "Ultrasound sensor", "distance", "cm",NULL}; | 4 | sensor ultrasound_sensor = {DISTANCE_ADDR, "Ultrasound sensor", "distance", "cm",NULL}; |
5 | sensor pressure_sensor = {PRESSURE_ADDR, "Pressure sensor", "pressure", "kPa",NULL}; | 5 | sensor pressure_sensor = {PRESSURE_ADDR, "Pressure sensor", "pressure", "kPa",NULL}; |
6 | 6 | ||
7 | -uint8_t register_sensor(sensor sens) | ||
8 | -{ | ||
9 | - uint8_t result; | ||
10 | - if(sens.ID == PRESSURE_ADDR) | ||
11 | - { | ||
12 | - sens.additional_data = callibration_pressure_data_csv(get_pressure_callibration_data()); | ||
13 | - } | ||
14 | - char *statement = prepare_json_register_statement(mod,sens); | ||
15 | - chHeapFree(sens.additional_data); | ||
16 | - sens.additional_data = NULL; | ||
17 | - result = send_json(statement,strlen(statement),mod.ID,sens.ID); | ||
18 | - chHeapFree(statement); | ||
19 | - return result; | ||
20 | -} | ||
21 | - | ||
22 | uint32_t get_light_data(void) | 7 | uint32_t get_light_data(void) |
23 | { | 8 | { |
24 | uint32_t data = 0; | 9 | uint32_t data = 0; |
@@ -220,7 +205,6 @@ bmp085_callibration get_pressure_callibration_data(void) | @@ -220,7 +205,6 @@ bmp085_callibration get_pressure_callibration_data(void) | ||
220 | } | 205 | } |
221 | char* callibration_pressure_data_csv(bmp085_callibration parameters) | 206 | char* callibration_pressure_data_csv(bmp085_callibration parameters) |
222 | { | 207 | { |
223 | - uint8_t i; | ||
224 | char *str = chHeapAlloc(NULL,sizeof(char)*(4*11-1)); | 208 | char *str = chHeapAlloc(NULL,sizeof(char)*(4*11-1)); |
225 | memset(str,0x00,sizeof(char)*(4*11-1)); | 209 | memset(str,0x00,sizeof(char)*(4*11-1)); |
226 | sprintf(str + strlen(str),"%d,",parameters.AC1); | 210 | sprintf(str + strlen(str),"%d,",parameters.AC1); |