-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsocket.h
More file actions
61 lines (51 loc) · 1.75 KB
/
socket.h
File metadata and controls
61 lines (51 loc) · 1.75 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
#ifndef SOCKET_H
#define SOCKET_H
#define PORT_NUMBER 5000
#define PROTOCOL_CHECK 0x2a
extern WiFiClient client;
/**
* @brief Establish the socket with the server
* @note Connect to the server and enable the led to notice the connection
* @note If the connection fails, try again every 500ms
* @note the module connects to the gateway at port defined by PORT_NUMBER
*/
void establish_socket();
/**
* @brief Construct the pair message
* @return the pair message
* @note The pair message is a JSON object with the action pair, the ip address and the mac address of the module
*/
char *construct_pair_message();
/**
* @brief Construct the bottle taken message
* @return the bottle taken message
* @note The bottle taken message is a JSON object with the action bottle_taken
*/
char *construct_bottle_taken_message();
/**
* @brief Construct the set battery message
* @param battery_level the battery level of the module
* @return the set battery message
* @note The set battery message is a JSON object with the action set_battery and the battery level of the module
*/
char *construct_set_battery_message(int battery_level);
/**
* @brief Check if the protocol is correct
* @return true if the protocol is correct, false otherwise
* @note The protocol is correct if the first byte received is PROTOCOL_CHECK
* @note If the protocol is not correct, all data received is discarded
*/
bool check_protocol();
/**
* @brief Retrieve the json data received from the server by parsing it
* @note The data is parsed according to the protocol
*/
char *get_response_data();
/**
* @brief Retrieve the action from the json data
* @param data the json data as string
* @return the action
* @note The action is the first key of the json data
*/
char *get_action(char *data);
#endif