Commit fe05e0a518df4aace7b5bfd8838b478508c69c4b

Authored by Imanol-Mikel Barba Sabariego
1 parent 3820dbc0

--no commit message

Project/applications/smartcities/include/globals.h 0 โ†’ 100644
  1 +#ifndef GLOBALS_H
  2 +#define GLOBALS_H
  3 +
  4 +#define SERVER_IP "10.0.60.241"
  5 +
  6 +#endif
0 7 \ No newline at end of file
... ...
Project/applications/smartcities/include/json.h
... ... @@ -3,7 +3,7 @@
3 3  
4 4 #include <string.h>
5 5 #include <stdint.h>
6   -#include "http.h"
  6 +#include "httpClient.h"
7 7 #include "libwismart.h"
8 8 #include "ch.h"
9 9  
... ...
Project/applications/smartcities/include/module.h 0 โ†’ 100644
  1 +#ifndef MODULE_H
  2 +#define MODULE_H
  3 +
  4 +#define SERIAL_NUMBER 123456
  5 +
  6 +#endif
0 7 \ No newline at end of file
... ...
Project/applications/smartcities/include/sensors.h 0 โ†’ 100644
  1 +#ifndef SENSORS_H
  2 +#define SENSORS_H
  3 +
  4 +
  5 +#endif
... ...
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)
... ...