test_httpClient.c
3.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#include "libwismart.h"
#include "libwismart_irqs.h" /* implement irq handlers */
#include "lwip/inet.h"
#include "globals.h"
#include "httpClient.h"
#include "callbacks.h"
#include "buffer.h"
#define WIFI_MODE WIFI_MODE_CLIENT
#define NETWORK_SSID "linksys"
#define NETWORK_KEY ""
#define WPA_USER "smartcities"
#define WPA_PASS "superpass"
void initLibwismart(void)
{
wismart_hwif_t hwif = libwismart_GetDefaultHWIF();
libwismart_Init(hwif);
}
int main(void)
{
//WPA (RADIUS)
/*
struct wpa_param wpa;
wpa.eap_method = WISMART_EAP_METHOD_TTLS;
wpa.u.ttls.identity=WPA_USER;
wpa.u.ttls.password=WPA_PASS;
wpa.u.ttls.ca_cert=NULL;
*/
//NO SECURITY (HOTSPOT)
/**/
/*GET / HTTP/1.1
Host: www.upc.edu*/
struct httpHeaders head200 = { get, "/", 1, "www.upc.edu", 11 };
/*GET / HTTP/1.1
Host: upc.edu*/
struct httpHeaders head301 = { get, "/", 1, "upc.edu", 7 };
/*GET /errorerror HTTP/1.1
Host: www.upc.edu*/
struct httpHeaders head404 = { get, "/errorerrorerror", 15, "www.upc.edu", 11 };
initLibwismart();
libwismart_PowerSave_Enable();
libwismart_PowerSave_HigherProfile(TRUE);
printf("\r\n\r\n,------------------.\r\n");
printf("| GRUP ARM DE PAET |\r\n");
printf("`------------------'\r\n");
libwismart_RegisterDhcpCB(dhcp_connect_result_cb);
libwismart_WiFiInit();
//falta definir les variables de la xarxa
/* // WPA (RADIUS)
libwismart_WiFiConnectEnterprise(NETWORK_SSID, &wpa, wifi_connect_result_cb);
*/
// NO Security (hotspot)
libwismart_WiFiConnect("ARMwifi",NULL, wifi_connect_result_cb);
libwismart_EnableBsdSocketAPI();
//chThdSleepMilliseconds(5000);
DBG("HTTP Request expected to receive code 200 OK");
httpRequest(head200, NULL, 0);
DBG("HTTP Request expected to receive code 301 OK");
httpRequest(head301, NULL, 0);
DBG("HTTP Request expected to receive code 404 OK");
httpRequest(head404, NULL, 0);
/*
for(;;)
{
// i2c get info= data
char* data=NULL;
put_message(data, buffer ,&ind);
int res=check_memory();
if(res==SOFT_REACHED){
int ok=send(buffer, ind, "", "");
if(ok==JSON_COMM_ERROR)
{
printf("wismart is not connected\r\n");
}
else if( ok==JSON_OTHER_ERROR){
printf("some error ocurred\r\n");
}
else if(ok ==JSON_POST_OK){
printf(" send OK \r\n");
}
}
else if(res==HARD_REACHED){
destroy(buffer);
}
chThdSleepMilliseconds(500);
}*/
return 0;
}
/*
#
# WiSmart Applications Makefile
#
# Copyright 2012 eConais S.A
#
# Set the sdk root folder
SDK_ROOT = ../../
PROJECT_OUT = smartcities
USER_SRC = main.c httpClient.c callbacks.c module.c sensors.c json.c i2c.c buffer.c
USER_INCDIR = include/
# if you need to add build Defines options add to USER_DEFS define
#USER_DEFS += -D
# select SDK's version:
SDK_VERSION = SDK_REV_9_2
# select the MCU type e.g. STM32F1, STM32F4
PLAT = STM32F1
# select the MCU flash/ram size e.g. MCU_386K_64K, MCU_768K_96K, MCU_1M_96K
MCU_SIZE = MCU_768K_96K
USER_DEFS += -D$(SDK_VERSION)
# this must be the last include
include $(SDK_ROOT)/applications/rules.mk
*/