Commit 7a957821e966d0c894d4e637697c82627a12ee31

Authored by Imanol-Mikel Barba Sabariego
1 parent 502f6269

--no commit message

Project/applications/smartcities/buffer.c
@@ -6,7 +6,7 @@ char** put_message(char* info, char** buf,uint32_t *index, uint32_t *buf_len){ @@ -6,7 +6,7 @@ char** put_message(char* info, char** buf,uint32_t *index, uint32_t *buf_len){
6 uint32_t i,len; 6 uint32_t i,len;
7 len=*buf_len; 7 len=*buf_len;
8 if(len==*index) 8 if(len==*index)
9 -{ 9 +{
10 10
11 char** buffer=join_buf(buf, buf_len); 11 char** buffer=join_buf(buf, buf_len);
12 buffer[*index]=chHeapAlloc(NULL,strlen(info)+1); 12 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 @@ -56,12 +56,14 @@ int send(char** buf, uint32_t *index, uint32_t *size_buf, char *provider_ID, cha
56 { return 2; } 56 { return 2; }
57 printf("abans del JSON\r\n"); 57 printf("abans del JSON\r\n");
58 uint8_t res=send_json(statement, size, provider_ID, sensor_ID); 58 uint8_t res=send_json(statement, size, provider_ID, sensor_ID);
  59 + chHeapFree(statement);
59 int i; 60 int i;
60 printf("JSON_POST_OK ? %d\r\n",res == JSON_POST_OK); 61 printf("JSON_POST_OK ? %d\r\n",res == JSON_POST_OK);
61 if(res==JSON_POST_OK){ 62 if(res==JSON_POST_OK){
62 - //for(i=0;i<*index;i++){  
63 - // chHeapFree(buf[i]);  
64 - //} 63 + for(i=0;i<*index;i++)
  64 + {
  65 + chHeapFree(buf[i]);
  66 + }
65 printf("djfkhvldkfjhdñkfgv\r\n"); 67 printf("djfkhvldkfjhdñkfgv\r\n");
66 if(buf!=NULL) 68 if(buf!=NULL)
67 chHeapFree(buf); 69 chHeapFree(buf);
Project/applications/smartcities/include/buffer.h
@@ -4,8 +4,8 @@ @@ -4,8 +4,8 @@
4 #include "libwismart.h" 4 #include "libwismart.h"
5 #include "json.h" 5 #include "json.h"
6 6
7 -#define SOFT_LIMIT 20480 /* en bytes -> 25k * 1024 */  
8 -#define HARD_LIMIT 25600 7 +#define SOFT_LIMIT 8192 /* en bytes -> 10k * 1024 */
  8 +#define HARD_LIMIT 10240
9 #define MEMORY_OK 0 9 #define MEMORY_OK 0
10 #define SOFT_REACHED 1 10 #define SOFT_REACHED 1
11 #define HARD_REACHED 2 11 #define HARD_REACHED 2
Project/applications/smartcities/json.c
1 #include "json.h" 1 #include "json.h"
  2 +#include "buffer.h"
2 3
3 uint8_t register_sensor(sensor sens) 4 uint8_t register_sensor(sensor sens)
4 { 5 {
@@ -23,15 +24,14 @@ char* prepare_json_observation_statement(char** data, uint32_t nObservations) @@ -23,15 +24,14 @@ char* prepare_json_observation_statement(char** data, uint32_t nObservations)
23 char *json_statement, *str_aux, *str_aux2; 24 char *json_statement, *str_aux, *str_aux2;
24 length = 17; 25 length = 17;
25 str_aux = join_strings("{\"observations\":[","",length,0,JOIN_NO_FREE); 26 str_aux = join_strings("{\"observations\":[","",length,0,JOIN_NO_FREE);
26 - printf("nobs=%d\r\n",nObservations);  
27 for(i = 0; i < nObservations; i++) 27 for(i = 0; i < nObservations; i++)
28 { 28 {
29 str_aux2 = prepare_observation(data[i],strlen(data[i])); 29 str_aux2 = prepare_observation(data[i],strlen(data[i]));
30 observation_length = strlen(str_aux2); 30 observation_length = strlen(str_aux2);
31 str_aux = join_strings(str_aux,str_aux2,length,observation_length,JOIN_FREE_MEM); 31 str_aux = join_strings(str_aux,str_aux2,length,observation_length,JOIN_FREE_MEM);
32 length += observation_length; 32 length += observation_length;
33 - chHeapFree(data[i]);  
34 printf("data=%s %d \r\n",data[i],i); 33 printf("data=%s %d \r\n",data[i],i);
  34 + check_memory();
35 } 35 }
36 length--; //REMOVE LAST ',' 36 length--; //REMOVE LAST ','
37 json_statement = join_strings(str_aux,"]}\0",length,3,JOIN_NO_FREE); 37 json_statement = join_strings(str_aux,"]}\0",length,3,JOIN_NO_FREE);
Project/applications/smartcities/main.c
@@ -8,6 +8,7 @@ @@ -8,6 +8,7 @@
8 #include "buffer.h" 8 #include "buffer.h"
9 #include "i2c.h" 9 #include "i2c.h"
10 #include "configServer.h" 10 #include "configServer.h"
  11 +#include "sensors.h"
11 12
12 #define WIFI_MODE WIFI_MODE_CLIENT 13 #define WIFI_MODE WIFI_MODE_CLIENT
13 #define NETWORK_SSID_AP "modularsens" 14 #define NETWORK_SSID_AP "modularsens"
@@ -15,7 +16,6 @@ @@ -15,7 +16,6 @@
15 #define NETWORK_CHANNEL_AP 1 16 #define NETWORK_CHANNEL_AP 1
16 17
17 #define HARD_LIMIT_WAIT_TIME 10*1000 //5*60*1000 18 #define HARD_LIMIT_WAIT_TIME 10*1000 //5*60*1000
18 -#define NUMSENSORS 4  
19 19
20 wismart_registryKey_t geo; 20 wismart_registryKey_t geo;
21 21
@@ -124,7 +124,7 @@ int main(void) @@ -124,7 +124,7 @@ int main(void)
124 char* data="message,0"; 124 char* data="message,0";
125 char* data2="message,1"; 125 char* data2="message,1";
126 char* data3="message,2"; 126 char* data3="message,2";
127 - for(i=0;i<NUMSENSORS;i++){ 127 + for(i=0;i<TOTAL_SENSORS;i++){
128 128
129 printf("------------------BUFFER %d ----------------------\r\n",i); 129 printf("------------------BUFFER %d ----------------------\r\n",i);
130 printf("index=%d\r\n",ind[i]); 130 printf("index=%d\r\n",ind[i]);
@@ -138,12 +138,13 @@ int main(void) @@ -138,12 +138,13 @@ int main(void)
138 if(res==SOFT_REACHED){ 138 if(res==SOFT_REACHED){
139 printf("--------------soft limit-------------\r\n"); 139 printf("--------------soft limit-------------\r\n");
140 int j; 140 int j;
141 - for(j=0;j<NUMSENSORS;j++) 141 + for(j=0;j<TOTAL_SENSORS;j++)
142 { 142 {
143 printf(" enviant buffer %d\r\n",j); 143 printf(" enviant buffer %d\r\n",j);
144 144
145 // fem servir 085 de prova, però haurem de fer servir sensor_id[j] 145 // fem servir 085 de prova, però haurem de fer servir sensor_id[j]
146 int ok=send(buffers[j],&ind[j],&sizes[j], "bmp", "085"); 146 int ok=send(buffers[j],&ind[j],&sizes[j], "bmp", "085");
  147 +
147 if(ok==JSON_COMM_ERROR) 148 if(ok==JSON_COMM_ERROR)
148 { 149 {
149 printf("wismart is not connected\r\n"); 150 printf("wismart is not connected\r\n");
@@ -170,7 +171,7 @@ int main(void) @@ -170,7 +171,7 @@ int main(void)
170 chThdSleepMilliseconds(HARD_LIMIT_WAIT_TIME); 171 chThdSleepMilliseconds(HARD_LIMIT_WAIT_TIME);
171 } 172 }
172 int j; 173 int j;
173 - for(j=1;j<NUMSENSORS;j++) 174 + for(j=1;j<TOTAL_SENSORS;j++)
174 { 175 {
175 printf(" enviant buffer %d\r\n",j); 176 printf(" enviant buffer %d\r\n",j);
176 177