Commit 08e2e9ee14324e946caa8500c2e4830f76f6de12
1 parent
a83c0d53
DEMO LISTA
Showing
6 changed files
with
42 additions
and
173 deletions
Project/applications/smartcities/httpClient.c
@@ -19,8 +19,7 @@ int httpRequest(struct httpHeaders head, char* content, int content_size) | @@ -19,8 +19,7 @@ int httpRequest(struct httpHeaders head, char* content, int content_size) | ||
19 | char* request; | 19 | char* request; |
20 | char* response; | 20 | char* response; |
21 | 21 | ||
22 | - //LE PARCHE | ||
23 | - initialize_IP(&remote_ip,SERVER_IP); | 22 | + ip4_addr_set_u32(&remote_ip,ipaddr_addr(SERVER_IP)); |
24 | 23 | ||
25 | // Check or default params | 24 | // Check or default params |
26 | printf("httpRequest: Checking params\r\n"); | 25 | printf("httpRequest: Checking params\r\n"); |
@@ -108,29 +107,6 @@ int httpRequest(struct httpHeaders head, char* content, int content_size) | @@ -108,29 +107,6 @@ int httpRequest(struct httpHeaders head, char* content, int content_size) | ||
108 | return http_response; | 107 | return http_response; |
109 | } | 108 | } |
110 | 109 | ||
111 | -void initialize_IP(struct ip_addr* addr,char* IP) | ||
112 | -{ | ||
113 | - uint8_t b[4],i,j = 0,k = 0,l; | ||
114 | - char byte[4]; | ||
115 | - for(i = 0; i < (strlen(IP)+1); i++) | ||
116 | - { | ||
117 | - if(IP[i] == '.' || IP[i] == '\0') | ||
118 | - { | ||
119 | - for(l = 0; l < (3-j); l++) | ||
120 | - { | ||
121 | - byte[2] = byte[1]; | ||
122 | - byte[1] = byte[0]; | ||
123 | - byte[0] = '0'; | ||
124 | - } | ||
125 | - b[k++] = response2int(byte); | ||
126 | - j = 0; | ||
127 | - continue; | ||
128 | - } | ||
129 | - byte[j++] = IP[i]; | ||
130 | - } | ||
131 | - IP4_ADDR(addr,b[0],b[1],b[2],b[3]); | ||
132 | -} | ||
133 | - | ||
134 | /* | 110 | /* |
135 | err_t netconn_write ( struct netconn * aNetConn, const void * aData, size_t aSize, u8_t aApiFlags ); | 111 | err_t netconn_write ( struct netconn * aNetConn, const void * aData, size_t aSize, u8_t aApiFlags ); |
136 | 112 |
Project/applications/smartcities/include/httpClient.h
@@ -47,7 +47,6 @@ const char* reqMethod2text(enum reqMethod method); | @@ -47,7 +47,6 @@ const char* reqMethod2text(enum reqMethod method); | ||
47 | char* int2string(int num); | 47 | char* int2string(int num); |
48 | int numberofdigits(int number); | 48 | int numberofdigits(int number); |
49 | int response2int(char* chars); | 49 | int response2int(char* chars); |
50 | -void initialize_IP(struct ip_addr* addr,char* IP); | ||
51 | 50 | ||
52 | #endif | 51 | #endif |
53 | 52 |
Project/applications/smartcities/include/ntp.h
@@ -8,9 +8,17 @@ | @@ -8,9 +8,17 @@ | ||
8 | #include "lwip/sys.h" | 8 | #include "lwip/sys.h" |
9 | #include "lwip/api.h" | 9 | #include "lwip/api.h" |
10 | #include "ch.h" | 10 | #include "ch.h" |
11 | +#include <stdio.h> | ||
12 | +#include <time.h> | ||
13 | +#include <string.h> | ||
14 | +#include <stdlib.h> | ||
15 | +#include <unistd.h> | ||
16 | +#include <math.h> | ||
17 | +#include <sys/time.h> | ||
18 | + | ||
11 | 19 | ||
12 | #define NTP_PACKET_LENGTH 48 | 20 | #define NTP_PACKET_LENGTH 48 |
13 | -//char* remoteIpString ="81.184.154.182"; | 21 | +#define NTP_SERVER "81.184.154.182" |
14 | //const uint16_t remotePort = 123; | 22 | //const uint16_t remotePort = 123; |
15 | 23 | ||
16 | 24 | ||
@@ -40,6 +48,7 @@ void udpNtp_dataReceivedCb(void * arg, struct udp_pcb * upcb,struct pbuf * first | @@ -40,6 +48,7 @@ void udpNtp_dataReceivedCb(void * arg, struct udp_pcb * upcb,struct pbuf * first | ||
40 | uint32_t udpNtp_setupConnection(void); | 48 | uint32_t udpNtp_setupConnection(void); |
41 | uint32_t udpNtp_setupConnectionL(void); | 49 | uint32_t udpNtp_setupConnectionL(void); |
42 | uint32_t read32(char* buffer, int offset); | 50 | uint32_t read32(char* buffer, int offset); |
51 | +char* timestamp_data(char* value,Date time); | ||
43 | 52 | ||
44 | 53 | ||
45 | #endif | 54 | #endif |
Project/applications/smartcities/json.c
@@ -116,8 +116,6 @@ uint8_t send_json(char* statement, uint32_t length, char* provider_ID, char* sen | @@ -116,8 +116,6 @@ uint8_t send_json(char* statement, uint32_t length, char* provider_ID, char* sen | ||
116 | strcpy(PATH+6+strlen(provider_ID),sensor_ID); | 116 | strcpy(PATH+6+strlen(provider_ID),sensor_ID); |
117 | PATH[7+strlen(provider_ID)+strlen(sensor_ID)] = '\0'; | 117 | PATH[7+strlen(provider_ID)+strlen(sensor_ID)] = '\0'; |
118 | } | 118 | } |
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)}; | 119 | struct httpHeaders server = { put,PATH,strlen(PATH),URL,strlen(URL)}; |
122 | response_code = httpRequest(server, statement, length); | 120 | response_code = httpRequest(server, statement, length); |
123 | chHeapFree(PATH); | 121 | chHeapFree(PATH); |
Project/applications/smartcities/ntp.c
1 | -#include <stdio.h> | ||
2 | -#include <time.h> | ||
3 | -#include <string.h> | ||
4 | -#include <stdlib.h> | ||
5 | -#include <unistd.h> | ||
6 | -#include <errno.h> | ||
7 | -#include <math.h> | ||
8 | -#include <sys/time.h> | ||
9 | - | ||
10 | #include "ntp.h" | 1 | #include "ntp.h" |
11 | 2 | ||
12 | #define DBG(fmt,...) if(1){printf("[NTP] "fmt"\r\n", ##__VA_ARGS__);}else{({});} | 3 | #define DBG(fmt,...) if(1){printf("[NTP] "fmt"\r\n", ##__VA_ARGS__);}else{({});} |
@@ -52,7 +43,6 @@ UDP TRANSMISSION HANDLING FUNCTIONS | @@ -52,7 +43,6 @@ UDP TRANSMISSION HANDLING FUNCTIONS | ||
52 | * Sends a new message to the remote peer | 43 | * Sends a new message to the remote peer |
53 | */ | 44 | */ |
54 | void udpNtp_send(){ | 45 | void udpNtp_send(){ |
55 | - char* remoteIpString ="81.184.154.182";/*"192.168.43.83";"165.193.126.229";*/ | ||
56 | uint16_t remotePort = 123; | 46 | uint16_t remotePort = 123; |
57 | char packetBuffer[NTP_PACKET_LENGTH]; | 47 | char packetBuffer[NTP_PACKET_LENGTH]; |
58 | static uint32_t messageCount = 0; | 48 | static uint32_t messageCount = 0; |
@@ -73,7 +63,7 @@ void udpNtp_send(){ | @@ -73,7 +63,7 @@ void udpNtp_send(){ | ||
73 | err_t err; | 63 | err_t err; |
74 | 64 | ||
75 | //Convert the IP address from string to lwip format | 65 | //Convert the IP address from string to lwip format |
76 | - ipaddr = ipaddr_addr(remoteIpString); | 66 | + ipaddr = ipaddr_addr(NTP_SERVER); |
77 | ip4_addr_set_u32((&addr), ipaddr); | 67 | ip4_addr_set_u32((&addr), ipaddr); |
78 | 68 | ||
79 | /* | 69 | /* |
@@ -302,6 +292,36 @@ void udpNTP_Setup(){ | @@ -302,6 +292,36 @@ void udpNTP_Setup(){ | ||
302 | udpNtp_process(); | 292 | udpNtp_process(); |
303 | } | 293 | } |
304 | 294 | ||
295 | +char* timestamp_data(char* value,Date time) | ||
296 | +{ | ||
297 | + uint8_t length = strlen(value) + strlen(",00/00/0000T00:00:00") + 1; | ||
298 | + char str_day[3],str_month[3],str_year[5],str_hour[3],str_minute[3],str_second[3]; | ||
299 | + char* data = chHeapAlloc(NULL,length*sizeof(char)); | ||
300 | + | ||
301 | + sprintf(str_day,"%d",time.day); | ||
302 | + sprintf(str_month,"%d",time.month); | ||
303 | + sprintf(str_year,"%d",time.year); | ||
304 | + sprintf(str_hour,"%d",time.hour); | ||
305 | + sprintf(str_minute,"%d",time.minute); | ||
306 | + sprintf(str_second,"%d",time.second); | ||
307 | + | ||
308 | + strcpy(data,value); | ||
309 | + strcat(data,","); | ||
310 | + strcat(data, str_day); | ||
311 | + strcat(data,"/"); | ||
312 | + strcat(data, str_month); | ||
313 | + strcat(data,"/"); | ||
314 | + strcat(data, str_year); | ||
315 | + strcat(data,"T"); | ||
316 | + strcat(data, str_hour); | ||
317 | + strcat(data,":"); | ||
318 | + strcat(data, str_minute); | ||
319 | + strcat(data,":"); | ||
320 | + strcat(data, str_second); | ||
321 | + data[length-1] = '\0'; | ||
322 | + return data; | ||
323 | +} | ||
324 | + | ||
305 | 325 | ||
306 | /*Funcion para testeo del resto de funciones relacionadas con NTP. En el main() el orden de ejecuciรณn debe ser el siguiente. | 326 | /*Funcion para testeo del resto de funciones relacionadas con NTP. En el main() el orden de ejecuciรณn debe ser el siguiente. |
307 | 1ro: udpNTP_Setup | 327 | 1ro: udpNTP_Setup |
Project/applications/smartcities/test_httpClient.c deleted
1 | -#include "libwismart.h" | ||
2 | -#include "libwismart_irqs.h" /* implement irq handlers */ | ||
3 | -#include "lwip/inet.h" | ||
4 | -#include "globals.h" | ||
5 | -#include "httpClient.h" | ||
6 | -#include "callbacks.h" | ||
7 | -#include "buffer.h" | ||
8 | - | ||
9 | -#define WIFI_MODE WIFI_MODE_CLIENT | ||
10 | -#define NETWORK_SSID "linksys" | ||
11 | -#define NETWORK_KEY "" | ||
12 | -#define WPA_USER "smartcities" | ||
13 | -#define WPA_PASS "superpass" | ||
14 | - | ||
15 | -void initLibwismart(void) | ||
16 | -{ | ||
17 | - wismart_hwif_t hwif = libwismart_GetDefaultHWIF(); | ||
18 | - libwismart_Init(hwif); | ||
19 | -} | ||
20 | - | ||
21 | -int main(void) | ||
22 | -{ | ||
23 | - //WPA (RADIUS) | ||
24 | - /* | ||
25 | - struct wpa_param wpa; | ||
26 | - wpa.eap_method = WISMART_EAP_METHOD_TTLS; | ||
27 | - wpa.u.ttls.identity=WPA_USER; | ||
28 | - wpa.u.ttls.password=WPA_PASS; | ||
29 | - wpa.u.ttls.ca_cert=NULL; | ||
30 | - */ | ||
31 | - | ||
32 | - //NO SECURITY (HOTSPOT) | ||
33 | - /**/ | ||
34 | - | ||
35 | - /*GET / HTTP/1.1 | ||
36 | - Host: www.upc.edu*/ | ||
37 | - struct httpHeaders head200 = { get, "/", 1, "www.upc.edu", 11 }; | ||
38 | - | ||
39 | - /*GET / HTTP/1.1 | ||
40 | - Host: upc.edu*/ | ||
41 | - struct httpHeaders head301 = { get, "/", 1, "upc.edu", 7 }; | ||
42 | - | ||
43 | - /*GET /errorerror HTTP/1.1 | ||
44 | - Host: www.upc.edu*/ | ||
45 | - struct httpHeaders head404 = { get, "/errorerrorerror", 15, "www.upc.edu", 11 }; | ||
46 | - | ||
47 | - initLibwismart(); | ||
48 | - libwismart_PowerSave_Enable(); | ||
49 | - libwismart_PowerSave_HigherProfile(TRUE); | ||
50 | - | ||
51 | - printf("\r\n\r\n,------------------.\r\n"); | ||
52 | - printf("| GRUP ARM DE PAET |\r\n"); | ||
53 | - printf("`------------------'\r\n"); | ||
54 | - | ||
55 | - libwismart_RegisterDhcpCB(dhcp_connect_result_cb); | ||
56 | - libwismart_WiFiInit(); | ||
57 | - //falta definir les variables de la xarxa | ||
58 | - | ||
59 | - /* // WPA (RADIUS) | ||
60 | - libwismart_WiFiConnectEnterprise(NETWORK_SSID, &wpa, wifi_connect_result_cb); | ||
61 | - */ | ||
62 | - // NO Security (hotspot) | ||
63 | - libwismart_WiFiConnect("ARMwifi",NULL, wifi_connect_result_cb); | ||
64 | - | ||
65 | - libwismart_EnableBsdSocketAPI(); | ||
66 | - //chThdSleepMilliseconds(5000); | ||
67 | - | ||
68 | - DBG("HTTP Request expected to receive code 200 OK"); | ||
69 | - httpRequest(head200, NULL, 0); | ||
70 | - DBG("HTTP Request expected to receive code 301 OK"); | ||
71 | - httpRequest(head301, NULL, 0); | ||
72 | - DBG("HTTP Request expected to receive code 404 OK"); | ||
73 | - httpRequest(head404, NULL, 0); | ||
74 | - /* | ||
75 | - for(;;) | ||
76 | - { | ||
77 | - // i2c get info= data | ||
78 | - char* data=NULL; | ||
79 | - put_message(data, buffer ,&ind); | ||
80 | - int res=check_memory(); | ||
81 | - if(res==SOFT_REACHED){ | ||
82 | - | ||
83 | - int ok=send(buffer, ind, "", ""); | ||
84 | - if(ok==JSON_COMM_ERROR) | ||
85 | - { | ||
86 | - printf("wismart is not connected\r\n"); | ||
87 | - } | ||
88 | - else if( ok==JSON_OTHER_ERROR){ | ||
89 | - printf("some error ocurred\r\n"); | ||
90 | - } | ||
91 | - else if(ok ==JSON_POST_OK){ | ||
92 | - printf(" send OK \r\n"); | ||
93 | - } | ||
94 | - } | ||
95 | - else if(res==HARD_REACHED){ | ||
96 | - destroy(buffer); | ||
97 | - } | ||
98 | - chThdSleepMilliseconds(500); | ||
99 | - }*/ | ||
100 | - return 0; | ||
101 | -} | ||
102 | -/* | ||
103 | - # | ||
104 | - # WiSmart Applications Makefile | ||
105 | - # | ||
106 | - # Copyright 2012 eConais S.A | ||
107 | - # | ||
108 | - | ||
109 | - | ||
110 | - # Set the sdk root folder | ||
111 | - SDK_ROOT = ../../ | ||
112 | - PROJECT_OUT = smartcities | ||
113 | - | ||
114 | - USER_SRC = main.c httpClient.c callbacks.c module.c sensors.c json.c i2c.c buffer.c | ||
115 | - USER_INCDIR = include/ | ||
116 | - | ||
117 | - # if you need to add build Defines options add to USER_DEFS define | ||
118 | - #USER_DEFS += -D | ||
119 | - | ||
120 | - # select SDK's version: | ||
121 | - SDK_VERSION = SDK_REV_9_2 | ||
122 | - | ||
123 | - # select the MCU type e.g. STM32F1, STM32F4 | ||
124 | - PLAT = STM32F1 | ||
125 | - | ||
126 | - # select the MCU flash/ram size e.g. MCU_386K_64K, MCU_768K_96K, MCU_1M_96K | ||
127 | - MCU_SIZE = MCU_768K_96K | ||
128 | - | ||
129 | - USER_DEFS += -D$(SDK_VERSION) | ||
130 | - | ||
131 | - # this must be the last include | ||
132 | - include $(SDK_ROOT)/applications/rules.mk | ||
133 | -*/ | ||
134 | \ No newline at end of file | 0 | \ No newline at end of file |