httpClient.h 1.55 KB
/*
 * Custom http client implementation based on httpServer
 *
 */
#ifndef HTTP_CLIENT_H
#define HTTP_CLIENT_H

#include "libwismart.h"
#include "lwip/opt.h"
#include "lwip/tcp.h"
#include "lwip/udp.h"
#include "lwip/sys.h"
#include "lwip/api.h"
#include "ch.h"
#include "globals.h"

/*
 * No fem servir DEFAULT_REMOTE_IP. Fem servir en canvi SERVER_IP, definida a globals.h 
 */
#define DEFAULT_REMOTE_IP  "147.83.2.135" // www.upc.edu
#define DEFAULT_REMOTE_PORT 80
#define ENDL "\r\n"
#define CONTENT_TYPE_HEADER "Content-Type: application/json; charset=UTF-8"

typedef enum reqMethod
{
	post,
	get,
	put,
	del //delete may be a special word.
	
}reqMethod;

typedef struct httpHeaders
{
	enum reqMethod method;
	char* uri;
	int uri_size;
	char* host;
	int host_size;
	
}httpHeaders;


int httpRequest(struct httpHeaders head, char* content, int content_size);
const char* reqMethod2text(enum reqMethod method);
char* int2string(int num);
int numberofdigits(int number);
int response2int(char* chars);

#endif

/*

-------------
Sentilo codes
-------------

Error Code	HTTP	Description
200	Success	Request accepted and processed correctly
4xx	Client Error	Error in request (Wrong format, forbidden mandatory parameters, ...)
401	Unauthorized	Unauthorized request: empty or invalid credential 
403	Forbidden	Not authorized for the requested action
5xx	Server Error	Error processing the request

PUT - Publish sensor data
DELETE - Erase sensor data
GET - Download sensor data
(POST - create new sensor or publisher?)

*/