From 626579214fa75723c349260631a950df357ba214 Mon Sep 17 00:00:00 2001 From: Maria Jorba Brosa Date: Thu, 22 May 2014 07:30:20 +0000 Subject: [PATCH] --- Project/applications/smartcities/main2.c | 116 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 112 insertions(+), 4 deletions(-) diff --git a/Project/applications/smartcities/main2.c b/Project/applications/smartcities/main2.c index 05e2596..4461a1d 100644 --- a/Project/applications/smartcities/main2.c +++ b/Project/applications/smartcities/main2.c @@ -84,6 +84,38 @@ void init_registry(void) {chThdSleepMilliseconds(500);} } + +void send_data() +{ + 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]; + char* valueSensors[TOTAL_SENSORS]; I2C_scan(sensors); - int i = 1; + //unsigned int time = getNTPTime(); unsigned int time = getSecsSince1900(); @@ -108,6 +140,24 @@ int main(void) unsigned int delay2 = 0; sleep_thread(SHORT_PERIOD - time%SHORT_PERIOD); + uint32_t ind[4]={0}; + char** buffers[4]; + uint32_t sizes[4]={0}; + + init_registry(); + + if(timeout==1) + { + printf("Creating AP\r\n"); + //corroborar los parametros del AP + configServer_start(1); + libwismart_WiFi_SoftAP_Start(NETWORK_SSID_AP,NETWORK_CHANNEL_AP,NULL,softapMode_apStartedCb, softapMode_clientIndicationCb); + for(;;) + { + chThdSleepMilliseconds(1000); + } + + int i = 1; while(1){ time += getElapsedTime(delay); printf("time (absolute):\t%d\r\ntime mod LONG_PERIOD:\t%d\r\ntime mod SHORT_PERIOD:\t%d\r\n",time,time%LONG_PERIOD,time%SHORT_PERIOD); @@ -122,10 +172,12 @@ int main(void) printf("time (absolute):\t%d\r\ntime mod LONG_PERIOD:\t%d\r\ntime mod SHORT_PERIOD:\t%d\r\n",time,time%LONG_PERIOD,time%SHORT_PERIOD); delay = getSystemTime(); + //cada mitja hora if (i == LONG_PERIOD/SHORT_PERIOD ){ /* Wi-Fi connect */ wifi_connect(); /* Send data to server, empty the buffer */ + send_data(); //time = getNTPTime(); time = getSecsSince1900(); printf("time (absolute):\t%d\r\ntime mod LONG_PERIOD:\t%d\r\ntime mod SHORT_PERIOD:\t%d\r\n",time,time%LONG_PERIOD,time%SHORT_PERIOD); @@ -138,8 +190,64 @@ int main(void) printf("timestamp (absolute):\t%d\r\ntimestamp mod LONG_PERIOD:\t%d\r\ntimestamp mod SHORT_PERIOD:\t%d\r\n",timestamp,timestamp%LONG_PERIOD,timestamp%SHORT_PERIOD); /* Add data to the buffer with timestamp*/ + put_buffers(buffers,ind,sizes,valueSensors); + printf("mirant memoria\r\n"); + int res=check_memory(); + if(res==SOFT_REACHED){ + printf("--------------soft limit-------------\r\n"); + int j; + for(j=0;j