diff --git a/Project/applications/smartcities/example-code/httpClient/JSON_POST.pcapng b/Project/applications/smartcities/example-code/httpClient/JSON_POST.pcapng new file mode 100644 index 0000000..db4c923 --- /dev/null +++ b/Project/applications/smartcities/example-code/httpClient/JSON_POST.pcapng diff --git a/Project/applications/smartcities/example-code/httpClient/post http.txt b/Project/applications/smartcities/example-code/httpClient/post http.txt new file mode 100644 index 0000000..502fb20 --- /dev/null +++ b/Project/applications/smartcities/example-code/httpClient/post http.txt @@ -0,0 +1,39 @@ +Hola ferran +t'explico lo del HTTP +básicament, es fer un POST a un servidor HTTP normal i corrent +la funcion a fer hauria d'acceptar com a arguments lo següent: + + char* data (string a posar a pincho al camp de dades, aqui va el JSON) + uint32_t length (la longitud del camp de dades) + char* URL (aqui va la URL a la que fer la petició POST) + uint32_t URL_length (longitud de la URL) + + retorna un uint8_t + +que fos el codi HTTP de resposta (200, 401 etc) +recorda que es un POST normal, excepte que la capçalera ha de tenir el + + Content-type a application/json + +et passo una captura del wireshark d'exemple +un sec que la generi +en la captura veuras que el servidor respon amb dades +es un script de prova que vai fer jo +Aqui estan les respostes del servidor +realment sols es necessari el codi +http://www.sentilo.io/xwiki/bin/view/APIDocs/Overview#HReply +http://imanolbarba.myftp.biz/upload/JSON_POST.pcapng +els 3 ultims paquets son caca +quan abans ho tinguis millor, recorda que lo altre que feu tu i la maria ha d'estar per l'1 d'abril +si aneu molt de cul avisam i ho faig jo, pero amb temps si pot ser xd +qualsevol cosa em dius +ah se me olvidava +si la connexio amb el servidor no ha estat possible +fes que retorni un numero especial i el fots en un #define +per saber com va el tema sockets en la placa, a la documentació t'explica com obrir sockets BSD amb el lwip +o mira una de les aplicacions d'exemple +en l'exemple fan servir la API del Netconn crec, no sockets BSD +fes servir allò que t'agradi més +amb els sockets BSD t'hi sentiràs més familiar per que son els sockets normals de linux que es veuen també a ARISO 2, pero si veus més clar l'altra manera o t'agrada més endevant +hi ha mes info al Developer manual a la documentació +Developer guide perdó \ No newline at end of file diff --git a/Project/applications/smartcities/httpClient.c b/Project/applications/smartcities/httpClient.c index 6e32fcd..c5f24f7 100644 --- a/Project/applications/smartcities/httpClient.c +++ b/Project/applications/smartcities/httpClient.c @@ -44,7 +44,80 @@ GET /path/file.html HTTP/1.1 Host: www.host1.com:80 [Content] +----------- +POST:4 GET:3 PUT:3 DELETE:6 +espai +1 +255.255.255.255:15 o bé sizeof(*uri) +rn +2 +HTTP/1.1:8 ++2 +Host: :6 + sizeof(host) */ //const static char httpHeaders[] = "HTTP/1.1 200 OK\r\nContent-type: text/html\r\n\r\n"; -const static char httpHeaders[] = "HTTP/1.1 OK\r\nContent-type: text/html\r\n\r\n"; +struct netconn* neocon; +struct ip_addr local_ip; +struct ip_addr remote_ip; +char* httpHeaders; +char* httpContent; + +int httpRequest(struct httpHeaders head_in, struct ip_addr remote_ip, u16_t remote_port, char* content, int content_size) +{ + // Check or default params + if (remote_ip == NULL || remote_ip == 0) remote_ip = DEFAULT_REMOTE_IP; + if (host == NULL) host = DEFAULT_REMOTE_IP; + if (remote_port == NULL || remote_port == 0) remote_port = DEFAULT_REMOTE_PORT; + if (uri == NULL || content == NULL) return 1; + + // Calculate header size + int header_size = sizeof(reqMethod2text(method)); + header_size += sizeof " "; + header_size += strlen(uri); + header_size += sizeof(\r\n); + header_size += sizeof("Host: "); + header_size += + + // Set connection + neocon = netconn_new(NETCONN_TCP); + local_ip.addr = 0;//getip + netconn_bind(neocon, IP_ADDR_ANY, 88); //88 is provisional local port. + netconn_connect(neocon, &remote_ip, remote_port); + + + +} + +*char reqMethod2text(enum reqMethod method) +{ + switch(method) + { + case post: + return "POST"; + case put: + return "PUT"; + case get: + return "GET"; + case delete: + return "DELETE"; + default: + return NULL; + } +} +/* + struct netconn* httpServerConnection; + httpServerConnection = netconn_new(NETCONN_TCP); + netconn_bind(httpServerConnection, IP_ADDR_ANY, cTcpPort); // bind, to a local IP/port + netconn_connect ( xNetConn, &remote_ip, cClientPort ); // connect, to a remote IP/port + + libwismart_GetCurrentIP(libwismart_ip_addr_t *adress, *netmask, *gateway); +*/ + + + + + + + + + + diff --git a/Project/applications/smartcities/include/httpClient.h b/Project/applications/smartcities/include/httpClient.h index a216d4f..5da7dda 100644 --- a/Project/applications/smartcities/include/httpClient.h +++ b/Project/applications/smartcities/include/httpClient.h @@ -16,10 +16,34 @@ #define DBG(fmt,...) if(1){printf("[SRV] "fmt"\r\n", ##__VA_ARGS__);}else{({});} #define DBG_WARNING(fmt,...) if(1){printf("[SRV_WARNING] "fmt"\r\n", ##__VA_ARGS__);}else{({});} -void httpServer_init(void); +#define DEFAULT_REMOTE_IP 192.168.1.1 + +/*void httpServer_init(void); void httpServer_start(void); msg_t httpServer_threadFunc(void *arg); void httpServer_serveClient(struct netconn* httpClientConnection); void getLocalTime(uint32_t* hours, uint32_t* minutes, uint32_t* seconds); +*/ + +int httpRequest(struct httpHeaders head_in, struct ip_addr remote_ip, u16_t remote_port, char* content, int content_size); + +typedef enum reqMethod +{ + post, + get, + put, + del //delete may be a special word. + +}reqMethod; + +typedef struct httpHeader +{ + enum reqMethod method, + char* uri; + int uri_size; + char* host; + int host_size; + +}httpHeader; #endif \ No newline at end of file