diff --git a/Project/applications/smartcities/adc.c b/Project/applications/smartcities/adc.c index b30ba17..2aa6a12 100644 --- a/Project/applications/smartcities/adc.c +++ b/Project/applications/smartcities/adc.c @@ -22,49 +22,36 @@ void adc_batt_peripheralInit() ADC_InitTypeDef ADC_InitStructure; RCC_APB2PeriphClockCmd(ADCbatt_GPIO_RCC, ENABLE); GPIO_InitStructure.GPIO_Pin = ADCbatt_GPIO_PIN; - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN; - GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; - GPIO_Init(ADCbatt_GPIO_PORT, &GPIO_InitStructure); + GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN; + GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; + GPIO_Init(ADCbatt_GPIO_PORT, &GPIO_InitStructure); RCC_ADCCLKConfig(ADCbatt_DIVIDER); RCC_APB2PeriphClockCmd(ADCbatt_RCC, ENABLE); ADC_DeInit(ADCbatt); - /* ADC1 and ADC2 operate independently */ ADC_InitStructure.ADC_Mode = ADC_Mode_Independent; - /* Disable the scan conversion so we do one at a time */ ADC_InitStructure.ADC_ScanConvMode = DISABLE; - /* Don't do contimuous conversions - do them on demand */ ADC_InitStructure.ADC_ContinuousConvMode = DISABLE; - /* Start conversin by software, not an external trigger */ ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None; - /* Conversions are 12 bit - put them in the lower 12 bits of the result */ ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; - /* Say how many channels would be used by the sequencer */ ADC_InitStructure.ADC_NbrOfChannel = 1; ADC_RegularChannelConfig(ADCbatt, ADCbatt_CHANNEL, 1, ADCbatt_SAMPLETIME); ADC_Init(ADCbatt, &ADC_InitStructure); ADC_Cmd(ADCbatt, ENABLE); - /* Enable ADCbatt reset calibaration register */ ADC_ResetCalibration(ADCbatt); - /* Check the end of ADCbatt reset calibration register */ while(ADC_GetResetCalibrationStatus(ADCbatt)); - /* Start ADCbatt calibaration */ ADC_StartCalibration(ADCbatt); - /* Check the end of ADC1 calibration */ while(ADC_GetCalibrationStatus(ADCbatt)); } uint16_t adc_batt_read() { - /* Start the conversion */ - ADC_SoftwareStartConvCmd(ADCbatt, ENABLE); - /* Wait until conversion completion */ - while(ADC_GetFlagStatus(ADCbatt, ADC_FLAG_EOC) == RESET); - /* Get the conversion value */ - return ADC_GetConversionValue(ADCbatt); + ADC_SoftwareStartConvCmd(ADCbatt, ENABLE); + while(ADC_GetFlagStatus(ADCbatt, ADC_FLAG_EOC) == RESET); + return ADC_GetConversionValue(ADCbatt); } void adc_sound_init() @@ -89,49 +76,35 @@ void adc_sound_peripheralInit() ADC_InitTypeDef ADC_InitStructure; RCC_APB2PeriphClockCmd(ADCsound_GPIO_RCC, ENABLE); GPIO_InitStructure.GPIO_Pin = ADCsound_GPIO_PIN; - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN; - GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; - GPIO_Init(ADCsound_GPIO_PORT, &GPIO_InitStructure); + GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN; + GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; + GPIO_Init(ADCsound_GPIO_PORT, &GPIO_InitStructure); RCC_ADCCLKConfig(ADCsound_DIVIDER); RCC_APB2PeriphClockCmd(ADCsound_RCC, ENABLE); ADC_DeInit(ADCsound); - - /* ADC1 and ADC2 operate independently */ ADC_InitStructure.ADC_Mode = ADC_Mode_Independent; - /* Disable the scan conversion so we do one at a time */ ADC_InitStructure.ADC_ScanConvMode = DISABLE; - /* Don't do contimuous conversions - do them on demand */ ADC_InitStructure.ADC_ContinuousConvMode = DISABLE; - /* Start conversin by software, not an external trigger */ ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None; - /* Conversions are 12 bit - put them in the lower 12 bits of the result */ ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; - /* Say how many channels would be used by the sequencer */ ADC_InitStructure.ADC_NbrOfChannel = 1; - - ADC_RegularChannelConfig(ADCsound, ADCsound_CHANNEL, 1, ADCsound_SAMPLETIME); + + ADC_RegularChannelConfig(ADCsound, ADCsound_CHANNEL, 1, ADCsound_SAMPLETIME); ADC_Init(ADCsound, &ADC_InitStructure); ADC_Cmd(ADCsound, ENABLE); - /* Enable ADCsound reset calibaration register */ ADC_ResetCalibration(ADCsound); - /* Check the end of ADCsound reset calibration register */ while(ADC_GetResetCalibrationStatus(ADCsound)); - /* Start ADCsound calibaration */ ADC_StartCalibration(ADCsound); - /* Check the end of ADC1 calibration */ while(ADC_GetCalibrationStatus(ADCsound)); } uint16_t adc_sound_read() { - /* Start the conversion */ - ADC_SoftwareStartConvCmd(ADCsound, ENABLE); - /* Wait until conversion completion */ - while(ADC_GetFlagStatus(ADCsound, ADC_FLAG_EOC) == RESET); - /* Get the conversion value */ - return ADC_GetConversionValue(ADCsound); + ADC_SoftwareStartConvCmd(ADCsound, ENABLE); + while(ADC_GetFlagStatus(ADCsound, ADC_FLAG_EOC) == RESET); + return ADC_GetConversionValue(ADCsound); } diff --git a/Project/applications/smartcities/buffer.c b/Project/applications/smartcities/buffer.c index 53d95ea..935e885 100644 --- a/Project/applications/smartcities/buffer.c +++ b/Project/applications/smartcities/buffer.c @@ -1,75 +1,73 @@ #include "buffer.h" #include "globals.h" -char** put_message(char* info, char** buf,uint32_t *index, uint32_t *buf_len){ - -uint32_t i,len; -len=*buf_len; -if(len==*index) -{ - printf("Joining buffer...\r\n"); - char** buffer=join_buf(buf, buf_len); - printf("Joined buffer...\r\n"); - buffer[*index]=chHeapAlloc(NULL,strlen(info)+1); - printf("Memory allocated...\r\n"); - strcpy(buffer[*index],info); - printf("Data copied...\r\n"); - i=*index+1; - *index = i; - return buffer; -} -else +char** put_message(char* info, char** buf,uint32_t *index, uint32_t *buf_len) { - printf("WTF in put_message\r\n"); - buf[*index] = chHeapAlloc(NULL,strlen(info)+1); - buf[*index]=info; - i=*index+1; - *index = i; - return buf; -} - + uint32_t i,len; + len=*buf_len; + if(len==*index) + { + printf("Joining buffer...\r\n"); + char** buffer = join_buf(buf, buf_len); + printf("Joined buffer...\r\n"); + buffer[*index] = chHeapAlloc(NULL,strlen(info)+1); + printf("Memory allocated...\r\n"); + strcpy(buffer[*index],info); + printf("Data copied...\r\n"); + i = *index+1; + *index = i; + return buffer; + } + else + { + printf("WTF in put_message\r\n"); + buf[*index] = chHeapAlloc(NULL,strlen(info)+1); + buf[*index] = info; + i = *index+1; + *index = i; + return buf; + } } -int check_memory(){ - +int check_memory() +{ printf("Memòria disponible en bytes segons:\r\n"); - - int mem_free=libwismart_GetMemFree_Ram().free; - //printf("- free_core: %d %d\r\n", mem_free, MAX_RAM-mem_free); - printf("- free: %d %d\r\n", libwismart_GetMemFree_Ram().free, MAX_RAM- libwismart_GetMemFree_Ram().free); - - - //int mem_free=20000; - int mem=MAX_RAM-mem_free; + int mem_free = libwismart_GetMemFree_Ram().free; + printf("- free: %d %d\r\n", libwismart_GetMemFree_Ram().free, MAX_RAM - libwismart_GetMemFree_Ram().free); + int mem = MAX_RAM - mem_free; printf("mem ocupada=%d\r\n",mem); - if(mem>=HARD_LIMIT) + if(mem >= HARD_LIMIT) { return HARD_REACHED; } - else if(mem >= SOFT_LIMIT){ + else if(mem >= SOFT_LIMIT) + { return SOFT_REACHED; } return MEMORY_OK; } -int send(char** buf, uint32_t *index, uint32_t *size_buf, char *provider_ID, char *sensor_ID){ +int send(char** buf, uint32_t *index, uint32_t *size_buf, char *provider_ID, char *sensor_ID) +{ printf("abans del JSON statement\r\n"); printf("index= %d \r\n",*index); char* statement=prepare_json_observation_statement(buf, *index); uint32_t size = strlen(statement); if(buf==NULL) - { return 2; } + { + return 2; + } printf("abans del JSON\r\n"); - uint8_t res=send_json(statement, size, provider_ID, sensor_ID); + uint8_t res = send_json(statement, size, provider_ID, sensor_ID); chHeapFree(statement); int i; printf("JSON_POST_OK ? %d\r\n",res == JSON_POST_OK); - if(res==JSON_POST_OK){ + if(res==JSON_POST_OK) + { for(i=0;i<*index;i++) { chHeapFree(buf[i]); } - printf("djfkhvldkfjhdñkfgv\r\n"); if(buf!=NULL) chHeapFree(buf); @@ -81,15 +79,17 @@ int send(char** buf, uint32_t *index, uint32_t *size_buf, char *provider_ID, cha } //realloc -char** join_buf(char** buf, uint32_t *buf_len){ +char** join_buf(char** buf, uint32_t *buf_len) +{ char** n_buf; - int len= *buf_len; - n_buf=chHeapAlloc (NULL,sizeof (char *) * (len+1)); + int len = *buf_len; + n_buf = chHeapAlloc (NULL,sizeof (char *) * (len+1)); int i; printf("Start buffer join...\r\n"); - for(i=0; i standard - I2C_InitStruct.I2C_OwnAddress1 = 0x00; // own address, not relevant in master mode - I2C_InitStruct.I2C_Ack = I2C_Ack_Enable; // disable acknowledge when reading (can be changed later on) - I2C_InitStruct.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit; // set address length to 7 bit addresses - I2C_Init(I2C1, &I2C_InitStruct); // init I2C1 - - //Enable clock stretching + I2C_InitStruct.I2C_ClockSpeed = 100000; + I2C_InitStruct.I2C_Mode = I2C_Mode_I2C; + I2C_InitStruct.I2C_DutyCycle = I2C_DutyCycle_2; + I2C_InitStruct.I2C_OwnAddress1 = 0x00; + I2C_InitStruct.I2C_Ack = I2C_Ack_Enable; + I2C_InitStruct.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit; + I2C_Init(I2C1, &I2C_InitStruct); I2C_StretchClockCmd(I2C1, ENABLE); - - // enable I2C1 - I2C_Cmd(I2C1, ENABLE); //sets PE bit in CR1, at end` + I2C_Cmd(I2C1, ENABLE); } void I2C_start(I2C_TypeDef* I2Cx, uint8_t address, uint8_t direction) diff --git a/Project/applications/smartcities/main.c b/Project/applications/smartcities/main.c index 38e2019..4e951f1 100644 --- a/Project/applications/smartcities/main.c +++ b/Project/applications/smartcities/main.c @@ -8,10 +8,12 @@ #include "buffer.h" #include "i2c.h" #include "configServer.h" +#include "timer-loop.h" +#include "ntp.h" #include "sensors.h" #define WIFI_MODE WIFI_MODE_CLIENT -#define NETWORK_SSID_AP "modularsens" +#define NETWORK_SSID_AP "modularsense" #define NETWORK_KEY_AP NULL #define NETWORK_CHANNEL_AP 1 @@ -29,14 +31,33 @@ void initLibwismart(void) uint8_t connected=0; uint8_t timeout=0; uint8_t retries=0; +uint8_t sensors_length=0; +uint8_t registry_opened=0; + +module mod; + +void update_time(unsigned long *time) +{ + printf("Requesting new NTP time...\r\n"); + unsigned long new_time = getSecsSince1900(); + if(new_time) + { + *time = getSecsSince1900(); + } + printf("Time updated...\r\n"); +} void init_registry(void) { config_params_t config; strcpy(config.localization,"none"); - libwismart_RegistryCreateKey(&geo, 1, sizeof(config)); - libwismart_RegistryOpen(1); + if(!registry_opened) + { + libwismart_RegistryCreateKey(&geo, 1, sizeof(config)); + libwismart_RegistryOpen(1); + registry_opened = 1; + } if(!libwismart_RegistryIsValueEmpty(&geo)) { libwismart_RegistryGet(&geo,&config); @@ -51,6 +72,7 @@ void init_registry(void) printf("Geo Localization = %s\r\n", config.localization); strcpy(mod.geoloc,config.localization); + strcpy(mod.ID,MODULE_ID); if(config.security == PROFILE_SECURITY_OPEN) { printf("open detected\r\n"); @@ -79,29 +101,75 @@ void init_registry(void) printf("wep detected\r\n"); //Is WEP libwismart_WiFiConnect(config.ssid,config.wepkey,wifi_connect_result_cb); + libwismart_WiFiSetWep(config.wepkey,1); } while(connected == 0 && timeout != 1 ) {chThdSleepMilliseconds(500);} } -int main(void) + +void send_data(char** buffers[], uint32_t ind[], uint32_t sizes[], uint8_t sensors[]) { - initLibwismart(); - libwismart_PowerSave_Enable(); - libwismart_PowerSave_HigherProfile(TRUE); - libwismart_RegisterDhcpCB(dhcp_connect_result_cb); - libwismart_WiFiInit(); - libwismart_SetScanRunsForConnTimeout(4); //Edit a 4 - libwismart_EnableBsdSocketAPI(); + 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 + //Escanea y registra + I2C_scan(I2C1,sensors); + sensors_length=strlen((char*)sensors); + printf("%d sensor detected...\r\n",sensors_length); + + unsigned long time; + update_time(&time); + //desconectarwifi + printf("Disconecting wifi...\r\n"); + wifi_disconnect(); + + unsigned long timestamp = 0; + unsigned long delay = getSystemTime(); + sleep_thread(SHORT_PERIOD - time%SHORT_PERIOD); + + uint32_t ind[TOTAL_SENSORS]={0}; + char** buffers[TOTAL_SENSORS]; + uint32_t sizes[TOTAL_SENSORS]={0}; + + i = 1; + + while(1) + { + time += getElapsedTime(delay); + 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); + + delay = getSystemTime(); + /* Collect data from sensors */ + printf("Collecting data...\r\n"); + collectData(valueSensors, sensors); + printf("Data collected...\r\n"); + time += getElapsedTime(delay); + 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); + timestamp = time; + 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); + delay = getSystemTime(); + printf("Timestamping data...\r\n"); + char** values=timestamp_datas(valueSensors,timestamp,sensors); + printf("Putting data in buffer...\r\n"); + put_buffers(buffers,ind,sizes,values,sensors); + printf("Data is now in buffer...\n\r"); + if (i == LONG_PERIOD/SHORT_PERIOD ){ + printf("Programmed Send cycle...\r\n"); + /* Wi-Fi connect */ + printf("Connecting to wifi...\r\n"); + wifi_connect(); + /* Send data to server, empty the buffer */ + send_data(buffers, ind, sizes, sensors); + printf("Data sent!\r\n"); + //Now sending battery level + send_battery_level(timestamp); + //time = getNTPTime(); + update_time(&time); + delay = getSystemTime(); + //desconectar wifi + wifi_disconnect(); + 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); + i = 0; + } + + printf("mirant memoria\r\n"); + int res=check_memory(); + if(res==SOFT_REACHED){ + printf("--------------soft limit-------------\r\n"); + wifi_connect(); + send_data(buffers, ind, sizes, sensors); + //Now sending battery level + send_battery_level(timestamp); + //disconect_wifi() + wifi_disconnect(); + } + else if(res==HARD_REACHED){ + printf("--------------hard limit-------------\r\n"); + wifi_connect(); + char id_0[3]; + 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. + // No podem enviar només una mostra perquè json és rígid en aquest sentit. + + printf("hard_reached and unable to sentd.\r\nLa biblia en vers: i Jesús digué: Aixeca't, Llàtzer!!\r\n"); + chThdSleepMilliseconds(HARD_LIMIT_WAIT_TIME); + } + int j; + for(j=1;j -#include "libwismart.h" -#include "libwismart_irqs.h" /* implement irq handlers */ -#include "lwip/inet.h" -#include "globals.h" -#include "httpClient.h" -#include "callbacks.h" -#include "buffer.h" -#include "i2c.h" -#include "configServer.h" -#include "timer-loop.h" -#include "ntp.h" -#include "sensors.h" - -#define WIFI_MODE WIFI_MODE_CLIENT -#define NETWORK_SSID_AP "modularsense" -#define NETWORK_KEY_AP NULL -#define NETWORK_CHANNEL_AP 1 - -#define HARD_LIMIT_WAIT_TIME 10*1000 //5*60*1000 - -wismart_registryKey_t geo; - - -void initLibwismart(void) -{ - wismart_hwif_t hwif = libwismart_GetDefaultHWIF(); - libwismart_Init(hwif); -} - -uint8_t connected=0; -uint8_t timeout=0; -uint8_t retries=0; -uint8_t sensors_length=0; -uint8_t registry_opened=0; - -module mod; - -void update_time(unsigned long *time) -{ - printf("Requesting new NTP time...\r\n"); - unsigned long new_time = getSecsSince1900(); - if(new_time) - { - *time = getSecsSince1900(); - } - printf("Time updated...\r\n"); -} - -void init_registry(void) -{ - config_params_t config; - - strcpy(config.localization,"none"); - if(!registry_opened) - { - libwismart_RegistryCreateKey(&geo, 1, sizeof(config)); - libwismart_RegistryOpen(1); - registry_opened = 1; - } - if(!libwismart_RegistryIsValueEmpty(&geo)) - { - libwismart_RegistryGet(&geo,&config); - } - - printf("SSID = %s\r\n",config.ssid); - printf("Wep key = %s\r\n",config.wepkey); - printf("Passphrase = %s\r\n", config.passphrase); - printf("User = %s\r\n",config.user); - printf("Password = %s\r\n",config.password); - printf("Encryption type = %d\r\n",config.security); - printf("Geo Localization = %s\r\n", config.localization); - - strcpy(mod.geoloc,config.localization); - strcpy(mod.ID,MODULE_ID); - if(config.security == PROFILE_SECURITY_OPEN) - { - printf("open detected\r\n"); - libwismart_WiFiConnect(config.ssid,NULL,wifi_connect_result_cb); - } - else if(config.security == PROFILE_SECURITY_WPA_WPA2) - { - if(!strcmp(config.user,"")) - { - printf("wpa detected\r\n"); - libwismart_WiFiConnect(config.ssid,config.passphrase,wifi_connect_result_cb); - } - else - { - printf("wpa Enterprise detected\r\n"); - struct wpa_param wpa; - wpa.eap_method = WISMART_EAP_METHOD_TTLS; - wpa.u.ttls.identity = config.user; - wpa.u.ttls.password = config.password; - wpa.u.ttls.ca_cert=NULL; - libwismart_WiFiConnectEnterprise(config.ssid, &wpa, wifi_connect_result_cb); - } - } - else - { - printf("wep detected\r\n"); - //Is WEP - libwismart_WiFiConnect(config.ssid,config.wepkey,wifi_connect_result_cb); - libwismart_WiFiSetWep(config.wepkey,1); - } - while(connected == 0 && timeout != 1 ) - {chThdSleepMilliseconds(500);} - -} - -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 - //Escanea y registra - I2C_scan(I2C1,sensors); - sensors_length=strlen((char*)sensors); - printf("%d sensor detected...\r\n",sensors_length); - - unsigned long time; - update_time(&time); - //desconectarwifi - printf("Disconecting wifi...\r\n"); - wifi_disconnect(); - - unsigned long timestamp = 0; - unsigned long delay = getSystemTime(); - sleep_thread(SHORT_PERIOD - time%SHORT_PERIOD); - - uint32_t ind[TOTAL_SENSORS]={0}; - char** buffers[TOTAL_SENSORS]; - uint32_t sizes[TOTAL_SENSORS]={0}; - - i = 1; - - while(1) - { - time += getElapsedTime(delay); - 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); - - delay = getSystemTime(); - /* Collect data from sensors */ - printf("Collecting data...\r\n"); - collectData(valueSensors, sensors); - printf("Data collected...\r\n"); - time += getElapsedTime(delay); - 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); - timestamp = time; - 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); - delay = getSystemTime(); - printf("Timestamping data...\r\n"); - char** values=timestamp_datas(valueSensors,timestamp,sensors); - printf("Putting data in buffer...\r\n"); - put_buffers(buffers,ind,sizes,values,sensors); - printf("Data is now in buffer...\n\r"); - if (i == LONG_PERIOD/SHORT_PERIOD ){ - printf("Programmed Send cycle...\r\n"); - /* Wi-Fi connect */ - printf("Connecting to wifi...\r\n"); - wifi_connect(); - /* Send data to server, empty the buffer */ - send_data(buffers, ind, sizes, sensors); - printf("Data sent!\r\n"); - //Now sending battery level - send_battery_level(timestamp); - //time = getNTPTime(); - update_time(&time); - delay = getSystemTime(); - //desconectar wifi - wifi_disconnect(); - 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); - i = 0; - } - - printf("mirant memoria\r\n"); - int res=check_memory(); - if(res==SOFT_REACHED){ - printf("--------------soft limit-------------\r\n"); - wifi_connect(); - send_data(buffers, ind, sizes, sensors); - //Now sending battery level - send_battery_level(timestamp); - //disconect_wifi() - wifi_disconnect(); - } - else if(res==HARD_REACHED){ - printf("--------------hard limit-------------\r\n"); - wifi_connect(); - char id_0[3]; - 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. - // No podem enviar només una mostra perquè json és rígid en aquest sentit. - - printf("hard_reached and unable to sentd.\r\nLa biblia en vers: i Jesús digué: Aixeca't, Llàtzer!!\r\n"); - chThdSleepMilliseconds(HARD_LIMIT_WAIT_TIME); - } - int j; - for(j=1;j