Commit ad23cb4c6dc8673b239e416c41253478927736c6
1 parent
1a74fac0
--no commit message
Showing
8 changed files
with
39 additions
and
14 deletions
Project/applications/smartcities/Makefile
... | ... | @@ -10,7 +10,7 @@ |
10 | 10 | SDK_ROOT = ../../ |
11 | 11 | PROJECT_OUT = smartcities |
12 | 12 | |
13 | -USER_SRC = main2.c configServer.c httpClient.c callbacks.c module.c sensors.c json.c i2c.c ntp.c buffer.c timer-loop.c adc.c | |
13 | +USER_SRC = main2.c configServer.c httpClient.c callbacks.c sensors.c json.c i2c.c ntp.c buffer.c timer-loop.c adc.c | |
14 | 14 | USER_INCDIR = include/ makefsdata/ |
15 | 15 | |
16 | 16 | # if you need to add build Defines options add to USER_DEFS define | ... | ... |
Project/applications/smartcities/i2c.c
Project/applications/smartcities/include/globals.h
Project/applications/smartcities/include/module.h
Project/applications/smartcities/json.c
... | ... | @@ -19,7 +19,8 @@ uint8_t register_sensor(sensor sens) |
19 | 19 | printf("%s\r\n",statement); |
20 | 20 | char sensor_ID[3]; |
21 | 21 | sprintf(sensor_ID,"%d",sens.ID); |
22 | - result = send_json(statement,strlen(statement),mod.ID,sensor_ID); | |
22 | + printf("REMOVE COMMENTARY IN send_json ON json.c LINE 23!!!!!!!\r\n"); | |
23 | + //result = send_json(statement,strlen(statement),mod.ID,sensor_ID); | |
23 | 24 | chHeapFree(statement); |
24 | 25 | return result; |
25 | 26 | } |
... | ... | @@ -52,7 +53,7 @@ char* prepare_json_register_statement(module mod, sensor sens) |
52 | 53 | char ID[MODULE_ID_LENGTH+3]; |
53 | 54 | length = 23; |
54 | 55 | strcpy(ID,mod.ID); |
55 | - sprintf(ID+MODULE_ID_LENGTH,"%X",sens.ID); | |
56 | + sprintf(ID+MODULE_ID_LENGTH,"%02X",sens.ID); | |
56 | 57 | str_aux = join_strings("{\"sensors\":[{\"sensor\":\"",ID,length,MODULE_ID_LENGTH+2,JOIN_NO_FREE); |
57 | 58 | length += MODULE_ID_LENGTH+2; |
58 | 59 | str_aux2 = join_strings(str_aux,"\",\"description\":\"",length,17,JOIN_NO_FREE); | ... | ... |
Project/applications/smartcities/main2.c
... | ... | @@ -34,6 +34,8 @@ uint8_t retries=0; |
34 | 34 | uint8_t sensors_length=0; |
35 | 35 | uint8_t registry_opened=0; |
36 | 36 | |
37 | +module mod; | |
38 | + | |
37 | 39 | void update_time(unsigned long *time) |
38 | 40 | { |
39 | 41 | printf("Requesting new NTP time...\r\n"); |
... | ... | @@ -70,6 +72,7 @@ void init_registry(void) |
70 | 72 | printf("Geo Localization = %s\r\n", config.localization); |
71 | 73 | |
72 | 74 | strcpy(mod.geoloc,config.localization); |
75 | + strcpy(mod.ID,MODULE_ID); | |
73 | 76 | printf("%s\r\n", mod.geoloc); |
74 | 77 | if(config.security == PROFILE_SECURITY_OPEN) |
75 | 78 | { |
... | ... | @@ -178,6 +181,19 @@ void wifi_connect(void) |
178 | 181 | } |
179 | 182 | } |
180 | 183 | |
184 | +void send_battery_level(unsigned long timestamp) | |
185 | +{ | |
186 | + char *batt_level = battery_value(get_battery_data()); | |
187 | + char *batt_data = timestamp_data(batt_level,getDate(timestamp)); | |
188 | + chHeapFree(batt_level); | |
189 | + char *statement = prepare_json_observation_statement(&batt_data,1); | |
190 | + chHeapFree(batt_data); | |
191 | + char id[3]; | |
192 | + sprintf(id,"%d",battery.ID); | |
193 | + send_json(statement,strlen(statement),id,mod.ID); | |
194 | + chHeapFree(statement); | |
195 | +} | |
196 | + | |
181 | 197 | void wifi_disconnect(void){ |
182 | 198 | uint8_t res=libwismart_WiFiDisconnect(); |
183 | 199 | if(res) |
... | ... | @@ -204,6 +220,7 @@ int main(void) |
204 | 220 | char* valueSensors[TOTAL_SENSORS]; |
205 | 221 | memset (valueSensors, 0, TOTAL_SENSORS); |
206 | 222 | |
223 | + | |
207 | 224 | printf("Connecting to wifi...\r\n"); |
208 | 225 | wifi_connect(); |
209 | 226 | |
... | ... | @@ -262,6 +279,8 @@ int main(void) |
262 | 279 | /* Send data to server, empty the buffer */ |
263 | 280 | send_data(buffers, ind, sizes, sensors); |
264 | 281 | printf("Data sent!\r\n"); |
282 | + //Now sending battery level | |
283 | + send_battery_level(timestamp); | |
265 | 284 | //time = getNTPTime(); |
266 | 285 | update_time(&time); |
267 | 286 | delay = getSystemTime(); |
... | ... | @@ -277,6 +296,8 @@ int main(void) |
277 | 296 | printf("--------------soft limit-------------\r\n"); |
278 | 297 | wifi_connect(); |
279 | 298 | send_data(buffers, ind, sizes, sensors); |
299 | + //Now sending battery level | |
300 | + send_battery_level(timestamp); | |
280 | 301 | //disconect_wifi() |
281 | 302 | wifi_disconnect(); |
282 | 303 | } |
... | ... | @@ -314,6 +335,8 @@ int main(void) |
314 | 335 | } |
315 | 336 | |
316 | 337 | } |
338 | + //Now sending battery level | |
339 | + send_battery_level(timestamp); | |
317 | 340 | wifi_disconnect(); |
318 | 341 | } |
319 | 342 | time += getElapsedTime(delay); | ... | ... |
Project/applications/smartcities/module.c deleted
Project/applications/smartcities/sensors.c
1 | 1 | #include "sensors.h" |
2 | 2 | |
3 | -sensor light_sensor = {LIGHT_ADDR, "Light sensor", "illumination", "lux",NULL}; | |
4 | -sensor ultrasound_sensor = {DISTANCE_ADDR, "Ultrasound sensor", "distance", "cm",NULL}; | |
5 | -sensor pressure_sensor = {PRESSURE_ADDR, "Pressure sensor", "pressure", "hPa",NULL}; | |
6 | -sensor humidity_temp_sensor = {HUMIDITY_TEMP_ADDR, "Humidity and Temperature","ºC,RH",NULL}; | |
7 | -sensor sound_sensor = {SOUND_ADDR, "Sound sensor","mV",NULL}; | |
8 | -sensor battery = {BATTERY_ADDR, "Battery Level","mV",NULL}; | |
3 | +sensor light_sensor = {LIGHT_ADDR, "Light sensor", "illumination", "lux", NULL}; | |
4 | +sensor ultrasound_sensor = {DISTANCE_ADDR, "Ultrasound sensor", "distance", "cm", NULL}; | |
5 | +sensor pressure_sensor = {PRESSURE_ADDR, "Pressure sensor", "pressure", "hPa", NULL}; | |
6 | +sensor humidity_temp_sensor = {HUMIDITY_TEMP_ADDR, "Temperature and humidity sensor", "temperature,humidity", "ºC,RH",NULL}; | |
7 | +sensor sound_sensor = {SOUND_ADDR, "Sound sensor", "sound", "mV", NULL}; | |
8 | +sensor battery = {BATTERY_ADDR, "Battery Level", "power", "mV", NULL}; | |
9 | 9 | |
10 | 10 | sensor* sensors[TOTAL_SENSORS+1] = {&light_sensor,&ultrasound_sensor,&pressure_sensor,&humidity_temp_sensor,&sound_sensor,&battery}; |
11 | 11 | ... | ... |