Commit fe05e0a518df4aace7b5bfd8838b478508c69c4b
1 parent
3820dbc0
--no commit message
Showing
5 changed files
with
35 additions
and
2 deletions
Project/applications/smartcities/include/globals.h
0 โ 100644
Project/applications/smartcities/include/json.h
Project/applications/smartcities/include/module.h
0 โ 100644
Project/applications/smartcities/include/sensors.h
0 โ 100644
Project/applications/smartcities/json.c
... | ... | @@ -21,7 +21,23 @@ char* prepare_json_observation_statement(char** data, uint32_t nObservations) |
21 | 21 | |
22 | 22 | char* prepare_json_register_statement(char* module_ID, uint8_t sensor_type) |
23 | 23 | { |
24 | - | |
24 | + char *json_data, *str_aux, *str_aux2; | |
25 | + int value_length = find_next_index(observation,length,','); //EXPECTS FORMATTING!!! | |
26 | + int timestamp_length = length - (value_length + 1); | |
27 | + char *value = (char*) chHeapAlloc(NULL,value_length+1); | |
28 | + char *timestamp = (char*) chHeapAlloc(NULL,timestamp_length+1); | |
29 | + strncpy(value,observation,value_length); | |
30 | + strncpy(timestamp,observation+(value_length+1),timestamp_length); | |
31 | + value[value_length] = '\0'; | |
32 | + timestamp[timestamp_length] = '\0'; | |
33 | + str_aux = join_strings("{\"value\":\"",value,10,value_length,JOIN_NO_FREE); | |
34 | + str_aux2 = join_strings(str_aux,"\",\"timestamp\":\"",10+value_length,15,JOIN_NO_FREE); | |
35 | + str_aux2 = join_strings(str_aux2,timestamp,25+value_length,timestamp_length,JOIN_FREE_MEM); | |
36 | + json_data = join_strings(str_aux2,"\"},",25+value_length+timestamp_length,3,JOIN_NO_FREE); | |
37 | + chHeapFree(str_aux); | |
38 | + chHeapFree(str_aux2); | |
39 | + chHeapFree(value); | |
40 | + return json_data; | |
25 | 41 | } |
26 | 42 | |
27 | 43 | char* prepare_observation(char* observation, uint32_t length) | ... | ... |