diff --git a/Project/applications/smartcities/buffer.c b/Project/applications/smartcities/buffer.c index 35b9c73..0b5aee1 100644 --- a/Project/applications/smartcities/buffer.c +++ b/Project/applications/smartcities/buffer.c @@ -6,7 +6,7 @@ char** put_message(char* info, char** buf,uint32_t *index, uint32_t *buf_len){ uint32_t i,len; len=*buf_len; if(len==*index) -{ +{ char** buffer=join_buf(buf, buf_len); buffer[*index]=chHeapAlloc(NULL,strlen(info)+1); @@ -56,12 +56,14 @@ int send(char** buf, uint32_t *index, uint32_t *size_buf, char *provider_ID, cha { return 2; } printf("abans del JSON\r\n"); uint8_t res=send_json(statement, size, provider_ID, sensor_ID); + chHeapFree(statement); int i; printf("JSON_POST_OK ? %d\r\n",res == JSON_POST_OK); if(res==JSON_POST_OK){ - //for(i=0;i<*index;i++){ - // chHeapFree(buf[i]); - //} + for(i=0;i<*index;i++) + { + chHeapFree(buf[i]); + } printf("djfkhvldkfjhdñkfgv\r\n"); if(buf!=NULL) chHeapFree(buf); diff --git a/Project/applications/smartcities/include/buffer.h b/Project/applications/smartcities/include/buffer.h index 49a3340..14bca06 100644 --- a/Project/applications/smartcities/include/buffer.h +++ b/Project/applications/smartcities/include/buffer.h @@ -4,8 +4,8 @@ #include "libwismart.h" #include "json.h" -#define SOFT_LIMIT 20480 /* en bytes -> 25k * 1024 */ -#define HARD_LIMIT 25600 +#define SOFT_LIMIT 8192 /* en bytes -> 10k * 1024 */ +#define HARD_LIMIT 10240 #define MEMORY_OK 0 #define SOFT_REACHED 1 #define HARD_REACHED 2 diff --git a/Project/applications/smartcities/json.c b/Project/applications/smartcities/json.c index 5d7727a..68859b8 100644 --- a/Project/applications/smartcities/json.c +++ b/Project/applications/smartcities/json.c @@ -1,4 +1,5 @@ #include "json.h" +#include "buffer.h" uint8_t register_sensor(sensor sens) { @@ -23,15 +24,14 @@ char* prepare_json_observation_statement(char** data, uint32_t nObservations) char *json_statement, *str_aux, *str_aux2; length = 17; str_aux = join_strings("{\"observations\":[","",length,0,JOIN_NO_FREE); - printf("nobs=%d\r\n",nObservations); for(i = 0; i < nObservations; i++) { str_aux2 = prepare_observation(data[i],strlen(data[i])); observation_length = strlen(str_aux2); str_aux = join_strings(str_aux,str_aux2,length,observation_length,JOIN_FREE_MEM); length += observation_length; - chHeapFree(data[i]); printf("data=%s %d \r\n",data[i],i); + check_memory(); } length--; //REMOVE LAST ',' json_statement = join_strings(str_aux,"]}\0",length,3,JOIN_NO_FREE); diff --git a/Project/applications/smartcities/main.c b/Project/applications/smartcities/main.c index 0a7025b..0205b85 100644 --- a/Project/applications/smartcities/main.c +++ b/Project/applications/smartcities/main.c @@ -8,6 +8,7 @@ #include "buffer.h" #include "i2c.h" #include "configServer.h" +#include "sensors.h" #define WIFI_MODE WIFI_MODE_CLIENT #define NETWORK_SSID_AP "modularsens" @@ -15,7 +16,6 @@ #define NETWORK_CHANNEL_AP 1 #define HARD_LIMIT_WAIT_TIME 10*1000 //5*60*1000 -#define NUMSENSORS 4 wismart_registryKey_t geo; @@ -124,7 +124,7 @@ int main(void) char* data="message,0"; char* data2="message,1"; char* data3="message,2"; - for(i=0;i