Commit 041e39452f8795e667572e5247268406ec65a22c
1 parent
1e762ea6
--no commit message
Showing
4 changed files
with
26 additions
and
27 deletions
Project/applications/smartcities/callbacks.c
Project/applications/smartcities/include/callbacks.h
Project/applications/smartcities/include/json.h
... | ... | @@ -9,6 +9,7 @@ |
9 | 9 | #include <string.h> |
10 | 10 | #include <stdio.h> |
11 | 11 | #include "libwismart.h" |
12 | +#include "httpClient.h" | |
12 | 13 | |
13 | 14 | #define JSON_POST_OK 0 |
14 | 15 | #define JSON_COMM_ERROR 1 |
... | ... | @@ -17,7 +18,7 @@ |
17 | 18 | #define JOIN_NO_FREE 0 |
18 | 19 | #define JOIN_FREE_MEM 1 |
19 | 20 | |
20 | -char* prepare_json_statement(char** data, uint32_t nObservations); | |
21 | +char* prepare_json_observation_statement(char** data, uint32_t nObservations); | |
21 | 22 | char* prepare_json_register_statement(module mod, sensor sens); |
22 | 23 | char* prepare_observation(char* observation, uint32_t length); |
23 | 24 | uint8_t send_json(char* statement, uint32_t length, char* provider_ID, char* sensor_ID); | ... | ... |
Project/applications/smartcities/json.c
... | ... | @@ -89,8 +89,7 @@ char* prepare_observation(char* observation, uint32_t length) |
89 | 89 | uint8_t send_json(char* statement, uint32_t length, char* provider_ID, char* sensor_ID) |
90 | 90 | { |
91 | 91 | int connectivity, response_code; |
92 | - char* URL; | |
93 | - int server_hostname_length = strlen(SERVER_HOSTNAME); | |
92 | + char *URL, *PATH; | |
94 | 93 | connectivity = libwismart_IsConnected(); |
95 | 94 | if(connectivity != WISMART_CONNECTED) |
96 | 95 | { |
... | ... | @@ -98,32 +97,31 @@ uint8_t send_json(char* statement, uint32_t length, char* provider_ID, char* sen |
98 | 97 | } |
99 | 98 | if(sensor_ID == NULL) //Register sensor |
100 | 99 | { |
101 | - URL = (char*) chHeapAlloc(NULL,17+server_hostname_length+strlen(provider_ID)); | |
100 | + URL = (char*) chHeapAlloc(NULL,8+strlen(SERVER_HOSTNAME)); | |
102 | 101 | strcpy(URL,"http://"); |
103 | 102 | strcpy(URL+7,SERVER_HOSTNAME); |
104 | - strcpy(URL+7+server_hostname_length,"/catalog/"); | |
105 | - strcpy(URL+16+server_hostname_length,provider_ID); | |
103 | + PATH = (char*) chHeapAlloc(NULL,10+strlen(provider_ID)); | |
104 | + strcpy(PATH,"/catalog/"); | |
105 | + strcpy(PATH+9,provider_ID); | |
106 | 106 | } |
107 | 107 | else //Post data |
108 | 108 | { |
109 | - URL = (char*) chHeapAlloc(NULL,18+server_hostname_length+strlen(provider_ID)+strlen(sensor_ID)); | |
109 | + URL = (char*) chHeapAlloc(NULL,8+strlen(SERVER_HOSTNAME)); | |
110 | 110 | strcpy(URL,"http://"); |
111 | 111 | strcpy(URL+7,SERVER_HOSTNAME); |
112 | - strcpy(URL+7+server_hostname_length,"/data/"); | |
113 | - strcpy(URL+16+server_hostname_length,provider_ID); | |
114 | - strcpy(URL+16+server_hostname_length+strlen(provider_ID),"/"); | |
115 | - strcpy(URL+17+server_hostname_length+strlen(provider_ID),sensor_ID); | |
112 | + URL[7+strlen(SERVER_HOSTNAME)] = '\0'; | |
113 | + PATH = (char*) chHeapAlloc(NULL,8+strlen(provider_ID)+strlen(sensor_ID)); | |
114 | + strcpy(PATH,"/data/"); | |
115 | + strcpy(PATH+6,provider_ID); | |
116 | + strcpy(PATH+6+strlen(provider_ID),sensor_ID); | |
117 | + PATH[7+strlen(provider_ID)+strlen(sensor_ID)] = '\0'; | |
116 | 118 | } |
117 | - | |
118 | - /* SELF-REMINDER | |
119 | - * | |
120 | - * Cambiar esto pa usar la función de Ferràn | |
121 | - * | |
122 | - * --Imanol | |
123 | - */ | |
124 | - | |
125 | - //response_code = http_post(URL,statement,URL_length,length); | |
126 | - response_code = 200; //placeholder | |
119 | + printf("%s: %d\n\r",PATH,strlen(PATH)); | |
120 | + printf("%s: %d\n\r",URL,strlen(URL)); | |
121 | + struct httpHeaders server = { put,PATH,strlen(PATH),URL,strlen(URL)}; | |
122 | + response_code = httpRequest(server, statement, length); | |
123 | + chHeapFree(PATH); | |
124 | + chHeapFree(URL); | |
127 | 125 | if(response_code == 200) |
128 | 126 | { |
129 | 127 | return JSON_POST_OK; |
... | ... | @@ -159,11 +157,8 @@ char* join_strings(char* str1, char* str2, uint32_t len1, uint32_t len2, uint8_t |
159 | 157 | strncat(str,str2,len2); |
160 | 158 | if(free_mem) |
161 | 159 | { |
162 | - free(str1); | |
163 | - free(str2); | |
160 | + chHeapFree(str1); | |
161 | + chHeapFree(str2); | |
164 | 162 | } |
165 | 163 | return str; |
166 | -} | |
167 | - | |
168 | -//check if exists | |
169 | -//subscribe | |
170 | 164 | \ No newline at end of file |
165 | +} | |
171 | 166 | \ No newline at end of file | ... | ... |