Commit 8450820ad9383ca2a04b09da375a370fe778c778

Authored by Imanol-Mikel Barba Sabariego
1 parent 39f62a6d

--no commit message

Project/applications/smartcities/adc.c
@@ -11,14 +11,8 @@ uint32_t adc_batt_process() @@ -11,14 +11,8 @@ uint32_t adc_batt_process()
11 uint32_t analogValue; 11 uint32_t analogValue;
12 12
13 adcRegisterValue = adc_batt_read(); 13 adcRegisterValue = adc_batt_read();
14 -  
15 - /*  
16 - * Calculate the register value to volts  
17 - * 1. adcRegisterValue Range is [ADC_MIN_VALUE, ADC_MAX_VALUE]  
18 - * 2. analogValue Range is [ADC_VREF_MINUS, ADC_VREF_PLUS]  
19 - */  
20 analogValue = ADCbatt_VREF_MINUS + (((adcRegisterValue - ADCbatt_MIN_VALUE)*(ADCbatt_VREF_PLUS - ADCbatt_VREF_MINUS))/(ADCbatt_MAX_VALUE - ADCbatt_MIN_VALUE)); 14 analogValue = ADCbatt_VREF_MINUS + (((adcRegisterValue - ADCbatt_MIN_VALUE)*(ADCbatt_VREF_PLUS - ADCbatt_VREF_MINUS))/(ADCbatt_MAX_VALUE - ADCbatt_MIN_VALUE));
21 - DBG("Register value is %4u [%4u milliVolts are currently given to gpio %s]",adcRegisterValue, analogValue, ADCbatt_GPIO_STR); 15 + printf("Register value is %4u [%4u milliVolts are currently given to gpio %s]",adcRegisterValue, analogValue, ADCbatt_GPIO_STR);
22 return analogValue; 16 return analogValue;
23 } 17 }
24 18
@@ -84,14 +78,8 @@ uint32_t adc_sound_process() @@ -84,14 +78,8 @@ uint32_t adc_sound_process()
84 uint32_t analogValue; 78 uint32_t analogValue;
85 79
86 adcRegisterValue = adc_sound_read(); 80 adcRegisterValue = adc_sound_read();
87 -  
88 - /*  
89 - * Calculate the register value to volts  
90 - * 1. adcRegisterValue Range is [ADC_MIN_VALUE, ADC_MAX_VALUE]  
91 - * 2. analogValue Range is [ADC_VREF_MINUS, ADC_VREF_PLUS]  
92 - */  
93 analogValue = ADCsound_VREF_MINUS + (((adcRegisterValue - ADCsound_MIN_VALUE)*(ADCsound_VREF_PLUS - ADCsound_VREF_MINUS))/(ADCsound_MAX_VALUE - ADCsound_MIN_VALUE)); 81 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, ADCsound_GPIO_STR); 82 + printf("Register value is %4u [%4u milliVolts are currently given to gpio %s]",adcRegisterValue, analogValue, ADCsound_GPIO_STR);
95 return analogValue; 83 return analogValue;
96 } 84 }
97 85
Project/applications/smartcities/callbacks.c
@@ -25,7 +25,8 @@ void dhcp_connect_result_cb(int result) @@ -25,7 +25,8 @@ void dhcp_connect_result_cb(int result)
25 25
26 void wifi_connect_result_cb(int result) 26 void wifi_connect_result_cb(int result)
27 { 27 {
28 - if(result==WISMART_WIFI_CONN_TIMEOUT){ 28 + if(result==WISMART_WIFI_CONN_TIMEOUT)
  29 + {
29 timeout=1; 30 timeout=1;
30 } 31 }
31 printf("WiFi Connect indication: "); 32 printf("WiFi Connect indication: ");
@@ -44,27 +45,22 @@ void wifi_connect_result_cb(int result) @@ -44,27 +45,22 @@ void wifi_connect_result_cb(int result)
44 } 45 }
45 } 46 }
46 47
47 -void wifi_connect_ap_result_cb(int result) 48 +void softapMode_apStartedCb(int result)
48 { 49 {
49 -  
50 - printf("New WiFi Network state: %s\r\n", (result == WISMART_WIFI_CONNECTED) ? "Created": "Failed\r\n");  
51 -}  
52 -  
53 -void softapMode_apStartedCb(int result){  
54 - if (result == WISMART_WIFI_CONNECTED){  
55 - wifiConnected(WIFI_MODE_SOFTAP); 50 + if (result == WISMART_WIFI_CONNECTED)
  51 + {
  52 + printWifiInfo(WIFI_MODE_SOFTAP);
  53 + configServer_connect();
56 } 54 }
57 } 55 }
58 56
59 -  
60 -/**  
61 - * @brief Informs the application about client events in softap mode  
62 -*/  
63 -void softapMode_clientIndicationCb(wismart_softap_cb_t reason, const uint8_t *mac, const libwismart_ip_addr_t *ip){ 57 +void softapMode_clientIndicationCb(wismart_softap_cb_t reason, const uint8_t *mac, const libwismart_ip_addr_t *ip)
  58 +{
64 #define MAC2STR(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5] 59 #define MAC2STR(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5]
65 #define MACSTR "%02x:%02x:%02x:%02x:%02x:%02x" 60 #define MACSTR "%02x:%02x:%02x:%02x:%02x:%02x"
66 61
67 - switch(reason){ 62 + switch(reason)
  63 + {
68 case WISMART_WIFI_AP_CLIENT_CONNECTED: 64 case WISMART_WIFI_AP_CLIENT_CONNECTED:
69 printf("Client: "MACSTR" connected\r\n",MAC2STR(mac)); 65 printf("Client: "MACSTR" connected\r\n",MAC2STR(mac));
70 break; 66 break;
@@ -83,35 +79,8 @@ void softapMode_clientIndicationCb(wismart_softap_cb_t reason, const uint8_t *ma @@ -83,35 +79,8 @@ void softapMode_clientIndicationCb(wismart_softap_cb_t reason, const uint8_t *ma
83 #undef MACSTR 79 #undef MACSTR
84 } 80 }
85 81
86 -void wifiConnected(uint8_t wifiMode){  
87 - static uint8_t networkInited = 0;  
88 -  
89 - printWifiInfo(wifiMode);  
90 -  
91 - if(networkInited != 0){  
92 - return;  
93 - }else{  
94 - networkInited = 1;  
95 - }  
96 -  
97 - switch(wifiMode){  
98 - case WIFI_MODE_SOFTAP:  
99 -  
100 - configServer_connect();  
101 - break;  
102 - case WIFI_MODE_CLIENT:  
103 -  
104 - configServer_connect();  
105 - break;  
106 - }  
107 -  
108 -}  
109 -  
110 -void printWifiInfo(uint8_t wifiMode){  
111 -  
112 - libwismart_ip_addr_t ip, nm, gw;  
113 - libwismart_GetCurrentIP(&ip, &nm, &gw);  
114 - 82 +void printWifiInfo(uint8_t wifiMode)
  83 +{
115 printf("\r\n\r\n"); 84 printf("\r\n\r\n");
116 printf("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\r\n"); 85 printf("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\r\n");
117 printf("| Network Is Ready!\r\n"); 86 printf("| Network Is Ready!\r\n");
Project/applications/smartcities/configServer.c
@@ -13,7 +13,6 @@ wismart_server_resource_t configServerResources[22]; @@ -13,7 +13,6 @@ wismart_server_resource_t configServerResources[22];
13 13
14 void configServer_start(uint8_t enableApScan) 14 void configServer_start(uint8_t enableApScan)
15 { 15 {
16 - //create_keys();  
17 configServer_buildResources(); 16 configServer_buildResources();
18 libwismart_server_start(80, "WismartServer", configServer_dynamicCb, chHeapFree, configServerResources); 17 libwismart_server_start(80, "WismartServer", configServer_dynamicCb, chHeapFree, configServerResources);
19 } 18 }
Project/applications/smartcities/adc.h renamed to Project/applications/smartcities/include/adc.h
@@ -10,9 +10,9 @@ @@ -10,9 +10,9 @@
10 #define DBG(fmt,...) if(1){printf("[ADC] "fmt"\r\n", ##__VA_ARGS__);}else{({});} 10 #define DBG(fmt,...) if(1){printf("[ADC] "fmt"\r\n", ##__VA_ARGS__);}else{({});}
11 11
12 #define ADCbatt_MIN_VALUE (0) 12 #define ADCbatt_MIN_VALUE (0)
13 -#define ADCbatt_MAX_VALUE (0xfff) /* 12-bit adc */  
14 -#define ADCbatt_VREF_PLUS (3300) /* Vref+ is connected with Vdda (3.3v) */  
15 -#define ADCbatt_VREF_MINUS (0) /* Vref- is connected with Vssa (2.1v) */ 13 +#define ADCbatt_MAX_VALUE (0xfff)
  14 +#define ADCbatt_VREF_PLUS (3300)
  15 +#define ADCbatt_VREF_MINUS (0)
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 */
Project/applications/smartcities/include/callbacks.h
@@ -15,7 +15,6 @@ void wifi_connect_ap_result_cb(int result); @@ -15,7 +15,6 @@ void wifi_connect_ap_result_cb(int result);
15 void wifi_connect_result_cb(int result); 15 void wifi_connect_result_cb(int result);
16 void softapMode_clientIndicationCb(wismart_softap_cb_t reason, const uint8_t *mac, const libwismart_ip_addr_t *ip); 16 void softapMode_clientIndicationCb(wismart_softap_cb_t reason, const uint8_t *mac, const libwismart_ip_addr_t *ip);
17 void softapMode_apStartedCb(int result); 17 void softapMode_apStartedCb(int result);
18 -void wifiConnected(uint8_t wifiMode);  
19 void printWifiInfo(uint8_t wifiMode); 18 void printWifiInfo(uint8_t wifiMode);
20 19
21 extern uint8_t connected; 20 extern uint8_t connected;
Project/applications/smartcities/include/sensors.h
@@ -10,7 +10,7 @@ @@ -10,7 +10,7 @@
10 10
11 #define LIGHT_ADDR 0x39 11 #define LIGHT_ADDR 0x39
12 #define DISTANCE_ADDR 0x01 12 #define DISTANCE_ADDR 0x01
13 -#define PRESSURE_ADDR 0x77 //Cambiar a MPL115A 13 +#define PRESSURE_ADDR 0x77
14 #define HUMIDITY_TEMP_ADDR 0x27 14 #define HUMIDITY_TEMP_ADDR 0x27
15 #define SOUND_ADDR 0x72 15 #define SOUND_ADDR 0x72
16 #define TOTAL_SENSORS 5 16 #define TOTAL_SENSORS 5
Project/applications/smartcities/json.c
@@ -125,22 +125,36 @@ uint8_t send_json(char* statement, uint32_t length, char* provider_ID, char* sen @@ -125,22 +125,36 @@ uint8_t send_json(char* statement, uint32_t length, char* provider_ID, char* sen
125 } 125 }
126 if(sensor_ID == NULL) //Register sensor 126 if(sensor_ID == NULL) //Register sensor
127 { 127 {
128 - URL = (char*) chHeapAlloc(NULL,8+strlen(SERVER_HOSTNAME)); 128 + URL = (char*) chHeapAlloc(NULL,1+strlen(SERVER_HOSTNAME));
129 strcpy(URL,SERVER_HOSTNAME); 129 strcpy(URL,SERVER_HOSTNAME);
  130 + //VANILLA SERVER (SENTILO)
130 PATH = (char*) chHeapAlloc(NULL,19); 131 PATH = (char*) chHeapAlloc(NULL,19);
131 strcpy(PATH,"/catalog/register"); 132 strcpy(PATH,"/catalog/register");
132 - //strcpy(PATH+9,provider_ID); 133 + //FUCKING LEWIS...
  134 + //TODO
  135 + /*PATH = (char*) chHeapAlloc(NULL,19);
  136 + strcpy(PATH,"/catalog/register");
  137 + */
133 } 138 }
134 else //Post data 139 else //Post data
135 { 140 {
136 URL = (char*) chHeapAlloc(NULL,1+strlen(SERVER_HOSTNAME)); 141 URL = (char*) chHeapAlloc(NULL,1+strlen(SERVER_HOSTNAME));
137 strcpy(URL,SERVER_HOSTNAME); 142 strcpy(URL,SERVER_HOSTNAME);
138 URL[strlen(SERVER_HOSTNAME)] = '\0'; 143 URL[strlen(SERVER_HOSTNAME)] = '\0';
  144 + //VANILLA SERVER (SENTILO)
139 PATH = (char*) chHeapAlloc(NULL,22+strlen(provider_ID)+strlen(sensor_ID)); 145 PATH = (char*) chHeapAlloc(NULL,22+strlen(provider_ID)+strlen(sensor_ID));
140 strcpy(PATH,"/data/modularupload/"); 146 strcpy(PATH,"/data/modularupload/");
141 strcpy(PATH+20,provider_ID); 147 strcpy(PATH+20,provider_ID);
142 strcpy(PATH+20+strlen(provider_ID),sensor_ID); 148 strcpy(PATH+20+strlen(provider_ID),sensor_ID);
143 - PATH[21+strlen(provider_ID)+strlen(sensor_ID)] = '\0'; 149 + //PATH[21+strlen(provider_ID)+strlen(sensor_ID)] = '\0';
  150 +
  151 + //FUCKING LEWIS...
  152 + //TODO
  153 + /*PATH = (char*) chHeapAlloc(NULL,22+strlen(provider_ID)+strlen(sensor_ID));
  154 + strcpy(PATH,"/data/modularupload/");
  155 + strcpy(PATH+20,provider_ID);
  156 + strcpy(PATH+20+strlen(provider_ID),sensor_ID);
  157 + PATH[21+strlen(provider_ID)+strlen(sensor_ID)] = '\0';*/
144 } 158 }
145 struct httpHeaders server = { put,PATH,strlen(PATH),URL,strlen(URL)}; 159 struct httpHeaders server = { put,PATH,strlen(PATH),URL,strlen(URL)};
146 response_code = httpRequest(server, statement, length); 160 response_code = httpRequest(server, statement, length);
Project/applications/smartcities/sensors.c
@@ -11,12 +11,6 @@ sensor* sensors[TOTAL_SENSORS+1] = {&light_sensor,&ultrasound_sensor,&pressure_s @@ -11,12 +11,6 @@ sensor* sensors[TOTAL_SENSORS+1] = {&light_sensor,&ultrasound_sensor,&pressure_s
11 11
12 void wakeup_sensors(uint8_t logic_address) 12 void wakeup_sensors(uint8_t logic_address)
13 { 13 {
14 - /* Aquí habría que implementar un control  
15 - * inteligente de la alimentación de los  
16 - * sensores, levantándolos y durmiéndolos  
17 - * cuando tocara  
18 - */  
19 -  
20 // X X X PA7 PA6 PA5 PA4 PA3 14 // X X X PA7 PA6 PA5 PA4 PA3
21 // b7 b6 b5 b4 b3 b2 b1 b0 15 // b7 b6 b5 b4 b3 b2 b1 b0
22 16