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 11 uint32_t analogValue;
12 12  
13 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 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 16 return analogValue;
23 17 }
24 18  
... ... @@ -84,14 +78,8 @@ uint32_t adc_sound_process()
84 78 uint32_t analogValue;
85 79  
86 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 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 83 return analogValue;
96 84 }
97 85  
... ...
Project/applications/smartcities/callbacks.c
... ... @@ -25,7 +25,8 @@ void dhcp_connect_result_cb(int result)
25 25  
26 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 30 timeout=1;
30 31 }
31 32 printf("WiFi Connect indication: ");
... ... @@ -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 59 #define MAC2STR(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5]
65 60 #define MACSTR "%02x:%02x:%02x:%02x:%02x:%02x"
66 61  
67   - switch(reason){
  62 + switch(reason)
  63 + {
68 64 case WISMART_WIFI_AP_CLIENT_CONNECTED:
69 65 printf("Client: "MACSTR" connected\r\n",MAC2STR(mac));
70 66 break;
... ... @@ -83,35 +79,8 @@ void softapMode_clientIndicationCb(wismart_softap_cb_t reason, const uint8_t *ma
83 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 84 printf("\r\n\r\n");
116 85 printf("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\r\n");
117 86 printf("| Network Is Ready!\r\n");
... ...
Project/applications/smartcities/configServer.c
... ... @@ -13,7 +13,6 @@ wismart_server_resource_t configServerResources[22];
13 13  
14 14 void configServer_start(uint8_t enableApScan)
15 15 {
16   - //create_keys();
17 16 configServer_buildResources();
18 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 10 #define DBG(fmt,...) if(1){printf("[ADC] "fmt"\r\n", ##__VA_ARGS__);}else{({});}
11 11  
12 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 17 #define ADCsound_MIN_VALUE (0)
18 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 15 void wifi_connect_result_cb(int result);
16 16 void softapMode_clientIndicationCb(wismart_softap_cb_t reason, const uint8_t *mac, const libwismart_ip_addr_t *ip);
17 17 void softapMode_apStartedCb(int result);
18   -void wifiConnected(uint8_t wifiMode);
19 18 void printWifiInfo(uint8_t wifiMode);
20 19  
21 20 extern uint8_t connected;
... ...
Project/applications/smartcities/include/sensors.h
... ... @@ -10,7 +10,7 @@
10 10  
11 11 #define LIGHT_ADDR 0x39
12 12 #define DISTANCE_ADDR 0x01
13   -#define PRESSURE_ADDR 0x77 //Cambiar a MPL115A
  13 +#define PRESSURE_ADDR 0x77
14 14 #define HUMIDITY_TEMP_ADDR 0x27
15 15 #define SOUND_ADDR 0x72
16 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 125 }
126 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 129 strcpy(URL,SERVER_HOSTNAME);
  130 + //VANILLA SERVER (SENTILO)
130 131 PATH = (char*) chHeapAlloc(NULL,19);
131 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 139 else //Post data
135 140 {
136 141 URL = (char*) chHeapAlloc(NULL,1+strlen(SERVER_HOSTNAME));
137 142 strcpy(URL,SERVER_HOSTNAME);
138 143 URL[strlen(SERVER_HOSTNAME)] = '\0';
  144 + //VANILLA SERVER (SENTILO)
139 145 PATH = (char*) chHeapAlloc(NULL,22+strlen(provider_ID)+strlen(sensor_ID));
140 146 strcpy(PATH,"/data/modularupload/");
141 147 strcpy(PATH+20,provider_ID);
142 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 159 struct httpHeaders server = { put,PATH,strlen(PATH),URL,strlen(URL)};
146 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 11  
12 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 14 // X X X PA7 PA6 PA5 PA4 PA3
21 15 // b7 b6 b5 b4 b3 b2 b1 b0
22 16  
... ...