Commit c4ac6baed74da6410e5b0f93024646402176caef
1 parent
c352e167
--no commit message
Showing
23 changed files
with
296 additions
and
353 deletions
Project/applications/smartcities/adc.c
@@ -12,7 +12,7 @@ uint32_t adc_batt_process() | @@ -12,7 +12,7 @@ uint32_t adc_batt_process() | ||
12 | 12 | ||
13 | adcRegisterValue = adc_batt_read(); | 13 | adcRegisterValue = adc_batt_read(); |
14 | 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)); |
15 | - printf("Register value is %4u [%4u milliVolts are currently given to gpio %s]\r\n",adcRegisterValue, analogValue, ADCbatt_GPIO_STR); | 15 | + DBG_ADC("Register value is %4u [%4u milliVolts are currently given to gpio %s]\r\n",adcRegisterValue, analogValue, ADCbatt_GPIO_STR); |
16 | return analogValue; | 16 | return analogValue; |
17 | } | 17 | } |
18 | 18 | ||
@@ -66,7 +66,7 @@ uint32_t adc_sound_process() | @@ -66,7 +66,7 @@ uint32_t adc_sound_process() | ||
66 | 66 | ||
67 | adcRegisterValue = adc_sound_read(); | 67 | adcRegisterValue = adc_sound_read(); |
68 | analogValue = ADCsound_VREF_MINUS + (((adcRegisterValue - ADCsound_MIN_VALUE)*(ADCsound_VREF_PLUS - ADCsound_VREF_MINUS))/(ADCsound_MAX_VALUE - ADCsound_MIN_VALUE)); | 68 | analogValue = ADCsound_VREF_MINUS + (((adcRegisterValue - ADCsound_MIN_VALUE)*(ADCsound_VREF_PLUS - ADCsound_VREF_MINUS))/(ADCsound_MAX_VALUE - ADCsound_MIN_VALUE)); |
69 | - printf("Register value is %4u [%4u milliVolts are currently given to gpio %s]\r\n",adcRegisterValue, analogValue, ADCsound_GPIO_STR); | 69 | + DBG_ADC("Register value is %4u [%4u milliVolts are currently given to gpio %s]\r\n",adcRegisterValue, analogValue, ADCsound_GPIO_STR); |
70 | return analogValue; | 70 | return analogValue; |
71 | } | 71 | } |
72 | 72 |
Project/applications/smartcities/buffer.c
@@ -7,20 +7,20 @@ char** put_message(char* info, char** buf,uint32_t *index, uint32_t *buf_len) | @@ -7,20 +7,20 @@ char** put_message(char* info, char** buf,uint32_t *index, uint32_t *buf_len) | ||
7 | len=*buf_len; | 7 | len=*buf_len; |
8 | if(len==*index) | 8 | if(len==*index) |
9 | { | 9 | { |
10 | - printf("Joining buffer...\r\n"); | 10 | + DBG_BUFFER("Joining buffer...\r\n"); |
11 | char** buffer = join_buf(buf, buf_len); | 11 | char** buffer = join_buf(buf, buf_len); |
12 | - printf("Joined buffer...\r\n"); | 12 | + DBG_BUFFER("Joined buffer...\r\n"); |
13 | buffer[*index] = chHeapAlloc(NULL,strlen(info)+1); | 13 | buffer[*index] = chHeapAlloc(NULL,strlen(info)+1); |
14 | - printf("Memory allocated...\r\n"); | 14 | + DBG_BUFFER("Memory allocated...\r\n"); |
15 | strcpy(buffer[*index],info); | 15 | strcpy(buffer[*index],info); |
16 | - printf("Data copied...\r\n"); | 16 | + DBG_BUFFER("Data copied...\r\n"); |
17 | i = *index+1; | 17 | i = *index+1; |
18 | *index = i; | 18 | *index = i; |
19 | return buffer; | 19 | return buffer; |
20 | } | 20 | } |
21 | else | 21 | else |
22 | { | 22 | { |
23 | - printf("WTF in put_message\r\n"); | 23 | + DBG_BUFFER("WTF in put_message\r\n"); |
24 | buf[*index] = chHeapAlloc(NULL,strlen(info)+1); | 24 | buf[*index] = chHeapAlloc(NULL,strlen(info)+1); |
25 | buf[*index] = info; | 25 | buf[*index] = info; |
26 | i = *index+1; | 26 | i = *index+1; |
@@ -31,17 +31,18 @@ char** put_message(char* info, char** buf,uint32_t *index, uint32_t *buf_len) | @@ -31,17 +31,18 @@ char** put_message(char* info, char** buf,uint32_t *index, uint32_t *buf_len) | ||
31 | 31 | ||
32 | int check_memory() | 32 | int check_memory() |
33 | { | 33 | { |
34 | - printf("Memòria disponible en bytes segons:\r\n"); | ||
35 | - int mem_free = libwismart_GetMemFree_Ram().free; | ||
36 | - printf("- free: %d %d\r\n", libwismart_GetMemFree_Ram().free, MAX_RAM - libwismart_GetMemFree_Ram().free); | ||
37 | - int mem = MAX_RAM - mem_free; | ||
38 | - printf("mem ocupada=%d\r\n",mem); | 34 | + DBG_BUFFER("Checking available memory...\r\n"); |
35 | + DBG_BUFFER("%c[1;36mAvailable memory: %d B%c[1;00m\r\n",0x1B,libwismart_GetMemFree_Ram().free,0x1B); | ||
36 | + int mem = MAX_RAM - libwismart_GetMemFree_Ram().free; | ||
37 | + DBG_BUFFER("%c[1;36mUsed memory: %d B%c[1;00m\r\n",0x1B,mem,0x1B); | ||
39 | if(mem >= HARD_LIMIT) | 38 | if(mem >= HARD_LIMIT) |
40 | { | 39 | { |
40 | + DBG_BUFFER("[WARNING] Hard limit reached\r\n"); | ||
41 | return HARD_REACHED; | 41 | return HARD_REACHED; |
42 | } | 42 | } |
43 | else if(mem >= SOFT_LIMIT) | 43 | else if(mem >= SOFT_LIMIT) |
44 | { | 44 | { |
45 | + DBG_BUFFER("[WARNING] Soft limit reached\r\n"); | ||
45 | return SOFT_REACHED; | 46 | return SOFT_REACHED; |
46 | } | 47 | } |
47 | return MEMORY_OK; | 48 | return MEMORY_OK; |
@@ -49,21 +50,20 @@ int check_memory() | @@ -49,21 +50,20 @@ int check_memory() | ||
49 | 50 | ||
50 | int send(char** buf, uint32_t *index, uint32_t *size_buf, char *provider_ID, char *sensor_ID) | 51 | int send(char** buf, uint32_t *index, uint32_t *size_buf, char *provider_ID, char *sensor_ID) |
51 | { | 52 | { |
52 | - printf("abans del JSON statement\r\n"); | ||
53 | - printf("index= %d \r\n",*index); | ||
54 | - char* statement=prepare_json_observation_statement(buf, *index); | 53 | + DBG_BUFFER("Preparing JSON statement...\r\n"); |
54 | + char* statement = prepare_json_observation_statement(buf, *index); | ||
55 | uint32_t size = strlen(statement); | 55 | uint32_t size = strlen(statement); |
56 | if(buf==NULL) | 56 | if(buf==NULL) |
57 | { | 57 | { |
58 | + DBG_BUFFER("[ERROR] Buffer not initialized!\r\n"); | ||
58 | return 2; | 59 | return 2; |
59 | } | 60 | } |
60 | - printf("abans del JSON\r\n"); | ||
61 | uint8_t res = send_json(statement, size, provider_ID, sensor_ID); | 61 | uint8_t res = send_json(statement, size, provider_ID, sensor_ID); |
62 | chHeapFree(statement); | 62 | chHeapFree(statement); |
63 | int i; | 63 | int i; |
64 | - printf("JSON_POST_OK ? %d\r\n",res == JSON_POST_OK); | ||
65 | if(res==JSON_POST_OK) | 64 | if(res==JSON_POST_OK) |
66 | { | 65 | { |
66 | + DBG_BUFFER("Data sent successfully\r\n"); | ||
67 | for(i=0;i<*index;i++) | 67 | for(i=0;i<*index;i++) |
68 | { | 68 | { |
69 | chHeapFree(buf[i]); | 69 | chHeapFree(buf[i]); |
@@ -72,7 +72,6 @@ int send(char** buf, uint32_t *index, uint32_t *size_buf, char *provider_ID, cha | @@ -72,7 +72,6 @@ int send(char** buf, uint32_t *index, uint32_t *size_buf, char *provider_ID, cha | ||
72 | { | 72 | { |
73 | chHeapFree(buf); | 73 | chHeapFree(buf); |
74 | } | 74 | } |
75 | - printf("posant la mida i l'index a 0\r\n"); | ||
76 | *index=0; | 75 | *index=0; |
77 | *size_buf=0; | 76 | *size_buf=0; |
78 | } | 77 | } |
@@ -86,23 +85,23 @@ char** join_buf(char** buf, uint32_t *buf_len) | @@ -86,23 +85,23 @@ char** join_buf(char** buf, uint32_t *buf_len) | ||
86 | int len = *buf_len; | 85 | int len = *buf_len; |
87 | n_buf = chHeapAlloc (NULL,sizeof (char *) * (len+1)); | 86 | n_buf = chHeapAlloc (NULL,sizeof (char *) * (len+1)); |
88 | int i; | 87 | int i; |
89 | - printf("Start buffer join...\r\n"); | 88 | + DBG_BUFFER("Start buffer join...\r\n"); |
90 | for(i=0; i<len;i++) | 89 | for(i=0; i<len;i++) |
91 | { | 90 | { |
92 | - printf("in join_buf for, Asking for %d bytes...\r\n",strlen(buf[i]+1)); | 91 | + DBG_BUFFER("in join_buf for, Asking for %d bytes...\r\n",strlen(buf[i]+1)); |
93 | n_buf[i] = chHeapAlloc(NULL,strlen(buf[i])+1); | 92 | n_buf[i] = chHeapAlloc(NULL,strlen(buf[i])+1); |
94 | - printf("in join_buf for, Memory allocated...\r\n"); | 93 | + DBG_BUFFER("in join_buf for, Memory allocated...\r\n"); |
95 | strcpy(n_buf[i],buf[i]); | 94 | strcpy(n_buf[i],buf[i]); |
96 | - printf("in join_buf for, Message copied...\r\n"); | 95 | + DBG_BUFFER("in join_buf for, Message copied...\r\n"); |
97 | chHeapFree(buf[i]); | 96 | chHeapFree(buf[i]); |
98 | - printf("in join_buf for, Memory cleared...\r\n"); | 97 | + DBG_BUFFER("in join_buf for, Memory cleared...\r\n"); |
99 | } | 98 | } |
100 | - printf("All data transferred\r\n"); | 99 | + DBG_BUFFER("All data transferred\r\n"); |
101 | if(len != 0) | 100 | if(len != 0) |
102 | { | 101 | { |
103 | chHeapFree(buf); | 102 | chHeapFree(buf); |
104 | } | 103 | } |
105 | - printf("Old buffer cleared\r\n"); | 104 | + DBG_BUFFER("Old buffer cleared\r\n"); |
106 | len++; | 105 | len++; |
107 | *buf_len=len; | 106 | *buf_len=len; |
108 | return n_buf; | 107 | return n_buf; |
Project/applications/smartcities/callbacks.c
@@ -6,18 +6,18 @@ void dhcp_connect_result_cb(int result) | @@ -6,18 +6,18 @@ void dhcp_connect_result_cb(int result) | ||
6 | if(result==LIBWISMART_DHCP_ADDRESS_ASSIGNED) | 6 | if(result==LIBWISMART_DHCP_ADDRESS_ASSIGNED) |
7 | { | 7 | { |
8 | libwismart_GetCurrentIP(&ip,NULL,NULL); | 8 | libwismart_GetCurrentIP(&ip,NULL,NULL); |
9 | - printf("IP: %d.%d.%d.%d \r\n",ip.addr[3],ip.addr[2],ip.addr[1],ip.addr[0]); | 9 | + DBG_CALLBACKS("IP: %d.%d.%d.%d \r\n",ip.addr[3],ip.addr[2],ip.addr[1],ip.addr[0]); |
10 | connected = 1; | 10 | connected = 1; |
11 | retries = 0; | 11 | retries = 0; |
12 | } | 12 | } |
13 | else if(result==LIBWISMART_DHCP_TIMEOUT) | 13 | else if(result==LIBWISMART_DHCP_TIMEOUT) |
14 | { | 14 | { |
15 | - printf("DHCP timeout\r\n"); | 15 | + DBG_CALLBACKS("DHCP timeout\r\n"); |
16 | timeout = 1; | 16 | timeout = 1; |
17 | } | 17 | } |
18 | else | 18 | else |
19 | { | 19 | { |
20 | - printf("DHCP error\r\n"); | 20 | + DBG_CALLBACKS("DHCP error\r\n"); |
21 | timeout = 1; | 21 | timeout = 1; |
22 | } | 22 | } |
23 | 23 | ||
@@ -29,7 +29,7 @@ void wifi_connect_result_cb(int result) | @@ -29,7 +29,7 @@ void wifi_connect_result_cb(int result) | ||
29 | { | 29 | { |
30 | timeout=1; | 30 | timeout=1; |
31 | } | 31 | } |
32 | - printf("WiFi Connect indication: "); | 32 | + DBG_CALLBACKS("WiFi Connect indication: "); |
33 | if(result == WISMART_WIFI_CONNECTED) | 33 | if(result == WISMART_WIFI_CONNECTED) |
34 | { | 34 | { |
35 | printf("Connected\r\n"); | 35 | printf("Connected\r\n"); |
@@ -62,16 +62,16 @@ void softapMode_clientIndicationCb(wismart_softap_cb_t reason, const uint8_t *ma | @@ -62,16 +62,16 @@ void softapMode_clientIndicationCb(wismart_softap_cb_t reason, const uint8_t *ma | ||
62 | switch(reason) | 62 | switch(reason) |
63 | { | 63 | { |
64 | case WISMART_WIFI_AP_CLIENT_CONNECTED: | 64 | case WISMART_WIFI_AP_CLIENT_CONNECTED: |
65 | - printf("Client: "MACSTR" connected\r\n",MAC2STR(mac)); | 65 | + DBG_CALLBACKS("Client: "MACSTR" connected\r\n",MAC2STR(mac)); |
66 | break; | 66 | break; |
67 | case WISMART_WIFI_AP_CLIENT_DISCONNECTED: | 67 | case WISMART_WIFI_AP_CLIENT_DISCONNECTED: |
68 | - printf("Client: "MACSTR" disconnected\r\n",MAC2STR(mac)); | 68 | + DBG_CALLBACKS("Client: "MACSTR" disconnected\r\n",MAC2STR(mac)); |
69 | break; | 69 | break; |
70 | case WISMART_WIFI_AP_CLIENT_EXPIRED: | 70 | case WISMART_WIFI_AP_CLIENT_EXPIRED: |
71 | - printf("Client: "MACSTR" connection have expired\r\n",MAC2STR(mac)); | 71 | + DBG_CALLBACKS("Client: "MACSTR" connection have expired\r\n",MAC2STR(mac)); |
72 | break; | 72 | break; |
73 | case WISMART_WIFI_AP_CLIENT_GET_IP: | 73 | case WISMART_WIFI_AP_CLIENT_GET_IP: |
74 | - printf("Client: "MACSTR" got ip: %s\r\n", MAC2STR(mac), inet_ntoa(*ip)); | 74 | + DBG_CALLBACKS("Client: "MACSTR" got ip: %s\r\n", MAC2STR(mac), inet_ntoa(*ip)); |
75 | break; | 75 | break; |
76 | } | 76 | } |
77 | 77 | ||
@@ -81,11 +81,11 @@ void softapMode_clientIndicationCb(wismart_softap_cb_t reason, const uint8_t *ma | @@ -81,11 +81,11 @@ void softapMode_clientIndicationCb(wismart_softap_cb_t reason, const uint8_t *ma | ||
81 | 81 | ||
82 | void printWifiInfo(uint8_t wifiMode) | 82 | void printWifiInfo(uint8_t wifiMode) |
83 | { | 83 | { |
84 | - printf("\r\n\r\n"); | ||
85 | - printf("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\r\n"); | ||
86 | - printf("| Network Is Ready!\r\n"); | ||
87 | - printf("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\r\n"); | ||
88 | - printf("| Mode : %s\r\n", (wifiMode == WIFI_MODE_CLIENT) ? "Client":"Soft Access Point"); | ||
89 | - printf("| IP : 192.168.1.1\r\n"); | ||
90 | - printf("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\r\n"); | 84 | + DBG_CALLBACKS("\r\n\r\n"); |
85 | + DBG_CALLBACKS("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\r\n"); | ||
86 | + DBG_CALLBACKS("| Network Is Ready!\r\n"); | ||
87 | + DBG_CALLBACKS("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\r\n"); | ||
88 | + DBG_CALLBACKS("| Mode : %s\r\n", (wifiMode == WIFI_MODE_CLIENT) ? "Client":"Soft Access Point"); | ||
89 | + DBG_CALLBACKS("| IP : 192.168.1.1\r\n"); | ||
90 | + DBG_CALLBACKS("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\r\n"); | ||
91 | } | 91 | } |
92 | \ No newline at end of file | 92 | \ No newline at end of file |
Project/applications/smartcities/configServer.c
@@ -100,7 +100,7 @@ void configServer_setClientParameters() | @@ -100,7 +100,7 @@ void configServer_setClientParameters() | ||
100 | if(ret == 0) | 100 | if(ret == 0) |
101 | { | 101 | { |
102 | //successful conversion | 102 | //successful conversion |
103 | - printf("%d,%d,%d,%d,%d\r\n",asciiBuf[0],asciiBuf[1],asciiBuf[2],asciiBuf[3],asciiBuf[4]); | 103 | + CONFIG_SERVER_DBG("%d,%d,%d,%d,%d\r\n",asciiBuf[0],asciiBuf[1],asciiBuf[2],asciiBuf[3],asciiBuf[4]); |
104 | memset(arg_passphraseStr, 0, sizeof(arg_passphraseStr)); | 104 | memset(arg_passphraseStr, 0, sizeof(arg_passphraseStr)); |
105 | memcpy(arg_passphraseStr, asciiBuf, 5); | 105 | memcpy(arg_passphraseStr, asciiBuf, 5); |
106 | } | 106 | } |
Project/applications/smartcities/flash.sh
0 → 100755
Project/applications/smartcities/httpClient.c
@@ -24,14 +24,14 @@ int httpRequest(struct httpHeaders head, char* content, int content_size) | @@ -24,14 +24,14 @@ int httpRequest(struct httpHeaders head, char* content, int content_size) | ||
24 | ip4_addr_set_u32(&remote_ip,ipaddr_addr(SERVER_IP)); | 24 | ip4_addr_set_u32(&remote_ip,ipaddr_addr(SERVER_IP)); |
25 | 25 | ||
26 | // Check or default params | 26 | // Check or default params |
27 | - printf("httpRequest: Checking params\r\n"); | 27 | + DBG_HTTP("Checking params\r\n"); |
28 | if (head.uri == NULL || head.host == NULL) | 28 | if (head.uri == NULL || head.host == NULL) |
29 | { | 29 | { |
30 | return 1; | 30 | return 1; |
31 | } | 31 | } |
32 | 32 | ||
33 | // Calculate header size | 33 | // Calculate header size |
34 | - printf("httpRequest: Calculating header size\r\n"); | 34 | + DBG_HTTP("Calculating header size\r\n"); |
35 | int head_size = strlen(reqMethod2text(head.method)); | 35 | int head_size = strlen(reqMethod2text(head.method)); |
36 | head_size += strlen(" ") + head.uri_size + strlen(" HTTP/1.1") + strlen(ENDL); | 36 | head_size += strlen(" ") + head.uri_size + strlen(" HTTP/1.1") + strlen(ENDL); |
37 | head_size += strlen("Host: ") + head.host_size + strlen(ENDL); | 37 | head_size += strlen("Host: ") + head.host_size + strlen(ENDL); |
@@ -42,7 +42,7 @@ int httpRequest(struct httpHeaders head, char* content, int content_size) | @@ -42,7 +42,7 @@ int httpRequest(struct httpHeaders head, char* content, int content_size) | ||
42 | head_size += strlen("Content-Length: ") + numberofdigits(content_size) + 2*(strlen(ENDL)); | 42 | head_size += strlen("Content-Length: ") + numberofdigits(content_size) + 2*(strlen(ENDL)); |
43 | } | 43 | } |
44 | // Build request head | 44 | // Build request head |
45 | - printf("httpRequest: Building request head\r\n"); | 45 | + DBG_HTTP("Building request head\r\n"); |
46 | int request_size = head_size + content_size + 2*(strlen(ENDL)); | 46 | int request_size = head_size + content_size + 2*(strlen(ENDL)); |
47 | request = (char *) chHeapAlloc(NULL,request_size); | 47 | request = (char *) chHeapAlloc(NULL,request_size); |
48 | strcpy(request, reqMethod2text(head.method)); | 48 | strcpy(request, reqMethod2text(head.method)); |
@@ -70,56 +70,51 @@ int httpRequest(struct httpHeaders head, char* content, int content_size) | @@ -70,56 +70,51 @@ int httpRequest(struct httpHeaders head, char* content, int content_size) | ||
70 | // Build request with content | 70 | // Build request with content |
71 | if(content_size > 0) | 71 | if(content_size > 0) |
72 | { | 72 | { |
73 | - printf("httpRequest: Adding content to request string\r\n"); | 73 | + DBG_HTTP("Adding content to request string\r\n"); |
74 | strcat(request, content); | 74 | strcat(request, content); |
75 | } | 75 | } |
76 | else | 76 | else |
77 | { | 77 | { |
78 | - printf("httpRequest: Skipping void content\r\n"); | 78 | + DBG_HTTP("Skipping void content\r\n"); |
79 | } | 79 | } |
80 | - printf("packet: %s\r\n",request); | 80 | + DBG_HTTP("Packet:\r\n\r\n%c[1;33m%s%c[1;00m \r\n\r\n",0x1B,request,0x1B); |
81 | // Set connection | 81 | // Set connection |
82 | - /*while(connection_ok !=0) // != ERR_OK | ||
83 | - {*/ | ||
84 | - printf("httpRequest: Setting connection\r\n"); | ||
85 | - neocon = netconn_new(NETCONN_TCP); | ||
86 | - if(neocon == NULL) | ||
87 | - { | ||
88 | - printf("\\->Socket creation FAILED. Have you called libwismart_init_bsd_sockets ?\r\n"); | ||
89 | - } | ||
90 | - /*local_ip.addr = 0;//getip | ||
91 | - netconn_bind(neocon, IP_ADDR_ANY, LOCAL_PORT); //88 is provisional local port.*/ | ||
92 | - printf("httpRequest: Establishing connection\r\n"); | ||
93 | - netconn_connect(neocon, &remote_ip, DEFAULT_REMOTE_PORT); | 82 | + DBG_HTTP("Setting connection\r\n"); |
83 | + neocon = netconn_new(NETCONN_TCP); | ||
84 | + if(neocon == NULL) | ||
85 | + { | ||
86 | + DBG_HTTP("[ERROR] Socket creation FAILED. Have you called libwismart_EnableBsdSocketAPI()?\r\n"); | ||
87 | + } | ||
88 | + /*local_ip.addr = 0;//getip | ||
89 | + netconn_bind(neocon, IP_ADDR_ANY, LOCAL_PORT); //88 is provisional local port.*/ | ||
90 | + DBG_HTTP("Establishing connection\r\n"); | ||
91 | + netconn_connect(neocon, &remote_ip, DEFAULT_REMOTE_PORT); | ||
92 | + | ||
93 | + // Send Request | ||
94 | + DBG_HTTP("Sending request\r\n"); | ||
95 | + err_t err=netconn_write(neocon, request, request_size, NETCONN_NOCOPY); | ||
96 | + DBG_HTTP("Write returned: %d\r\n",err); | ||
97 | + chHeapFree(request); | ||
94 | 98 | ||
95 | - // Send Request | ||
96 | - printf("httpRequest: Sending request\r\n"); | ||
97 | - err_t err=netconn_write(neocon, request, request_size, NETCONN_NOCOPY); | ||
98 | - printf("res write= %d\r\n",err); | ||
99 | - chHeapFree(request); | ||
100 | - | ||
101 | - // Wait for Response | ||
102 | - printf("httpRequest: Waiting for response\r\n"); | ||
103 | - //neocon->recv_timeout = 5000; // for 5s | ||
104 | - connection_ok = netconn_recv(neocon, &netBufs); | ||
105 | - printf("res recv= %d\r\n",connection_ok); | ||
106 | - | ||
107 | - if(connection_ok !=0) | ||
108 | - { | ||
109 | - netbuf_delete(netBufs); | ||
110 | - netconn_close(neocon); | ||
111 | - netconn_delete(neocon); | ||
112 | - return 0; | ||
113 | - } | ||
114 | - //} | 99 | + // Wait for Response |
100 | + DBG_HTTP("Waiting for response\r\n"); | ||
101 | + //neocon->recv_timeout = 5000; // for 5s | ||
102 | + connection_ok = netconn_recv(neocon, &netBufs); | ||
103 | + DBG_HTTP("Receive returned: %d\r\n",connection_ok); | ||
104 | + if(connection_ok !=0) | ||
105 | + { | ||
106 | + netbuf_delete(netBufs); | ||
107 | + netconn_close(neocon); | ||
108 | + netconn_delete(neocon); | ||
109 | + return 0; | ||
110 | + } | ||
115 | // Manage Response | 111 | // Manage Response |
116 | - printf("httpRequest: Response received. Let's parse the information\r\n"); | 112 | + DBG_HTTP("Response received. Let's parse the information\r\n"); |
117 | response = (char*)chHeapAlloc(NULL,4*sizeof(char)); | 113 | response = (char*)chHeapAlloc(NULL,4*sizeof(char)); |
118 | netbuf_copy_partial(netBufs,response,3,9); // read 3B starting from 9th -> read response code. "HTTP/1.1 301 Moved Permanently" | 114 | netbuf_copy_partial(netBufs,response,3,9); // read 3B starting from 9th -> read response code. "HTTP/1.1 301 Moved Permanently" |
119 | - printf("httpRequest: Unbelievablelybilbiyblyib successful! :D\r\nResponse code: %s\r\n",response); | 115 | + DBG_HTTP("Response code: %s\r\n",response); |
120 | int http_response = response2int(response); | 116 | int http_response = response2int(response); |
121 | - | ||
122 | - // alliberem Mandela i Willy | 117 | + |
123 | netbuf_delete(netBufs); | 118 | netbuf_delete(netBufs); |
124 | netconn_close(neocon); | 119 | netconn_close(neocon); |
125 | netconn_delete(neocon); | 120 | netconn_delete(neocon); |
@@ -127,32 +122,6 @@ int httpRequest(struct httpHeaders head, char* content, int content_size) | @@ -127,32 +122,6 @@ int httpRequest(struct httpHeaders head, char* content, int content_size) | ||
127 | return http_response; | 122 | return http_response; |
128 | } | 123 | } |
129 | 124 | ||
130 | -/* | ||
131 | - err_t netconn_write ( struct netconn * aNetConn, const void * aData, size_t aSize, u8_t aApiFlags ); | ||
132 | - | ||
133 | - aNetConn : the netconn object the data is written to | ||
134 | - aData : address of beginning of the data to write | ||
135 | - aSize : the length of the data in bytes | ||
136 | - aApiFlags : either of | ||
137 | - NETCONN_NOCOPY if the data is stable for the time of the transmission (static data or heap) | ||
138 | - NETCONN_COPY if the data is not stable for the time of the transmission (stack) | ||
139 | - | ||
140 | - With the netconn API, netconn_recv() returns a netbuf which may contain a chain of pbufs. You have no control over how much data will be returned in a single request, which may be more or less than you want to deal with. You can use various netbuf functions to copy data out of the buffer. If you need more data, you must call netconn_recv() again to get the next netbuf. If you received more data than you wanted, you will have to manage the extra data yourself. | ||
141 | - | ||
142 | - | ||
143 | - u16_t netbuf_copy_partial ( struct netbuf * aNetBuf, void * aData, u16_t aLen, u16_t aOffset ); | ||
144 | - | ||
145 | - Copy at most "aLen" bytes from the netbuf object to the destination location. The second alternative can start at an offset instead of 0. | ||
146 | - | ||
147 | - in aNetBuf : netbuf object the data is copied from | ||
148 | - out aData : address of the memory where the data is copied to | ||
149 | - in aLen : the size of the buffer, or the length of data to copy | ||
150 | - in aOffset : an offset to start the with copy operation. In "netbuf_copy" this value is 0 | ||
151 | - return : total number of copied bytes, might be 0 | ||
152 | - | ||
153 | - Contray to using "netbuf_data" you don't have to fumble around with chained buffers. You get all the data out of the buffer. As a drawback you have an extra overhead of memory usage. | ||
154 | -*/ | ||
155 | - | ||
156 | const char* reqMethod2text(enum reqMethod method) | 125 | const char* reqMethod2text(enum reqMethod method) |
157 | { | 126 | { |
158 | switch(method) | 127 | switch(method) |
Project/applications/smartcities/i2c.c
@@ -3,7 +3,7 @@ | @@ -3,7 +3,7 @@ | ||
3 | 3 | ||
4 | void I2C_init(void) | 4 | void I2C_init(void) |
5 | { | 5 | { |
6 | - printf("Initializing I2C...\r\n"); | 6 | + DBG_I2C("Initializing I2C...\r\n"); |
7 | GPIO_InitTypeDef GPIO_InitStruct; | 7 | GPIO_InitTypeDef GPIO_InitStruct; |
8 | I2C_InitTypeDef I2C_InitStruct; | 8 | I2C_InitTypeDef I2C_InitStruct; |
9 | 9 | ||
@@ -30,28 +30,28 @@ void I2C_init(void) | @@ -30,28 +30,28 @@ void I2C_init(void) | ||
30 | 30 | ||
31 | void I2C_start(I2C_TypeDef* I2Cx, uint8_t address, uint8_t direction) | 31 | void I2C_start(I2C_TypeDef* I2Cx, uint8_t address, uint8_t direction) |
32 | { | 32 | { |
33 | - printf("Sending I2C Start...\r\n"); | 33 | + DBG_I2C("Sending I2C Start...\r\n"); |
34 | while(I2C_GetFlagStatus(I2Cx, I2C_FLAG_BUSY)) | 34 | while(I2C_GetFlagStatus(I2Cx, I2C_FLAG_BUSY)) |
35 | { | 35 | { |
36 | // wait until I2C1 is not busy any more | 36 | // wait until I2C1 is not busy any more |
37 | } | 37 | } |
38 | - printf("I2C ready\r\n"); | 38 | + DBG_I2C("I2C ready\r\n"); |
39 | I2C_GenerateSTART(I2Cx, ENABLE); | 39 | I2C_GenerateSTART(I2Cx, ENABLE); |
40 | - printf("Start sent\r\n"); | 40 | + DBG_I2C("Start sent\r\n"); |
41 | while(!I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_MODE_SELECT)) | 41 | while(!I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_MODE_SELECT)) |
42 | { | 42 | { |
43 | // wait for I2C1 EV5 --> Slave has acknowledged start condition | 43 | // wait for I2C1 EV5 --> Slave has acknowledged start condition |
44 | } | 44 | } |
45 | - printf("Start ACK\r\n"); | 45 | + DBG_I2C("Start ACK\r\n"); |
46 | I2C_Send7bitAddress(I2Cx, address, direction); | 46 | I2C_Send7bitAddress(I2Cx, address, direction); |
47 | - printf("Master -> Slave Address and R/W sent\r\n"); | 47 | + DBG_I2C("Master -> Slave Address and R/W sent\r\n"); |
48 | if(direction == I2C_Direction_Transmitter) | 48 | if(direction == I2C_Direction_Transmitter) |
49 | { | 49 | { |
50 | while(!I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED)) | 50 | while(!I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED)) |
51 | { | 51 | { |
52 | // wait for I2Cx EV6, check if Slave has acknowledged Master transmitter mode | 52 | // wait for I2Cx EV6, check if Slave has acknowledged Master transmitter mode |
53 | } | 53 | } |
54 | - printf("Slave -> Master ACK\r\n"); | 54 | + DBG_I2C("Slave -> Master ACK\r\n"); |
55 | } | 55 | } |
56 | else if(direction == I2C_Direction_Receiver) | 56 | else if(direction == I2C_Direction_Receiver) |
57 | { | 57 | { |
@@ -59,29 +59,29 @@ void I2C_start(I2C_TypeDef* I2Cx, uint8_t address, uint8_t direction) | @@ -59,29 +59,29 @@ void I2C_start(I2C_TypeDef* I2Cx, uint8_t address, uint8_t direction) | ||
59 | { | 59 | { |
60 | // wait for I2Cx EV6, check if Slave has acknowledged Master receiver mode | 60 | // wait for I2Cx EV6, check if Slave has acknowledged Master receiver mode |
61 | } | 61 | } |
62 | - printf("Slave -> Master ACK\r\n"); | 62 | + DBG_I2C("Slave -> Master ACK\r\n"); |
63 | } | 63 | } |
64 | } | 64 | } |
65 | 65 | ||
66 | void I2C_restart(I2C_TypeDef* I2Cx, uint8_t address, uint8_t direction) | 66 | void I2C_restart(I2C_TypeDef* I2Cx, uint8_t address, uint8_t direction) |
67 | { | 67 | { |
68 | - printf("Sending repeated I2C Start...\r\n"); | 68 | + DBG_I2C("Sending repeated I2C Start...\r\n"); |
69 | I2C_GenerateSTART(I2Cx, ENABLE); | 69 | I2C_GenerateSTART(I2Cx, ENABLE); |
70 | - printf("Start sent\r\n"); | 70 | + DBG_I2C("Start sent\r\n"); |
71 | while(!I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_MODE_SELECT)) | 71 | while(!I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_MODE_SELECT)) |
72 | { | 72 | { |
73 | // wait for I2C1 EV5 --> Slave has acknowledged start condition | 73 | // wait for I2C1 EV5 --> Slave has acknowledged start condition |
74 | } | 74 | } |
75 | - printf("Start ACK\r\n"); | 75 | + DBG_I2C("Start ACK\r\n"); |
76 | I2C_Send7bitAddress(I2Cx, address, direction); | 76 | I2C_Send7bitAddress(I2Cx, address, direction); |
77 | - printf("Master -> Slave Address and R/W sent\r\n"); | 77 | + DBG_I2C("Master -> Slave Address and R/W sent\r\n"); |
78 | if(direction == I2C_Direction_Transmitter) | 78 | if(direction == I2C_Direction_Transmitter) |
79 | { | 79 | { |
80 | while(!I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED)) | 80 | while(!I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED)) |
81 | { | 81 | { |
82 | // wait for I2Cx EV6, check if Slave has acknowledged Master transmitter mode | 82 | // wait for I2Cx EV6, check if Slave has acknowledged Master transmitter mode |
83 | } | 83 | } |
84 | - printf("Slave -> Master ACK\r\n"); | 84 | + DBG_I2C("Slave -> Master ACK\r\n"); |
85 | } | 85 | } |
86 | else if(direction == I2C_Direction_Receiver) | 86 | else if(direction == I2C_Direction_Receiver) |
87 | { | 87 | { |
@@ -89,37 +89,37 @@ void I2C_restart(I2C_TypeDef* I2Cx, uint8_t address, uint8_t direction) | @@ -89,37 +89,37 @@ void I2C_restart(I2C_TypeDef* I2Cx, uint8_t address, uint8_t direction) | ||
89 | { | 89 | { |
90 | // wait for I2Cx EV6, check if Slave has acknowledged Master receiver mode | 90 | // wait for I2Cx EV6, check if Slave has acknowledged Master receiver mode |
91 | } | 91 | } |
92 | - printf("Slave -> Master ACK\r\n"); | 92 | + DBG_I2C("Slave -> Master ACK\r\n"); |
93 | } | 93 | } |
94 | } | 94 | } |
95 | 95 | ||
96 | void I2C_write(I2C_TypeDef* I2Cx, uint8_t data) | 96 | void I2C_write(I2C_TypeDef* I2Cx, uint8_t data) |
97 | { | 97 | { |
98 | - printf("Sending I2C byte %02x...\r\n",data); | 98 | + DBG_I2C("Sending I2C byte %02x...\r\n",data); |
99 | I2C_SendData(I2Cx, data); | 99 | I2C_SendData(I2Cx, data); |
100 | while(!I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_BYTE_TRANSMITTED)) | 100 | while(!I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_BYTE_TRANSMITTED)) |
101 | { | 101 | { |
102 | // wait for I2C1 EV8_2 --> last byte is transmitted | 102 | // wait for I2C1 EV8_2 --> last byte is transmitted |
103 | } | 103 | } |
104 | - printf("Data sent\r\n"); | 104 | + DBG_I2C("Data sent\r\n"); |
105 | } | 105 | } |
106 | 106 | ||
107 | uint8_t I2C_read_ack(I2C_TypeDef* I2Cx) | 107 | uint8_t I2C_read_ack(I2C_TypeDef* I2Cx) |
108 | { | 108 | { |
109 | - printf("Listening for byte in I2C (ACK)\r\n"); | 109 | + DBG_I2C("Listening for byte in I2C (ACK)\r\n"); |
110 | I2C_AcknowledgeConfig(I2Cx, ENABLE); | 110 | I2C_AcknowledgeConfig(I2Cx, ENABLE); |
111 | while( !I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_BYTE_RECEIVED)) | 111 | while( !I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_BYTE_RECEIVED)) |
112 | { | 112 | { |
113 | // wait until one byte has been received | 113 | // wait until one byte has been received |
114 | } | 114 | } |
115 | uint8_t data = I2C_ReceiveData(I2Cx); | 115 | uint8_t data = I2C_ReceiveData(I2Cx); |
116 | - printf("Received byte: %02x\r\n",data); | 116 | + DBG_I2C("Received byte: %02x\r\n",data); |
117 | return data; | 117 | return data; |
118 | } | 118 | } |
119 | 119 | ||
120 | uint8_t I2C_read_nack(I2C_TypeDef* I2Cx) | 120 | uint8_t I2C_read_nack(I2C_TypeDef* I2Cx) |
121 | { | 121 | { |
122 | - printf("Listening for byte in I2C (NACK)\r\n"); | 122 | + DBG_I2C("Listening for byte in I2C (NACK)\r\n"); |
123 | I2C_AcknowledgeConfig(I2Cx, DISABLE); | 123 | I2C_AcknowledgeConfig(I2Cx, DISABLE); |
124 | //I2C_GenerateSTOP(I2Cx, ENABLE); | 124 | //I2C_GenerateSTOP(I2Cx, ENABLE); |
125 | while( !I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_BYTE_RECEIVED)) | 125 | while( !I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_BYTE_RECEIVED)) |
@@ -127,19 +127,19 @@ uint8_t I2C_read_nack(I2C_TypeDef* I2Cx) | @@ -127,19 +127,19 @@ uint8_t I2C_read_nack(I2C_TypeDef* I2Cx) | ||
127 | // wait until one byte has been received | 127 | // wait until one byte has been received |
128 | } | 128 | } |
129 | uint8_t data = I2C_ReceiveData(I2Cx); | 129 | uint8_t data = I2C_ReceiveData(I2Cx); |
130 | - printf("Received byte: %02x\r\n",data); | 130 | + DBG_I2C("Received byte: %02x\r\n",data); |
131 | return data; | 131 | return data; |
132 | } | 132 | } |
133 | 133 | ||
134 | void I2C_stop(I2C_TypeDef* I2Cx) | 134 | void I2C_stop(I2C_TypeDef* I2Cx) |
135 | { | 135 | { |
136 | - printf("Sending I2C Stop...\r\n"); | 136 | + DBG_I2C("Sending I2C Stop...\r\n"); |
137 | I2C_GenerateSTOP(I2Cx, ENABLE); | 137 | I2C_GenerateSTOP(I2Cx, ENABLE); |
138 | /*while(!I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_BYTE_TRANSMITTING)) | 138 | /*while(!I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_BYTE_TRANSMITTING)) |
139 | { | 139 | { |
140 | // wait for I2C1 EV8_2 --> byte has been transmitted | 140 | // wait for I2C1 EV8_2 --> byte has been transmitted |
141 | }*/ | 141 | }*/ |
142 | - printf("Stop sent\r\n"); | 142 | + DBG_I2C("Stop sent\r\n"); |
143 | } | 143 | } |
144 | 144 | ||
145 | uint8_t I2C_check(I2C_TypeDef* I2Cx, uint8_t address) | 145 | uint8_t I2C_check(I2C_TypeDef* I2Cx, uint8_t address) |
@@ -153,14 +153,14 @@ uint8_t I2C_check(I2C_TypeDef* I2Cx, uint8_t address) | @@ -153,14 +153,14 @@ uint8_t I2C_check(I2C_TypeDef* I2Cx, uint8_t address) | ||
153 | { | 153 | { |
154 | // wait for I2C1 EV5 --> Slave has acknowledged start condition | 154 | // wait for I2C1 EV5 --> Slave has acknowledged start condition |
155 | } | 155 | } |
156 | - printf("Probing address %x ...\r\n",address); | 156 | + DBG_I2C("Probing address %x ...\r\n",address); |
157 | I2C_Send7bitAddress(I2Cx, address, I2C_Direction_Transmitter); | 157 | I2C_Send7bitAddress(I2Cx, address, I2C_Direction_Transmitter); |
158 | chThdSleepMilliseconds(I2C_TIMEOUT); | 158 | chThdSleepMilliseconds(I2C_TIMEOUT); |
159 | if(!I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED)) | 159 | if(!I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED)) |
160 | { | 160 | { |
161 | return 1; | 161 | return 1; |
162 | } | 162 | } |
163 | - printf("I2C address detected: %x\r\n", address); | 163 | + DBG_I2C("I2C address detected: %x\r\n", address); |
164 | I2C_write(I2Cx,0x00); | 164 | I2C_write(I2Cx,0x00); |
165 | I2C_stop(I2Cx); | 165 | I2C_stop(I2Cx); |
166 | return 0; | 166 | return 0; |
@@ -168,7 +168,7 @@ uint8_t I2C_check(I2C_TypeDef* I2Cx, uint8_t address) | @@ -168,7 +168,7 @@ uint8_t I2C_check(I2C_TypeDef* I2Cx, uint8_t address) | ||
168 | 168 | ||
169 | void I2C_reset(I2C_TypeDef* I2Cx) | 169 | void I2C_reset(I2C_TypeDef* I2Cx) |
170 | { | 170 | { |
171 | - printf("Resetting I2C...\r\n"); | 171 | + DBG_I2C("Resetting I2C...\r\n"); |
172 | I2C_SoftwareResetCmd(I2Cx, ENABLE); | 172 | I2C_SoftwareResetCmd(I2Cx, ENABLE); |
173 | I2C_DeInit(I2Cx); | 173 | I2C_DeInit(I2Cx); |
174 | I2C_init(); | 174 | I2C_init(); |
@@ -177,6 +177,7 @@ void I2C_reset(I2C_TypeDef* I2Cx) | @@ -177,6 +177,7 @@ void I2C_reset(I2C_TypeDef* I2Cx) | ||
177 | 177 | ||
178 | void I2C_scan(I2C_TypeDef* I2Cx,uint8_t *addresses) | 178 | void I2C_scan(I2C_TypeDef* I2Cx,uint8_t *addresses) |
179 | { | 179 | { |
180 | + DBG_I2C("Scanning sensors...\r\n"); | ||
180 | uint8_t i, j = 0; | 181 | uint8_t i, j = 0; |
181 | I2C_init(); | 182 | I2C_init(); |
182 | for(i = 0; i < TOTAL_SENSORS; i++) | 183 | for(i = 0; i < TOTAL_SENSORS; i++) |
Project/applications/smartcities/include/adc.h
@@ -7,7 +7,7 @@ | @@ -7,7 +7,7 @@ | ||
7 | #include "stm32f10x_gpio.h" | 7 | #include "stm32f10x_gpio.h" |
8 | #include "stm32f10x_adc.h" | 8 | #include "stm32f10x_adc.h" |
9 | 9 | ||
10 | -#define DBG(fmt,...) if(1){printf("[ADC] "fmt"\r\n", ##__VA_ARGS__);}else{({});} | 10 | +#define DBG_ADC(fmt,...) printf("%c[1;31madc.c:%c[1;00m "fmt,0x1B,0x1B, ##__VA_ARGS__) |
11 | 11 | ||
12 | #define ADCbatt_MIN_VALUE (0) | 12 | #define ADCbatt_MIN_VALUE (0) |
13 | #define ADCbatt_MAX_VALUE (0xfff) | 13 | #define ADCbatt_MAX_VALUE (0xfff) |
Project/applications/smartcities/include/buffer.h
@@ -10,6 +10,8 @@ | @@ -10,6 +10,8 @@ | ||
10 | #define SOFT_REACHED 1 | 10 | #define SOFT_REACHED 1 |
11 | #define HARD_REACHED 2 | 11 | #define HARD_REACHED 2 |
12 | 12 | ||
13 | +#define DBG_BUFFER(fmt,...) printf("%c[1;31mbuffer.c:%c[1;00m "fmt,0x1B,0x1B, ##__VA_ARGS__) | ||
14 | + | ||
13 | char** put_message(char* info, char** buf,uint32_t *index, uint32_t *buf_len); | 15 | char** put_message(char* info, char** buf,uint32_t *index, uint32_t *buf_len); |
14 | int check_memory(void); | 16 | int check_memory(void); |
15 | int send(char** buf, uint32_t *index, uint32_t *size, char *provider_ID, char *sensor_ID); | 17 | int send(char** buf, uint32_t *index, uint32_t *size, char *provider_ID, char *sensor_ID); |
Project/applications/smartcities/include/callbacks.h
@@ -17,6 +17,8 @@ void softapMode_clientIndicationCb(wismart_softap_cb_t reason, const uint8_t *ma | @@ -17,6 +17,8 @@ void softapMode_clientIndicationCb(wismart_softap_cb_t reason, const uint8_t *ma | ||
17 | void softapMode_apStartedCb(int result); | 17 | void softapMode_apStartedCb(int result); |
18 | void printWifiInfo(uint8_t wifiMode); | 18 | void printWifiInfo(uint8_t wifiMode); |
19 | 19 | ||
20 | +#define DBG_CALLBACKS(fmt,...) printf("%c[1;31mcallbacks.c:%c[1;00m "fmt,0x1B,0x1B, ##__VA_ARGS__) | ||
21 | + | ||
20 | extern uint8_t connected; | 22 | extern uint8_t connected; |
21 | extern uint8_t timeout; | 23 | extern uint8_t timeout; |
22 | extern uint8_t retries; | 24 | extern uint8_t retries; |
Project/applications/smartcities/include/configServer.h
@@ -10,8 +10,8 @@ | @@ -10,8 +10,8 @@ | ||
10 | #include "ch.h" | 10 | #include "ch.h" |
11 | #include "fsdata.c" | 11 | #include "fsdata.c" |
12 | 12 | ||
13 | -#define CONFIG_SERVER_DBG(fmt,...) if(1){printf("[SRV] "fmt"\r\n", ##__VA_ARGS__);}else{({});} | ||
14 | -#define CONFIG_SERVER_DBG_WARNING(fmt,...) if(1){printf("[SRV_WARNING] "fmt"\r\n", ##__VA_ARGS__);}else{({});} | 13 | +#define CONFIG_SERVER_DBG(fmt,...) printf("%c[1;31mconfigServer.c:%c[1;00m "fmt,0x1B,0x1B, ##__VA_ARGS__) |
14 | +#define CONFIG_SERVER_DBG_WARNING(fmt,...) printf("%c[1;31mconfigServer.c:%c[1;00m [WARNING] "fmt,0x1B,0x1B, ##__VA_ARGS__) | ||
15 | 15 | ||
16 | void configServer_start(uint8_t enableApScan); | 16 | void configServer_start(uint8_t enableApScan); |
17 | void configServer_connect(void); | 17 | void configServer_connect(void); |
Project/applications/smartcities/include/globals.h
@@ -5,13 +5,14 @@ | @@ -5,13 +5,14 @@ | ||
5 | #define SERVER_HOSTNAME SERVER_IP | 5 | #define SERVER_HOSTNAME SERVER_IP |
6 | #define MODULE_ID_LENGTH 6 | 6 | #define MODULE_ID_LENGTH 6 |
7 | #define BUFFER_LENGTH 30 | 7 | #define BUFFER_LENGTH 30 |
8 | -#define MAX_RAM 30000 | ||
9 | -#define MODULE_ID "123456" | 8 | +#define MAX_RAM 34704 |
9 | +#define MODULE_ID "000001" | ||
10 | #define WIFI_MODE WIFI_MODE_CLIENT | 10 | #define WIFI_MODE WIFI_MODE_CLIENT |
11 | #define NETWORK_SSID_AP "modularsense" | 11 | #define NETWORK_SSID_AP "modularsense" |
12 | #define NETWORK_KEY_AP NULL | 12 | #define NETWORK_KEY_AP NULL |
13 | #define NETWORK_CHANNEL_AP 1 | 13 | #define NETWORK_CHANNEL_AP 1 |
14 | -#define HARD_LIMIT_WAIT_TIME 10*1000 //5*60*1000 | ||
15 | - | 14 | +#define HARD_LIMIT_WAIT_TIME 10*1000 //5*60*1000 |
15 | +#define SNTP_SERVER_ADDRESS ipaddr_addr("81.184.154.182") /* your ntp server */ | ||
16 | 16 | ||
17 | +#define SERVER_LEWIS | ||
17 | #endif | 18 | #endif |
Project/applications/smartcities/include/httpClient.h
@@ -22,6 +22,9 @@ | @@ -22,6 +22,9 @@ | ||
22 | #define ENDL "\r\n" | 22 | #define ENDL "\r\n" |
23 | #define CONTENT_TYPE_HEADER "Content-Type: application/json; charset=UTF-8" | 23 | #define CONTENT_TYPE_HEADER "Content-Type: application/json; charset=UTF-8" |
24 | 24 | ||
25 | +#define DBG_HTTP(fmt,...) printf("%c[1;31mhttpClient.c:%c[1;00m "fmt,0x1B,0x1B, ##__VA_ARGS__) | ||
26 | + | ||
27 | + | ||
25 | typedef enum reqMethod | 28 | typedef enum reqMethod |
26 | { | 29 | { |
27 | post, | 30 | post, |
Project/applications/smartcities/include/i2c.h
@@ -9,6 +9,8 @@ | @@ -9,6 +9,8 @@ | ||
9 | 9 | ||
10 | #define I2C_TIMEOUT 100 | 10 | #define I2C_TIMEOUT 100 |
11 | 11 | ||
12 | +#define DBG_I2C(fmt,...) printf("%c[1;31mi2c.c:%c[1;00m "fmt,0x1B,0x1B, ##__VA_ARGS__) | ||
13 | + | ||
12 | void I2C_init(void); | 14 | void I2C_init(void); |
13 | void I2C_start(I2C_TypeDef* I2Cx, uint8_t address, uint8_t direction); | 15 | void I2C_start(I2C_TypeDef* I2Cx, uint8_t address, uint8_t direction); |
14 | void I2C_stop(I2C_TypeDef* I2Cx); | 16 | void I2C_stop(I2C_TypeDef* I2Cx); |
Project/applications/smartcities/include/json.h
@@ -18,6 +18,8 @@ | @@ -18,6 +18,8 @@ | ||
18 | #define JOIN_NO_FREE 0 | 18 | #define JOIN_NO_FREE 0 |
19 | #define JOIN_FREE_MEM 1 | 19 | #define JOIN_FREE_MEM 1 |
20 | 20 | ||
21 | +#define DBG_JSON(fmt,...) printf("%c[1;31mjson.c:%c[1;00m "fmt,0x1B,0x1B, ##__VA_ARGS__) | ||
22 | + | ||
21 | uint8_t register_sensor(sensor sens); | 23 | uint8_t register_sensor(sensor sens); |
22 | char* prepare_json_observation_statement(char** data, uint32_t nObservations); | 24 | char* prepare_json_observation_statement(char** data, uint32_t nObservations); |
23 | char* prepare_json_register_statement(module mod, sensor sens, char *additional_info); | 25 | char* prepare_json_register_statement(module mod, sensor sens, char *additional_info); |
Project/applications/smartcities/include/ntp.h
@@ -16,51 +16,17 @@ | @@ -16,51 +16,17 @@ | ||
16 | #include "lwip/sys.h" | 16 | #include "lwip/sys.h" |
17 | #include "lwip/api.h" | 17 | #include "lwip/api.h" |
18 | #include "ch.h" | 18 | #include "ch.h" |
19 | +#include "globals.h" | ||
19 | 20 | ||
20 | -typedef struct { | ||
21 | - int second; | ||
22 | - int minute; | ||
23 | - int hour; | ||
24 | - int day; | ||
25 | - int month; | ||
26 | - int year; | ||
27 | -}Date; | ||
28 | - | ||
29 | -char* timestamp_data(char* value,Date time); | ||
30 | -unsigned long getSecsSince1900(void); | ||
31 | -Date getDate(unsigned long); | ||
32 | -void udpNtp_test(void); | 21 | +#define DBG_NTP(fmt,...) printf("%c[1;31mntp.c:%c[1;00m "fmt,0x1B,0x1B, ##__VA_ARGS__) |
33 | 22 | ||
34 | #define LEAP_YEAR(Y) (((1970+Y)>0) && !((1970+Y)%4) && (((1970+Y)%100) || !((1970+Y)%400))) | 23 | #define LEAP_YEAR(Y) (((1970+Y)>0) && !((1970+Y)%4) && (((1970+Y)%100) || !((1970+Y)%400))) |
35 | - | ||
36 | #define NTP_PACKET_LENGTH 48 | 24 | #define NTP_PACKET_LENGTH 48 |
37 | - | ||
38 | -//cabecera de netconn api | ||
39 | -#ifndef SNTP_PORT | ||
40 | #define SNTP_PORT 123 | 25 | #define SNTP_PORT 123 |
41 | -#endif | ||
42 | - | ||
43 | -/** SNTP server address as IPv4 address in "u32_t" format */ | ||
44 | -#ifndef SNTP_SERVER_ADDRESS | ||
45 | -#define SNTP_SERVER_ADDRESS ipaddr_addr("81.184.154.182") /* your ntp server */ | ||
46 | -#endif | ||
47 | - | ||
48 | /** SNTP receive timeout - in milliseconds */ | 26 | /** SNTP receive timeout - in milliseconds */ |
49 | -#ifndef SNTP_RECV_TIMEOUT | ||
50 | #define SNTP_RECV_TIMEOUT 3000 | 27 | #define SNTP_RECV_TIMEOUT 3000 |
51 | -#endif | ||
52 | - | ||
53 | /** SNTP update delay - in milliseconds */ | 28 | /** SNTP update delay - in milliseconds */ |
54 | -#ifndef SNTP_UPDATE_DELAY | ||
55 | #define SNTP_UPDATE_DELAY 60000 | 29 | #define SNTP_UPDATE_DELAY 60000 |
56 | -#endif | ||
57 | - | ||
58 | -/** SNTP macro to change system time and/or the update the RTC clock */ | ||
59 | -#ifndef SNTP_SYSTEM_TIME | ||
60 | -#define SNTP_SYSTEM_TIME(t) | ||
61 | -#endif | ||
62 | - | ||
63 | -/* SNTP protocol defines */ | ||
64 | #define SNTP_MAX_DATA_LEN 48 | 30 | #define SNTP_MAX_DATA_LEN 48 |
65 | #define SNTP_RCV_TIME_OFS 32 | 31 | #define SNTP_RCV_TIME_OFS 32 |
66 | #define SNTP_LI_NO_WARNING 0x00 | 32 | #define SNTP_LI_NO_WARNING 0x00 |
@@ -69,12 +35,24 @@ void udpNtp_test(void); | @@ -69,12 +35,24 @@ void udpNtp_test(void); | ||
69 | #define SNTP_MODE_SERVER 0x04 | 35 | #define SNTP_MODE_SERVER 0x04 |
70 | #define SNTP_MODE_BROADCAST 0x05 | 36 | #define SNTP_MODE_BROADCAST 0x05 |
71 | #define SNTP_MODE_MASK 0x07 | 37 | #define SNTP_MODE_MASK 0x07 |
72 | - | ||
73 | /* number of seconds between 1900 and 1970 */ | 38 | /* number of seconds between 1900 and 1970 */ |
74 | #define DIFF_SEC_1900_1970 (2208988800LL) | 39 | #define DIFF_SEC_1900_1970 (2208988800LL) |
75 | - | ||
76 | /*timezone from GMT*/ | 40 | /*timezone from GMT*/ |
77 | #define TIME_ZONE 2 | 41 | #define TIME_ZONE 2 |
78 | 42 | ||
43 | +typedef struct { | ||
44 | + int second; | ||
45 | + int minute; | ||
46 | + int hour; | ||
47 | + int day; | ||
48 | + int month; | ||
49 | + int year; | ||
50 | +}Date; | ||
51 | + | ||
52 | +char* timestamp_data(char* value,Date time); | ||
53 | +unsigned long getSecsSince1900(void); | ||
54 | +Date getDate(unsigned long); | ||
55 | +void udpNtp_test(void); | ||
56 | + | ||
79 | 57 | ||
80 | #endif | 58 | #endif |
Project/applications/smartcities/include/sensors.h
@@ -19,6 +19,8 @@ | @@ -19,6 +19,8 @@ | ||
19 | 19 | ||
20 | #define BATTERY_ADDR 0x00 //SIEMPRE PRESENTE, NUNCA BUSCAR EN i2c_scan | 20 | #define BATTERY_ADDR 0x00 //SIEMPRE PRESENTE, NUNCA BUSCAR EN i2c_scan |
21 | 21 | ||
22 | +#define DBG_SENSORS(fmt,...) printf("%c[1;31msensors.c:%c[1;00m "fmt,0x1B,0x1B, ##__VA_ARGS__) | ||
23 | + | ||
22 | typedef struct { | 24 | typedef struct { |
23 | uint8_t ID; | 25 | uint8_t ID; |
24 | char* description; | 26 | char* description; |
Project/applications/smartcities/include/timer-loop.h
@@ -11,6 +11,8 @@ | @@ -11,6 +11,8 @@ | ||
11 | #define LONG_PERIOD 60*3 //60*3 // for testing | 11 | #define LONG_PERIOD 60*3 //60*3 // for testing |
12 | #define SHORT_PERIOD 60*1 //60*1 // for testing | 12 | #define SHORT_PERIOD 60*1 //60*1 // for testing |
13 | 13 | ||
14 | +#define DBG_TIMER(fmt,...) printf("%c[1;31mtimer-loop.c:%c[1;00m "fmt,0x1B,0x1B, ##__VA_ARGS__) | ||
15 | + | ||
14 | unsigned long getSystemTime(void); | 16 | unsigned long getSystemTime(void); |
15 | 17 | ||
16 | unsigned long getElapsedTime(unsigned long t); | 18 | unsigned long getElapsedTime(unsigned long t); |
Project/applications/smartcities/json.c
@@ -2,14 +2,14 @@ | @@ -2,14 +2,14 @@ | ||
2 | 2 | ||
3 | uint8_t register_sensor(sensor sens) | 3 | uint8_t register_sensor(sensor sens) |
4 | { | 4 | { |
5 | - printf("Registering sensor: %s\r\n",sens.description); | 5 | + DBG_JSON("Registering sensor: %s\r\n",sens.description); |
6 | uint8_t result; | 6 | uint8_t result; |
7 | char *statement; | 7 | char *statement; |
8 | if(sens.ID == PRESSURE_ADDR) | 8 | if(sens.ID == PRESSURE_ADDR) |
9 | { | 9 | { |
10 | - printf("Putting additional info for pressure sensor...\r\n"); | 10 | + DBG_JSON("Putting additional info for pressure sensor...\r\n"); |
11 | char *callibration_data = callibration_pressure_data_csv(get_pressure_callibration_data()); | 11 | char *callibration_data = callibration_pressure_data_csv(get_pressure_callibration_data()); |
12 | - printf("callibration_data is: %s\r\n",callibration_data); | 12 | + DBG_JSON("callibration_data is: %s\r\n",callibration_data); |
13 | statement = prepare_json_register_statement(mod,sens,callibration_data); | 13 | statement = prepare_json_register_statement(mod,sens,callibration_data); |
14 | chHeapFree(callibration_data); | 14 | chHeapFree(callibration_data); |
15 | } | 15 | } |
@@ -36,7 +36,6 @@ char* prepare_json_observation_statement(char** data, uint32_t nObservations) | @@ -36,7 +36,6 @@ char* prepare_json_observation_statement(char** data, uint32_t nObservations) | ||
36 | observation_length = strlen(str_aux2); | 36 | observation_length = strlen(str_aux2); |
37 | str_aux = join_strings(str_aux,str_aux2,length,observation_length,JOIN_FREE_MEM); | 37 | str_aux = join_strings(str_aux,str_aux2,length,observation_length,JOIN_FREE_MEM); |
38 | length += observation_length; | 38 | length += observation_length; |
39 | - printf("data=%s %d \r\n",data[i],i); | ||
40 | } | 39 | } |
41 | length--; //REMOVE LAST ',' | 40 | length--; //REMOVE LAST ',' |
42 | json_statement = join_strings(str_aux,"]}\0",length,3,JOIN_NO_FREE); | 41 | json_statement = join_strings(str_aux,"]}\0",length,3,JOIN_NO_FREE); |
@@ -80,7 +79,7 @@ char* prepare_json_register_statement(module mod, sensor sens, char *additional_ | @@ -80,7 +79,7 @@ char* prepare_json_register_statement(module mod, sensor sens, char *additional_ | ||
80 | length += strlen(mod.geoloc); | 79 | length += strlen(mod.geoloc); |
81 | if(additional_info != NULL) | 80 | if(additional_info != NULL) |
82 | { | 81 | { |
83 | - printf("In prepare_json_register_statement: Detected additional_info\r\n"); | 82 | + DBG_JSON("In prepare_json_register_statement: Detected additional_info\r\n"); |
84 | str_aux2 = join_strings(str_aux,"\",\"additionalInfo\":\"",length,20,JOIN_NO_FREE); | 83 | str_aux2 = join_strings(str_aux,"\",\"additionalInfo\":\"",length,20,JOIN_NO_FREE); |
85 | chHeapFree(str_aux); | 84 | chHeapFree(str_aux); |
86 | length += 20; | 85 | length += 20; |
@@ -99,14 +98,12 @@ char* prepare_observation(char* observation, uint32_t length) | @@ -99,14 +98,12 @@ char* prepare_observation(char* observation, uint32_t length) | ||
99 | int value_length = find_next_index(observation,length,','); | 98 | int value_length = find_next_index(observation,length,','); |
100 | while(1) | 99 | while(1) |
101 | { | 100 | { |
102 | - printf("value_length = %d\r\n",value_length); | ||
103 | if(find_next_index(observation+value_length+1,length,',')) | 101 | if(find_next_index(observation+value_length+1,length,',')) |
104 | { | 102 | { |
105 | value_length += find_next_index(observation+value_length+1,length,',')+1; | 103 | value_length += find_next_index(observation+value_length+1,length,',')+1; |
106 | } | 104 | } |
107 | else | 105 | else |
108 | { | 106 | { |
109 | - printf("Comma in %d\r\n",value_length); | ||
110 | break; | 107 | break; |
111 | } | 108 | } |
112 | } | 109 | } |
@@ -140,29 +137,40 @@ uint8_t send_json(char* statement, uint32_t length, char* provider_ID, char* sen | @@ -140,29 +137,40 @@ uint8_t send_json(char* statement, uint32_t length, char* provider_ID, char* sen | ||
140 | { | 137 | { |
141 | URL = (char*) chHeapAlloc(NULL,1+strlen(SERVER_HOSTNAME)); | 138 | URL = (char*) chHeapAlloc(NULL,1+strlen(SERVER_HOSTNAME)); |
142 | strcpy(URL,SERVER_HOSTNAME); | 139 | strcpy(URL,SERVER_HOSTNAME); |
140 | + #ifdef SERVER_VANILLA | ||
143 | //VANILLA SERVER (SENTILO) | 141 | //VANILLA SERVER (SENTILO) |
144 | - /*PATH = (char*) chHeapAlloc(NULL,19); | ||
145 | - strcpy(PATH,"/catalog/register");*/ | 142 | + DBG_JSON("Server is vanilla\r\n") |
143 | + PATH = (char*) chHeapAlloc(NULL,19); | ||
144 | + strcpy(PATH,"/catalog/register"); | ||
145 | + #endif | ||
146 | + #ifdef SERVER_LEWIS | ||
146 | //FUCKING LEWIS... | 147 | //FUCKING LEWIS... |
148 | + DBG_JSON("Server is lewis.upc.es\r\n"); | ||
147 | PATH = (char*) chHeapAlloc(NULL,50); | 149 | PATH = (char*) chHeapAlloc(NULL,50); |
148 | strcpy(PATH,"/modularsense/wordpress/opendata/catalog/register"); | 150 | strcpy(PATH,"/modularsense/wordpress/opendata/catalog/register"); |
151 | + #endif | ||
149 | } | 152 | } |
150 | else //Post data | 153 | else //Post data |
151 | { | 154 | { |
152 | URL = (char*) chHeapAlloc(NULL,1+strlen(SERVER_HOSTNAME)); | 155 | URL = (char*) chHeapAlloc(NULL,1+strlen(SERVER_HOSTNAME)); |
153 | strcpy(URL,SERVER_HOSTNAME); | 156 | strcpy(URL,SERVER_HOSTNAME); |
154 | URL[strlen(SERVER_HOSTNAME)] = '\0'; | 157 | URL[strlen(SERVER_HOSTNAME)] = '\0'; |
158 | + #ifdef SERVER_VANILLA | ||
155 | //VANILLA SERVER (SENTILO) | 159 | //VANILLA SERVER (SENTILO) |
156 | - /*PATH = (char*) chHeapAlloc(NULL,22+strlen(provider_ID)+strlen(sensor_ID)); | 160 | + DBG_JSON("Server is vanilla\r\n") |
161 | + PATH = (char*) chHeapAlloc(NULL,22+strlen(provider_ID)+strlen(sensor_ID)); | ||
157 | strcpy(PATH,"/data/modularupload/"); | 162 | strcpy(PATH,"/data/modularupload/"); |
158 | strcpy(PATH+20,provider_ID); | 163 | strcpy(PATH+20,provider_ID); |
159 | - strcpy(PATH+20+strlen(provider_ID),sensor_ID);*/ | ||
160 | - | 164 | + strcpy(PATH+20+strlen(provider_ID),sensor_ID); |
165 | + #endif | ||
166 | + #ifdef SERVER_LEWIS | ||
161 | //FUCKING LEWIS... | 167 | //FUCKING LEWIS... |
168 | + DBG_JSON("Server is lewis.upc.es\r\n"); | ||
162 | PATH = (char*) chHeapAlloc(NULL,54+strlen(provider_ID)+strlen(sensor_ID)); | 169 | PATH = (char*) chHeapAlloc(NULL,54+strlen(provider_ID)+strlen(sensor_ID)); |
163 | strcpy(PATH,"/modularsense/wordpress/opendata/data/modularupload/"); | 170 | strcpy(PATH,"/modularsense/wordpress/opendata/data/modularupload/"); |
164 | strcpy(PATH+52,provider_ID); | 171 | strcpy(PATH+52,provider_ID); |
165 | strcpy(PATH+52+strlen(provider_ID),sensor_ID); | 172 | strcpy(PATH+52+strlen(provider_ID),sensor_ID); |
173 | + #endif | ||
166 | } | 174 | } |
167 | struct httpHeaders server = { put,PATH,strlen(PATH),URL,strlen(URL)}; | 175 | struct httpHeaders server = { put,PATH,strlen(PATH),URL,strlen(URL)}; |
168 | response_code = httpRequest(server, statement, length); | 176 | response_code = httpRequest(server, statement, length); |
@@ -170,14 +178,17 @@ uint8_t send_json(char* statement, uint32_t length, char* provider_ID, char* sen | @@ -170,14 +178,17 @@ uint8_t send_json(char* statement, uint32_t length, char* provider_ID, char* sen | ||
170 | chHeapFree(URL); | 178 | chHeapFree(URL); |
171 | if(response_code == 200) | 179 | if(response_code == 200) |
172 | { | 180 | { |
181 | + DBG_JSON("Success: JSON_POST_OK\r\n"); | ||
173 | return JSON_POST_OK; | 182 | return JSON_POST_OK; |
174 | } | 183 | } |
175 | else if((response_code >= 400) && (response_code < 500)) | 184 | else if((response_code >= 400) && (response_code < 500)) |
176 | { | 185 | { |
186 | + DBG_JSON("[ERROR] Communication with server FAILED: JSON_COMM_ERROR\r\n"); | ||
177 | return JSON_COMM_ERROR; | 187 | return JSON_COMM_ERROR; |
178 | } | 188 | } |
179 | else | 189 | else |
180 | { | 190 | { |
191 | + DBG_JSON("[ERROR] Unspecified error: JSON_ERROR_OTHER\r\n"); | ||
181 | return JSON_OTHER_ERROR; | 192 | return JSON_OTHER_ERROR; |
182 | } | 193 | } |
183 | } | 194 | } |
@@ -207,4 +218,4 @@ char* join_strings(char* str1, char* str2, uint32_t len1, uint32_t len2, uint8_t | @@ -207,4 +218,4 @@ char* join_strings(char* str1, char* str2, uint32_t len1, uint32_t len2, uint8_t | ||
207 | chHeapFree(str2); | 218 | chHeapFree(str2); |
208 | } | 219 | } |
209 | return str; | 220 | return str; |
210 | -} | 221 | -} |
222 | +} | ||
211 | \ No newline at end of file | 223 | \ No newline at end of file |
Project/applications/smartcities/main.c
@@ -12,6 +12,8 @@ | @@ -12,6 +12,8 @@ | ||
12 | #include "ntp.h" | 12 | #include "ntp.h" |
13 | #include "sensors.h" | 13 | #include "sensors.h" |
14 | 14 | ||
15 | +#define DBG(fmt,...) printf("%c[1;31mmain.c:%c[1;00m "fmt,0x1B,0x1B, ##__VA_ARGS__) | ||
16 | + | ||
15 | uint8_t connected=0; | 17 | uint8_t connected=0; |
16 | uint8_t timeout=0; | 18 | uint8_t timeout=0; |
17 | uint8_t retries=0; | 19 | uint8_t retries=0; |
@@ -29,13 +31,13 @@ void initLibwismart(void) | @@ -29,13 +31,13 @@ void initLibwismart(void) | ||
29 | 31 | ||
30 | void update_time(unsigned long *time) | 32 | void update_time(unsigned long *time) |
31 | { | 33 | { |
32 | - printf("Requesting new NTP time...\r\n"); | 34 | + DBG("Requesting new NTP time...\r\n"); |
33 | unsigned long new_time = getSecsSince1900(); | 35 | unsigned long new_time = getSecsSince1900(); |
34 | if(new_time) | 36 | if(new_time) |
35 | { | 37 | { |
36 | *time = getSecsSince1900(); | 38 | *time = getSecsSince1900(); |
37 | } | 39 | } |
38 | - printf("Time updated...\r\n"); | 40 | + DBG("Time updated\r\n"); |
39 | } | 41 | } |
40 | 42 | ||
41 | void init_registry(void) | 43 | void init_registry(void) |
@@ -54,31 +56,31 @@ void init_registry(void) | @@ -54,31 +56,31 @@ void init_registry(void) | ||
54 | libwismart_RegistryGet(&geo,&config); | 56 | libwismart_RegistryGet(&geo,&config); |
55 | } | 57 | } |
56 | 58 | ||
57 | - printf("SSID = %s\r\n",config.ssid); | ||
58 | - printf("Wep key = %s\r\n",config.wepkey); | ||
59 | - printf("Passphrase = %s\r\n", config.passphrase); | ||
60 | - printf("User = %s\r\n",config.user); | ||
61 | - printf("Password = %s\r\n",config.password); | ||
62 | - printf("Encryption type = %d\r\n",config.security); | ||
63 | - printf("Geo Localization = %s\r\n", config.localization); | 59 | + DBG("SSID = %s\r\n",config.ssid); |
60 | + DBG("Wep key = %s\r\n",config.wepkey); | ||
61 | + DBG("Passphrase = %s\r\n", config.passphrase); | ||
62 | + DBG("User = %s\r\n",config.user); | ||
63 | + DBG("Password = %s\r\n",config.password); | ||
64 | + DBG("Encryption type = %d\r\n",config.security); | ||
65 | + DBG("Geo Localization = %s\r\n", config.localization); | ||
64 | 66 | ||
65 | strcpy(mod.geoloc,config.localization); | 67 | strcpy(mod.geoloc,config.localization); |
66 | strcpy(mod.ID,MODULE_ID); | 68 | strcpy(mod.ID,MODULE_ID); |
67 | if(config.security == PROFILE_SECURITY_OPEN) | 69 | if(config.security == PROFILE_SECURITY_OPEN) |
68 | { | 70 | { |
69 | - printf("open detected\r\n"); | 71 | + DBG("Open network detected\r\n"); |
70 | libwismart_WiFiConnect(config.ssid,NULL,wifi_connect_result_cb); | 72 | libwismart_WiFiConnect(config.ssid,NULL,wifi_connect_result_cb); |
71 | } | 73 | } |
72 | else if(config.security == PROFILE_SECURITY_WPA_WPA2) | 74 | else if(config.security == PROFILE_SECURITY_WPA_WPA2) |
73 | { | 75 | { |
74 | if(!strcmp(config.user,"")) | 76 | if(!strcmp(config.user,"")) |
75 | { | 77 | { |
76 | - printf("wpa detected\r\n"); | 78 | + DBG("WPA network detected\r\n"); |
77 | libwismart_WiFiConnect(config.ssid,config.passphrase,wifi_connect_result_cb); | 79 | libwismart_WiFiConnect(config.ssid,config.passphrase,wifi_connect_result_cb); |
78 | } | 80 | } |
79 | else | 81 | else |
80 | { | 82 | { |
81 | - printf("wpa Enterprise detected\r\n"); | 83 | + DBG("WPA Enterprise network detected\r\n"); |
82 | struct wpa_param wpa; | 84 | struct wpa_param wpa; |
83 | wpa.eap_method = WISMART_EAP_METHOD_TTLS; | 85 | wpa.eap_method = WISMART_EAP_METHOD_TTLS; |
84 | wpa.u.ttls.identity = config.user; | 86 | wpa.u.ttls.identity = config.user; |
@@ -89,7 +91,7 @@ void init_registry(void) | @@ -89,7 +91,7 @@ void init_registry(void) | ||
89 | } | 91 | } |
90 | else | 92 | else |
91 | { | 93 | { |
92 | - printf("wep detected\r\n"); | 94 | + DBG("WEP network detected\r\n"); |
93 | //Is WEP | 95 | //Is WEP |
94 | libwismart_WiFiConnect(config.ssid,config.wepkey,wifi_connect_result_cb); | 96 | libwismart_WiFiConnect(config.ssid,config.wepkey,wifi_connect_result_cb); |
95 | libwismart_WiFiSetWep(config.wepkey,1); | 97 | libwismart_WiFiSetWep(config.wepkey,1); |
@@ -104,67 +106,52 @@ void send_data(char** buffers[], uint32_t ind[], uint32_t sizes[], uint8_t senso | @@ -104,67 +106,52 @@ void send_data(char** buffers[], uint32_t ind[], uint32_t sizes[], uint8_t senso | ||
104 | int j; | 106 | int j; |
105 | for(j=0;j<sensors_length;j++) | 107 | for(j=0;j<sensors_length;j++) |
106 | { | 108 | { |
107 | - printf(" enviant buffer %d\r\n",j); | 109 | + DBG("Sending buffer %d\r\n",j); |
108 | char id[3]; | 110 | char id[3]; |
109 | sprintf(id,"%x",sensors[j]); | 111 | sprintf(id,"%x",sensors[j]); |
110 | - int ok=send(buffers[j],&ind[j],&sizes[j], mod.ID, id); | ||
111 | - | ||
112 | - if(ok==JSON_COMM_ERROR) | ||
113 | - { | ||
114 | - printf("wismart is not connected\r\n"); | ||
115 | - } | ||
116 | - else if( ok==JSON_OTHER_ERROR) | ||
117 | - { | ||
118 | - printf("some error ocurred\r\n"); | ||
119 | - } | ||
120 | - else if(ok ==JSON_POST_OK) | ||
121 | - { | ||
122 | - printf(" send OK \r\n"); | ||
123 | - } | 112 | + send(buffers[j],&ind[j],&sizes[j], mod.ID, id); |
124 | } | 113 | } |
125 | } | 114 | } |
126 | 115 | ||
127 | void put_buffers(char** buffers[],uint32_t ind[],uint32_t sizes[],char** cooked, uint8_t* sensors) | 116 | void put_buffers(char** buffers[],uint32_t ind[],uint32_t sizes[],char** cooked, uint8_t* sensors) |
128 | { | 117 | { |
118 | + DBG("Putting data in buffers...\r\n"); | ||
129 | int i; | 119 | int i; |
130 | for(i=0;i<sensors_length;i++) | 120 | for(i=0;i<sensors_length;i++) |
131 | { | 121 | { |
132 | - printf("For %d and %d\n\r", ind[i],sizes[i]); | ||
133 | - printf("Putting data: %s\n\r",cooked[i]); | 122 | + DBG("Putting data: %s\n\r",cooked[i]); |
134 | buffers[i] = put_message(cooked[i], buffers[i] ,&ind[i],&sizes[i]); | 123 | buffers[i] = put_message(cooked[i], buffers[i] ,&ind[i],&sizes[i]); |
135 | - printf("Message put: %s\r\n",buffers[i][ind[i]-1]); | 124 | + DBG("Message put: %s\r\n",buffers[i][ind[i]-1]); |
136 | chHeapFree(cooked[i]); | 125 | chHeapFree(cooked[i]); |
137 | - printf("Memory freed\n\r"); | ||
138 | - printf("Message put (assertion): %s with length %d\r\n",buffers[i][ind[i]-1] ,strlen(buffers[i][ind[i]-1])); | 126 | + DBG("Memory freed\n\r"); |
127 | + DBG("[ASSERTION] Message put: %s with length %d\r\n",buffers[i][ind[i]-1] ,strlen(buffers[i][ind[i]-1])); | ||
139 | } | 128 | } |
140 | - | ||
141 | } | 129 | } |
142 | char** timestamp_datas(char* value[],unsigned long timestamp, uint8_t* sensors) | 130 | char** timestamp_datas(char* value[],unsigned long timestamp, uint8_t* sensors) |
143 | { | 131 | { |
132 | + DBG("Timestamping data...\r\n"); | ||
144 | char** cooked_data; | 133 | char** cooked_data; |
145 | cooked_data = (char**) chHeapAlloc(NULL,sensors_length * sizeof(char*)); | 134 | cooked_data = (char**) chHeapAlloc(NULL,sensors_length * sizeof(char*)); |
146 | - printf("Data allocated...\r\n"); | ||
147 | Date t=getDate(timestamp); | 135 | Date t=getDate(timestamp); |
148 | int i; | 136 | int i; |
149 | for(i=0;i<sensors_length;i++) | 137 | for(i=0;i<sensors_length;i++) |
150 | { | 138 | { |
151 | - printf("Calling timestamp_data...\r\n"); | ||
152 | cooked_data[i]=timestamp_data(value[i], t); | 139 | cooked_data[i]=timestamp_data(value[i], t); |
153 | - printf("Finished timestamp_data...\r\n"); | ||
154 | - printf("Data is: %s\r\n",cooked_data[i]); | 140 | + DBG("Data is: %s\r\n",cooked_data[i]); |
155 | chHeapFree(value[i]); | 141 | chHeapFree(value[i]); |
156 | value[i] = NULL; | 142 | value[i] = NULL; |
157 | } | 143 | } |
158 | - printf("Returning timestamped data...\r\n"); | 144 | + DBG("Returning timestamped data...\r\n"); |
159 | return cooked_data; | 145 | return cooked_data; |
160 | } | 146 | } |
161 | 147 | ||
162 | void wifi_connect(void) | 148 | void wifi_connect(void) |
163 | { | 149 | { |
150 | + DBG("Connecting wifi...\r\n"); | ||
164 | init_registry(); | 151 | init_registry(); |
165 | if(timeout==1) | 152 | if(timeout==1) |
166 | { | 153 | { |
167 | - printf("Creating AP\r\n"); | 154 | + DBG("Creating AP\r\n"); |
168 | configServer_start(1); | 155 | configServer_start(1); |
169 | libwismart_WiFi_SoftAP_Start(NETWORK_SSID_AP,NETWORK_CHANNEL_AP,NULL,softapMode_apStartedCb, softapMode_clientIndicationCb); | 156 | libwismart_WiFi_SoftAP_Start(NETWORK_SSID_AP,NETWORK_CHANNEL_AP,NULL,softapMode_apStartedCb, softapMode_clientIndicationCb); |
170 | for(;;) | 157 | for(;;) |
@@ -176,7 +163,7 @@ void wifi_connect(void) | @@ -176,7 +163,7 @@ void wifi_connect(void) | ||
176 | 163 | ||
177 | void send_battery_level(unsigned long timestamp) | 164 | void send_battery_level(unsigned long timestamp) |
178 | { | 165 | { |
179 | - uint8_t result; | 166 | + DBG("Polling battery level...\r\n"); |
180 | char *batt_level = battery_value(get_battery_data()); | 167 | char *batt_level = battery_value(get_battery_data()); |
181 | //char *batt_level = battery_value(3300); | 168 | //char *batt_level = battery_value(3300); |
182 | char *batt_data = timestamp_data(batt_level,getDate(timestamp)); | 169 | char *batt_data = timestamp_data(batt_level,getDate(timestamp)); |
@@ -185,30 +172,20 @@ void send_battery_level(unsigned long timestamp) | @@ -185,30 +172,20 @@ void send_battery_level(unsigned long timestamp) | ||
185 | chHeapFree(batt_data); | 172 | chHeapFree(batt_data); |
186 | char id[3]; | 173 | char id[3]; |
187 | sprintf(id,"%02x",battery.ID); | 174 | sprintf(id,"%02x",battery.ID); |
188 | - result = send_json(statement,strlen(statement),mod.ID,id); | ||
189 | - if(result) | ||
190 | - { | ||
191 | - if(result != 200) | ||
192 | - { | ||
193 | - printf("ERROR: SERVER RETURNED %d\r\n",result); | ||
194 | - } | ||
195 | - } | ||
196 | - else | ||
197 | - { | ||
198 | - printf("ERROR: CONNECTION FAILED\r\n"); | ||
199 | - } | 175 | + send_json(statement,strlen(statement),mod.ID,id); |
200 | chHeapFree(statement); | 176 | chHeapFree(statement); |
201 | } | 177 | } |
202 | 178 | ||
203 | void wifi_disconnect(void) | 179 | void wifi_disconnect(void) |
204 | { | 180 | { |
181 | + DBG("Disconnecting wifi...\r\n"); | ||
205 | connected = 0; | 182 | connected = 0; |
206 | timeout = 0; | 183 | timeout = 0; |
207 | uint8_t res=libwismart_WiFiDisconnect(); | 184 | uint8_t res=libwismart_WiFiDisconnect(); |
208 | if(res) | 185 | if(res) |
209 | - printf("WIFI_DISCONNECT_SUCCESS\r\n"); | 186 | + DBG("Disconnecting Successful: WIFI_DISCONNECT_SUCCESS\r\n"); |
210 | else | 187 | else |
211 | - printf("WIFI_DISCONNECT_FAILURE\r\n"); | 188 | + DBG("Disconnecting Failed: WIFI_DISCONNECT_FAILURE\r\n"); |
212 | } | 189 | } |
213 | 190 | ||
214 | int main(void) | 191 | int main(void) |
@@ -220,88 +197,80 @@ int main(void) | @@ -220,88 +197,80 @@ int main(void) | ||
220 | libwismart_WiFiInit(); | 197 | libwismart_WiFiInit(); |
221 | libwismart_SetScanRunsForConnTimeout(4); //Edit a 4 | 198 | libwismart_SetScanRunsForConnTimeout(4); //Edit a 4 |
222 | libwismart_EnableBsdSocketAPI(); | 199 | libwismart_EnableBsdSocketAPI(); |
223 | - | ||
224 | - int i; | ||
225 | 200 | ||
201 | + int i; | ||
202 | + int j; | ||
226 | uint8_t sensors[TOTAL_SENSORS]; | 203 | uint8_t sensors[TOTAL_SENSORS]; |
227 | - memset (sensors, 0, TOTAL_SENSORS); | ||
228 | - | ||
229 | char* valueSensors[TOTAL_SENSORS]; | 204 | char* valueSensors[TOTAL_SENSORS]; |
205 | + unsigned long time; | ||
206 | + unsigned long timestamp; | ||
207 | + unsigned long delay; | ||
208 | + uint32_t ind[TOTAL_SENSORS]={0}; | ||
209 | + char** buffers[TOTAL_SENSORS]; | ||
210 | + uint32_t sizes[TOTAL_SENSORS]={0}; | ||
211 | + char** values; | ||
212 | + int res; | ||
213 | + char id[3]; | ||
230 | 214 | ||
215 | + memset (sensors, 0, TOTAL_SENSORS); | ||
231 | for(i = 0; i < TOTAL_SENSORS; i++) | 216 | for(i = 0; i < TOTAL_SENSORS; i++) |
232 | { | 217 | { |
233 | valueSensors[i] = NULL; | 218 | valueSensors[i] = NULL; |
234 | } | 219 | } |
235 | 220 | ||
236 | - printf("Connecting to wifi...\r\n"); | 221 | + DBG("%c[1;35m--------------WI-SENSE STARTED-------------%c[1;00m\r\n",0x1B,0x1B); |
222 | + | ||
237 | wifi_connect(); | 223 | wifi_connect(); |
224 | + check_memory(); | ||
238 | 225 | ||
239 | wakeup_sensors(0xFF); | 226 | wakeup_sensors(0xFF); |
240 | - printf("Scanning sensors...\r\n"); | 227 | + |
241 | //Escanea y registra | 228 | //Escanea y registra |
242 | I2C_scan(I2C1,sensors); | 229 | I2C_scan(I2C1,sensors); |
243 | sensors_length=strlen((char*)sensors); | 230 | sensors_length=strlen((char*)sensors); |
244 | - printf("%d sensor detected...\r\n",sensors_length); | 231 | + DBG("%d sensor detected...\r\n",sensors_length); |
245 | 232 | ||
246 | - unsigned long time; | ||
247 | update_time(&time); | 233 | update_time(&time); |
248 | //desconectarwifi | 234 | //desconectarwifi |
249 | - printf("Disconecting wifi...\r\n"); | ||
250 | wifi_disconnect(); | 235 | wifi_disconnect(); |
251 | 236 | ||
252 | - unsigned long timestamp = 0; | ||
253 | - unsigned long delay = getSystemTime(); | 237 | + timestamp = 0; |
238 | + delay = getSystemTime(); | ||
254 | sleep_thread(SHORT_PERIOD - time%SHORT_PERIOD); | 239 | sleep_thread(SHORT_PERIOD - time%SHORT_PERIOD); |
255 | 240 | ||
256 | - uint32_t ind[TOTAL_SENSORS]={0}; | ||
257 | - char** buffers[TOTAL_SENSORS]; | ||
258 | - uint32_t sizes[TOTAL_SENSORS]={0}; | ||
259 | - | ||
260 | i = 1; | 241 | i = 1; |
261 | 242 | ||
262 | while(1) | 243 | while(1) |
263 | { | 244 | { |
264 | time += getElapsedTime(delay); | 245 | time += getElapsedTime(delay); |
265 | - printf("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); | ||
266 | - | 246 | + DBG("Time (absolute):\t%ul\r\nTime LONG_PERIOD:\t%ul\r\nTime SHORT_PERIOD:\t%ul\r\n",time,time%LONG_PERIOD,time%SHORT_PERIOD); |
267 | delay = getSystemTime(); | 247 | delay = getSystemTime(); |
268 | /* Collect data from sensors */ | 248 | /* Collect data from sensors */ |
269 | - printf("Collecting data...\r\n"); | ||
270 | collectData(valueSensors, sensors); | 249 | collectData(valueSensors, sensors); |
271 | - printf("Data collected...\r\n"); | ||
272 | time += getElapsedTime(delay); | 250 | time += getElapsedTime(delay); |
273 | - printf("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); | 251 | + DBG("Time (absolute):\t%ul\r\nTime LONG_PERIOD:\t%ul\r\nTime SHORT_PERIOD:\t%ul\r\n",time,time%LONG_PERIOD,time%SHORT_PERIOD); |
274 | timestamp = time; | 252 | timestamp = time; |
275 | - printf("timestamp (absolute):\t%ul\r\ntimestamp mod LONG_PERIOD:\t%ul\r\ntimestamp mod SHORT_PERIOD:\t%ul\r\n",timestamp,timestamp%LONG_PERIOD,timestamp%SHORT_PERIOD); | 253 | + DBG("Timestamp (absolute):\t%ul\r\nTimestamp LONG_PERIOD:\t%ul\r\nTimestamp SHORT_PERIOD:\t%ul\r\n",timestamp,timestamp%LONG_PERIOD,timestamp%SHORT_PERIOD); |
276 | delay = getSystemTime(); | 254 | delay = getSystemTime(); |
277 | - printf("Timestamping data...\r\n"); | ||
278 | - char** values=timestamp_datas(valueSensors,timestamp,sensors); | ||
279 | - printf("Putting data in buffer...\r\n"); | 255 | + values=timestamp_datas(valueSensors,timestamp,sensors); |
280 | put_buffers(buffers,ind,sizes,values,sensors); | 256 | put_buffers(buffers,ind,sizes,values,sensors); |
281 | - printf("Data is now in buffer...\n\r"); | 257 | + DBG("Data is now in buffer\n\r"); |
282 | if (i == LONG_PERIOD/SHORT_PERIOD ) | 258 | if (i == LONG_PERIOD/SHORT_PERIOD ) |
283 | { | 259 | { |
284 | - printf("Programmed Send cycle...\r\n"); | ||
285 | - /* Wi-Fi connect */ | ||
286 | - printf("Connecting to wifi...\r\n"); | 260 | + DBG("Programmed send cycle...\r\n"); |
287 | wifi_connect(); | 261 | wifi_connect(); |
288 | - /* Send data to server, empty the buffer */ | ||
289 | send_data(buffers, ind, sizes, sensors); | 262 | send_data(buffers, ind, sizes, sensors); |
290 | - printf("Data sent!\r\n"); | ||
291 | - //Now sending battery level | ||
292 | send_battery_level(timestamp); | 263 | send_battery_level(timestamp); |
293 | update_time(&time); | 264 | update_time(&time); |
294 | delay = getSystemTime(); | 265 | delay = getSystemTime(); |
295 | wifi_disconnect(); | 266 | wifi_disconnect(); |
296 | - 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); | 267 | + DBG("New NTP time (absolute):\t%ul\r\nTime LONG_PERIOD:\t%ul\r\nTime SHORT_PERIOD:\t%ul\r\n",time,time%LONG_PERIOD,time%SHORT_PERIOD); |
297 | i = 0; | 268 | i = 0; |
298 | } | 269 | } |
299 | - | ||
300 | - printf("mirant memoria\r\n"); | ||
301 | - int res=check_memory(); | 270 | + res=check_memory(); |
302 | if(res==SOFT_REACHED) | 271 | if(res==SOFT_REACHED) |
303 | { | 272 | { |
304 | - printf("--------------soft limit-------------\r\n"); | 273 | + DBG("%c[1;35m--------------SOFT LIMIT-------------%c[1;00m\r\n",0x1B,0x1B); |
305 | wifi_connect(); | 274 | wifi_connect(); |
306 | send_data(buffers, ind, sizes, sensors); | 275 | send_data(buffers, ind, sizes, sensors); |
307 | //Now sending battery level | 276 | //Now sending battery level |
@@ -310,7 +279,7 @@ int main(void) | @@ -310,7 +279,7 @@ int main(void) | ||
310 | } | 279 | } |
311 | else if(res==HARD_REACHED) | 280 | else if(res==HARD_REACHED) |
312 | { | 281 | { |
313 | - printf("--------------hard limit-------------\r\n"); | 282 | + DBG("%c[1;35m--------------HARD LIMIT-------------%c[1;00m\r\n",0x1B,0x1B); |
314 | wifi_connect(); | 283 | wifi_connect(); |
315 | char id_0[3]; | 284 | char id_0[3]; |
316 | sprintf(id_0,"%x",sensors[0]); | 285 | sprintf(id_0,"%x",sensors[0]); |
@@ -320,37 +289,23 @@ int main(void) | @@ -320,37 +289,23 @@ int main(void) | ||
320 | // Intentem enviar un buffer sencer, a veure si ja podem buidar. | 289 | // Intentem enviar un buffer sencer, a veure si ja podem buidar. |
321 | // No podem enviar només una mostra perquè json és rígid en aquest sentit. | 290 | // No podem enviar només una mostra perquè json és rígid en aquest sentit. |
322 | 291 | ||
323 | - printf("hard_reached and unable to sentd.\r\nLa biblia en vers: i Jesús digué: Aixeca't, Llàtzer!!\r\n"); | 292 | + DBG("[HARD LIMIT] unable to send\r\n"); |
324 | chThdSleepMilliseconds(HARD_LIMIT_WAIT_TIME); | 293 | chThdSleepMilliseconds(HARD_LIMIT_WAIT_TIME); |
325 | } | 294 | } |
326 | - int j; | ||
327 | for(j=1;j<sensors_length;j++) | 295 | for(j=1;j<sensors_length;j++) |
328 | { | 296 | { |
329 | 297 | ||
330 | - printf(" enviant buffer %d\r\n",j); | ||
331 | - char id[3]; | 298 | + DBG("Sending buffer %d\r\n",j); |
332 | sprintf(id,"%x",sensors[j]); | 299 | sprintf(id,"%x",sensors[j]); |
333 | - int ok=send(buffers[j],&ind[j],&sizes[j], mod.ID, id); | ||
334 | - if(ok==JSON_COMM_ERROR) | ||
335 | - { | ||
336 | - printf("wismart is not connected\r\n"); | ||
337 | - } | ||
338 | - else if( ok==JSON_OTHER_ERROR){ | ||
339 | - printf("some error ocurred\r\n"); | ||
340 | - } | ||
341 | - else if(ok ==JSON_POST_OK){ | ||
342 | - printf(" send OK \r\n"); | ||
343 | - } | 300 | + send(buffers[j],&ind[j],&sizes[j], mod.ID, id); |
344 | } | 301 | } |
345 | //Now sending battery level | 302 | //Now sending battery level |
346 | send_battery_level(timestamp); | 303 | send_battery_level(timestamp); |
347 | wifi_disconnect(); | 304 | wifi_disconnect(); |
348 | } | 305 | } |
349 | time += getElapsedTime(delay); | 306 | time += getElapsedTime(delay); |
350 | - printf("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); | ||
351 | - | 307 | + DBG("Time (absolute):\t%ul\r\nTime LONG_PERIOD:\t%ul\r\nTime SHORT_PERIOD:\t%ul\r\n",time,time%LONG_PERIOD,time%SHORT_PERIOD); |
352 | delay = getSystemTime(); | 308 | delay = getSystemTime(); |
353 | - printf("Time to sleep! for %d seconds\r\n", SHORT_PERIOD - time%SHORT_PERIOD); | ||
354 | sleep_thread(SHORT_PERIOD - time%SHORT_PERIOD); | 309 | sleep_thread(SHORT_PERIOD - time%SHORT_PERIOD); |
355 | i++; | 310 | i++; |
356 | } | 311 | } |
@@ -361,4 +316,4 @@ int main(void) | @@ -361,4 +316,4 @@ int main(void) | ||
361 | * | 316 | * |
362 | * - Test distance | 317 | * - Test distance |
363 | * - Reset timer-related defines | 318 | * - Reset timer-related defines |
364 | - */ | ||
365 | \ No newline at end of file | 319 | \ No newline at end of file |
320 | + */ |
Project/applications/smartcities/ntp.c
@@ -113,38 +113,38 @@ unsigned long getSecsSince1900 (void) | @@ -113,38 +113,38 @@ unsigned long getSecsSince1900 (void) | ||
113 | memcpy(×tamp, (sntp_response + SNTP_RCV_TIME_OFS), sizeof(timestamp)); | 113 | memcpy(×tamp, (sntp_response + SNTP_RCV_TIME_OFS), sizeof(timestamp)); |
114 | timestamp=(ntohl(timestamp)); | 114 | timestamp=(ntohl(timestamp)); |
115 | 115 | ||
116 | - printf("Received timestamp %u\r\n", timestamp); | 116 | + DBG_NTP("Received timestamp %u\r\n", timestamp); |
117 | } | 117 | } |
118 | else | 118 | else |
119 | { | 119 | { |
120 | - printf("Received data did not match frame code\r\n"); | 120 | + DBG_NTP("[ERROR] Received data did not match frame code\r\n"); |
121 | } | 121 | } |
122 | } | 122 | } |
123 | else | 123 | else |
124 | { | 124 | { |
125 | - printf("Length of data did not match SNTP_MAX_DATA_LEN, received len %u\r\n", dataLen); | 125 | + DBG_NTP("[ERROR] Length of data did not match SNTP_MAX_DATA_LEN, received len %u\r\n", dataLen); |
126 | } | 126 | } |
127 | // Deallocate space hold for netbuf structure. | 127 | // Deallocate space hold for netbuf structure. |
128 | netbuf_delete(receiveUDPNetBuf); | 128 | netbuf_delete(receiveUDPNetBuf); |
129 | } | 129 | } |
130 | else | 130 | else |
131 | { | 131 | { |
132 | - printf("Netconn receive failed with %d\r\n", netconn_err(sendUDPNetConn)); | 132 | + DBG_NTP("[ERROR] Netconn receive failed with %d\r\n", netconn_err(sendUDPNetConn)); |
133 | } | 133 | } |
134 | } | 134 | } |
135 | else | 135 | else |
136 | { | 136 | { |
137 | - printf("Netconn sendto failed with %d\r\n", errLWIP); | 137 | + DBG_NTP("[ERROR] Netconn sendto failed with %d\r\n", errLWIP); |
138 | } | 138 | } |
139 | } | 139 | } |
140 | else | 140 | else |
141 | { | 141 | { |
142 | - printf("Netconn connect to server %X, port %u failed with %d\r\n", sntp_server_address.addr, SNTP_PORT, errLWIP); | 142 | + DBG_NTP("[ERROR] Netconn connect to server %X, port %u failed with %d\r\n", sntp_server_address.addr, SNTP_PORT, errLWIP); |
143 | } | 143 | } |
144 | } | 144 | } |
145 | else | 145 | else |
146 | { | 146 | { |
147 | - printf("Netconn or netbuf or data allocation failed.\r\n"); | 147 | + DBG_NTP("[ERROR] Netconn or netbuf or data allocation failed.\r\n"); |
148 | } | 148 | } |
149 | // Deallocate space hold for netconn and netbuf structure. | 149 | // Deallocate space hold for netconn and netbuf structure. |
150 | netbuf_delete(sendUDPNetBuf); | 150 | netbuf_delete(sendUDPNetBuf); |
@@ -152,7 +152,7 @@ unsigned long getSecsSince1900 (void) | @@ -152,7 +152,7 @@ unsigned long getSecsSince1900 (void) | ||
152 | } //if (sntp_server_address != 0) | 152 | } //if (sntp_server_address != 0) |
153 | else | 153 | else |
154 | { | 154 | { |
155 | - printf("Invalid NTP server address %X\r\n", SNTP_SERVER_ADDRESS); | 155 | + DBG_NTP("[ERROR] Invalid NTP server address %X\r\n", SNTP_SERVER_ADDRESS); |
156 | } | 156 | } |
157 | 157 | ||
158 | return (unsigned long) timestamp; | 158 | return (unsigned long) timestamp; |
Project/applications/smartcities/sensors.c
@@ -14,7 +14,7 @@ void wakeup_sensors(uint8_t logic_address) | @@ -14,7 +14,7 @@ void wakeup_sensors(uint8_t logic_address) | ||
14 | // X X X PA7 PA6 PA5 PA4 PA3 | 14 | // X X X PA7 PA6 PA5 PA4 PA3 |
15 | // b7 b6 b5 b4 b3 b2 b1 b0 | 15 | // b7 b6 b5 b4 b3 b2 b1 b0 |
16 | 16 | ||
17 | - printf("GRAB A BRUSH AND PUT A LITTLE MAKE-UP\r\n"); | 17 | + DBG_SENSORS("Waking up sensors...\r\n"); |
18 | GPIO_InitTypeDef GPIO_InitStructure; | 18 | GPIO_InitTypeDef GPIO_InitStructure; |
19 | RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); | 19 | RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); |
20 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7; | 20 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7; |
@@ -24,47 +24,52 @@ void wakeup_sensors(uint8_t logic_address) | @@ -24,47 +24,52 @@ void wakeup_sensors(uint8_t logic_address) | ||
24 | 24 | ||
25 | if(logic_address & 0x1) | 25 | if(logic_address & 0x1) |
26 | { | 26 | { |
27 | - printf("Woken Pin 3\r\n"); | 27 | + DBG_SENSORS("Woken Pin 3\r\n"); |
28 | GPIO_SetBits(GPIOA,GPIO_Pin_3); | 28 | GPIO_SetBits(GPIOA,GPIO_Pin_3); |
29 | } | 29 | } |
30 | else | 30 | else |
31 | { | 31 | { |
32 | + DBG_SENSORS("Pin 3 gone low\r\n"); | ||
32 | GPIO_ResetBits(GPIOA,GPIO_Pin_3); | 33 | GPIO_ResetBits(GPIOA,GPIO_Pin_3); |
33 | } | 34 | } |
34 | if(logic_address & 0x2) | 35 | if(logic_address & 0x2) |
35 | { | 36 | { |
36 | - printf("Woken Pin 4\r\n"); | 37 | + DBG_SENSORS("Woken Pin 4\r\n"); |
37 | GPIO_SetBits(GPIOA,GPIO_Pin_4); | 38 | GPIO_SetBits(GPIOA,GPIO_Pin_4); |
38 | } | 39 | } |
39 | else | 40 | else |
40 | { | 41 | { |
42 | + DBG_SENSORS("Pin 4 gone low\r\n"); | ||
41 | GPIO_ResetBits(GPIOA,GPIO_Pin_4); | 43 | GPIO_ResetBits(GPIOA,GPIO_Pin_4); |
42 | } | 44 | } |
43 | if(logic_address & 0x4) | 45 | if(logic_address & 0x4) |
44 | { | 46 | { |
45 | - printf("Woken Pin 5\r\n"); | 47 | + DBG_SENSORS("Woken Pin 5\r\n"); |
46 | GPIO_SetBits(GPIOA,GPIO_Pin_5); | 48 | GPIO_SetBits(GPIOA,GPIO_Pin_5); |
47 | } | 49 | } |
48 | else | 50 | else |
49 | { | 51 | { |
52 | + DBG_SENSORS("Pin 5 gone low\r\n"); | ||
50 | GPIO_ResetBits(GPIOA,GPIO_Pin_5); | 53 | GPIO_ResetBits(GPIOA,GPIO_Pin_5); |
51 | } | 54 | } |
52 | if(logic_address & 0x8) | 55 | if(logic_address & 0x8) |
53 | { | 56 | { |
54 | - printf("Woken Pin 6\r\n"); | 57 | + DBG_SENSORS("Woken Pin 6\r\n"); |
55 | GPIO_SetBits(GPIOA,GPIO_Pin_6); | 58 | GPIO_SetBits(GPIOA,GPIO_Pin_6); |
56 | } | 59 | } |
57 | else | 60 | else |
58 | { | 61 | { |
62 | + DBG_SENSORS("Pin 6 gone low\r\n"); | ||
59 | GPIO_ResetBits(GPIOA,GPIO_Pin_6); | 63 | GPIO_ResetBits(GPIOA,GPIO_Pin_6); |
60 | } | 64 | } |
61 | if(logic_address & 0x10) | 65 | if(logic_address & 0x10) |
62 | { | 66 | { |
63 | - printf("Woken Pin 7\r\n"); | 67 | + DBG_SENSORS("Woken Pin 7\r\n"); |
64 | GPIO_SetBits(GPIOA,GPIO_Pin_7); | 68 | GPIO_SetBits(GPIOA,GPIO_Pin_7); |
65 | } | 69 | } |
66 | else | 70 | else |
67 | { | 71 | { |
72 | + DBG_SENSORS("Pin 7 gone low\r\n"); | ||
68 | GPIO_ResetBits(GPIOA,GPIO_Pin_7); | 73 | GPIO_ResetBits(GPIOA,GPIO_Pin_7); |
69 | } | 74 | } |
70 | } | 75 | } |
@@ -74,10 +79,10 @@ uint32_t get_light_data(void) | @@ -74,10 +79,10 @@ uint32_t get_light_data(void) | ||
74 | uint32_t data = 0; | 79 | uint32_t data = 0; |
75 | 80 | ||
76 | data = get_light_ch1(); | 81 | data = get_light_ch1(); |
77 | - printf("LIGHT: Got ch1\r\n"); | 82 | + DBG_SENSORS("[LIGHT] Got ch1\r\n"); |
78 | data = data << 16; | 83 | data = data << 16; |
79 | data = data | get_light_ch0(); | 84 | data = data | get_light_ch0(); |
80 | - printf("LIGHT: Got ch0\r\n"); | 85 | + DBG_SENSORS("[LIGHT] Got ch0\r\n"); |
81 | return data; | 86 | return data; |
82 | } | 87 | } |
83 | uint16_t get_light_ch0(void) | 88 | uint16_t get_light_ch0(void) |
@@ -86,13 +91,13 @@ uint16_t get_light_ch0(void) | @@ -86,13 +91,13 @@ uint16_t get_light_ch0(void) | ||
86 | 91 | ||
87 | I2C_start(I2C1,LIGHT_ADDR << 1, I2C_Direction_Transmitter); | 92 | I2C_start(I2C1,LIGHT_ADDR << 1, I2C_Direction_Transmitter); |
88 | I2C_write(I2C1, 0x0C); | 93 | I2C_write(I2C1, 0x0C); |
89 | - printf("LIGHT: Sent fetch command for CH1\r\n"); | 94 | + DBG_SENSORS("[LIGHT] Sent fetch command for CH1\r\n"); |
90 | 95 | ||
91 | I2C_restart(I2C1, LIGHT_ADDR << 1, I2C_Direction_Receiver); | 96 | I2C_restart(I2C1, LIGHT_ADDR << 1, I2C_Direction_Receiver); |
92 | data = I2C_read_ack(I2C1); | 97 | data = I2C_read_ack(I2C1); |
93 | - printf("LIGHT: Got low byte for CH1\r\n"); | 98 | + DBG_SENSORS("[LIGHT] Got low byte for CH1\r\n"); |
94 | data = data | (I2C_read_nack(I2C1) << 8); | 99 | data = data | (I2C_read_nack(I2C1) << 8); |
95 | - printf("LIGHT: Got high byte for CH1\r\n"); | 100 | + DBG_SENSORS("[LIGHT] Got high byte for CH1\r\n"); |
96 | I2C_stop(I2C1); | 101 | I2C_stop(I2C1); |
97 | 102 | ||
98 | return data; | 103 | return data; |
@@ -103,13 +108,13 @@ uint16_t get_light_ch1(void) | @@ -103,13 +108,13 @@ uint16_t get_light_ch1(void) | ||
103 | 108 | ||
104 | I2C_start(I2C1,LIGHT_ADDR << 1, I2C_Direction_Transmitter); | 109 | I2C_start(I2C1,LIGHT_ADDR << 1, I2C_Direction_Transmitter); |
105 | I2C_write(I2C1, 0x0E); | 110 | I2C_write(I2C1, 0x0E); |
106 | - printf("LIGHT: Sent fetch command for CH1\r\n"); | 111 | + DBG_SENSORS("[LIGHT] Sent fetch command for CH1\r\n"); |
107 | 112 | ||
108 | I2C_restart(I2C1, LIGHT_ADDR << 1, I2C_Direction_Receiver); | 113 | I2C_restart(I2C1, LIGHT_ADDR << 1, I2C_Direction_Receiver); |
109 | data = I2C_read_ack(I2C1); | 114 | data = I2C_read_ack(I2C1); |
110 | - printf("LIGHT: Got low byte for CH1\r\n"); | 115 | + DBG_SENSORS("[LIGHT] Got low byte for CH1\r\n"); |
111 | data = data | (I2C_read_nack(I2C1) << 8); | 116 | data = data | (I2C_read_nack(I2C1) << 8); |
112 | - printf("LIGHT: Got high byte for CH1\r\n"); | 117 | + DBG_SENSORS("[LIGHT] Got high byte for CH1\r\n"); |
113 | I2C_stop(I2C1); | 118 | I2C_stop(I2C1); |
114 | 119 | ||
115 | return data; | 120 | return data; |
@@ -135,7 +140,7 @@ void init_ultrasound(void) | @@ -135,7 +140,7 @@ void init_ultrasound(void) | ||
135 | uint16_t get_distance_data(void) | 140 | uint16_t get_distance_data(void) |
136 | { | 141 | { |
137 | init_ultrasound(); | 142 | init_ultrasound(); |
138 | - printf("DISTANCE: Initialized\r\n"); | 143 | + DBG_SENSORS("[DISTANCE] Initialized\r\n"); |
139 | 144 | ||
140 | uint16_t data; | 145 | uint16_t data; |
141 | I2C_start(I2C1,DISTANCE_ADDR << 1, I2C_Direction_Transmitter); | 146 | I2C_start(I2C1,DISTANCE_ADDR << 1, I2C_Direction_Transmitter); |
@@ -143,10 +148,10 @@ uint16_t get_distance_data(void) | @@ -143,10 +148,10 @@ uint16_t get_distance_data(void) | ||
143 | 148 | ||
144 | I2C_restart(I2C1, DISTANCE_ADDR << 1, I2C_Direction_Receiver); | 149 | I2C_restart(I2C1, DISTANCE_ADDR << 1, I2C_Direction_Receiver); |
145 | data = I2C_read_ack(I2C1); | 150 | data = I2C_read_ack(I2C1); |
146 | - printf("DISTANCE: Got high byte\r\n"); | 151 | + DBG_SENSORS("[DISTANCE] Got high byte\r\n"); |
147 | data = data << 8; | 152 | data = data << 8; |
148 | data = data | I2C_read_nack(I2C1); | 153 | data = data | I2C_read_nack(I2C1); |
149 | - printf("DISTANCE: Got low byte\r\n"); | 154 | + DBG_SENSORS("[DISTANCE] Got low byte\r\n"); |
150 | I2C_stop(I2C1); | 155 | I2C_stop(I2C1); |
151 | return data; | 156 | return data; |
152 | } | 157 | } |
@@ -180,7 +185,7 @@ void init_pressure_temperature(void) | @@ -180,7 +185,7 @@ void init_pressure_temperature(void) | ||
180 | 185 | ||
181 | bmp085_callibration get_pressure_callibration_data(void) | 186 | bmp085_callibration get_pressure_callibration_data(void) |
182 | { | 187 | { |
183 | - printf("PRESSURE: Fetching callibration data\r\n"); | 188 | + DBG_SENSORS("[PRESSURE] Fetching callibration data\r\n"); |
184 | bmp085_callibration calib_data; | 189 | bmp085_callibration calib_data; |
185 | 190 | ||
186 | I2C_start(I2C1,PRESSURE_ADDR << 1, I2C_Direction_Transmitter); | 191 | I2C_start(I2C1,PRESSURE_ADDR << 1, I2C_Direction_Transmitter); |
@@ -260,7 +265,7 @@ bmp085_callibration get_pressure_callibration_data(void) | @@ -260,7 +265,7 @@ bmp085_callibration get_pressure_callibration_data(void) | ||
260 | calib_data.MD |= I2C_read_nack(I2C1); | 265 | calib_data.MD |= I2C_read_nack(I2C1); |
261 | I2C_stop(I2C1); | 266 | I2C_stop(I2C1); |
262 | 267 | ||
263 | - printf("PRESSURE: Got callibration data\r\n"); | 268 | + DBG_SENSORS("[PRESSURE] Got callibration data\r\n"); |
264 | return calib_data; | 269 | return calib_data; |
265 | } | 270 | } |
266 | 271 | ||
@@ -286,16 +291,16 @@ uint16_t get_pressure_data(void) | @@ -286,16 +291,16 @@ uint16_t get_pressure_data(void) | ||
286 | { | 291 | { |
287 | uint16_t data; | 292 | uint16_t data; |
288 | init_pressure(); | 293 | init_pressure(); |
289 | - printf("PRESSURE: Initialized\r\n"); | 294 | + DBG_SENSORS("[PRESSURE] Initialized\r\n"); |
290 | I2C_start(I2C1,PRESSURE_ADDR << 1, I2C_Direction_Transmitter); | 295 | I2C_start(I2C1,PRESSURE_ADDR << 1, I2C_Direction_Transmitter); |
291 | I2C_write(I2C1, 0xF6); | 296 | I2C_write(I2C1, 0xF6); |
292 | 297 | ||
293 | I2C_restart(I2C1, PRESSURE_ADDR << 1, I2C_Direction_Receiver); | 298 | I2C_restart(I2C1, PRESSURE_ADDR << 1, I2C_Direction_Receiver); |
294 | data = I2C_read_ack(I2C1); | 299 | data = I2C_read_ack(I2C1); |
295 | - printf("PRESSURE: Got high byte\r\n"); | 300 | + DBG_SENSORS("[PRESSURE] Got high byte\r\n"); |
296 | data = data << 8; | 301 | data = data << 8; |
297 | data = data | I2C_read_nack(I2C1); | 302 | data = data | I2C_read_nack(I2C1); |
298 | - printf("PRESSURE: Got low byte\r\n"); | 303 | + DBG_SENSORS("[PRESSURE] Got low byte\r\n"); |
299 | I2C_stop(I2C1); | 304 | I2C_stop(I2C1); |
300 | return data; | 305 | return data; |
301 | } | 306 | } |
@@ -304,16 +309,16 @@ uint16_t get_pressure_temperature_data(void) | @@ -304,16 +309,16 @@ uint16_t get_pressure_temperature_data(void) | ||
304 | { | 309 | { |
305 | uint16_t data; | 310 | uint16_t data; |
306 | init_pressure_temperature(); | 311 | init_pressure_temperature(); |
307 | - printf("PRESSURE: Initialized temperature\r\n"); | 312 | + DBG_SENSORS("[PRESSURE] Initialized temperature\r\n"); |
308 | I2C_start(I2C1,PRESSURE_ADDR << 1, I2C_Direction_Transmitter); | 313 | I2C_start(I2C1,PRESSURE_ADDR << 1, I2C_Direction_Transmitter); |
309 | I2C_write(I2C1, 0xF6); | 314 | I2C_write(I2C1, 0xF6); |
310 | 315 | ||
311 | I2C_restart(I2C1, PRESSURE_ADDR << 1, I2C_Direction_Receiver); | 316 | I2C_restart(I2C1, PRESSURE_ADDR << 1, I2C_Direction_Receiver); |
312 | data = I2C_read_ack(I2C1); | 317 | data = I2C_read_ack(I2C1); |
313 | - printf("PRESSURE: Got temperature high byte\r\n"); | 318 | + DBG_SENSORS("[PRESSURE] Got temperature high byte\r\n"); |
314 | data = data << 8; | 319 | data = data << 8; |
315 | data = data | I2C_read_nack(I2C1); | 320 | data = data | I2C_read_nack(I2C1); |
316 | - printf("PRESSURE: Got temperature low byte\r\n"); | 321 | + DBG_SENSORS("[PRESSURE] Got temperature low byte\r\n"); |
317 | I2C_stop(I2C1); | 322 | I2C_stop(I2C1); |
318 | return data; | 323 | return data; |
319 | } | 324 | } |
@@ -327,39 +332,39 @@ char* pressure_value(uint16_t pressure, uint16_t temperature) | @@ -327,39 +332,39 @@ char* pressure_value(uint16_t pressure, uint16_t temperature) | ||
327 | 332 | ||
328 | void init_humidity_temp(void) | 333 | void init_humidity_temp(void) |
329 | { | 334 | { |
330 | - printf("HUMIDITY: Initializing sensor\r\n"); | 335 | + DBG_SENSORS("[HUMIDITY_TEMP] Initializing sensor\r\n"); |
331 | I2C_start(I2C1,HUMIDITY_TEMP_ADDR << 1, I2C_Direction_Transmitter); | 336 | I2C_start(I2C1,HUMIDITY_TEMP_ADDR << 1, I2C_Direction_Transmitter); |
332 | I2C_stop(I2C1); | 337 | I2C_stop(I2C1); |
333 | } | 338 | } |
334 | uint16_t get_humidity_data(void) | 339 | uint16_t get_humidity_data(void) |
335 | { | 340 | { |
336 | init_humidity_temp(); | 341 | init_humidity_temp(); |
337 | - printf("HUMIDITY_TEMP: Initialized humidity\r\n"); | 342 | + DBG_SENSORS("[HUMIDITY_TEMP] Initialized humidity\r\n"); |
338 | uint16_t data = 0; | 343 | uint16_t data = 0; |
339 | I2C_start(I2C1,HUMIDITY_TEMP_ADDR << 1, I2C_Direction_Receiver); | 344 | I2C_start(I2C1,HUMIDITY_TEMP_ADDR << 1, I2C_Direction_Receiver); |
340 | data = I2C_read_ack(I2C1) & 0x3F; | 345 | data = I2C_read_ack(I2C1) & 0x3F; |
341 | - printf("HUMIDITY_TEMP: Got humidity high byte\r\n"); | 346 | + DBG_SENSORS("[HUMIDITY_TEMP] Got humidity high byte\r\n"); |
342 | data = data << 8; | 347 | data = data << 8; |
343 | data |= I2C_read_nack(I2C1); | 348 | data |= I2C_read_nack(I2C1); |
344 | - printf("HUMIDITY_TEMP: Got humidity low byte\r\n"); | 349 | + DBG_SENSORS("[HUMIDITY_TEMP] Got humidity low byte\r\n"); |
345 | I2C_stop(I2C1); | 350 | I2C_stop(I2C1); |
346 | return data; | 351 | return data; |
347 | } | 352 | } |
348 | uint16_t get_temperature_data(void) | 353 | uint16_t get_temperature_data(void) |
349 | { | 354 | { |
350 | init_humidity_temp(); | 355 | init_humidity_temp(); |
351 | - printf("HUMIDITY_TEMP: Initialized temperature\r\n"); | 356 | + DBG_SENSORS("[HUMIDITY_TEMP] Initialized temperature\r\n"); |
352 | uint16_t data = 0; | 357 | uint16_t data = 0; |
353 | I2C_start(I2C1,HUMIDITY_TEMP_ADDR << 1, I2C_Direction_Receiver); | 358 | I2C_start(I2C1,HUMIDITY_TEMP_ADDR << 1, I2C_Direction_Receiver); |
354 | I2C_read_ack(I2C1); | 359 | I2C_read_ack(I2C1); |
355 | - printf("HUMIDITY_TEMP: Discarded first humidity byte\r\n"); | 360 | + DBG_SENSORS("[HUMIDITY_TEMP] Discarded first humidity byte\r\n"); |
356 | I2C_read_ack(I2C1); | 361 | I2C_read_ack(I2C1); |
357 | - printf("HUMIDITY_TEMP: Discarded second humidity byte\r\n"); | 362 | + DBG_SENSORS("[HUMIDITY_TEMP] Discarded second humidity byte\r\n"); |
358 | data = I2C_read_ack(I2C1); | 363 | data = I2C_read_ack(I2C1); |
359 | - printf("HUMIDITY_TEMP: Got temperature high byte\r\n"); | 364 | + DBG_SENSORS("[HUMIDITY_TEMP] Got temperature high byte\r\n"); |
360 | data = data << 8; | 365 | data = data << 8; |
361 | data |= I2C_read_nack(I2C1) & 0xFC ; | 366 | data |= I2C_read_nack(I2C1) & 0xFC ; |
362 | - printf("HUMIDITY_TEMP: Got temperature low byte\r\n"); | 367 | + DBG_SENSORS("[HUMIDITY_TEMP] Got temperature low byte\r\n"); |
363 | data = data >> 2; | 368 | data = data >> 2; |
364 | I2C_stop(I2C1); | 369 | I2C_stop(I2C1); |
365 | return data; | 370 | return data; |
@@ -406,45 +411,48 @@ char* battery_value(uint32_t battery) | @@ -406,45 +411,48 @@ char* battery_value(uint32_t battery) | ||
406 | return value; | 411 | return value; |
407 | } | 412 | } |
408 | 413 | ||
409 | -void collectData(char* valueSensors[], uint8_t* sensors){ | 414 | +void collectData(char* valueSensors[], uint8_t* sensors) |
415 | +{ | ||
416 | + DBG_SENSORS("Collecting data...\r\n"); | ||
410 | uint8_t i; | 417 | uint8_t i; |
411 | for(i=0;i<strlen((char*)sensors);i++) | 418 | for(i=0;i<strlen((char*)sensors);i++) |
412 | { | 419 | { |
413 | 420 | ||
414 | if(valueSensors[i]!=NULL) | 421 | if(valueSensors[i]!=NULL) |
415 | { | 422 | { |
416 | - printf("Freeing memory from previous entry on index %d\r\n",i); | 423 | + DBG_SENSORS("Freeing memory from previous entry on index %d\r\n",i); |
417 | chHeapFree(valueSensors[i]); | 424 | chHeapFree(valueSensors[i]); |
418 | } | 425 | } |
419 | else | 426 | else |
420 | { | 427 | { |
421 | - printf("Not freeing memory on index %d\r\n",i); | 428 | + DBG_SENSORS("Not freeing memory on index %d\r\n",i); |
422 | } | 429 | } |
423 | 430 | ||
424 | if(sensors[i]==LIGHT_ADDR) | 431 | if(sensors[i]==LIGHT_ADDR) |
425 | { | 432 | { |
426 | - printf("Fetching data from light sensor\r\n"); | 433 | + DBG_SENSORS("Fetching data from light sensor\r\n"); |
427 | valueSensors[i]=light_value(get_light_data()); | 434 | valueSensors[i]=light_value(get_light_data()); |
428 | } | 435 | } |
429 | else if(sensors[i]==DISTANCE_ADDR) | 436 | else if(sensors[i]==DISTANCE_ADDR) |
430 | { | 437 | { |
431 | - printf("Fetching data from distance sensor\r\n"); | 438 | + DBG_SENSORS("Fetching data from distance sensor\r\n"); |
432 | valueSensors[i]=distance_value(get_distance_data()); | 439 | valueSensors[i]=distance_value(get_distance_data()); |
433 | } | 440 | } |
434 | else if(sensors[i]==SOUND_ADDR) | 441 | else if(sensors[i]==SOUND_ADDR) |
435 | { | 442 | { |
436 | - printf("Fetching data from sound sensor\r\n"); | 443 | + DBG_SENSORS("Fetching data from sound sensor\r\n"); |
437 | valueSensors[i]=sound_value(get_sound_data()); | 444 | valueSensors[i]=sound_value(get_sound_data()); |
438 | } | 445 | } |
439 | else if(sensors[i]==PRESSURE_ADDR) | 446 | else if(sensors[i]==PRESSURE_ADDR) |
440 | { | 447 | { |
441 | - printf("Fetching data from pressure sensor\r\n"); | 448 | + DBG_SENSORS("Fetching data from pressure sensor\r\n"); |
442 | valueSensors[i]=pressure_value(get_pressure_data(), get_pressure_temperature_data()); | 449 | valueSensors[i]=pressure_value(get_pressure_data(), get_pressure_temperature_data()); |
443 | } | 450 | } |
444 | else if(sensors[i]==HUMIDITY_TEMP_ADDR) | 451 | else if(sensors[i]==HUMIDITY_TEMP_ADDR) |
445 | { | 452 | { |
446 | - printf("Fetching data from humidity and temperature sensor\r\n"); | 453 | + DBG_SENSORS("Fetching data from humidity and temperature sensor\r\n"); |
447 | valueSensors[i]=temp_humidity_value(get_temperature_data(),get_humidity_data()); | 454 | valueSensors[i]=temp_humidity_value(get_temperature_data(),get_humidity_data()); |
448 | } | 455 | } |
449 | } | 456 | } |
457 | + DBG_SENSORS("Data collected...\r\n"); | ||
450 | } | 458 | } |
451 | \ No newline at end of file | 459 | \ No newline at end of file |
Project/applications/smartcities/timer-loop.c
@@ -30,5 +30,6 @@ unsigned long getElapsedTime(unsigned long t) | @@ -30,5 +30,6 @@ unsigned long getElapsedTime(unsigned long t) | ||
30 | 30 | ||
31 | void sleep_thread(unsigned long seconds) | 31 | void sleep_thread(unsigned long seconds) |
32 | { | 32 | { |
33 | + DBG_TIMER("Time to sleep! for %d seconds\r\n", seconds); | ||
33 | chThdSleepMilliseconds( (unsigned int)seconds*1000 ); | 34 | chThdSleepMilliseconds( (unsigned int)seconds*1000 ); |
34 | } | 35 | } |
35 | \ No newline at end of file | 36 | \ No newline at end of file |