docs: swap _all_protocol_vhost cut and paste
[platform/upstream/libwebsockets.git] / plugins / protocol_esp32_lws_reboot_to_factory.c
1 /*
2  * Example ESP32 app code using Libwebsockets
3  *
4  * Copyright (C) 2017 Andy Green <andy@warmcat.com>
5  *
6  *  This library is free software; you can redistribute it and/or
7  *  modify it under the terms of the GNU Lesser General Public
8  *  License as published by the Free Software Foundation:
9  *  version 2.1 of the License.
10  *
11  *  This library is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  *  Lesser General Public License for more details.
15  *
16  *  You should have received a copy of the GNU Lesser General Public
17  *  License along with this library; if not, write to the Free Software
18  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19  *  MA  02110-1301  USA
20  *
21  * This is intended to be mounted somewhere in your ESP32 user app... if the
22  * client touched the mount, the plugin hangs up and reboots into the
23  * factory mode one second later.
24  *
25  * The factory mode will reassociate with the same IP with the same MAC
26  * shortly afterwards and be accessible by the same IP / mDNS name.
27  */
28 #include <string.h>
29 #include <esp_partition.h>
30 #include <esp_ota_ops.h>
31 #include <nvs.h>
32
33 static int
34 callback_esplws_rtf(struct lws *wsi, enum lws_callback_reasons reason,
35                     void *user, void *in, size_t len)
36 {
37         switch (reason) {
38
39         case LWS_CALLBACK_HTTP:
40                 
41                 lws_esp32_restart_guided(LWS_MAGIC_REBOOT_TYPE_REQ_FACTORY);
42                 return 1;
43
44         default:
45                 break;
46         }
47
48         return 0;
49 }
50
51 #define LWS_PLUGIN_PROTOCOL_ESPLWS_RTF \
52         { \
53                 "esplws-rtf", \
54                 callback_esplws_rtf, \
55                 0, \
56                 10, 0, NULL, 0 \
57         }
58