diff --git a/Project/applications/smartcities/test_httpClient.c b/Project/applications/smartcities/example-code/httpClient/test_httpClient.c index 493000a..493000a 100644 --- a/Project/applications/smartcities/test_httpClient.c +++ b/Project/applications/smartcities/example-code/httpClient/test_httpClient.c diff --git a/Project/applications/smartcities/test_timer-loop.c b/Project/applications/smartcities/example-code/test_timer-loop.c index 1031574..1031574 100644 --- a/Project/applications/smartcities/test_timer-loop.c +++ b/Project/applications/smartcities/example-code/test_timer-loop.c diff --git a/Project/applications/smartcities/include/buffer.h b/Project/applications/smartcities/include/buffer.h index 14bca06..7768d8d 100644 --- a/Project/applications/smartcities/include/buffer.h +++ b/Project/applications/smartcities/include/buffer.h @@ -4,7 +4,7 @@ #include "libwismart.h" #include "json.h" -#define SOFT_LIMIT 8192 /* en bytes -> 10k * 1024 */ +#define SOFT_LIMIT 8192 /* en bytes -> 8k * 1024 */ #define HARD_LIMIT 10240 #define MEMORY_OK 0 #define SOFT_REACHED 1 diff --git a/Project/applications/smartcities/include/globals.h b/Project/applications/smartcities/include/globals.h index 2088933..e9a9d50 100644 --- a/Project/applications/smartcities/include/globals.h +++ b/Project/applications/smartcities/include/globals.h @@ -7,5 +7,11 @@ #define BUFFER_LENGTH 30 #define MAX_RAM 30000 #define MODULE_ID "123456" +#define WIFI_MODE WIFI_MODE_CLIENT +#define NETWORK_SSID_AP "modularsense" +#define NETWORK_KEY_AP NULL +#define NETWORK_CHANNEL_AP 1 +#define HARD_LIMIT_WAIT_TIME 10*1000 //5*60*1000 + #endif diff --git a/Project/applications/smartcities/include/sensors.h b/Project/applications/smartcities/include/sensors.h index ad2af33..e1713d8 100644 --- a/Project/applications/smartcities/include/sensors.h +++ b/Project/applications/smartcities/include/sensors.h @@ -67,13 +67,13 @@ typedef struct { uint16_t MD; } bmp085_callibration; +void init_pressure(void); +void init_pressure_temperature(void); uint16_t get_pressure_data(void); uint16_t get_pressure_temperature_data(void); bmp085_callibration get_pressure_callibration_data(void); char* callibration_pressure_data_csv(bmp085_callibration parameters); char* pressure_value(uint16_t pressure,uint16_t temperature); -void init_pressure(void); -void init_pressure_temperature(void); //HUMIDITY AND TEMPERATURE SENSOR diff --git a/Project/applications/smartcities/json.c b/Project/applications/smartcities/json.c index d5c0c30..c87abf9 100644 --- a/Project/applications/smartcities/json.c +++ b/Project/applications/smartcities/json.c @@ -157,14 +157,12 @@ uint8_t send_json(char* statement, uint32_t length, char* provider_ID, char* sen strcpy(PATH,"/data/modularupload/"); strcpy(PATH+20,provider_ID); strcpy(PATH+20+strlen(provider_ID),sensor_ID);*/ - //PATH[21+strlen(provider_ID)+strlen(sensor_ID)] = '\0'; //FUCKING LEWIS... PATH = (char*) chHeapAlloc(NULL,54+strlen(provider_ID)+strlen(sensor_ID)); strcpy(PATH,"/modularsense/wordpress/opendata/data/modularupload/"); strcpy(PATH+52,provider_ID); strcpy(PATH+52+strlen(provider_ID),sensor_ID); - //PATH[53+strlen(provider_ID)+strlen(sensor_ID)] = '\0'; } struct httpHeaders server = { put,PATH,strlen(PATH),URL,strlen(URL)}; response_code = httpRequest(server, statement, length); diff --git a/Project/applications/smartcities/main.c b/Project/applications/smartcities/main.c index 4e951f1..0631106 100644 --- a/Project/applications/smartcities/main.c +++ b/Project/applications/smartcities/main.c @@ -12,15 +12,13 @@ #include "ntp.h" #include "sensors.h" -#define WIFI_MODE WIFI_MODE_CLIENT -#define NETWORK_SSID_AP "modularsense" -#define NETWORK_KEY_AP NULL -#define NETWORK_CHANNEL_AP 1 - -#define HARD_LIMIT_WAIT_TIME 10*1000 //5*60*1000 - +uint8_t connected=0; +uint8_t timeout=0; +uint8_t retries=0; +uint8_t sensors_length=0; +uint8_t registry_opened=0; wismart_registryKey_t geo; - +module mod; void initLibwismart(void) { @@ -28,13 +26,6 @@ void initLibwismart(void) libwismart_Init(hwif); } -uint8_t connected=0; -uint8_t timeout=0; -uint8_t retries=0; -uint8_t sensors_length=0; -uint8_t registry_opened=0; - -module mod; void update_time(unsigned long *time) { @@ -114,8 +105,6 @@ void send_data(char** buffers[], uint32_t ind[], uint32_t sizes[], uint8_t senso for(j=0;j retorna un vector con las direcciones en cada posición del vector, si la posición del vector retorna un cero -> no existe el sensor //Escanea y registra I2C_scan(I2C1,sensors); sensors_length=strlen((char*)sensors); @@ -289,7 +279,8 @@ int main(void) printf("Putting data in buffer...\r\n"); put_buffers(buffers,ind,sizes,values,sensors); printf("Data is now in buffer...\n\r"); - if (i == LONG_PERIOD/SHORT_PERIOD ){ + if (i == LONG_PERIOD/SHORT_PERIOD ) + { printf("Programmed Send cycle...\r\n"); /* Wi-Fi connect */ printf("Connecting to wifi...\r\n"); @@ -299,10 +290,8 @@ int main(void) printf("Data sent!\r\n"); //Now sending battery level send_battery_level(timestamp); - //time = getNTPTime(); update_time(&time); delay = getSystemTime(); - //desconectar wifi wifi_disconnect(); printf("new ntp time (absolute):\t%ul\r\ntime mod LONG_PERIOD:\t%ul\r\ntime mod SHORT_PERIOD:\t%ul\r\n",time,time%LONG_PERIOD,time%SHORT_PERIOD); i = 0; @@ -310,16 +299,17 @@ int main(void) printf("mirant memoria\r\n"); int res=check_memory(); - if(res==SOFT_REACHED){ + if(res==SOFT_REACHED) + { printf("--------------soft limit-------------\r\n"); wifi_connect(); send_data(buffers, ind, sizes, sensors); //Now sending battery level send_battery_level(timestamp); - //disconect_wifi() wifi_disconnect(); } - else if(res==HARD_REACHED){ + else if(res==HARD_REACHED) + { printf("--------------hard limit-------------\r\n"); wifi_connect(); char id_0[3]; @@ -351,7 +341,6 @@ int main(void) else if(ok ==JSON_POST_OK){ printf(" send OK \r\n"); } - } //Now sending battery level send_battery_level(timestamp); @@ -370,8 +359,6 @@ int main(void) /* * TO-DO * - * - Test distance and humidity sensors - * - Test ADC - * - Test register, data send and battery send + * - Test distance * - Reset timer-related defines */ \ No newline at end of file diff --git a/Project/applications/smartcities/ntp.c b/Project/applications/smartcities/ntp.c index 9d152a7..6b733db 100644 --- a/Project/applications/smartcities/ntp.c +++ b/Project/applications/smartcities/ntp.c @@ -1,8 +1,8 @@ #include "ntp.h" -Date getDate(unsigned long secsSince1900){ +Date getDate(unsigned long secsSince1900) +{ unsigned long daysPerMonth[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; - unsigned long epoch = secsSince1900 - DIFF_SEC_1900_1970; int second = epoch % 60; @@ -14,7 +14,8 @@ Date getDate(unsigned long secsSince1900){ int year = 0; unsigned long days = 0; - while((unsigned)(days += (LEAP_YEAR(year) ? 366 : 365)) <= epoch){ + while((unsigned)(days += (LEAP_YEAR(year) ? 366 : 365)) <= epoch) + { year++; } days -= LEAP_YEAR(year) ? 366 : 365; @@ -23,14 +24,17 @@ Date getDate(unsigned long secsSince1900){ int j=0; int cont=0; int aux=epoch; - if(LEAP_YEAR(year)){ + if(LEAP_YEAR(year)) + { daysPerMonth[1]=29; } - while (daysPerMonth[j]