-
-
Notifications
You must be signed in to change notification settings - Fork 348
Expand file tree
/
Copy pathapplication.cpp
More file actions
85 lines (68 loc) · 1.87 KB
/
application.cpp
File metadata and controls
85 lines (68 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include <SmingCore.h>
#include <WebcamStream.h>
#include <Camera/FakeCamera.h>
// If you want, you can define WiFi settings globally in Eclipse Environment Variables
#ifndef WIFI_SSID
#define WIFI_SSID "PleaseEnterSSID" // Put your SSID and password here
#define WIFI_PWD "PleaseEnterPass"
#endif
namespace
{
HttpServer server;
FakeCamera* camera;
/*
* default http handler to check if server is up and running
*/
void onIndex(HttpRequest&, HttpResponse& response)
{
response.sendFile(_F("index.html"));
}
void onFile(HttpRequest& request, HttpResponse& response)
{
String file = request.uri.getRelativePath();
if(file[0] == '.') {
response.code = HTTP_STATUS_FORBIDDEN;
} else {
response.setCache(86400, true); // It's important to use cache for better performance.
response.sendFile(file);
}
}
void onStream(HttpRequest& request, HttpResponse& response)
{
Serial.println(_F("perform onCapture()"));
WebcamStream* stream = new WebcamStream(camera);
response.sendDataStream(stream, F("multipart/x-mixed-replace; boundary=") + stream->getBoundary());
}
void onFavicon(HttpRequest& request, HttpResponse& response)
{
response.code = HTTP_STATUS_NOT_FOUND;
}
// Will be called when station is fully operational
void startWebServer()
{
// Initialize the camera
Vector<String> images;
for(unsigned int i = 1; i < 6; i++) {
String s = "img";
s.concat(i, DEC, 2);
s += ".jpeg";
images.add(s);
}
camera = new FakeCamera(images);
camera->init();
// .. and run the HTTP server
server.listen(80);
server.paths.set("/", onIndex);
server.paths.set("/stream", onStream);
server.paths.set("/favicon.ico", onFavicon);
server.paths.setDefault(onFile);
}
} // namespace
void init()
{
Serial.begin(SERIAL_BAUD_RATE); // Enable serial
Serial.systemDebugOutput(true); // Allow debug output to serial
spiffs_mount();
WifiStation.enable(true);
System.onReady(startWebServer);
}