httpClient.h
1.55 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
/*
* 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?)
*/