Commit 2b4419ff5ad627637d27dbc1c13391dde09363d0

Authored by Imanol-Mikel Barba Sabariego
1 parent ad23cb4c

--no commit message

Project/applications/smartcities/i2c.c
... ... @@ -69,7 +69,7 @@ void I2C_start(I2C_TypeDef* I2Cx, uint8_t address, uint8_t direction)
69 69  
70 70 void I2C_write(I2C_TypeDef* I2Cx, uint8_t data)
71 71 {
72   - printf("Sending I2C byte %x...\r\n",data);
  72 + printf("Sending I2C byte %02x...\r\n",data);
73 73 /* WARNING
74 74 *
75 75 * OJITO QUE ESTÁ ESPERANDO EL EV8 Y NO EL EV8_2
... ... @@ -91,7 +91,9 @@ uint8_t I2C_read_ack(I2C_TypeDef* I2Cx)
91 91 {
92 92 // wait until one byte has been received
93 93 }
94   - return I2C_ReceiveData(I2Cx);
  94 + uint8_t data = I2C_ReceiveData(I2Cx);
  95 + printf("Received byte: %02x",data);
  96 + return data;
95 97 }
96 98  
97 99 uint8_t I2C_read_nack(I2C_TypeDef* I2Cx)
... ... @@ -103,7 +105,9 @@ uint8_t I2C_read_nack(I2C_TypeDef* I2Cx)
103 105 {
104 106 // wait until one byte has been received
105 107 }
106   - return I2C_ReceiveData(I2Cx);
  108 + uint8_t data = I2C_ReceiveData(I2Cx);
  109 + printf("Received byte: %02x",data);
  110 + return data;
107 111 }
108 112  
109 113 void I2C_stop(I2C_TypeDef* I2Cx)
... ...
Project/applications/smartcities/main2.c
... ... @@ -183,7 +183,8 @@ void wifi_connect(void)
183 183  
184 184 void send_battery_level(unsigned long timestamp)
185 185 {
186   - char *batt_level = battery_value(get_battery_data());
  186 + //char *batt_level = battery_value(get_battery_data());
  187 + char *batt_level = battery_value(3300);
187 188 char *batt_data = timestamp_data(batt_level,getDate(timestamp));
188 189 chHeapFree(batt_level);
189 190 char *statement = prepare_json_observation_statement(&batt_data,1);
... ... @@ -220,11 +221,12 @@ int main(void)
220 221 char* valueSensors[TOTAL_SENSORS];
221 222 memset (valueSensors, 0, TOTAL_SENSORS);
222 223  
223   -
224 224 printf("Connecting to wifi...\r\n");
225 225 wifi_connect();
226   -
227   - wakeup_sensors(0x15);
  226 +
  227 + send_battery_level(getSecsSince1900());
  228 +
  229 + wakeup_sensors(0xFF);
228 230 printf("Scanning sensors...\r\n");
229 231 //Escanea y registra
230 232 I2C_scan(sensors);
... ... @@ -349,3 +351,13 @@ int main(void)
349 351 }
350 352 }
351 353  
  354 +/*
  355 + * TO-DO
  356 + *
  357 + * - I2C issues
  358 + * - Test all sensors
  359 + * - Test ADC
  360 + * - Network fault tolerance
  361 + * - Reset server-related defines
  362 + * - Reset timer-related defines
  363 + */
352 364 \ No newline at end of file
... ...
Project/applications/smartcities/sensors.c
... ... @@ -24,9 +24,9 @@ void wakeup_sensors(uint8_t logic_address)
24 24 GPIO_InitTypeDef GPIO_InitStructure;
25 25 RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
26 26 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7;
27   - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  27 + GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
28 28 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
29   - GPIO_Init(ADCsound_GPIO_PORT, &GPIO_InitStructure);
  29 + GPIO_Init(GPIOA, &GPIO_InitStructure);
30 30  
31 31 if(logic_address & 0x1)
32 32 {
... ...