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 7 len=*buf_len;
8 8 if(len==*index)
9 9 {
10   -
  10 + printf("Joining buffer...\r\n");
11 11 char** buffer=join_buf(buf, buf_len);
  12 + printf("Joined buffer...\r\n");
12 13 buffer[*index]=chHeapAlloc(NULL,strlen(info)+1);
  14 + printf("Memory allocated...\r\n");
13 15 strcpy(buffer[*index],info);
  16 + printf("Data copied...\r\n");
14 17 i=*index+1;
15 18 *index = i;
16 19 return buffer;
17 20 }
18   -else{
  21 +else
  22 +{
  23 + printf("WTF in put_message\r\n");
19 24 buf[*index] = chHeapAlloc(NULL,strlen(info)+1);
20 25 buf[*index]=info;
21 26 i=*index+1;
... ... @@ -81,13 +86,20 @@ char** join_buf(char** buf, uint32_t *buf_len){
81 86 int len= *buf_len;
82 87 n_buf=chHeapAlloc (NULL,sizeof (char *) * (len+1));
83 88 int i;
  89 + printf("Start buffer join...\r\n");
84 90 for(i=0; i<len;i++){
  91 + printf("in join_buf for, Asking for %d bytes...\r\n",strlen(buf[i]+1));
85 92 n_buf[i]=chHeapAlloc(NULL,strlen(buf[i])+1);
  93 + printf("in join_buf for, Memory allocated...\r\n");
86 94 strcpy(n_buf[i],buf[i]);
  95 + printf("in join_buf for, Message copied...\r\n");
87 96 chHeapFree(buf[i]);
  97 + printf("in join_buf for, Memory cleared...\r\n");
88 98 }
  99 + printf("All data transferred\r\n");
89 100 if(len!=0)
90 101 { chHeapFree(buf); }
  102 + printf("Old buffer cleared\r\n");
91 103 len++;
92 104 *buf_len=len;
93 105 return n_buf;
... ...
Project/applications/smartcities/configServer.c
... ... @@ -61,7 +61,6 @@ void configServer_setClientParameters()
61 61 strcpy(config.password,arg_radPassStr);
62 62 strcpy(config.localization,arg_geoLocalizationStr);
63 63 strcpy(config.ssid,arg_networkNameStr);
64   - strcpy(config.wepkey,arg_passphraseStr);
65 64 strcpy(config.passphrase,arg_passphraseStr);
66 65  
67 66 /* Value validation */
... ...
Project/applications/smartcities/main2.c
... ... @@ -13,7 +13,7 @@
13 13 #include "sensors.h"
14 14  
15 15 #define WIFI_MODE WIFI_MODE_CLIENT
16   -#define NETWORK_SSID_AP "modularsens"
  16 +#define NETWORK_SSID_AP "modularsense"
17 17 #define NETWORK_KEY_AP NULL
18 18 #define NETWORK_CHANNEL_AP 1
19 19  
... ... @@ -32,14 +32,30 @@ uint8_t connected=0;
32 32 uint8_t timeout=0;
33 33 uint8_t retries=0;
34 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 48 void init_registry(void)
37 49 {
38 50 config_params_t config;
39 51  
40 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 59 if(!libwismart_RegistryIsValueEmpty(&geo))
44 60 {
45 61 libwismart_RegistryGet(&geo,&config);
... ... @@ -117,8 +133,12 @@ void put_buffers(char** buffers[],uint32_t ind[],uint32_t sizes[],char** cooked,
117 133 int i;
118 134 for(i=0;i<sensors_length;i++){
119 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 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 212 printf("Connecting to wifi...\r\n");
193 213 wifi_connect();
194 214 //unsigned int time = getNTPTime();
195   - unsigned int time = getSecsSince1900();
  215 + unsigned long time;
  216 + update_time(&time);
196 217 //desconectarwifi
197 218 printf("Disconecting wifi...\r\n");
198 219 wifi_disconnect();
... ... @@ -224,16 +245,16 @@ int main(void)
224 245 time += getElapsedTime(delay);
225 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 249 //cada mitja hora
229 250  
230 251 //delay2 = getElapsedTime(delay);
231 252  
232   - delay = getSystemTime();
  253 + //delay = getSystemTime();
233 254 //timestamp = time - delay2;
234   - timestamp = time - delay;
  255 + timestamp = time;
235 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 258 /* Add data to the buffer with timestamp*/
238 259  
239 260 //a_cookedData = format_data(a_rawData, timestamp);
... ... @@ -242,6 +263,7 @@ int main(void)
242 263 printf("Putting data in buffer...\r\n");
243 264 put_buffers(buffers,ind,sizes,values,sensors);
244 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 267 if (i == LONG_PERIOD/SHORT_PERIOD ){
246 268 printf("Programmed Send cycle...\r\n");
247 269 /* Wi-Fi connect */
... ... @@ -249,11 +271,13 @@ int main(void)
249 271 wifi_connect();
250 272 /* Send data to server, empty the buffer */
251 273 send_data(buffers, ind, sizes, sensors);
  274 + printf("Data sent!\r\n");
252 275 //time = getNTPTime();
253   - time = getSecsSince1900();
  276 + update_time(&time);
  277 + delay = getSystemTime();
254 278 //desconectar wifi
255 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 281 i = 0;
258 282 }
259 283  
... ...