Wed, 03 Jul 2024 20:01:31 +0200
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
0 | 1 | /** |
2 | * @file task_http.c | |
3 | * @brief HTTP and Websocket server functions. | |
4 | */ | |
5 | #include "config.h" | |
142
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
6 | #include "sys/param.h" |
0 | 7 | #include "mbedtls/base64.h" |
8 | #include "mbedtls/sha1.h" | |
41
7639cfa6aec0
Websocket interface is working for the main screen and manual mode.
Michiel Broek <mbroek@mbse.eu>
parents:
38
diff
changeset
|
9 | #include "cJSON.h" |
0 | 10 | |
11 | ||
1
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
12 | static const char *TAG = "task_http"; |
142
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
13 | httpd_handle_t web_server = NULL; ///< The http server handle. |
0 | 14 | |
41
7639cfa6aec0
Websocket interface is working for the main screen and manual mode.
Michiel Broek <mbroek@mbse.eu>
parents:
38
diff
changeset
|
15 | cJSON *root = NULL; |
7639cfa6aec0
Websocket interface is working for the main screen and manual mode.
Michiel Broek <mbroek@mbse.eu>
parents:
38
diff
changeset
|
16 | cJSON *touch = NULL; |
0 | 17 | |
142
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
18 | |
80
9d2c0a85ee6e
Added directory sorting for the logfiles. Sort in reverse order on the timestamp so the last files will be on top.
Michiel Broek <mbroek@mbse.eu>
parents:
64
diff
changeset
|
19 | typedef struct _ls_list { |
9d2c0a85ee6e
Added directory sorting for the logfiles. Sort in reverse order on the timestamp so the last files will be on top.
Michiel Broek <mbroek@mbse.eu>
parents:
64
diff
changeset
|
20 | struct _ls_list *next; |
9d2c0a85ee6e
Added directory sorting for the logfiles. Sort in reverse order on the timestamp so the last files will be on top.
Michiel Broek <mbroek@mbse.eu>
parents:
64
diff
changeset
|
21 | char d_name[64]; |
9d2c0a85ee6e
Added directory sorting for the logfiles. Sort in reverse order on the timestamp so the last files will be on top.
Michiel Broek <mbroek@mbse.eu>
parents:
64
diff
changeset
|
22 | off_t size; |
9d2c0a85ee6e
Added directory sorting for the logfiles. Sort in reverse order on the timestamp so the last files will be on top.
Michiel Broek <mbroek@mbse.eu>
parents:
64
diff
changeset
|
23 | long mtime; |
9d2c0a85ee6e
Added directory sorting for the logfiles. Sort in reverse order on the timestamp so the last files will be on top.
Michiel Broek <mbroek@mbse.eu>
parents:
64
diff
changeset
|
24 | } ls_list; |
9d2c0a85ee6e
Added directory sorting for the logfiles. Sort in reverse order on the timestamp so the last files will be on top.
Michiel Broek <mbroek@mbse.eu>
parents:
64
diff
changeset
|
25 | |
9d2c0a85ee6e
Added directory sorting for the logfiles. Sort in reverse order on the timestamp so the last files will be on top.
Michiel Broek <mbroek@mbse.eu>
parents:
64
diff
changeset
|
26 | |
142
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
27 | /** |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
28 | * @brief Clear the linked list and release memory. |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
29 | */ |
80
9d2c0a85ee6e
Added directory sorting for the logfiles. Sort in reverse order on the timestamp so the last files will be on top.
Michiel Broek <mbroek@mbse.eu>
parents:
64
diff
changeset
|
30 | void tidy_lslist(ls_list **lap) |
9d2c0a85ee6e
Added directory sorting for the logfiles. Sort in reverse order on the timestamp so the last files will be on top.
Michiel Broek <mbroek@mbse.eu>
parents:
64
diff
changeset
|
31 | { |
9d2c0a85ee6e
Added directory sorting for the logfiles. Sort in reverse order on the timestamp so the last files will be on top.
Michiel Broek <mbroek@mbse.eu>
parents:
64
diff
changeset
|
32 | ls_list *tmp, *old; |
9d2c0a85ee6e
Added directory sorting for the logfiles. Sort in reverse order on the timestamp so the last files will be on top.
Michiel Broek <mbroek@mbse.eu>
parents:
64
diff
changeset
|
33 | |
9d2c0a85ee6e
Added directory sorting for the logfiles. Sort in reverse order on the timestamp so the last files will be on top.
Michiel Broek <mbroek@mbse.eu>
parents:
64
diff
changeset
|
34 | for (tmp = *lap; tmp; tmp = old) { |
9d2c0a85ee6e
Added directory sorting for the logfiles. Sort in reverse order on the timestamp so the last files will be on top.
Michiel Broek <mbroek@mbse.eu>
parents:
64
diff
changeset
|
35 | old = tmp->next; |
9d2c0a85ee6e
Added directory sorting for the logfiles. Sort in reverse order on the timestamp so the last files will be on top.
Michiel Broek <mbroek@mbse.eu>
parents:
64
diff
changeset
|
36 | free(tmp); |
9d2c0a85ee6e
Added directory sorting for the logfiles. Sort in reverse order on the timestamp so the last files will be on top.
Michiel Broek <mbroek@mbse.eu>
parents:
64
diff
changeset
|
37 | } |
9d2c0a85ee6e
Added directory sorting for the logfiles. Sort in reverse order on the timestamp so the last files will be on top.
Michiel Broek <mbroek@mbse.eu>
parents:
64
diff
changeset
|
38 | *lap = NULL; |
9d2c0a85ee6e
Added directory sorting for the logfiles. Sort in reverse order on the timestamp so the last files will be on top.
Michiel Broek <mbroek@mbse.eu>
parents:
64
diff
changeset
|
39 | } |
9d2c0a85ee6e
Added directory sorting for the logfiles. Sort in reverse order on the timestamp so the last files will be on top.
Michiel Broek <mbroek@mbse.eu>
parents:
64
diff
changeset
|
40 | |
9d2c0a85ee6e
Added directory sorting for the logfiles. Sort in reverse order on the timestamp so the last files will be on top.
Michiel Broek <mbroek@mbse.eu>
parents:
64
diff
changeset
|
41 | |
142
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
42 | /** |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
43 | * @brief Add a file entry to the linked list. |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
44 | * @param lap Pointer to the linked list. |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
45 | * @param name The entry filename. |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
46 | * @param size The entry filesize. |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
47 | * @param mtime The entry filedate. |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
48 | */ |
80
9d2c0a85ee6e
Added directory sorting for the logfiles. Sort in reverse order on the timestamp so the last files will be on top.
Michiel Broek <mbroek@mbse.eu>
parents:
64
diff
changeset
|
49 | void fill_list(ls_list **lap, char *name, off_t size, long mtime) |
9d2c0a85ee6e
Added directory sorting for the logfiles. Sort in reverse order on the timestamp so the last files will be on top.
Michiel Broek <mbroek@mbse.eu>
parents:
64
diff
changeset
|
50 | { |
9d2c0a85ee6e
Added directory sorting for the logfiles. Sort in reverse order on the timestamp so the last files will be on top.
Michiel Broek <mbroek@mbse.eu>
parents:
64
diff
changeset
|
51 | ls_list **tmp; |
9d2c0a85ee6e
Added directory sorting for the logfiles. Sort in reverse order on the timestamp so the last files will be on top.
Michiel Broek <mbroek@mbse.eu>
parents:
64
diff
changeset
|
52 | |
9d2c0a85ee6e
Added directory sorting for the logfiles. Sort in reverse order on the timestamp so the last files will be on top.
Michiel Broek <mbroek@mbse.eu>
parents:
64
diff
changeset
|
53 | for (tmp = lap; *tmp; tmp = &((*tmp)->next)); |
9d2c0a85ee6e
Added directory sorting for the logfiles. Sort in reverse order on the timestamp so the last files will be on top.
Michiel Broek <mbroek@mbse.eu>
parents:
64
diff
changeset
|
54 | |
9d2c0a85ee6e
Added directory sorting for the logfiles. Sort in reverse order on the timestamp so the last files will be on top.
Michiel Broek <mbroek@mbse.eu>
parents:
64
diff
changeset
|
55 | *tmp = (ls_list *)malloc(sizeof(ls_list)); |
9d2c0a85ee6e
Added directory sorting for the logfiles. Sort in reverse order on the timestamp so the last files will be on top.
Michiel Broek <mbroek@mbse.eu>
parents:
64
diff
changeset
|
56 | (*tmp)->next = NULL; |
9d2c0a85ee6e
Added directory sorting for the logfiles. Sort in reverse order on the timestamp so the last files will be on top.
Michiel Broek <mbroek@mbse.eu>
parents:
64
diff
changeset
|
57 | strncpy((*tmp)->d_name, name, 63); |
9d2c0a85ee6e
Added directory sorting for the logfiles. Sort in reverse order on the timestamp so the last files will be on top.
Michiel Broek <mbroek@mbse.eu>
parents:
64
diff
changeset
|
58 | (*tmp)->size = size; |
9d2c0a85ee6e
Added directory sorting for the logfiles. Sort in reverse order on the timestamp so the last files will be on top.
Michiel Broek <mbroek@mbse.eu>
parents:
64
diff
changeset
|
59 | (*tmp)->mtime = mtime; |
9d2c0a85ee6e
Added directory sorting for the logfiles. Sort in reverse order on the timestamp so the last files will be on top.
Michiel Broek <mbroek@mbse.eu>
parents:
64
diff
changeset
|
60 | tmp = &((*tmp)->next); |
9d2c0a85ee6e
Added directory sorting for the logfiles. Sort in reverse order on the timestamp so the last files will be on top.
Michiel Broek <mbroek@mbse.eu>
parents:
64
diff
changeset
|
61 | } |
9d2c0a85ee6e
Added directory sorting for the logfiles. Sort in reverse order on the timestamp so the last files will be on top.
Michiel Broek <mbroek@mbse.eu>
parents:
64
diff
changeset
|
62 | |
9d2c0a85ee6e
Added directory sorting for the logfiles. Sort in reverse order on the timestamp so the last files will be on top.
Michiel Broek <mbroek@mbse.eu>
parents:
64
diff
changeset
|
63 | |
142
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
64 | /** |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
65 | * @brief Compare for sorting files by datetime, reversed. |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
66 | * @param lsp1 Entry 1 |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
67 | * @param lsp2 Entry 2 |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
68 | */ |
80
9d2c0a85ee6e
Added directory sorting for the logfiles. Sort in reverse order on the timestamp so the last files will be on top.
Michiel Broek <mbroek@mbse.eu>
parents:
64
diff
changeset
|
69 | int comp(ls_list **lsp1, ls_list **lsp2) |
9d2c0a85ee6e
Added directory sorting for the logfiles. Sort in reverse order on the timestamp so the last files will be on top.
Michiel Broek <mbroek@mbse.eu>
parents:
64
diff
changeset
|
70 | { |
9d2c0a85ee6e
Added directory sorting for the logfiles. Sort in reverse order on the timestamp so the last files will be on top.
Michiel Broek <mbroek@mbse.eu>
parents:
64
diff
changeset
|
71 | char as[20], bs[20]; |
9d2c0a85ee6e
Added directory sorting for the logfiles. Sort in reverse order on the timestamp so the last files will be on top.
Michiel Broek <mbroek@mbse.eu>
parents:
64
diff
changeset
|
72 | |
9d2c0a85ee6e
Added directory sorting for the logfiles. Sort in reverse order on the timestamp so the last files will be on top.
Michiel Broek <mbroek@mbse.eu>
parents:
64
diff
changeset
|
73 | snprintf(as, 19, "%ld", (*lsp1)->mtime); |
9d2c0a85ee6e
Added directory sorting for the logfiles. Sort in reverse order on the timestamp so the last files will be on top.
Michiel Broek <mbroek@mbse.eu>
parents:
64
diff
changeset
|
74 | snprintf(bs, 19, "%ld", (*lsp2)->mtime); |
9d2c0a85ee6e
Added directory sorting for the logfiles. Sort in reverse order on the timestamp so the last files will be on top.
Michiel Broek <mbroek@mbse.eu>
parents:
64
diff
changeset
|
75 | // Reverse order |
9d2c0a85ee6e
Added directory sorting for the logfiles. Sort in reverse order on the timestamp so the last files will be on top.
Michiel Broek <mbroek@mbse.eu>
parents:
64
diff
changeset
|
76 | return strcmp(bs, as); |
9d2c0a85ee6e
Added directory sorting for the logfiles. Sort in reverse order on the timestamp so the last files will be on top.
Michiel Broek <mbroek@mbse.eu>
parents:
64
diff
changeset
|
77 | } |
9d2c0a85ee6e
Added directory sorting for the logfiles. Sort in reverse order on the timestamp so the last files will be on top.
Michiel Broek <mbroek@mbse.eu>
parents:
64
diff
changeset
|
78 | |
9d2c0a85ee6e
Added directory sorting for the logfiles. Sort in reverse order on the timestamp so the last files will be on top.
Michiel Broek <mbroek@mbse.eu>
parents:
64
diff
changeset
|
79 | |
142
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
80 | /** |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
81 | * @brief Sort the linked list. |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
82 | */ |
80
9d2c0a85ee6e
Added directory sorting for the logfiles. Sort in reverse order on the timestamp so the last files will be on top.
Michiel Broek <mbroek@mbse.eu>
parents:
64
diff
changeset
|
83 | void sort_list(ls_list **lap) |
9d2c0a85ee6e
Added directory sorting for the logfiles. Sort in reverse order on the timestamp so the last files will be on top.
Michiel Broek <mbroek@mbse.eu>
parents:
64
diff
changeset
|
84 | { |
9d2c0a85ee6e
Added directory sorting for the logfiles. Sort in reverse order on the timestamp so the last files will be on top.
Michiel Broek <mbroek@mbse.eu>
parents:
64
diff
changeset
|
85 | ls_list *ta, **vector; |
9d2c0a85ee6e
Added directory sorting for the logfiles. Sort in reverse order on the timestamp so the last files will be on top.
Michiel Broek <mbroek@mbse.eu>
parents:
64
diff
changeset
|
86 | size_t n = 0, i; |
9d2c0a85ee6e
Added directory sorting for the logfiles. Sort in reverse order on the timestamp so the last files will be on top.
Michiel Broek <mbroek@mbse.eu>
parents:
64
diff
changeset
|
87 | |
9d2c0a85ee6e
Added directory sorting for the logfiles. Sort in reverse order on the timestamp so the last files will be on top.
Michiel Broek <mbroek@mbse.eu>
parents:
64
diff
changeset
|
88 | if (*lap == NULL) |
9d2c0a85ee6e
Added directory sorting for the logfiles. Sort in reverse order on the timestamp so the last files will be on top.
Michiel Broek <mbroek@mbse.eu>
parents:
64
diff
changeset
|
89 | return; |
9d2c0a85ee6e
Added directory sorting for the logfiles. Sort in reverse order on the timestamp so the last files will be on top.
Michiel Broek <mbroek@mbse.eu>
parents:
64
diff
changeset
|
90 | |
9d2c0a85ee6e
Added directory sorting for the logfiles. Sort in reverse order on the timestamp so the last files will be on top.
Michiel Broek <mbroek@mbse.eu>
parents:
64
diff
changeset
|
91 | for (ta = *lap; ta; ta = ta->next) |
9d2c0a85ee6e
Added directory sorting for the logfiles. Sort in reverse order on the timestamp so the last files will be on top.
Michiel Broek <mbroek@mbse.eu>
parents:
64
diff
changeset
|
92 | n++; |
9d2c0a85ee6e
Added directory sorting for the logfiles. Sort in reverse order on the timestamp so the last files will be on top.
Michiel Broek <mbroek@mbse.eu>
parents:
64
diff
changeset
|
93 | vector = (ls_list **)malloc(n * sizeof(ls_list *)); |
9d2c0a85ee6e
Added directory sorting for the logfiles. Sort in reverse order on the timestamp so the last files will be on top.
Michiel Broek <mbroek@mbse.eu>
parents:
64
diff
changeset
|
94 | i = 0; |
9d2c0a85ee6e
Added directory sorting for the logfiles. Sort in reverse order on the timestamp so the last files will be on top.
Michiel Broek <mbroek@mbse.eu>
parents:
64
diff
changeset
|
95 | |
9d2c0a85ee6e
Added directory sorting for the logfiles. Sort in reverse order on the timestamp so the last files will be on top.
Michiel Broek <mbroek@mbse.eu>
parents:
64
diff
changeset
|
96 | for (ta = *lap; ta; ta = ta->next) { |
9d2c0a85ee6e
Added directory sorting for the logfiles. Sort in reverse order on the timestamp so the last files will be on top.
Michiel Broek <mbroek@mbse.eu>
parents:
64
diff
changeset
|
97 | vector[i++] = ta; |
9d2c0a85ee6e
Added directory sorting for the logfiles. Sort in reverse order on the timestamp so the last files will be on top.
Michiel Broek <mbroek@mbse.eu>
parents:
64
diff
changeset
|
98 | } |
9d2c0a85ee6e
Added directory sorting for the logfiles. Sort in reverse order on the timestamp so the last files will be on top.
Michiel Broek <mbroek@mbse.eu>
parents:
64
diff
changeset
|
99 | qsort(vector, n, sizeof(ls_list *), (int(*)(const void*, const void*))comp); |
9d2c0a85ee6e
Added directory sorting for the logfiles. Sort in reverse order on the timestamp so the last files will be on top.
Michiel Broek <mbroek@mbse.eu>
parents:
64
diff
changeset
|
100 | |
9d2c0a85ee6e
Added directory sorting for the logfiles. Sort in reverse order on the timestamp so the last files will be on top.
Michiel Broek <mbroek@mbse.eu>
parents:
64
diff
changeset
|
101 | (*lap) = vector[0]; |
9d2c0a85ee6e
Added directory sorting for the logfiles. Sort in reverse order on the timestamp so the last files will be on top.
Michiel Broek <mbroek@mbse.eu>
parents:
64
diff
changeset
|
102 | i = 1; |
9d2c0a85ee6e
Added directory sorting for the logfiles. Sort in reverse order on the timestamp so the last files will be on top.
Michiel Broek <mbroek@mbse.eu>
parents:
64
diff
changeset
|
103 | |
9d2c0a85ee6e
Added directory sorting for the logfiles. Sort in reverse order on the timestamp so the last files will be on top.
Michiel Broek <mbroek@mbse.eu>
parents:
64
diff
changeset
|
104 | for (ta = *lap; ta; ta = ta->next) { |
9d2c0a85ee6e
Added directory sorting for the logfiles. Sort in reverse order on the timestamp so the last files will be on top.
Michiel Broek <mbroek@mbse.eu>
parents:
64
diff
changeset
|
105 | if (i < n) |
9d2c0a85ee6e
Added directory sorting for the logfiles. Sort in reverse order on the timestamp so the last files will be on top.
Michiel Broek <mbroek@mbse.eu>
parents:
64
diff
changeset
|
106 | ta->next = vector[i++]; |
9d2c0a85ee6e
Added directory sorting for the logfiles. Sort in reverse order on the timestamp so the last files will be on top.
Michiel Broek <mbroek@mbse.eu>
parents:
64
diff
changeset
|
107 | else |
9d2c0a85ee6e
Added directory sorting for the logfiles. Sort in reverse order on the timestamp so the last files will be on top.
Michiel Broek <mbroek@mbse.eu>
parents:
64
diff
changeset
|
108 | ta->next = NULL; |
9d2c0a85ee6e
Added directory sorting for the logfiles. Sort in reverse order on the timestamp so the last files will be on top.
Michiel Broek <mbroek@mbse.eu>
parents:
64
diff
changeset
|
109 | } |
9d2c0a85ee6e
Added directory sorting for the logfiles. Sort in reverse order on the timestamp so the last files will be on top.
Michiel Broek <mbroek@mbse.eu>
parents:
64
diff
changeset
|
110 | |
9d2c0a85ee6e
Added directory sorting for the logfiles. Sort in reverse order on the timestamp so the last files will be on top.
Michiel Broek <mbroek@mbse.eu>
parents:
64
diff
changeset
|
111 | free(vector); |
9d2c0a85ee6e
Added directory sorting for the logfiles. Sort in reverse order on the timestamp so the last files will be on top.
Michiel Broek <mbroek@mbse.eu>
parents:
64
diff
changeset
|
112 | return; |
9d2c0a85ee6e
Added directory sorting for the logfiles. Sort in reverse order on the timestamp so the last files will be on top.
Michiel Broek <mbroek@mbse.eu>
parents:
64
diff
changeset
|
113 | } |
9d2c0a85ee6e
Added directory sorting for the logfiles. Sort in reverse order on the timestamp so the last files will be on top.
Michiel Broek <mbroek@mbse.eu>
parents:
64
diff
changeset
|
114 | |
9d2c0a85ee6e
Added directory sorting for the logfiles. Sort in reverse order on the timestamp so the last files will be on top.
Michiel Broek <mbroek@mbse.eu>
parents:
64
diff
changeset
|
115 | |
142
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
116 | #define CHECK_FILE_EXTENSION(filename, ext) (strcasecmp(&filename[strlen(filename) - strlen(ext)], ext) == 0) |
0 | 117 | |
1
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
118 | /** |
142
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
119 | * @brief Set HTTP response content type according to file extension |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
120 | * @param req The request where the content type will be set. |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
121 | * @param filepath The filename to get the extension from. |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
122 | * @return ESP_OK if success. |
1
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
123 | */ |
142
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
124 | static esp_err_t set_content_type_from_file(httpd_req_t *req, const char *filepath) |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
125 | { |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
126 | const char *type = "text/plain"; |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
127 | if (CHECK_FILE_EXTENSION(filepath, ".html")) { |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
128 | type = "text/html"; |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
129 | } else if (CHECK_FILE_EXTENSION(filepath, ".log")) { |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
130 | type = "text/plain"; |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
131 | } else if (CHECK_FILE_EXTENSION(filepath, ".js")) { |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
132 | type = "application/javascript"; |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
133 | } else if (CHECK_FILE_EXTENSION(filepath, ".json")) { |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
134 | type = "text/json"; |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
135 | } else if (CHECK_FILE_EXTENSION(filepath, ".gz")) { |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
136 | type = "application/x-gzip"; |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
137 | } else if (CHECK_FILE_EXTENSION(filepath, ".css")) { |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
138 | type = "text/css"; |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
139 | } else if (CHECK_FILE_EXTENSION(filepath, ".png")) { |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
140 | type = "image/png"; |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
141 | } else if (CHECK_FILE_EXTENSION(filepath, ".ico")) { |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
142 | type = "image/x-icon"; |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
143 | } else if (CHECK_FILE_EXTENSION(filepath, ".svg")) { |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
144 | type = "text/xml"; |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
145 | } else if (CHECK_FILE_EXTENSION(filepath, ".ttf")) { |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
146 | type = "font/ttf"; |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
147 | } else if (CHECK_FILE_EXTENSION(filepath, ".woff")) { |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
148 | type = "font/woff"; |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
149 | } else if (CHECK_FILE_EXTENSION(filepath, ".woff2")) { |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
150 | type = "font/woff2"; |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
151 | } else if (CHECK_FILE_EXTENSION(filepath, ".xml")) { |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
152 | type = "text/xml"; |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
153 | } |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
154 | return httpd_resp_set_type(req, type); |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
155 | } |
0 | 156 | |
1
ad2c8b13eb88
Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
157 | |
0 | 158 | /** |
142
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
159 | * @brief Send text message to a single websocket client. |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
160 | * @param num The client socket to send to. |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
161 | * @param msg The message to send. |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
162 | * @return ESP_OK. |
0 | 163 | */ |
142
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
164 | int ws_server_send_text_client(int num, char* msg) |
0 | 165 | { |
142
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
166 | httpd_ws_frame_t ws_pkt; |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
167 | |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
168 | memset(&ws_pkt, 0, sizeof(httpd_ws_frame_t)); |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
169 | ws_pkt.type = HTTPD_WS_TYPE_TEXT; |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
170 | ws_pkt.len = strlen(msg); |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
171 | ws_pkt.payload = (uint8_t*)msg; |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
172 | httpd_ws_send_frame_async(web_server, num, &ws_pkt); |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
173 | ESP_LOGD(TAG, "ws_server_send_text_client(%d, %s)", num, msg); |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
174 | return ESP_OK; |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
175 | } |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
176 | |
0 | 177 | |
142
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
178 | /** |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
179 | * @brief Broadcast text message to all connected websocket clients. |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
180 | * @param msg The text message. |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
181 | * @return -1 if error, else the number of clients. |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
182 | */ |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
183 | int ws_server_send_text_clients(char* msg) |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
184 | { |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
185 | httpd_ws_frame_t ws_pkt; |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
186 | static size_t max_clients = CONFIG_LWIP_MAX_LISTENING_TCP; |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
187 | size_t fds = max_clients; |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
188 | int client_fds[CONFIG_LWIP_MAX_LISTENING_TCP] = {0}; |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
189 | int count = 0; |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
190 | |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
191 | memset(&ws_pkt, 0, sizeof(httpd_ws_frame_t)); |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
192 | ws_pkt.type = HTTPD_WS_TYPE_TEXT; |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
193 | ws_pkt.len = strlen(msg); |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
194 | ws_pkt.payload = (uint8_t*)msg; |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
195 | |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
196 | esp_err_t ret = httpd_get_client_list(web_server, &fds, client_fds); |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
197 | if (ret != ESP_OK) { |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
198 | return -1; |
0 | 199 | } |
142
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
200 | |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
201 | for (int i = 0; i < fds; i++) { |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
202 | httpd_ws_client_info_t client_info = httpd_ws_get_fd_info(web_server, client_fds[i]); |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
203 | if (client_info == HTTPD_WS_CLIENT_WEBSOCKET) { |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
204 | httpd_ws_send_frame_async(web_server, client_fds[i], &ws_pkt); |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
205 | count++; |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
206 | } |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
207 | } |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
208 | return count; |
0 | 209 | } |
210 | ||
211 | ||
142
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
212 | /** |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
213 | * @brief Websocket handler. |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
214 | * @param req The request structure. |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
215 | * @return ESP_OK or error. |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
216 | */ |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
217 | static esp_err_t ws_handler(httpd_req_t *req) |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
218 | { |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
219 | if (req->method == HTTP_GET) { |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
220 | ESP_LOGI(TAG, "New websocket connection %d", httpd_req_to_sockfd(req)); |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
221 | /* Send initial screen */ |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
222 | TFTstartWS(httpd_req_to_sockfd(req)); |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
223 | return ESP_OK; |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
224 | } |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
225 | |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
226 | httpd_ws_frame_t ws_pkt; |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
227 | uint8_t *buf = NULL; |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
228 | char jbuf[128]; |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
229 | cJSON *root = NULL, *touch = NULL; |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
230 | |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
231 | memset(&ws_pkt, 0, sizeof(httpd_ws_frame_t)); |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
232 | ws_pkt.type = HTTPD_WS_TYPE_TEXT; |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
233 | /* Set max_len = 0 to get the frame len */ |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
234 | esp_err_t ret = httpd_ws_recv_frame(req, &ws_pkt, 0); |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
235 | if (ret != ESP_OK) { |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
236 | ESP_LOGE(TAG, "ws_handler() httpd_ws_recv_frame failed to get frame len with %d", ret); |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
237 | return ret; |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
238 | } |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
239 | ESP_LOGD(TAG, "frame len is %d type is %d socket %d", ws_pkt.len, ws_pkt.type, httpd_req_to_sockfd(req)); |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
240 | |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
241 | if (ws_pkt.len) { |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
242 | /* ws_pkt.len + 1 is for NULL termination as we are expecting a string */ |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
243 | buf = calloc(1, ws_pkt.len + 1); |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
244 | if (buf == NULL) { |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
245 | ESP_LOGE(TAG, "ws_handler() no memory for buf"); |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
246 | return ESP_ERR_NO_MEM; |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
247 | } |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
248 | ws_pkt.payload = buf; |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
249 | /* Set max_len = ws_pkt.len to get the frame payload */ |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
250 | ret = httpd_ws_recv_frame(req, &ws_pkt, ws_pkt.len); |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
251 | if (ret != ESP_OK) { |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
252 | ESP_LOGE(TAG, "ws_handler() httpd_ws_recv_frame failed with %d", ret); |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
253 | free(buf); |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
254 | return ret; |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
255 | } |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
256 | ESP_LOGI(TAG, "ws_handler() Got message: %s", ws_pkt.payload); |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
257 | } |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
258 | |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
259 | if ((ws_pkt.type == HTTPD_WS_TYPE_TEXT) && (ws_pkt.len > 0) && (ws_pkt.len < 128)) { |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
260 | memcpy(jbuf, ws_pkt.payload, ws_pkt.len); |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
261 | jbuf[ws_pkt.len] = '\0'; |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
262 | if ((root = cJSON_Parse(jbuf))) { |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
263 | if ((touch = cJSON_GetObjectItem(root,"touch"))) { |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
264 | int x = cJSON_GetObjectItem(touch, "x")->valueint; |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
265 | int y = cJSON_GetObjectItem(touch, "y")->valueint; |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
266 | WS_touched(x, y); |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
267 | } else { |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
268 | ESP_LOGI(TAG,"not json touch"); |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
269 | } |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
270 | cJSON_Delete(root); |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
271 | } else { |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
272 | ESP_LOGI(TAG,"not json"); |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
273 | } |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
274 | } |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
275 | |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
276 | free(buf); |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
277 | return ESP_OK; |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
278 | } |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
279 | |
0 | 280 | |
281 | /** | |
142
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
282 | * @brief Handle files download from /spiffs or /sdcard. |
0 | 283 | */ |
142
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
284 | static esp_err_t files_handler(httpd_req_t *req) |
0 | 285 | { |
142
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
286 | char temp_url[560], temp_url_gz[564]; |
0 | 287 | struct stat st; |
288 | off_t filesize; | |
289 | char strftime_buf[64]; | |
290 | bool send_gz; | |
142
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
291 | int fd = -1; |
0 | 292 | |
142
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
293 | if (req->uri[strlen(req->uri) - 1] == '/') { |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
294 | // If no filename given, use index.html |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
295 | sprintf(temp_url, "/spiffs/w%sindex.html", req->uri); |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
296 | } else if (strncmp(req->uri, "/log/", 5) == 0) { |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
297 | // Logfiles are on the SD card. |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
298 | sprintf(temp_url, "/sdcard/w%s", req->uri); |
0 | 299 | } else { |
142
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
300 | sprintf(temp_url, "/spiffs/w%s", req->uri); |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
301 | for (int i = 0; i < 127; i++) { |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
302 | if (temp_url[i] == '?') |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
303 | temp_url[i] = '\0'; |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
304 | if (temp_url[i] == '\0') |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
305 | break; |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
306 | } |
0 | 307 | } |
142
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
308 | snprintf(temp_url_gz, 563, "%s.gz", temp_url); |
0 | 309 | |
310 | /* | |
311 | * Get filesize and date for the response headers. | |
312 | * Note that the /spiffs filesystem doesn't support file timestamps | |
313 | * and returns the epoch for each file. Therefore we cannot use | |
314 | * the cache based on timestamps. | |
315 | */ | |
316 | filesize = 0; | |
317 | strftime_buf[0] = '\0'; | |
318 | send_gz = false; | |
319 | if (stat(temp_url_gz, &st) == 0) { | |
142
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
320 | /* The requested file is gzipped. */ |
0 | 321 | filesize = st.st_size; |
322 | strftime(strftime_buf, sizeof(strftime_buf), "%a, %d %b %Y %T %z", localtime(&(st.st_mtime))); | |
323 | send_gz = true; | |
324 | } else if (stat(temp_url, &st) == 0) { | |
325 | filesize = st.st_size; | |
326 | strftime(strftime_buf, sizeof(strftime_buf), "%a, %d %b %Y %T %z", localtime(&(st.st_mtime))); | |
327 | } | |
142
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
328 | ESP_LOGI(TAG, "GET `%s` file %s date %s size %d", req->uri, (send_gz) ? temp_url_gz : temp_url, strftime_buf, (int)filesize); |
0 | 329 | |
330 | if (send_gz) { | |
142
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
331 | fd = open(temp_url_gz, O_RDONLY, 0); |
0 | 332 | } else { |
142
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
333 | fd = open(temp_url, O_RDONLY, 0); |
0 | 334 | } |
142
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
335 | if (fd == -1) { |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
336 | ESP_LOGI(TAG, "files_handler() file not found"); |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
337 | httpd_resp_send_err(req, HTTPD_404_NOT_FOUND, "File does not exist"); |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
338 | return ESP_FAIL; |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
339 | } |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
340 | |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
341 | set_content_type_from_file(req, temp_url); |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
342 | if (send_gz) { |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
343 | httpd_resp_set_hdr(req, "Content-Encoding", "gzip"); |
0 | 344 | } |
345 | ||
142
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
346 | /* |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
347 | * Now the real file send in chunks. |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
348 | */ |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
349 | char *chunk = malloc(1024); |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
350 | ssize_t read_bytes; |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
351 | do { |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
352 | read_bytes = read(fd, chunk, 1024); |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
353 | if (read_bytes == -1) { |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
354 | ESP_LOGE(TAG, "files_handler() Failed to read file : %s", (send_gz) ? temp_url_gz : temp_url); |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
355 | } else if (read_bytes > 0) { |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
356 | /* Send the buffer contents as HTTP response chunk */ |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
357 | if (httpd_resp_send_chunk(req, chunk, read_bytes) != ESP_OK) { |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
358 | close(fd); |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
359 | ESP_LOGE(TAG, "files_handler() File sending failed!"); |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
360 | /* Abort sending file */ |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
361 | httpd_resp_sendstr_chunk(req, NULL); |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
362 | /* Respond with 500 Internal Server Error */ |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
363 | httpd_resp_send_err(req, HTTPD_500_INTERNAL_SERVER_ERROR, "Failed to send file"); |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
364 | return ESP_FAIL; |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
365 | } |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
366 | } |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
367 | } while (read_bytes > 0); |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
368 | /* Close file after sending complete */ |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
369 | close(fd); |
0 | 370 | |
142
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
371 | /* Respond with an empty chunk to signal HTTP response completion */ |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
372 | httpd_resp_send_chunk(req, NULL, 0); |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
373 | return ESP_OK; |
0 | 374 | } |
375 | ||
376 | ||
377 | /** | |
142
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
378 | * @brief Handle 'GET /logfiles.json' |
0 | 379 | */ |
142
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
380 | static esp_err_t logfiles_handler(httpd_req_t *req) |
0 | 381 | { |
142
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
382 | ls_list *lsx = NULL, *tmp; |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
383 | char temp[64]; |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
384 | FILE *dest = fopen("/spiffs/w/logfiles.json", "w"); |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
385 | |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
386 | if (dest) { |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
387 | DIR *dir = opendir("/sdcard/w/log"); |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
388 | if (dir) { |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
389 | struct dirent* de = readdir(dir); |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
390 | struct stat st; |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
391 | while (de) { |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
392 | snprintf(temp, 63, "/sdcard/w/log/"); |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
393 | strncat(temp, de->d_name, 63 - strlen(temp)); |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
394 | if (stat(temp, &st) == ESP_OK) { |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
395 | fill_list(&lsx, de->d_name, st.st_size, st.st_mtime); |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
396 | } |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
397 | de = readdir(dir); |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
398 | vTaskDelay(5 / portTICK_PERIOD_MS); |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
399 | } |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
400 | closedir(dir); |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
401 | } else { |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
402 | ESP_LOGE(TAG, "Error %d open directory /sdcard/w/log", errno); |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
403 | } |
41
7639cfa6aec0
Websocket interface is working for the main screen and manual mode.
Michiel Broek <mbroek@mbse.eu>
parents:
38
diff
changeset
|
404 | |
142
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
405 | sort_list(&lsx); |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
406 | bool comma = false; |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
407 | fprintf(dest, "{\"Dir\":[{\"Folder\":\"/log\",\"Files\":["); |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
408 | for (tmp = lsx; tmp; tmp = tmp->next) { |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
409 | fprintf(dest, "%s{\"File\":\"%s\",\"Size\":%ld,\"Date\":%ld}", (comma)?",":"", tmp->d_name, tmp->size, tmp->mtime); |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
410 | comma = true; |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
411 | } |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
412 | fprintf(dest, "]}]}"); |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
413 | fclose(dest); |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
414 | tidy_lslist(&lsx); |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
415 | } else { |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
416 | ESP_LOGE(TAG, "Error %d write /spiffs/w/logfiles.json", errno); |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
417 | httpd_resp_send_err(req, HTTPD_500_INTERNAL_SERVER_ERROR, "Failed to create file"); |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
418 | return ESP_FAIL; |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
419 | } |
0 | 420 | |
142
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
421 | /* |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
422 | * File is ready, send it using the files_handler(). |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
423 | */ |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
424 | esp_err_t ret = files_handler(req); |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
425 | unlink("/spiffs/w/logfiles.json"); |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
426 | return ret; |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
427 | } |
0 | 428 | |
142
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
429 | |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
430 | esp_err_t start_webserver(void) |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
431 | { |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
432 | httpd_config_t config = HTTPD_DEFAULT_CONFIG(); |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
433 | config.lru_purge_enable = true; |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
434 | config.uri_match_fn = httpd_uri_match_wildcard; |
0 | 435 | |
142
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
436 | // Start the httpd server |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
437 | if (web_server == NULL) { |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
438 | ESP_LOGI(TAG, "Starting httpd on port: '%d'", config.server_port); |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
439 | if (httpd_start(&web_server, &config) == ESP_OK) { |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
440 | // Set URI handlers |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
441 | ESP_LOGD(TAG, "Registering URI handlers"); |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
442 | |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
443 | httpd_uri_t ws = { |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
444 | .uri = "/ws", |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
445 | .method = HTTP_GET, |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
446 | .handler = ws_handler, |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
447 | .user_ctx = NULL, |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
448 | .is_websocket = true |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
449 | }; |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
450 | httpd_register_uri_handler(web_server, &ws); |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
451 | |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
452 | httpd_uri_t logfiles = { |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
453 | .uri = "/logfiles.json", |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
454 | .method = HTTP_GET, |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
455 | .handler = logfiles_handler, |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
456 | .user_ctx = NULL |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
457 | }; |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
458 | httpd_register_uri_handler(web_server, &logfiles); |
0 | 459 | |
142
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
460 | httpd_uri_t vfs_files = { |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
461 | .uri = "/*", |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
462 | .method = HTTP_GET, |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
463 | .handler = files_handler, |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
464 | .user_ctx = NULL |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
465 | }; |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
466 | httpd_register_uri_handler(web_server, &vfs_files); |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
467 | return ESP_OK; |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
468 | } |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
469 | } else { |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
470 | ESP_LOGI(TAG, "httpd server already started"); |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
471 | return ESP_OK; |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
472 | } |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
473 | |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
474 | ESP_LOGI(TAG, "Error starting server!"); |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
475 | return ESP_FAIL; |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
476 | } |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
477 | |
0 | 478 | |
142
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
479 | static esp_err_t stop_webserver(void) |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
480 | { |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
481 | esp_err_t ret; |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
482 | |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
483 | ESP_LOGI(TAG, "Stopping httpd server"); |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
484 | ret = httpd_stop(web_server); |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
485 | web_server = NULL; |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
486 | return ret; |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
487 | } |
0 | 488 | |
142
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
489 | |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
490 | static void disconnect_handler(void* arg, esp_event_base_t event_base, int32_t event_id, void* event_data) |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
491 | { |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
492 | if (web_server) { |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
493 | if (stop_webserver() == ESP_OK) { |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
494 | web_server = NULL; |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
495 | } else { |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
496 | ESP_LOGE(TAG, "Failed to stop http server"); |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
497 | } |
0 | 498 | } |
499 | } | |
500 | ||
501 | ||
142
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
502 | static void connect_handler(void* arg, esp_event_base_t event_base, int32_t event_id, void* event_data) |
0 | 503 | { |
142
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
504 | start_webserver(); |
0 | 505 | } |
506 | ||
507 | ||
508 | /** | |
142
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
509 | * @brief Install the HTTP server event handlers. |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
510 | * The real server is started and stopped on events. |
0 | 511 | */ |
142
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
512 | void install_http_server(void) |
0 | 513 | { |
142
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
514 | ESP_LOGI(TAG, "Install HTTP server"); |
0 | 515 | |
142
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
516 | /* |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
517 | * Respond to WiFi and network events. This is much better then letting the |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
518 | * server run forever. |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
519 | */ |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
520 | ESP_ERROR_CHECK(esp_event_handler_register(IP_EVENT, IP_EVENT_STA_GOT_IP, &connect_handler, web_server)); |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
521 | ESP_ERROR_CHECK(esp_event_handler_register(IP_EVENT, IP_EVENT_STA_LOST_IP, &disconnect_handler, web_server)); |
1f7069278fe7
Version 0.4.2. Removed the components/websocket server and switched to the official http and websockets server. This server will also recover if the wifi connection disconnects and reconnects.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
522 | ESP_ERROR_CHECK(esp_event_handler_register(WIFI_EVENT, WIFI_EVENT_STA_DISCONNECTED, &disconnect_handler, web_server)); |
0 | 523 | } |
524 | ||
525 |