Commit a2a87aa6fa1cdd2e596a2ac39cc845641970bd61

Authored by Imanol-Mikel Barba Sabariego
1 parent 84ae2579

--no commit message

Project/applications/smartcities/buffer.c
@@ -7,15 +7,20 @@ uint32_t i,len; @@ -7,15 +7,20 @@ uint32_t i,len;
7 len=*buf_len; 7 len=*buf_len;
8 if(len==*index) 8 if(len==*index)
9 { 9 {
10 - 10 + printf("Joining buffer...\r\n");
11 char** buffer=join_buf(buf, buf_len); 11 char** buffer=join_buf(buf, buf_len);
  12 + printf("Joined buffer...\r\n");
12 buffer[*index]=chHeapAlloc(NULL,strlen(info)+1); 13 buffer[*index]=chHeapAlloc(NULL,strlen(info)+1);
  14 + printf("Memory allocated...\r\n");
13 strcpy(buffer[*index],info); 15 strcpy(buffer[*index],info);
  16 + printf("Data copied...\r\n");
14 i=*index+1; 17 i=*index+1;
15 *index = i; 18 *index = i;
16 return buffer; 19 return buffer;
17 } 20 }
18 -else{ 21 +else
  22 +{
  23 + printf("WTF in put_message\r\n");
19 buf[*index] = chHeapAlloc(NULL,strlen(info)+1); 24 buf[*index] = chHeapAlloc(NULL,strlen(info)+1);
20 buf[*index]=info; 25 buf[*index]=info;
21 i=*index+1; 26 i=*index+1;
@@ -81,13 +86,20 @@ char** join_buf(char** buf, uint32_t *buf_len){ @@ -81,13 +86,20 @@ char** join_buf(char** buf, uint32_t *buf_len){
81 int len= *buf_len; 86 int len= *buf_len;
82 n_buf=chHeapAlloc (NULL,sizeof (char *) * (len+1)); 87 n_buf=chHeapAlloc (NULL,sizeof (char *) * (len+1));
83 int i; 88 int i;
  89 + printf("Start buffer join...\r\n");
84 for(i=0; i<len;i++){ 90 for(i=0; i<len;i++){
  91 + printf("in join_buf for, Asking for %d bytes...\r\n",strlen(buf[i]+1));
85 n_buf[i]=chHeapAlloc(NULL,strlen(buf[i])+1); 92 n_buf[i]=chHeapAlloc(NULL,strlen(buf[i])+1);
  93 + printf("in join_buf for, Memory allocated...\r\n");
86 strcpy(n_buf[i],buf[i]); 94 strcpy(n_buf[i],buf[i]);
  95 + printf("in join_buf for, Message copied...\r\n");
87 chHeapFree(buf[i]); 96 chHeapFree(buf[i]);
  97 + printf("in join_buf for, Memory cleared...\r\n");
88 } 98 }
  99 + printf("All data transferred\r\n");
89 if(len!=0) 100 if(len!=0)
90 { chHeapFree(buf); } 101 { chHeapFree(buf); }
  102 + printf("Old buffer cleared\r\n");
91 len++; 103 len++;
92 *buf_len=len; 104 *buf_len=len;
93 return n_buf; 105 return n_buf;
Project/applications/smartcities/configServer.c
@@ -61,7 +61,6 @@ void configServer_setClientParameters() @@ -61,7 +61,6 @@ void configServer_setClientParameters()
61 strcpy(config.password,arg_radPassStr); 61 strcpy(config.password,arg_radPassStr);
62 strcpy(config.localization,arg_geoLocalizationStr); 62 strcpy(config.localization,arg_geoLocalizationStr);
63 strcpy(config.ssid,arg_networkNameStr); 63 strcpy(config.ssid,arg_networkNameStr);
64 - strcpy(config.wepkey,arg_passphraseStr);  
65 strcpy(config.passphrase,arg_passphraseStr); 64 strcpy(config.passphrase,arg_passphraseStr);
66 65
67 /* Value validation */ 66 /* Value validation */
Project/applications/smartcities/main2.c
@@ -13,7 +13,7 @@ @@ -13,7 +13,7 @@
13 #include "sensors.h" 13 #include "sensors.h"
14 14
15 #define WIFI_MODE WIFI_MODE_CLIENT 15 #define WIFI_MODE WIFI_MODE_CLIENT
16 -#define NETWORK_SSID_AP "modularsens" 16 +#define NETWORK_SSID_AP "modularsense"
17 #define NETWORK_KEY_AP NULL 17 #define NETWORK_KEY_AP NULL
18 #define NETWORK_CHANNEL_AP 1 18 #define NETWORK_CHANNEL_AP 1
19 19
@@ -32,14 +32,30 @@ uint8_t connected=0; @@ -32,14 +32,30 @@ uint8_t connected=0;
32 uint8_t timeout=0; 32 uint8_t timeout=0;
33 uint8_t retries=0; 33 uint8_t retries=0;
34 uint8_t sensors_length=0; 34 uint8_t sensors_length=0;
  35 +uint8_t registry_opened=0;
  36 +
  37 +void update_time(unsigned long *time)
  38 +{
  39 + printf("Requesting new NTP time...\r\n");
  40 + unsigned long new_time = getSecsSince1900();
  41 + if(new_time)
  42 + {
  43 + *time = getSecsSince1900();
  44 + }
  45 + printf("Time updated...\r\n");
  46 +}
35 47
36 void init_registry(void) 48 void init_registry(void)
37 { 49 {
38 config_params_t config; 50 config_params_t config;
39 51
40 strcpy(config.localization,"none"); 52 strcpy(config.localization,"none");
41 - libwismart_RegistryCreateKey(&geo, 1, sizeof(config));  
42 - libwismart_RegistryOpen(1); 53 + if(!registry_opened)
  54 + {
  55 + libwismart_RegistryCreateKey(&geo, 1, sizeof(config));
  56 + libwismart_RegistryOpen(1);
  57 + registry_opened = 1;
  58 + }
43 if(!libwismart_RegistryIsValueEmpty(&geo)) 59 if(!libwismart_RegistryIsValueEmpty(&geo))
44 { 60 {
45 libwismart_RegistryGet(&geo,&config); 61 libwismart_RegistryGet(&geo,&config);
@@ -117,8 +133,12 @@ void put_buffers(char** buffers[],uint32_t ind[],uint32_t sizes[],char** cooked, @@ -117,8 +133,12 @@ void put_buffers(char** buffers[],uint32_t ind[],uint32_t sizes[],char** cooked,
117 int i; 133 int i;
118 for(i=0;i<sensors_length;i++){ 134 for(i=0;i<sensors_length;i++){
119 printf("For %d and %d\n\r", ind[i],sizes[i]); 135 printf("For %d and %d\n\r", ind[i],sizes[i]);
120 - put_message(cooked[i], buffers[i] ,&ind[i],&sizes[i]); 136 + printf("Putting data: %s\n\r",cooked[i]);
  137 + buffers[i] = put_message(cooked[i], buffers[i] ,&ind[i],&sizes[i]);
  138 + printf("Message put: %s\r\n",buffers[0][ind[0]-1]);
121 chHeapFree(cooked[i]); 139 chHeapFree(cooked[i]);
  140 + printf("Memory freed\n\r");
  141 + printf("Message put (assertion): %s\r\n",buffers[0][ind[0]-1]);
122 } 142 }
123 143
124 } 144 }
@@ -192,7 +212,8 @@ int main(void) @@ -192,7 +212,8 @@ int main(void)
192 printf("Connecting to wifi...\r\n"); 212 printf("Connecting to wifi...\r\n");
193 wifi_connect(); 213 wifi_connect();
194 //unsigned int time = getNTPTime(); 214 //unsigned int time = getNTPTime();
195 - unsigned int time = getSecsSince1900(); 215 + unsigned long time;
  216 + update_time(&time);
196 //desconectarwifi 217 //desconectarwifi
197 printf("Disconecting wifi...\r\n"); 218 printf("Disconecting wifi...\r\n");
198 wifi_disconnect(); 219 wifi_disconnect();
@@ -224,16 +245,16 @@ int main(void) @@ -224,16 +245,16 @@ int main(void)
224 time += getElapsedTime(delay); 245 time += getElapsedTime(delay);
225 printf("time (absolute):\t%ul\r\ntime mod LONG_PERIOD:\t%ul\r\ntime mod SHORT_PERIOD:\t%ul\r\n",time,time%LONG_PERIOD,time%SHORT_PERIOD); 246 printf("time (absolute):\t%ul\r\ntime mod LONG_PERIOD:\t%ul\r\ntime mod SHORT_PERIOD:\t%ul\r\n",time,time%LONG_PERIOD,time%SHORT_PERIOD);
226 247
227 - delay = getSystemTime(); 248 + //delay = getSystemTime();
228 //cada mitja hora 249 //cada mitja hora
229 250
230 //delay2 = getElapsedTime(delay); 251 //delay2 = getElapsedTime(delay);
231 252
232 - delay = getSystemTime(); 253 + //delay = getSystemTime();
233 //timestamp = time - delay2; 254 //timestamp = time - delay2;
234 - timestamp = time - delay; 255 + timestamp = time;
235 printf("timestamp (absolute):\t%ul\r\ntimestamp mod LONG_PERIOD:\t%ul\r\ntimestamp mod SHORT_PERIOD:\t%ul\r\n",timestamp,timestamp%LONG_PERIOD,timestamp%SHORT_PERIOD); 256 printf("timestamp (absolute):\t%ul\r\ntimestamp mod LONG_PERIOD:\t%ul\r\ntimestamp mod SHORT_PERIOD:\t%ul\r\n",timestamp,timestamp%LONG_PERIOD,timestamp%SHORT_PERIOD);
236 - 257 + delay = getSystemTime();
237 /* Add data to the buffer with timestamp*/ 258 /* Add data to the buffer with timestamp*/
238 259
239 //a_cookedData = format_data(a_rawData, timestamp); 260 //a_cookedData = format_data(a_rawData, timestamp);
@@ -242,6 +263,7 @@ int main(void) @@ -242,6 +263,7 @@ int main(void)
242 printf("Putting data in buffer...\r\n"); 263 printf("Putting data in buffer...\r\n");
243 put_buffers(buffers,ind,sizes,values,sensors); 264 put_buffers(buffers,ind,sizes,values,sensors);
244 printf("Data is now in buffer...\n\r"); 265 printf("Data is now in buffer...\n\r");
  266 + printf("Data stored in buffer: %s with index %d and size %d\r\n",buffers[0][ind[0]-1], ind[0],sizes[0]);
245 if (i == LONG_PERIOD/SHORT_PERIOD ){ 267 if (i == LONG_PERIOD/SHORT_PERIOD ){
246 printf("Programmed Send cycle...\r\n"); 268 printf("Programmed Send cycle...\r\n");
247 /* Wi-Fi connect */ 269 /* Wi-Fi connect */
@@ -249,11 +271,13 @@ int main(void) @@ -249,11 +271,13 @@ int main(void)
249 wifi_connect(); 271 wifi_connect();
250 /* Send data to server, empty the buffer */ 272 /* Send data to server, empty the buffer */
251 send_data(buffers, ind, sizes, sensors); 273 send_data(buffers, ind, sizes, sensors);
  274 + printf("Data sent!\r\n");
252 //time = getNTPTime(); 275 //time = getNTPTime();
253 - time = getSecsSince1900(); 276 + update_time(&time);
  277 + delay = getSystemTime();
254 //desconectar wifi 278 //desconectar wifi
255 wifi_disconnect(); 279 wifi_disconnect();
256 - printf("time (absolute):\t%ul\r\ntime mod LONG_PERIOD:\t%ul\r\ntime mod SHORT_PERIOD:\t%ul\r\n",time,time%LONG_PERIOD,time%SHORT_PERIOD); 280 + printf("new ntp time (absolute):\t%ul\r\ntime mod LONG_PERIOD:\t%ul\r\ntime mod SHORT_PERIOD:\t%ul\r\n",time,time%LONG_PERIOD,time%SHORT_PERIOD);
257 i = 0; 281 i = 0;
258 } 282 }
259 283