From 1a74fac0b68676600c82e5e956dabedf713f3cce Mon Sep 17 00:00:00 2001 From: Imanol-Mikel Barba Sabariego Date: Sun, 25 May 2014 21:20:16 +0000 Subject: [PATCH] --- Project/applications/smartcities/callbacks.c | 10 ++-------- Project/applications/smartcities/configServer.c | 32 ++++++++++++++++---------------- Project/applications/smartcities/i2c.c | 33 ++++++++++++++++++++++++--------- Project/applications/smartcities/include/i2c.h | 3 ++- Project/applications/smartcities/include/sensors.h | 7 +++++-- Project/applications/smartcities/json.c | 37 +++++++++++++++++++------------------ Project/applications/smartcities/main2.c | 41 +++++++++++++++-------------------------- Project/applications/smartcities/sensors.c | 93 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------------- 8 files changed, 142 insertions(+), 114 deletions(-) diff --git a/Project/applications/smartcities/callbacks.c b/Project/applications/smartcities/callbacks.c index 3891d2e..5000350 100644 --- a/Project/applications/smartcities/callbacks.c +++ b/Project/applications/smartcities/callbacks.c @@ -13,18 +13,12 @@ void dhcp_connect_result_cb(int result) else if(result==LIBWISMART_DHCP_TIMEOUT) { printf("DHCP timeout\r\n"); - if(++retries == MAX_RETRIES) - { - timeout = 1; - } + timeout = 1; } else { printf("DHCP error\r\n"); - if(++retries == MAX_RETRIES) - { - timeout = 1; - } + timeout = 1; } } diff --git a/Project/applications/smartcities/configServer.c b/Project/applications/smartcities/configServer.c index 249490e..43050bb 100644 --- a/Project/applications/smartcities/configServer.c +++ b/Project/applications/smartcities/configServer.c @@ -61,6 +61,7 @@ void configServer_setClientParameters() strcpy(config.password,arg_radPassStr); strcpy(config.localization,arg_geoLocalizationStr); strcpy(config.ssid,arg_networkNameStr); + strcpy(config.wepkey,arg_passphraseStr); strcpy(config.passphrase,arg_passphraseStr); /* Value validation */ @@ -105,6 +106,7 @@ void configServer_setClientParameters() if(ret == 0) { //successful conversion + printf("%d,%d,%d,%d,%d\r\n",asciiBuf[0],asciiBuf[1],asciiBuf[2],asciiBuf[3],asciiBuf[4]); memset(arg_passphraseStr, 0, sizeof(arg_passphraseStr)); memcpy(arg_passphraseStr, asciiBuf, 5); } @@ -143,8 +145,7 @@ void configServer_setClientParameters() } strcpy(config.passphrase, (char*)arg_passphraseStr); - //strcpy(config.wepkey, (char*)arg_passphraseStr); - strcpy(config.wepkey, "0009031991"); + strcpy(config.wepkey, (char*)arg_passphraseStr); } libwismart_RegistrySet(&geo,&config); } @@ -166,8 +167,6 @@ void configServer_setClientParameters() uint32_t configServer_dynamicCb(char* varName, char** varValue, uint8_t* varAllocType) { char* value; - uint16_t profile_enabled; - config_params_t config; if(libwismart_RegistryIsValueEmpty(&geo)) @@ -181,8 +180,6 @@ uint32_t configServer_dynamicCb(char* varName, char** varValue, uint8_t* varAllo libwismart_RegistryGet(&geo,&config); CONFIG_SERVER_DBG("Quering configuration server for variable '%s'", varName); - - libwismart_ProfileGet_Int("profile_enabled", &profile_enabled); if(strcmp((char*)varName,"WIFI_SECURITY") == 0){ uint16_t security; @@ -244,7 +241,7 @@ uint32_t configServer_dynamicCb(char* varName, char** varValue, uint8_t* varAllo if(value == NULL){ return WISMART_SERVER_ERR_MEM; } - + strcpy(value,config.passphrase); /* Display only visible characters */ @@ -339,20 +336,23 @@ HEX2BIN conversion * into "111" (byte array [49][49][49]). This is needed because WEP keys can be * givent either as HEX strigs or as ASCII strings. */ -int configServer_hex2bin(char *hex, char *buf, size_t hexLen){ - - size_t i; - char *ipos = hex; - char *opos = buf; - - if( (hexLen%2) != 0){ +int configServer_hex2bin(char *hex, char *buf, size_t hexLen) +{ + size_t i, j = 0; + uint8_t byte; + /*if( (hexLen%2) != 0){ return -1; - } + }* for (i = 0; i < hexLen; i += 2) { *opos++ = (ipos[i] << 4) | (ipos[i + 1]); + }*/ + + for(i = 0; i < strlen(hex); i += 2) + { + byte = (hex[i]-48)*16 + (hex[i+1]-48); + buf[j++] = byte; } - return 0; } diff --git a/Project/applications/smartcities/i2c.c b/Project/applications/smartcities/i2c.c index 009a630..6e329ef 100644 --- a/Project/applications/smartcities/i2c.c +++ b/Project/applications/smartcities/i2c.c @@ -1,7 +1,9 @@ #include "i2c.h" +#include "json.h" void I2C_init(void) { + printf("Initializing I2C...\r\n"); GPIO_InitTypeDef GPIO_InitStruct; I2C_InitTypeDef I2C_InitStruct; @@ -38,6 +40,7 @@ void I2C_init(void) void I2C_start(I2C_TypeDef* I2Cx, uint8_t address, uint8_t direction) { + printf("Sending I2C Start...\r\n"); while(I2C_GetFlagStatus(I2Cx, I2C_FLAG_BUSY)) { // wait until I2C1 is not busy any more @@ -66,6 +69,7 @@ void I2C_start(I2C_TypeDef* I2Cx, uint8_t address, uint8_t direction) void I2C_write(I2C_TypeDef* I2Cx, uint8_t data) { + printf("Sending I2C byte %x...\r\n",data); /* WARNING * * OJITO QUE ESTÁ ESPERANDO EL EV8 Y NO EL EV8_2 @@ -81,6 +85,7 @@ void I2C_write(I2C_TypeDef* I2Cx, uint8_t data) uint8_t I2C_read_ack(I2C_TypeDef* I2Cx) { + printf("Listening for byte in I2C (ACK)\r\n"); I2C_AcknowledgeConfig(I2Cx, ENABLE); while( !I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_BYTE_RECEIVED)) { @@ -91,8 +96,9 @@ uint8_t I2C_read_ack(I2C_TypeDef* I2Cx) uint8_t I2C_read_nack(I2C_TypeDef* I2Cx) { + printf("Listening for byte in I2C (NACK)\r\n"); I2C_AcknowledgeConfig(I2Cx, DISABLE); - I2C_GenerateSTOP(I2Cx, ENABLE); + //I2C_GenerateSTOP(I2Cx, ENABLE); while( !I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_BYTE_RECEIVED)) { // wait until one byte has been received @@ -102,8 +108,9 @@ uint8_t I2C_read_nack(I2C_TypeDef* I2Cx) void I2C_stop(I2C_TypeDef* I2Cx) { + printf("Sending I2C Stop...\r\n"); I2C_GenerateSTOP(I2Cx, ENABLE); - while(!I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_BYTE_TRANSMITTED)) + while(!I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_BYTE_TRANSMITTING)) { // wait for I2C1 EV8_2 --> byte has been transmitted } @@ -122,7 +129,7 @@ uint8_t I2C_check(I2C_TypeDef* I2Cx, uint8_t address) } printf("Probing address %x ...\r\n",address); I2C_Send7bitAddress(I2Cx, address, I2C_Direction_Transmitter); - chThdSleepMilliseconds(SCAN_TIMEOUT); + chThdSleepMilliseconds(I2C_TIMEOUT); if(!I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED)) { return 1; @@ -133,21 +140,29 @@ uint8_t I2C_check(I2C_TypeDef* I2Cx, uint8_t address) return 0; } +void I2C_reset() +{ + printf("Resetting I2C...\r\n"); + I2C_SoftwareResetCmd(I2C1, ENABLE); + I2C_DeInit(I2C1); + I2C_init(); + +} + void I2C_scan(uint8_t *addresses) { - uint8_t sensors[TOTAL_SENSORS] = {DISTANCE_ADDR,LIGHT_ADDR,PRESSURE_ADDR,HUMIDITY_TEMP_ADDR}; uint8_t i, j = 0; + I2C_init(); for(i = 0; i < TOTAL_SENSORS; i++) { - if(!I2C_check(I2C1,sensors[i] << 1)) + if(!I2C_check(I2C1,sensors[i]->ID << 1)) { - addresses[j++] = sensors[i]; + addresses[j++] = sensors[i]->ID; + register_sensor(*sensors[i]); } else { - I2C_SoftwareResetCmd(I2C1, ENABLE); - I2C_DeInit(I2C1); - I2C_init(); + I2C_reset(); } } } \ No newline at end of file diff --git a/Project/applications/smartcities/include/i2c.h b/Project/applications/smartcities/include/i2c.h index b448ade..8339ad9 100644 --- a/Project/applications/smartcities/include/i2c.h +++ b/Project/applications/smartcities/include/i2c.h @@ -7,7 +7,7 @@ #include "sensors.h" #include "libwismart.h" -#define SCAN_TIMEOUT 100 +#define I2C_TIMEOUT 100 void I2C_init(void); void I2C_start(I2C_TypeDef* I2Cx, uint8_t address, uint8_t direction); @@ -17,6 +17,7 @@ uint8_t I2C_read_ack(I2C_TypeDef* I2Cx); uint8_t I2C_read_nack(I2C_TypeDef* I2Cx); void I2C_scan(uint8_t *addresses); uint8_t I2C_check(I2C_TypeDef* I2Cx, uint8_t address); +void I2C_reset(void); #endif diff --git a/Project/applications/smartcities/include/sensors.h b/Project/applications/smartcities/include/sensors.h index 0fc5448..88551b4 100644 --- a/Project/applications/smartcities/include/sensors.h +++ b/Project/applications/smartcities/include/sensors.h @@ -13,7 +13,8 @@ #define PRESSURE_ADDR 0x77 //Cambiar a MPL115A #define HUMIDITY_TEMP_ADDR 0x27 #define SOUND_ADDR 0x72 -//REMEMBER TO UPDATE I2C_scan ROUTINE WITH EACH NEW SENSOR!!!! +//REMEMBER TO UPDATE collectData ROUTINE WITH EACH NEW SENSOR!!!! +//REMEMBER TO UPDATE I2C sensors in sensor definitions in this header and sensors.c WITH EACH NEW SENSOR!!!! #define TOTAL_SENSORS 5 #define BATTERY_ADDR 0x00 //SIEMPRE PRESENTE, NUNCA BUSCAR EN i2c_scan @@ -26,7 +27,7 @@ typedef struct { char* additional_info; } sensor; -void wakeup(uint8_t logic_address); +void wakeup_sensors(uint8_t logic_address); //SENSOR DEFINITIONS extern sensor light_sensor; @@ -36,6 +37,8 @@ extern sensor humidity_temp_sensor; extern sensor sound_sensor; extern sensor battery; +extern sensor* sensors[TOTAL_SENSORS+1]; + //SENSOR FUNCTIONS //LIGHT SENSOR diff --git a/Project/applications/smartcities/json.c b/Project/applications/smartcities/json.c index e3f17c0..cdba6cd 100644 --- a/Project/applications/smartcities/json.c +++ b/Project/applications/smartcities/json.c @@ -2,19 +2,26 @@ uint8_t register_sensor(sensor sens) { - uint8_t result; - if(sens.ID == PRESSURE_ADDR) - { - sens.additional_info = callibration_pressure_data_csv(get_pressure_callibration_data()); - } - char *statement = prepare_json_register_statement(mod,sens); - chHeapFree(sens.additional_info); - sens.additional_info = NULL; + printf("Registering sensor: %s\r\n",sens.description); + uint8_t result; + char *statement; + if(sens.ID == PRESSURE_ADDR) + { + sens.additional_info = callibration_pressure_data_csv(get_pressure_callibration_data()); + statement = prepare_json_register_statement(mod,sens); + chHeapFree(sens.additional_info); + sens.additional_info = NULL; + } + else + { + statement = prepare_json_register_statement(mod,sens); + } + printf("%s\r\n",statement); char sensor_ID[3]; sprintf(sensor_ID,"%d",sens.ID); - result = send_json(statement,strlen(statement),mod.ID,sensor_ID); - chHeapFree(statement); - return result; + result = send_json(statement,strlen(statement),mod.ID,sensor_ID); + chHeapFree(statement); + return result; } char* prepare_json_observation_statement(char** data, uint32_t nObservations) @@ -39,6 +46,7 @@ char* prepare_json_observation_statement(char** data, uint32_t nObservations) char* prepare_json_register_statement(module mod, sensor sens) { + printf("Registering sensor: %s in: %s\r\n",sens.description,mod.geoloc); unsigned int length; char *json_statement, *str_aux, *str_aux2; char ID[MODULE_ID_LENGTH+3]; @@ -85,13 +93,6 @@ char* prepare_json_register_statement(module mod, sensor sens) char* prepare_observation(char* observation, uint32_t length) { char *json_data, *str_aux, *str_aux2; - /* TOPKEK - * - * ¿Gestión de errores? - * ¿PA QUÉ? - * - * --le trole - */ int value_length = find_next_index(observation,length,','); //EXPECTS FORMATTING!!! int timestamp_length = length - (value_length + 1); char *value = (char*) chHeapAlloc(NULL,value_length+1); diff --git a/Project/applications/smartcities/main2.c b/Project/applications/smartcities/main2.c index 85044e3..4b8acc5 100644 --- a/Project/applications/smartcities/main2.c +++ b/Project/applications/smartcities/main2.c @@ -70,6 +70,7 @@ void init_registry(void) printf("Geo Localization = %s\r\n", config.localization); strcpy(mod.geoloc,config.localization); + printf("%s\r\n", mod.geoloc); if(config.security == PROFILE_SECURITY_OPEN) { printf("open detected\r\n"); @@ -98,6 +99,7 @@ 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);} @@ -201,16 +203,21 @@ int main(void) char* valueSensors[TOTAL_SENSORS]; memset (valueSensors, 0, TOTAL_SENSORS); + + printf("Connecting to wifi...\r\n"); + wifi_connect(); + + wakeup_sensors(0x15); printf("Scanning sensors...\r\n"); - //I2C_scan(sensors); - sensors[0] = LIGHT_ADDR; + //Escanea y registra + I2C_scan(sensors); sensors_length=strlen((char*)sensors); printf("%d sensor detected...\r\n",sensors_length); - //registrar sensores - //Esta funcion esta mas arriba para no repetir código luego -- Imanol - printf("Connecting to wifi...\r\n"); - wifi_connect(); - //unsigned int time = getNTPTime(); + + I2C_init(); + printf("%s\r\n",light_value(get_light_data())); + printf("%s\r\n",light_value(get_light_data())); + unsigned long time; update_time(&time); //desconectarwifi @@ -219,13 +226,11 @@ int main(void) unsigned long timestamp = 0; unsigned long delay = getSystemTime(); - 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}; - //char* cooked_data[TOTAL_SENSORS]; int i = 1; while(1){ @@ -234,29 +239,15 @@ int main(void) delay = getSystemTime(); /* Collect data from sensors */ - //collect_data(/*a_rawData*/); printf("Collecting data...\r\n"); - //collectData(valueSensors, sensors); - valueSensors[0] = chHeapAlloc(NULL,6); - strcpy(valueSensors[0],"123456"); + 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); - - //delay = getSystemTime(); - //cada mitja hora - - //delay2 = getElapsedTime(delay); - - //delay = getSystemTime(); - //timestamp = time - delay2; 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(); - /* Add data to the buffer with timestamp*/ - - //a_cookedData = format_data(a_rawData, timestamp); printf("Timestamping data...\r\n"); char** values=timestamp_datas(valueSensors,timestamp,sensors); printf("Putting data in buffer...\r\n"); @@ -292,7 +283,6 @@ int main(void) else if(res==HARD_REACHED){ printf("--------------hard limit-------------\r\n"); wifi_connect(); - // fem servir 085 de prova, però haurem de fer servir sensor_id[0] 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 ) @@ -309,7 +299,6 @@ int main(void) { printf(" enviant buffer %d\r\n",j); - // fem servir 085 de prova, però haurem de fer servir sensor_id[j] char id[3]; sprintf(id,"%x",sensors[j]); int ok=send(buffers[j],&ind[j],&sizes[j], mod.ID, id); diff --git a/Project/applications/smartcities/sensors.c b/Project/applications/smartcities/sensors.c index 1da2d28..f93bb0d 100644 --- a/Project/applications/smartcities/sensors.c +++ b/Project/applications/smartcities/sensors.c @@ -7,7 +7,9 @@ sensor humidity_temp_sensor = {HUMIDITY_TEMP_ADDR, "Humidity and Temperature"," sensor sound_sensor = {SOUND_ADDR, "Sound sensor","mV",NULL}; sensor battery = {BATTERY_ADDR, "Battery Level","mV",NULL}; -void wakeup(uint8_t logic_address) +sensor* sensors[TOTAL_SENSORS+1] = {&light_sensor,&ultrasound_sensor,&pressure_sensor,&humidity_temp_sensor,&sound_sensor,&battery}; + +void wakeup_sensors(uint8_t logic_address) { /* Aquí habría que implementar un control * inteligente de la alimentación de los @@ -78,9 +80,10 @@ uint32_t get_light_data(void) uint32_t data = 0; data = get_light_ch1(); + printf("LIGHT: Got ch1\r\n"); data = data << 16; data = data | get_light_ch0(); - + printf("LIGHT: Got ch0\r\n"); return data; } uint16_t get_light_ch0(void) @@ -88,21 +91,17 @@ uint16_t get_light_ch0(void) uint16_t data = 0; I2C_start(I2C1,LIGHT_ADDR << 1, I2C_Direction_Transmitter); - I2C_write(I2C1, 0x0D); - I2C_stop(I2C1); - - I2C_start(I2C1, LIGHT_ADDR << 1, I2C_Direction_Receiver); - data = I2C_read_ack(I2C1); - data = data << 8; - - I2C_start(I2C1,LIGHT_ADDR << 1, I2C_Direction_Transmitter); I2C_write(I2C1, 0x0C); I2C_stop(I2C1); + printf("LIGHT: Sent fetch command for low byte for CH1\r\n"); I2C_start(I2C1, LIGHT_ADDR << 1, I2C_Direction_Receiver); - data = data | I2C_read_ack(I2C1); - I2C_stop(I2C1); - + data = I2C_read_ack(I2C1); + printf("LIGHT: Got low byte for CH1\r\n"); + data = data | (I2C_read_ack(I2C1) << 8); + printf("LIGHT: Got high byte for CH1\r\n"); + I2C_stop(I2C1); + return data; } uint16_t get_light_ch1(void) @@ -110,30 +109,29 @@ uint16_t get_light_ch1(void) uint16_t data = 0; I2C_start(I2C1,LIGHT_ADDR << 1, I2C_Direction_Transmitter); - I2C_write(I2C1, 0x0F); - I2C_stop(I2C1); - - I2C_start(I2C1, LIGHT_ADDR << 1, I2C_Direction_Receiver); - data = I2C_read_ack(I2C1); - data = data << 8; - - I2C_start(I2C1,LIGHT_ADDR << 1, I2C_Direction_Transmitter); I2C_write(I2C1, 0x0E); I2C_stop(I2C1); + printf("LIGHT: Sent fetch command for low byte for CH1\r\n"); I2C_start(I2C1, LIGHT_ADDR << 1, I2C_Direction_Receiver); - data = data | I2C_read_ack(I2C1); + data = I2C_read_ack(I2C1); + printf("LIGHT: Got low byte for CH1\r\n"); + data = data | (I2C_read_ack(I2C1) << 8); + printf("LIGHT: Got high byte for CH1\r\n"); I2C_stop(I2C1); - + return data; } uint16_t get_distance_data(void) { init_ultrasound(); + printf("DISTANCE: Initialized\r\n"); uint16_t data = get_distance_high(); + printf("Got distance high byte\r\n"); data = data << 8; data = data | get_distance_low(); + printf("Got distance low byte\r\n"); return data; } void init_ultrasound(void) @@ -177,15 +175,17 @@ uint16_t get_pressure_data(void) { uint16_t data; init_pressure(); - + printf("PRESSURE: Initialized\r\n"); I2C_start(I2C1,DISTANCE_ADDR << 1, I2C_Direction_Transmitter); I2C_write(I2C1, 0xF6); I2C_stop(I2C1); I2C_start(I2C1, DISTANCE_ADDR << 1, I2C_Direction_Receiver); data = I2C_read_ack(I2C1); + printf("PRESSURE: Got high byte\r\n"); data = data << 8; data = data | I2C_read_nack(I2C1); + printf("PRESSURE: Got low byte\r\n"); return data; } @@ -193,20 +193,23 @@ uint16_t get_pressure_temperature_data(void) { uint16_t data; init_pressure_temperature(); - + printf("PRESSURE: Initialized temperature\r\n"); I2C_start(I2C1,DISTANCE_ADDR << 1, I2C_Direction_Transmitter); I2C_write(I2C1, 0xF6); I2C_stop(I2C1); I2C_start(I2C1, DISTANCE_ADDR << 1, I2C_Direction_Receiver); data = I2C_read_ack(I2C1); + printf("PRESSURE: Got temperature high byte\r\n"); data = data << 8; data = data | I2C_read_nack(I2C1); + printf("PRESSURE: Got temperature low byte\r\n"); return data; } bmp085_callibration get_pressure_callibration_data(void) { + printf("PRESSURE: Fetching callibration data\r\n"); bmp085_callibration calib_data; I2C_start(I2C1,PRESSURE_ADDR << 1, I2C_Direction_Transmitter); @@ -285,13 +288,13 @@ bmp085_callibration get_pressure_callibration_data(void) I2C_start(I2C1, PRESSURE_ADDR << 1, I2C_Direction_Receiver); calib_data.MD = I2C_read_ack(I2C1); I2C_stop(I2C1); - + printf("PRESSURE: Got callibration data\r\n"); return calib_data; } char* callibration_pressure_data_csv(bmp085_callibration parameters) { - char *str = chHeapAlloc(NULL,sizeof(char)*(4*11-1)); - memset(str,0x00,sizeof(char)*(4*11-1)); + char *str = chHeapAlloc(NULL,sizeof(char)*(11*11-1)); + memset(str,0x00,sizeof(char)*(11*11-1)); sprintf(str + strlen(str),"%d,",parameters.AC1); sprintf(str + strlen(str),"%d,",parameters.AC2); sprintf(str + strlen(str),"%d,",parameters.AC3); @@ -334,24 +337,32 @@ void init_humidity_temp(void) uint16_t get_humidity_data(void) { init_humidity_temp(); + printf("HUMIDITY_TEMP: Initialized humidity\r\n"); uint16_t data = 0; I2C_start(I2C1,PRESSURE_ADDR << 1, I2C_Direction_Receiver); data = I2C_read_ack(I2C1) & 0x3F; + printf("HUMIDITY_TEMP: Got humidity high byte\r\n"); data = data << 8; data |= I2C_read_nack(I2C1); + printf("HUMIDITY_TEMP: Got humidity low byte\r\n"); I2C_stop(I2C1); return data; } uint16_t get_temperature_data(void) { init_humidity_temp(); + printf("HUMIDITY_TEMP: Initialized temperature\r\n"); uint16_t data = 0; I2C_start(I2C1,PRESSURE_ADDR << 1, I2C_Direction_Receiver); I2C_read_ack(I2C1); + printf("HUMIDITY_TEMP: Discarded first humidity byte\r\n"); I2C_read_ack(I2C1); + printf("HUMIDITY_TEMP: Discarded second humidity byte\r\n"); data = I2C_read_ack(I2C1); + printf("HUMIDITY_TEMP: Got temperature high byte\r\n"); data = data << 8; data |= I2C_read_nack(I2C1) & 0xFC ; + printf("HUMIDITY_TEMP: Got temperature low byte\r\n"); data = data >> 2; I2C_stop(I2C1); return data; @@ -401,28 +412,42 @@ char* sound_value(uint32_t sound) void collectData(char* valueSensors[], uint8_t* sensors){ uint8_t i; - for(i=0;i