diff --git a/Project/applications/smartcities/main2.c b/Project/applications/smartcities/main2.c index 2c21e1f..776cd0d 100644 --- a/Project/applications/smartcities/main2.c +++ b/Project/applications/smartcities/main2.c @@ -31,7 +31,7 @@ void initLibwismart(void) uint8_t connected=0; uint8_t timeout=0; uint8_t retries=0; -uint8_t first_sensor=0; +uint8_t sensors_length=0; void init_registry(void) { @@ -91,64 +91,50 @@ void init_registry(void) void send_data(char** buffers[], uint32_t ind[], uint32_t sizes[], uint8_t sensors[]) { int j; - for(j=0;j 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 + uint8_t sensors[TOTAL_SENSORS]; char* valueSensors[TOTAL_SENSORS]; I2C_scan(sensors); - first_sens(sensors); + sensors_length=strlen(sensors); //registrar sensores //Esta funcion esta mas arriba para no repetir código luego -- Imanol wifi_connect(); @@ -202,9 +189,9 @@ int main(void) unsigned long delay2 = 0; sleep_thread(SHORT_PERIOD - time%SHORT_PERIOD); - uint32_t ind[TOTAL_SENSORS]={0}; - char** buffers[TOTAL_SENSORS]; - uint32_t sizes[TOTAL_SENSORS]={0}; + uint32_t ind[sensors_length]={0}; + char** buffers[sensors_length]; + uint32_t sizes[sensors_length]={0}; //char* cooked_data[TOTAL_SENSORS]; int i = 1; @@ -261,8 +248,8 @@ int main(void) wifi_connect(); // fem servir 085 de prova, però haurem de fer servir sensor_id[0] char id_0[3]; - sprintf(id_0,"%x",sensors[first_sensor]); - while( send(buffers[first_sensor],&ind[first_sensor],&sizes[first_sensor], mod.ID, id_0) != JSON_POST_OK ) + sprintf(id_0,"%x",sensors[0]); + while( send(buffers[0],&ind[0],&sizes[0], mod.ID, id_0) != JSON_POST_OK ) { // El servidor no ens sap dir si tenim permisos o no sense registrar una mostra. // Intentem enviar un buffer sencer, a veure si ja podem buidar. @@ -272,25 +259,25 @@ int main(void) chThdSleepMilliseconds(HARD_LIMIT_WAIT_TIME); } int j; - for(j=first_sensor;j