Commit 3813a6db45c4180b7fbd9dc367f2ac3690391c60
1 parent
6c5fd3ac
--no commit message
Showing
13 changed files
with
134 additions
and
15 deletions
Project/applications/smartcities/buffer.c
1 | +/**@file | ||
2 | + * @brief Definitions for the memory buffer management | ||
3 | + * @author Maria Jorba Brosa | ||
4 | + * @date 08/06/2014 | ||
5 | + * | ||
6 | + * This is where all the methods previously declared in buffer.h are defined. | ||
7 | + */ | ||
8 | + | ||
1 | #include "buffer.h" | 9 | #include "buffer.h" |
2 | -#include "globals.h" | ||
3 | 10 | ||
4 | char** put_message(char* info, char** buf,uint32_t *index, uint32_t *buf_len) | 11 | char** put_message(char* info, char** buf,uint32_t *index, uint32_t *buf_len) |
5 | { | 12 | { |
Project/applications/smartcities/callbacks.c
1 | +/**@file | ||
2 | + * @brief Definitions for the network callbacks | ||
3 | + * @author Imanol Barba Sabariego, Maria Jorba Brosa | ||
4 | + * @date 08/06/2014 | ||
5 | + * | ||
6 | + * This is where all the methods previously declared in callbacks.h are defined. | ||
7 | + */ | ||
8 | + | ||
1 | #include "callbacks.h" | 9 | #include "callbacks.h" |
2 | 10 | ||
3 | void dhcp_connect_result_cb(int result) | 11 | void dhcp_connect_result_cb(int result) |
Project/applications/smartcities/configServer.c
1 | +/**@file | ||
2 | + * @brief Definitions for the configuration HTTP server | ||
3 | + * @author Imanol Barba Sabariego | ||
4 | + * @date 08/06/2014 | ||
5 | + * | ||
6 | + * This is where all the methods previously declared in configServer.h are defined. | ||
7 | + */ | ||
8 | + | ||
1 | #include "configServer.h" | 9 | #include "configServer.h" |
2 | 10 | ||
11 | +//! POST variable for Wi-Fi network name | ||
3 | char arg_networkNameStr[100]; | 12 | char arg_networkNameStr[100]; |
13 | +//! POST variable for Wi-Fi network passphrase | ||
4 | char arg_passphraseStr[100]; | 14 | char arg_passphraseStr[100]; |
15 | +//! POST variable for Wi-Fi network security type | ||
5 | char arg_securityTypeStr[100]; | 16 | char arg_securityTypeStr[100]; |
17 | +//! POST variable for RADIUS username | ||
6 | char arg_radUserStr[100]; | 18 | char arg_radUserStr[100]; |
19 | +//! POST variable for RADIUS password | ||
7 | char arg_radPassStr[100]; | 20 | char arg_radPassStr[100]; |
21 | +//! POST variable for geolocalization coordinates (i.e: 41.557255 2.096183) | ||
8 | char arg_geoLocalizationStr[100]; | 22 | char arg_geoLocalizationStr[100]; |
23 | +//! Timer for device reboot | ||
9 | wismart_timer_t rebootTimer; | 24 | wismart_timer_t rebootTimer; |
10 | - | ||
11 | -/* This is the array that stores the http resources */ | 25 | +//! This is the array that stores the http resources |
12 | wismart_server_resource_t configServerResources[22]; | 26 | wismart_server_resource_t configServerResources[22]; |
13 | 27 | ||
14 | void configServer_start(uint8_t enableApScan) | 28 | void configServer_start(uint8_t enableApScan) |
Project/applications/smartcities/httpClient.c
Project/applications/smartcities/i2c.c
1 | +/**@file | ||
2 | + * @brief Definitions for the I2C functionality | ||
3 | + * @author Imanol Barba Sabariego | ||
4 | + * @date 08/06/2014 | ||
5 | + * | ||
6 | + * This is where all the methods previously declared in i2c.h are defined. | ||
7 | + */ | ||
8 | + | ||
1 | #include "i2c.h" | 9 | #include "i2c.h" |
2 | #include "json.h" | 10 | #include "json.h" |
3 | 11 |
Project/applications/smartcities/include/adc.h
@@ -2,9 +2,9 @@ | @@ -2,9 +2,9 @@ | ||
2 | /**@file | 2 | /**@file |
3 | * @brief Declaration for the ADC functionality | 3 | * @brief Declaration for the ADC functionality |
4 | * @author Imanol Barba Sabariego | 4 | * @author Imanol Barba Sabariego |
5 | - * @date 07/06/2014 | 5 | + * @date 08/06/2014 |
6 | * | 6 | * |
7 | - * This is where all the methods previously declared in adc.h are defined. | 7 | + * The functions declared in this file manage the ADC functionality of the device to use with the battery and sound sensor |
8 | */ | 8 | */ |
9 | 9 | ||
10 | #ifndef ADC_H | 10 | #ifndef ADC_H |
Project/applications/smartcities/include/callbacks.h
@@ -11,6 +11,7 @@ | @@ -11,6 +11,7 @@ | ||
11 | 11 | ||
12 | #define CONNECTED_PAST 0x02 | 12 | #define CONNECTED_PAST 0x02 |
13 | #define CONNECTED_NOW 0x01 | 13 | #define CONNECTED_NOW 0x01 |
14 | +#define NOT_CONNECTED 0x00 | ||
14 | 15 | ||
15 | void dhcp_connect_result_cb(int result); | 16 | void dhcp_connect_result_cb(int result); |
16 | void wifi_connect_result_cb(int result); | 17 | void wifi_connect_result_cb(int result); |
Project/applications/smartcities/json.c
1 | +/**@file | ||
2 | + * @brief Definitions for the JSON formatting functions | ||
3 | + * @author Imanol Barba Sabariego | ||
4 | + * @date 08/06/2014 | ||
5 | + * | ||
6 | + * This is where all the methods previously declared in json.h are defined. | ||
7 | + */ | ||
8 | + | ||
1 | #include "json.h" | 9 | #include "json.h" |
2 | 10 | ||
3 | uint8_t register_sensor(sensor sens) | 11 | uint8_t register_sensor(sensor sens) |
Project/applications/smartcities/main.c
@@ -12,26 +12,46 @@ | @@ -12,26 +12,46 @@ | ||
12 | #include "ntp.h" | 12 | #include "ntp.h" |
13 | #include "sensors.h" | 13 | #include "sensors.h" |
14 | 14 | ||
15 | +/*! This definition is used for debugging purposes, it is a shorthand for printing debug information */ | ||
15 | #define DBG(fmt,...) printf("%c[1;35mmain.c:%c[1;00m "fmt,0x1B,0x1B, ##__VA_ARGS__) | 16 | #define DBG(fmt,...) printf("%c[1;35mmain.c:%c[1;00m "fmt,0x1B,0x1B, ##__VA_ARGS__) |
16 | //#define DBG(fmt,...) printf("") | 17 | //#define DBG(fmt,...) printf("") |
17 | 18 | ||
18 | 19 | ||
19 | - | ||
20 | -uint8_t connected=0; | ||
21 | -uint8_t timeout=0; | ||
22 | -uint8_t retries=0; | ||
23 | -uint8_t sensors_length=0; | ||
24 | -uint8_t registry_opened=0; | 20 | +//! Connection state global variable |
21 | +/*! This variable stores the connection state of the device. Its possible values are defined in callbacks.h and are: | ||
22 | + * <br>NOT_CONNECTED | ||
23 | + * <br>CONNECTED_NOW | ||
24 | + * <br>CONNECTED_PAST | ||
25 | + */ | ||
26 | +uint8_t connected = NOT_CONNECTED; | ||
27 | +//! Connection timeout global variable | ||
28 | +/*! This variable tells if there's been a timeout while trying to connect to the Wi-Fi network */ | ||
29 | +uint8_t timeout = 0; | ||
30 | +//! Wi-Fi connection retries | ||
31 | +/*! This variable holds the number of times the device has retried to connect to the Wi-Fi network */ | ||
32 | +uint8_t retries = 0; | ||
33 | +//! Number of sensors | ||
34 | +/*! This variable is updated when the I2C scan is performed and stores how many sensors have been detected */ | ||
35 | +uint8_t sensors_length = 0; | ||
36 | +//! Configuration registry status | ||
37 | +/*! This variable tells if the configuration registry has already been opened to avoid reopening it, which causes a software fault */ | ||
38 | +uint8_t registry_opened = 0; | ||
39 | +//! Configuration registry variable | ||
40 | +/*! This variable is used to make R/W accesses to the configuration registry */ | ||
25 | wismart_registryKey_t geo; | 41 | wismart_registryKey_t geo; |
42 | +//! Current module information | ||
26 | module mod; | 43 | module mod; |
27 | 44 | ||
45 | +//! libwismart library initialization | ||
46 | +/*! This functions initializes the libwismart library, enabling all the functionality for posterior use */ | ||
28 | void initLibwismart(void) | 47 | void initLibwismart(void) |
29 | { | 48 | { |
30 | wismart_hwif_t hwif = libwismart_GetDefaultHWIF(); | 49 | wismart_hwif_t hwif = libwismart_GetDefaultHWIF(); |
31 | libwismart_Init(hwif); | 50 | libwismart_Init(hwif); |
32 | } | 51 | } |
33 | 52 | ||
34 | - | 53 | +//! NTP time update function |
54 | +/*! This function is called upon NTP update request and uses the methods declared in ntp.h to do so. */ | ||
35 | void update_time(unsigned long *time) | 55 | void update_time(unsigned long *time) |
36 | { | 56 | { |
37 | do | 57 | do |
@@ -51,6 +71,8 @@ void update_time(unsigned long *time) | @@ -51,6 +71,8 @@ void update_time(unsigned long *time) | ||
51 | }while(!(*time)); | 71 | }while(!(*time)); |
52 | } | 72 | } |
53 | 73 | ||
74 | +//! Configuration registry initialization and Wi-Fi network connection function | ||
75 | +/*! This function opens and reads the configuration registry and connects to the Wi-Fi network as there configured */ | ||
54 | void init_registry(void) | 76 | void init_registry(void) |
55 | { | 77 | { |
56 | config_params_t config; | 78 | config_params_t config; |
@@ -112,6 +134,8 @@ void init_registry(void) | @@ -112,6 +134,8 @@ void init_registry(void) | ||
112 | 134 | ||
113 | } | 135 | } |
114 | 136 | ||
137 | +//! Function to send data to the server | ||
138 | +/*! This function sends all the data in the memory to the server */ | ||
115 | void send_data(char** buffers[], uint32_t ind[], uint32_t sizes[], uint8_t sensors[]) | 139 | void send_data(char** buffers[], uint32_t ind[], uint32_t sizes[], uint8_t sensors[]) |
116 | { | 140 | { |
117 | int j; | 141 | int j; |
@@ -124,6 +148,8 @@ void send_data(char** buffers[], uint32_t ind[], uint32_t sizes[], uint8_t senso | @@ -124,6 +148,8 @@ void send_data(char** buffers[], uint32_t ind[], uint32_t sizes[], uint8_t senso | ||
124 | } | 148 | } |
125 | } | 149 | } |
126 | 150 | ||
151 | +//! Buffer data insertion function | ||
152 | +/*! This function inserts processed data in the memory */ | ||
127 | void put_buffers(char** buffers[],uint32_t ind[],uint32_t sizes[],char** cooked, uint8_t* sensors) | 153 | void put_buffers(char** buffers[],uint32_t ind[],uint32_t sizes[],char** cooked, uint8_t* sensors) |
128 | { | 154 | { |
129 | DBG("Putting data in buffers...\r\n"); | 155 | DBG("Putting data in buffers...\r\n"); |
@@ -139,6 +165,9 @@ void put_buffers(char** buffers[],uint32_t ind[],uint32_t sizes[],char** cooked, | @@ -139,6 +165,9 @@ void put_buffers(char** buffers[],uint32_t ind[],uint32_t sizes[],char** cooked, | ||
139 | DBG("Data is now in buffer\n\r"); | 165 | DBG("Data is now in buffer\n\r"); |
140 | chHeapFree(cooked); | 166 | chHeapFree(cooked); |
141 | } | 167 | } |
168 | + | ||
169 | +//! Data timestamping function | ||
170 | +/*! This function timestamps de collected data using the methods defined in ntp.h */ | ||
142 | char** timestamp_datas(char* value[],unsigned long timestamp, uint8_t* sensors) | 171 | char** timestamp_datas(char* value[],unsigned long timestamp, uint8_t* sensors) |
143 | { | 172 | { |
144 | DBG("Timestamping data...\r\n"); | 173 | DBG("Timestamping data...\r\n"); |
@@ -157,6 +186,7 @@ char** timestamp_datas(char* value[],unsigned long timestamp, uint8_t* sensors) | @@ -157,6 +186,7 @@ char** timestamp_datas(char* value[],unsigned long timestamp, uint8_t* sensors) | ||
157 | return cooked_data; | 186 | return cooked_data; |
158 | } | 187 | } |
159 | 188 | ||
189 | +//! Wi-Fi connect function | ||
160 | void wifi_connect(void) | 190 | void wifi_connect(void) |
161 | { | 191 | { |
162 | DBG("Connecting wifi...\r\n"); | 192 | DBG("Connecting wifi...\r\n"); |
@@ -174,6 +204,8 @@ void wifi_connect(void) | @@ -174,6 +204,8 @@ void wifi_connect(void) | ||
174 | timeout = 0; | 204 | timeout = 0; |
175 | } | 205 | } |
176 | 206 | ||
207 | +//! Battery reporting function | ||
208 | +/*! This function checks the battery level and sends it to the server */ | ||
177 | void send_battery_level(unsigned long timestamp) | 209 | void send_battery_level(unsigned long timestamp) |
178 | { | 210 | { |
179 | DBG("Polling battery level...\r\n"); | 211 | DBG("Polling battery level...\r\n"); |
@@ -191,6 +223,7 @@ void send_battery_level(unsigned long timestamp) | @@ -191,6 +223,7 @@ void send_battery_level(unsigned long timestamp) | ||
191 | chHeapFree(statement); | 223 | chHeapFree(statement); |
192 | } | 224 | } |
193 | 225 | ||
226 | +//! Wi-Fi Disocnnect function | ||
194 | void wifi_disconnect(void) | 227 | void wifi_disconnect(void) |
195 | { | 228 | { |
196 | DBG("Disconnecting wifi...\r\n"); | 229 | DBG("Disconnecting wifi...\r\n"); |
@@ -207,6 +240,7 @@ void wifi_disconnect(void) | @@ -207,6 +240,7 @@ void wifi_disconnect(void) | ||
207 | DBG("Disconnecting Failed: WIFI_DISCONNECT_FAILURE\r\n"); | 240 | DBG("Disconnecting Failed: WIFI_DISCONNECT_FAILURE\r\n"); |
208 | } | 241 | } |
209 | 242 | ||
243 | +//! Main loop | ||
210 | int main(void) | 244 | int main(void) |
211 | { | 245 | { |
212 | initLibwismart(); | 246 | initLibwismart(); |
Project/applications/smartcities/mainpage.dox
@@ -3,7 +3,7 @@ | @@ -3,7 +3,7 @@ | ||
3 | * | 3 | * |
4 | * This is the documentation for the <a target="_blank" href="http://lewis.upc.es/modularsense/wordpress/?page_id=11">Wi-Sense</a> software. | 4 | * This is the documentation for the <a target="_blank" href="http://lewis.upc.es/modularsense/wordpress/?page_id=11">Wi-Sense</a> software. |
5 | * | 5 | * |
6 | -* This software is based on the WiSmart library (libwismart) and STM32 Periph library. | 6 | +* This software is based on the WiSmart library (libwismart) and STM32 Standard Peripheral library. |
7 | * | 7 | * |
8 | * <br> | 8 | * <br> |
9 | * \section outline Product Outline | 9 | * \section outline Product Outline |
@@ -11,10 +11,10 @@ | @@ -11,10 +11,10 @@ | ||
11 | * The software consists in a first \ref boot and a \ref loop. | 11 | * The software consists in a first \ref boot and a \ref loop. |
12 | 12 | ||
13 | * \subsection boot Boot Stage | 13 | * \subsection boot Boot Stage |
14 | -* At the boot stage, it tries to connect to the default or previously configured (if applicable) Wi-Fi network. If this succeeds, it starts the \ref loop, but should it not work, then it will set up an AP called "modularsense" in which a web server is configured, allowing the user to set up the new parameters. | 14 | +* At the boot stage, it tries to connect to the default or previously configured (if applicable) Wi-Fi network. If this succeeds, it starts the \ref loop, but should it not work, then it will set up an AP called "modularsense" in which a web server is configured, allowing the user to set up the new parameters. More information on how to configure the web interface can be found <a target="_blank" href="http://www.modularsense.com/wp-content/uploads/2014/06/Modular-Sense-2.pdf">here</a>. |
15 | 15 | ||
16 | * \subsection loop Main Loop | 16 | * \subsection loop Main Loop |
17 | -* At the main loop, it initially scans for sensors and registers them in the <a href="http://sentilo.io" target="_blank">SENTILO</a>-compatible platform already configured on the device. Then, it collects data every 5 minutes, allocating memory for each iteration in which data is retrieved. After 30 minutes have passed, it sends the data to the platform if an Internet connection is available, if not, it will store it up until connectivity is reestablished. | 17 | +* At the main loop, it initially scans for sensors and registers them in the <a href="http://sentilo.io" target="_blank">SENTILO</a> compatible platform already configured on the device. Then, it collects data every 5 minutes, allocating memory for each iteration in which data is retrieved. After 30 minutes have passed, it sends the data to the platform if an Internet connection is available, if not, it will store it up until connectivity is reestablished. |
18 | * <br><br>This loop repeats until power runs out or until it runs out of memory. Given the case, it stops collecting data and tries to send the stored data until it is successful, then it frees the memory and resumes the cycle. | 18 | * <br><br>This loop repeats until power runs out or until it runs out of memory. Given the case, it stops collecting data and tries to send the stored data until it is successful, then it frees the memory and resumes the cycle. |
19 | 19 | ||
20 | * \subsection data Data Collection | 20 | * \subsection data Data Collection |
Project/applications/smartcities/ntp.c
1 | +/**@file | ||
2 | + * @brief Definitions for the NTP client functionality | ||
3 | + * @author Emilio Soca Herrera | ||
4 | + * @date 08/06/2014 | ||
5 | + * | ||
6 | + * This is where all the methods previously declared in ntp.h are defined. | ||
7 | + */ | ||
8 | + | ||
1 | #include "ntp.h" | 9 | #include "ntp.h" |
2 | 10 | ||
3 | Date getDate(unsigned long secsSince1900) | 11 | Date getDate(unsigned long secsSince1900) |
Project/applications/smartcities/sensors.c
1 | +/**@file | ||
2 | + * @brief Definitions for the sensor fetching methods and sensor definitions | ||
3 | + * @author Imanol Barba Sabariego | ||
4 | + * @date 08/06/2014 | ||
5 | + * | ||
6 | + * This is where all the methods previously declared in sensors.h are defined. Also, the different sensors are defined here | ||
7 | + */ | ||
8 | + | ||
1 | #include "sensors.h" | 9 | #include "sensors.h" |
2 | 10 | ||
11 | +//! Definition for the light sensor | ||
3 | sensor light_sensor = {LIGHT_ADDR, "Light sensor", "illumination", "lux"}; | 12 | sensor light_sensor = {LIGHT_ADDR, "Light sensor", "illumination", "lux"}; |
13 | +//! Definition for the distance sensor | ||
4 | sensor ultrasound_sensor = {DISTANCE_ADDR, "Ultrasound sensor", "distance", "cm"}; | 14 | sensor ultrasound_sensor = {DISTANCE_ADDR, "Ultrasound sensor", "distance", "cm"}; |
15 | +//! Definition for the pressure sensor | ||
5 | sensor pressure_sensor = {PRESSURE_ADDR, "Pressure sensor", "pressure", "hPa"}; | 16 | sensor pressure_sensor = {PRESSURE_ADDR, "Pressure sensor", "pressure", "hPa"}; |
17 | +//! Definition for the humidity and temnperature sensor | ||
6 | sensor humidity_temp_sensor = {HUMIDITY_TEMP_ADDR, "Temperature and humidity sensor", "temperature,humidity", "ºC,RH"}; | 18 | sensor humidity_temp_sensor = {HUMIDITY_TEMP_ADDR, "Temperature and humidity sensor", "temperature,humidity", "ºC,RH"}; |
19 | +//! Definition for the sound sensor | ||
7 | sensor sound_sensor = {SOUND_ADDR, "Sound sensor", "sound", "mV"}; | 20 | sensor sound_sensor = {SOUND_ADDR, "Sound sensor", "sound", "mV"}; |
21 | +//! Definition for the battery sensor battery | ||
8 | sensor battery = {BATTERY_ADDR, "Battery Level", "power", "mV"}; | 22 | sensor battery = {BATTERY_ADDR, "Battery Level", "power", "mV"}; |
9 | 23 | ||
24 | +//! Sensor definition array | ||
10 | sensor* sensors[TOTAL_SENSORS+1] = {&light_sensor,&ultrasound_sensor,&pressure_sensor,&humidity_temp_sensor,&sound_sensor,&battery}; | 25 | sensor* sensors[TOTAL_SENSORS+1] = {&light_sensor,&ultrasound_sensor,&pressure_sensor,&humidity_temp_sensor,&sound_sensor,&battery}; |
11 | 26 | ||
12 | void wakeup_sensors(uint8_t logic_address) | 27 | void wakeup_sensors(uint8_t logic_address) |
Project/applications/smartcities/timer-loop.c