Commit 39f62a6daf93f0cf016fde5e3672c30002db05b6

Authored by Imanol-Mikel Barba Sabariego
1 parent a920723c

--no commit message

Project/applications/smartcities/adc.c
@@ -91,7 +91,7 @@ uint32_t adc_sound_process() @@ -91,7 +91,7 @@ uint32_t adc_sound_process()
91 * 2. analogValue Range is [ADC_VREF_MINUS, ADC_VREF_PLUS] 91 * 2. analogValue Range is [ADC_VREF_MINUS, ADC_VREF_PLUS]
92 */ 92 */
93 analogValue = ADCsound_VREF_MINUS + (((adcRegisterValue - ADCsound_MIN_VALUE)*(ADCsound_VREF_PLUS - ADCsound_VREF_MINUS))/(ADCsound_MAX_VALUE - ADCsound_MIN_VALUE)); 93 analogValue = ADCsound_VREF_MINUS + (((adcRegisterValue - ADCsound_MIN_VALUE)*(ADCsound_VREF_PLUS - ADCsound_VREF_MINUS))/(ADCsound_MAX_VALUE - ADCsound_MIN_VALUE));
94 - DBG("Register value is %4u [%4u milliVolts are currently given to gpio %s]",adcRegisterValue, analogValue, ADCbatt_GPIO_STR); 94 + DBG("Register value is %4u [%4u milliVolts are currently given to gpio %s]",adcRegisterValue, analogValue, ADCsound_GPIO_STR);
95 return analogValue; 95 return analogValue;
96 } 96 }
97 97
Project/applications/smartcities/adc.h
@@ -12,11 +12,11 @@ @@ -12,11 +12,11 @@
12 #define ADCbatt_MIN_VALUE (0) 12 #define ADCbatt_MIN_VALUE (0)
13 #define ADCbatt_MAX_VALUE (0xfff) /* 12-bit adc */ 13 #define ADCbatt_MAX_VALUE (0xfff) /* 12-bit adc */
14 #define ADCbatt_VREF_PLUS (3300) /* Vref+ is connected with Vdda (3.3v) */ 14 #define ADCbatt_VREF_PLUS (3300) /* Vref+ is connected with Vdda (3.3v) */
15 -#define ADCbatt_VREF_MINUS (2300) /* Vref- is connected with Vssa (2.1v) */ 15 +#define ADCbatt_VREF_MINUS (0) /* Vref- is connected with Vssa (2.1v) */
16 16
17 #define ADCsound_MIN_VALUE (0) 17 #define ADCsound_MIN_VALUE (0)
18 #define ADCsound_MAX_VALUE (0xfff) /* 12-bit adc */ 18 #define ADCsound_MAX_VALUE (0xfff) /* 12-bit adc */
19 -#define ADCsound_VREF_PLUS (2600) /* Vref+ is connected with Vdda (3.3v) */ 19 +#define ADCsound_VREF_PLUS (2800) /* Vref+ is connected with Vdda (3.3v) */
20 #define ADCsound_VREF_MINUS (0) /* Vref- is connected with Vssa (0v) */ 20 #define ADCsound_VREF_MINUS (0) /* Vref- is connected with Vssa (0v) */
21 21
22 #define ADCbatt ADC1 22 #define ADCbatt ADC1
@@ -32,7 +32,7 @@ @@ -32,7 +32,7 @@
32 #define ADCsound ADC2 32 #define ADCsound ADC2
33 #define ADCsound_RCC RCC_APB2Periph_ADC2 /* */ 33 #define ADCsound_RCC RCC_APB2Periph_ADC2 /* */
34 #define ADCsound_DIVIDER RCC_PCLK2_Div4 /* Can be 2/4/6/8. PCLK2 runs at 32Mhz, and max ADC clock is 14Mhz */ 34 #define ADCsound_DIVIDER RCC_PCLK2_Div4 /* Can be 2/4/6/8. PCLK2 runs at 32Mhz, and max ADC clock is 14Mhz */
35 -#define ADCsound_CHANNEL ADC_Channel_12 /* 0/17 */ 35 +#define ADCsound_CHANNEL ADC_Channel_11 /* 0/17 */
36 #define ADCsound_SAMPLETIME ADC_SampleTime_239Cycles5 36 #define ADCsound_SAMPLETIME ADC_SampleTime_239Cycles5
37 #define ADCsound_GPIO_PIN GPIO_Pin_2 37 #define ADCsound_GPIO_PIN GPIO_Pin_2
38 #define ADCsound_GPIO_PORT GPIOA 38 #define ADCsound_GPIO_PORT GPIOA
Project/applications/smartcities/httpClient.c
@@ -85,7 +85,7 @@ int httpRequest(struct httpHeaders head, char* content, int content_size) @@ -85,7 +85,7 @@ int httpRequest(struct httpHeaders head, char* content, int content_size)
85 neocon = netconn_new(NETCONN_TCP); 85 neocon = netconn_new(NETCONN_TCP);
86 if(neocon == NULL) 86 if(neocon == NULL)
87 { 87 {
88 - printf("\\->Socket creation FAILED. Have you called liwb\r\n"); 88 + printf("\\->Socket creation FAILED. Have you called libwismart_init_bsd_sockets ?\r\n");
89 } 89 }
90 /*local_ip.addr = 0;//getip 90 /*local_ip.addr = 0;//getip
91 netconn_bind(neocon, IP_ADDR_ANY, LOCAL_PORT); //88 is provisional local port.*/ 91 netconn_bind(neocon, IP_ADDR_ANY, LOCAL_PORT); //88 is provisional local port.*/
@@ -103,7 +103,7 @@ int httpRequest(struct httpHeaders head, char* content, int content_size) @@ -103,7 +103,7 @@ int httpRequest(struct httpHeaders head, char* content, int content_size)
103 //neocon->recv_timeout = 5000; // for 5s 103 //neocon->recv_timeout = 5000; // for 5s
104 connection_ok = netconn_recv(neocon, &netBufs); 104 connection_ok = netconn_recv(neocon, &netBufs);
105 printf("res recv= %d\r\n",connection_ok); 105 printf("res recv= %d\r\n",connection_ok);
106 - 106 +
107 if(connection_ok !=0) 107 if(connection_ok !=0)
108 { 108 {
109 netbuf_delete(netBufs); 109 netbuf_delete(netBufs);
Project/applications/smartcities/json.c
@@ -19,7 +19,7 @@ uint8_t register_sensor(sensor sens) @@ -19,7 +19,7 @@ uint8_t register_sensor(sensor sens)
19 } 19 }
20 char sensor_ID[3]; 20 char sensor_ID[3];
21 sprintf(sensor_ID,"%02x",sens.ID); 21 sprintf(sensor_ID,"%02x",sens.ID);
22 - result = send_json(statement,strlen(statement),mod.ID,sensor_ID); 22 + result = send_json(statement,strlen(statement),mod.ID,NULL);
23 chHeapFree(statement); 23 chHeapFree(statement);
24 return result; 24 return result;
25 } 25 }
@@ -127,9 +127,9 @@ uint8_t send_json(char* statement, uint32_t length, char* provider_ID, char* sen @@ -127,9 +127,9 @@ uint8_t send_json(char* statement, uint32_t length, char* provider_ID, char* sen
127 { 127 {
128 URL = (char*) chHeapAlloc(NULL,8+strlen(SERVER_HOSTNAME)); 128 URL = (char*) chHeapAlloc(NULL,8+strlen(SERVER_HOSTNAME));
129 strcpy(URL,SERVER_HOSTNAME); 129 strcpy(URL,SERVER_HOSTNAME);
130 - PATH = (char*) chHeapAlloc(NULL,10+strlen(provider_ID));  
131 - strcpy(PATH,"/catalog/");  
132 - strcpy(PATH+9,provider_ID); 130 + PATH = (char*) chHeapAlloc(NULL,19);
  131 + strcpy(PATH,"/catalog/register");
  132 + //strcpy(PATH+9,provider_ID);
133 } 133 }
134 else //Post data 134 else //Post data
135 { 135 {
Project/applications/smartcities/main2.c
@@ -186,8 +186,8 @@ void wifi_connect(void) @@ -186,8 +186,8 @@ void wifi_connect(void)
186 void send_battery_level(unsigned long timestamp) 186 void send_battery_level(unsigned long timestamp)
187 { 187 {
188 uint8_t result; 188 uint8_t result;
189 - //char *batt_level = battery_value(get_battery_data());  
190 - char *batt_level = battery_value(3300); 189 + char *batt_level = battery_value(get_battery_data());
  190 + //char *batt_level = battery_value(3300);
191 char *batt_data = timestamp_data(batt_level,getDate(timestamp)); 191 char *batt_data = timestamp_data(batt_level,getDate(timestamp));
192 chHeapFree(batt_level); 192 chHeapFree(batt_level);
193 char *statement = prepare_json_observation_statement(&batt_data,1); 193 char *statement = prepare_json_observation_statement(&batt_data,1);
@@ -210,6 +210,8 @@ void send_battery_level(unsigned long timestamp) @@ -210,6 +210,8 @@ void send_battery_level(unsigned long timestamp)
210 } 210 }
211 211
212 void wifi_disconnect(void){ 212 void wifi_disconnect(void){
  213 + connected = 0;
  214 + timeout = 0;
213 uint8_t res=libwismart_WiFiDisconnect(); 215 uint8_t res=libwismart_WiFiDisconnect();
214 if(res) 216 if(res)
215 printf("WIFI_DISCONNECT_SUCCESS\r\n"); 217 printf("WIFI_DISCONNECT_SUCCESS\r\n");
Project/applications/smartcities/sensors.c
@@ -321,7 +321,7 @@ uint16_t get_humidity_data(void) @@ -321,7 +321,7 @@ uint16_t get_humidity_data(void)
321 init_humidity_temp(); 321 init_humidity_temp();
322 printf("HUMIDITY_TEMP: Initialized humidity\r\n"); 322 printf("HUMIDITY_TEMP: Initialized humidity\r\n");
323 uint16_t data = 0; 323 uint16_t data = 0;
324 - I2C_start(I2C1,PRESSURE_ADDR << 1, I2C_Direction_Receiver); 324 + I2C_start(I2C1,HUMIDITY_TEMP_ADDR << 1, I2C_Direction_Receiver);
325 data = I2C_read_ack(I2C1) & 0x3F; 325 data = I2C_read_ack(I2C1) & 0x3F;
326 printf("HUMIDITY_TEMP: Got humidity high byte\r\n"); 326 printf("HUMIDITY_TEMP: Got humidity high byte\r\n");
327 data = data << 8; 327 data = data << 8;
@@ -335,7 +335,7 @@ uint16_t get_temperature_data(void) @@ -335,7 +335,7 @@ uint16_t get_temperature_data(void)
335 init_humidity_temp(); 335 init_humidity_temp();
336 printf("HUMIDITY_TEMP: Initialized temperature\r\n"); 336 printf("HUMIDITY_TEMP: Initialized temperature\r\n");
337 uint16_t data = 0; 337 uint16_t data = 0;
338 - I2C_start(I2C1,PRESSURE_ADDR << 1, I2C_Direction_Receiver); 338 + I2C_start(I2C1,HUMIDITY_TEMP_ADDR << 1, I2C_Direction_Receiver);
339 I2C_read_ack(I2C1); 339 I2C_read_ack(I2C1);
340 printf("HUMIDITY_TEMP: Discarded first humidity byte\r\n"); 340 printf("HUMIDITY_TEMP: Discarded first humidity byte\r\n");
341 I2C_read_ack(I2C1); 341 I2C_read_ack(I2C1);