@@ -26,7 +26,9 @@ void testCallback(HTTPRequest * req, HTTPResponse * res) {
26
26
res->println (" </head>" );
27
27
res->println (" <body>" );
28
28
res->println (" <h1>Hello world!</h1>" );
29
- res->println (" <p>From your ESP32</p>" );
29
+ res->println (" <p>... from your ESP32</p>" );
30
+ // The image resource is created in the awesomeCallback some lines below
31
+ res->println (" <img src=\" images/awesome.svg\" alt=\" Awesome face\" />" );
30
32
res->print (" <p>System has been up for " );
31
33
res->print ((int )(millis ()/1000 ), DEC);
32
34
res->println (" seconds.</p>" );
@@ -46,6 +48,27 @@ void faviconCallback(HTTPRequest * req, HTTPResponse * res) {
46
48
res->write (FAVICON_DATA, FAVICON_LENGTH);
47
49
}
48
50
51
+ void awesomeCallback (HTTPRequest * req, HTTPResponse * res) {
52
+ res->setHeader (" Content-Type" , " image/svg+xml" );
53
+ // We can write anything here :)
54
+ res->setStatusText (" Awesome" );
55
+
56
+ // Print the data
57
+ // Source: https://commons.wikimedia.org/wiki/File:718smiley.svg
58
+ res->print (" <?xml version=\" 1.0\" encoding=\" UTF-8\" standalone=\" no\" ?>" );
59
+ res->print (" <svg id=\" svg1923\" width=\" 733\" xmlns=\" http://www.w3.org/2000/svg\" height=\" 733\" >" );
60
+ res->print (" <circle cy=\" 366.5\" cx=\" 366.5\" r=\" 366.5\" />" );
61
+ res->print (" <circle cy=\" 366.5\" cx=\" 366.5\" r=\" 336.5\" fill=\" #fede58\" />" );
62
+ res->print (" <path d=\" m325 665c-121-21-194-115-212-233v-8l-25-1-1-18h481c6 13 10 27 13 41 13 94-38 146-114 193-45 23-93 29-142 26z\" />" );
63
+ res->print (" <path d=\" m372 647c52-6 98-28 138-62 28-25 46-56 51-87 4-20 1-57-5-70l-423-1c-2 56 39 118 74 157 31 34 72 54 116 63 11 2 38 2 49 0z\" fill=\" #871945\" />" );
64
+ res->print (" <path d=\" m76 342c-13-26-13-57-9-85 6-27 18-52 35-68 21-20 50-23 77-18 15 4 28 12 39 23 18 17 30 40 36 67 4 20 4 41 0 60l-6 21z\" />" );
65
+ res->print (" <path d=\" m234 323c5-6 6-40 2-58-3-16-4-16-10-10-14 14-38 14-52 0-15-18-12-41 6-55 3-3 5-5 5-6-1-4-22-8-34-7-42 4-57.6 40-66.2 77-3 17-1 53 4 59h145.2z\" fill=\" #fff\" />" );
66
+ res->print (" <path d=\" m378 343c-2-3-6-20-7-29-5-28-1-57 11-83 15-30 41-52 72-60 29-7 57 0 82 15 26 17 45 49 50 82 2 12 2 33 0 45-1 10-5 26-8 30z\" />" );
67
+ res->print (" <path d=\" m565 324c4-5 5-34 4-50-2-14-6-24-8-24-1 0-3 2-6 5-17 17-47 13-58-9-7-16-4-31 8-43 4-4 7-8 7-9 0 0-4-2-8-3-51-17-105 20-115 80-3 15 0 43 3 53z\" fill=\" #fff\" />" );
68
+ res->print (" <path d=\" m504 590s-46 40-105 53c-66 15-114-7-114-7s14-76 93-95c76-18 126 49 126 49z\" fill=\" #f9bedd\" />" );
69
+ res->print (" </svg>" );
70
+ }
71
+
49
72
/* *
50
73
* This callback will be registered as default callback. The default callback is used
51
74
* if no other node matches the request.
@@ -128,6 +151,9 @@ void serverTask(void *params) {
128
151
// is used to show the icon in the tab of that website.
129
152
ResourceNode faviconNode = ResourceNode (" /favicon.ico" , " GET" , &faviconCallback);
130
153
154
+ // The awesomeCallback is very similar to the favicon.
155
+ ResourceNode awesomeNode = ResourceNode (" /images/awesome.svg" , " GET" , &awesomeCallback);
156
+
131
157
// The root node (on GET /) will be called when no directory on the server is specified in
132
158
// the request, so this node can be accessed through https://myesp/
133
159
ResourceNode rootNode = ResourceNode (" /" , " GET" , &testCallback);
@@ -147,6 +173,7 @@ void serverTask(void *params) {
147
173
server.setDefaultNode (¬FoundNode);
148
174
server.registerNode (&rootNode);
149
175
server.registerNode (&faviconNode);
176
+ server.registerNode (&awesomeNode);
150
177
151
178
// The web server can be start()ed and stop()ed. When it's stopped, it will close its server port and
152
179
// all open connections and free the resources. Theoretically, it should be possible to run multiple
0 commit comments