Commit c23a8c4548e43d7a49cbd6ca399c41eb28b8b1c4
1 parent
b4b1b5c4
--no commit message
Showing
1 changed file
with
55 additions
and
48 deletions
Project/applications/smartcities/main2.c
@@ -29,7 +29,7 @@ void initLibwismart(void) | @@ -29,7 +29,7 @@ void initLibwismart(void) | ||
29 | uint8_t connected=0; | 29 | uint8_t connected=0; |
30 | uint8_t timeout=0; | 30 | uint8_t timeout=0; |
31 | uint8_t retries=0; | 31 | uint8_t retries=0; |
32 | -uint8_t total_sensors=0; | 32 | +uint8_t first_sensor=0; |
33 | 33 | ||
34 | void init_registry(void) | 34 | void init_registry(void) |
35 | { | 35 | { |
@@ -86,55 +86,62 @@ void init_registry(void) | @@ -86,55 +86,62 @@ void init_registry(void) | ||
86 | 86 | ||
87 | } | 87 | } |
88 | 88 | ||
89 | -void send_data(char** buffers[j], uint32_t ind[], uint32_t sizes[j], uint8_t sensors[]); | 89 | +void send_data(char** buffers[j], uint32_t ind[], uint32_t sizes[j], uint8_t* sensors); |
90 | { | 90 | { |
91 | int j; | 91 | int j; |
92 | - for(j=0;j<total_sensors;j++) | ||
93 | - { | ||
94 | - printf(" enviant buffer %d\r\n",j); | ||
95 | - | ||
96 | - // fem servir 085 de prova, però haurem de fer servir sensor_id[j] | ||
97 | - int ok=send(buffers[j],&ind[j],&sizes[j], mod.ID, sensors[j]); | ||
98 | - | ||
99 | - if(ok==JSON_COMM_ERROR) | 92 | + for(j=0;j<TOTAL_SENSORS;j++) |
93 | + { | ||
94 | + if(sensors[i]!=0) | ||
100 | { | 95 | { |
101 | - printf("wismart is not connected\r\n"); | ||
102 | - } | ||
103 | - else if( ok==JSON_OTHER_ERROR){ | ||
104 | - printf("some error ocurred\r\n"); | ||
105 | - } | ||
106 | - else if(ok ==JSON_POST_OK){ | ||
107 | - printf(" send OK \r\n"); | 96 | + printf(" enviant buffer %d\r\n",j); |
97 | + | ||
98 | + // fem servir 085 de prova, però haurem de fer servir sensor_id[j] | ||
99 | + int ok=send(buffers[j],&ind[j],&sizes[j], mod.ID, sensors[j]); | ||
100 | + | ||
101 | + if(ok==JSON_COMM_ERROR) | ||
102 | + { | ||
103 | + printf("wismart is not connected\r\n"); | ||
104 | + } | ||
105 | + else if( ok==JSON_OTHER_ERROR){ | ||
106 | + printf("some error ocurred\r\n"); | ||
107 | + } | ||
108 | + else if(ok ==JSON_POST_OK){ | ||
109 | + printf(" send OK \r\n"); | ||
110 | + } | ||
108 | } | 111 | } |
109 | } | 112 | } |
110 | } | 113 | } |
111 | 114 | ||
112 | -void put_buffers(char** buffers,uint32_t ind[],uint32_t sizes[],char** cooked){ | 115 | +void put_buffers(char** buffers,uint32_t ind[],uint32_t sizes[],char** cooked, uint8_t* sensors){ |
113 | int i; | 116 | int i; |
114 | - for(i=0;i<total_sensors;i++){ | ||
115 | - put_message(cooked[i], buffers[i] ,&ind[i],&sizes[i]); | ||
116 | - chHeapFree(cooked[i]); | 117 | + for(i=0;i<TOTAL_SENSORS;i++){ |
118 | + if(sensors[i]!=0){ | ||
119 | + put_message(cooked[i], buffers[i] ,&ind[i],&sizes[i]); | ||
120 | + chHeapFree(cooked[i]); | ||
121 | + } | ||
117 | } | 122 | } |
118 | 123 | ||
119 | } | 124 | } |
120 | -char** timestamp_datas(char* value[],unsigned long timestamp){ | 125 | +char** timestamp_datas(char* value[],unsigned long timestamp, uint8_t* sensors){ |
121 | 126 | ||
122 | char** cooked_data; | 127 | char** cooked_data; |
123 | Date t=getDate(timestamp); | 128 | Date t=getDate(timestamp); |
124 | int i; | 129 | int i; |
125 | - for(i=0;i<total_sensors;i++){ | ||
126 | - cooked_data[i]=timestamp_data(value[i], t); | ||
127 | - chHeapFree(value[i]); | 130 | + for(i=0;i<TOTAL_SENSORS;i++){ |
131 | + if(sensors[i]!=0){ | ||
132 | + cooked_data[i]=timestamp_data(value[i], t); | ||
133 | + chHeapFree(value[i]); | ||
134 | + } | ||
128 | } | 135 | } |
129 | return cooked_data; | 136 | return cooked_data; |
130 | } | 137 | } |
131 | 138 | ||
132 | -void sensor_scan(){ | ||
133 | - I2C_scan(sensors); | 139 | +void first_sens(uint8_t* sensors){ |
134 | int i; | 140 | int i; |
135 | - for(i=0;i<TOTAL_SENSORS;i++){ | 141 | + for(i=0;i<TOTAL_SENSORS:i++){ |
136 | if(sensors[i]!=0){ | 142 | if(sensors[i]!=0){ |
137 | - total_sensors++; | 143 | + first_sensor=i; |
144 | + break; | ||
138 | } | 145 | } |
139 | } | 146 | } |
140 | } | 147 | } |
@@ -151,10 +158,8 @@ int main(void) | @@ -151,10 +158,8 @@ int main(void) | ||
151 | 158 | ||
152 | //Escanea los sensores -> retorna un vector con las direcciones en cada posición del vector, si la posición del vector retorna un cero -> no existe el sensor | 159 | //Escanea los sensores -> retorna un vector con las direcciones en cada posición del vector, si la posición del vector retorna un cero -> no existe el sensor |
153 | uint8_t sensors[TOTAL_SENSORS]; | 160 | uint8_t sensors[TOTAL_SENSORS]; |
154 | - sensor_scan(); | ||
155 | - char* valueSensors[total_sensors]; | 161 | + char* valueSensors[TOTAL_SENSORS]; |
156 | I2C_scan(sensors); | 162 | I2C_scan(sensors); |
157 | - | ||
158 | //conectar wifi | 163 | //conectar wifi |
159 | //unsigned int time = getNTPTime(); | 164 | //unsigned int time = getNTPTime(); |
160 | unsigned int time = getSecsSince1900(); | 165 | unsigned int time = getSecsSince1900(); |
@@ -231,7 +236,7 @@ int main(void) | @@ -231,7 +236,7 @@ int main(void) | ||
231 | printf("--------------hard limit-------------\r\n"); | 236 | printf("--------------hard limit-------------\r\n"); |
232 | 237 | ||
233 | // fem servir 085 de prova, però haurem de fer servir sensor_id[0] | 238 | // fem servir 085 de prova, però haurem de fer servir sensor_id[0] |
234 | - while( send(buffers[0],&ind[0],&sizes[0], mod.ID, sensors[j]) != JSON_POST_OK ) | 239 | + while( send(buffers[first_sensor],&ind[first_sensor],&sizes[first_sensor], mod.ID, sensors[first_sensor]) != JSON_POST_OK ) |
235 | { | 240 | { |
236 | // El servidor no ens sap dir si tenim permisos o no sense registrar una mostra. | 241 | // El servidor no ens sap dir si tenim permisos o no sense registrar una mostra. |
237 | // Intentem enviar un buffer sencer, a veure si ja podem buidar. | 242 | // Intentem enviar un buffer sencer, a veure si ja podem buidar. |
@@ -241,22 +246,24 @@ int main(void) | @@ -241,22 +246,24 @@ int main(void) | ||
241 | chThdSleepMilliseconds(HARD_LIMIT_WAIT_TIME); | 246 | chThdSleepMilliseconds(HARD_LIMIT_WAIT_TIME); |
242 | } | 247 | } |
243 | int j; | 248 | int j; |
244 | - for(j=1;j<total_sensors;j++) | ||
245 | - { | ||
246 | - printf(" enviant buffer %d\r\n",j); | ||
247 | - | ||
248 | - // fem servir 085 de prova, però haurem de fer servir sensor_id[j] | ||
249 | - int ok=send(buffers[j],&ind[j],&sizes[j], mod.ID, sensors[j]); | ||
250 | - if(ok==JSON_COMM_ERROR) | ||
251 | - { | ||
252 | - printf("wismart is not connected\r\n"); | ||
253 | - } | ||
254 | - else if( ok==JSON_OTHER_ERROR){ | ||
255 | - printf("some error ocurred\r\n"); | ||
256 | - } | ||
257 | - else if(ok ==JSON_POST_OK){ | ||
258 | - printf(" send OK \r\n"); | 249 | + for(j=1;j<TOTAL_SENSORS;j++) |
250 | + { | ||
251 | + if(sensors[j]!=0){ | ||
252 | + printf(" enviant buffer %d\r\n",j); | ||
253 | + // fem servir 085 de prova, però haurem de fer servir sensor_id[j] | ||
254 | + int ok=send(buffers[j],&ind[j],&sizes[j], mod.ID, sensors[j]); | ||
255 | + if(ok==JSON_COMM_ERROR) | ||
256 | + { | ||
257 | + printf("wismart is not connected\r\n"); | ||
258 | + } | ||
259 | + else if( ok==JSON_OTHER_ERROR){ | ||
260 | + printf("some error ocurred\r\n"); | ||
261 | + } | ||
262 | + else if(ok ==JSON_POST_OK){ | ||
263 | + printf(" send OK \r\n"); | ||
264 | + } | ||
259 | } | 265 | } |
266 | + | ||
260 | } | 267 | } |
261 | } | 268 | } |
262 | time += getElapsedTime(delay); | 269 | time += getElapsedTime(delay); |