Skip to content

Commit aa598b0

Browse files
committed
add push picture
1 parent 4c9ab6e commit aa598b0

File tree

6 files changed

+612
-322
lines changed

6 files changed

+612
-322
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
myconfig.h
2+
myconfig2.h
23
.pioenvs
34
.piolibdeps
45
.clang_complete
56
.gcc-flags.json
67
.pio
7-
.vscode
8+
.vscode
9+
/logs

app_httpd.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ void serialDump() {
148148
int McuTf = temprature_sens_read(); // fahrenheit
149149
Serial.printf("System up: %" PRId64 ":%02i:%02i:%02i (d:h:m:s)\r\n", upDays, upHours, upMin, upSec);
150150
Serial.printf("Active streams: %i, Previous streams: %lu, Images captured: %lu\r\n", streamCount, streamsServed, imagesServed);
151-
Serial.printf("CPU Freq: %i MHz, Xclk Freq: %i MHz\r\n", ESP.getCpuFreqMHz(), xclk);
151+
Serial.printf("CPU Freq: %i MHz, Xclk Freq: %lu MHz\r\n", ESP.getCpuFreqMHz(), xclk);
152152
Serial.printf("MCU temperature : %i C, %i F (approximate)\r\n", McuTc, McuTf);
153153
Serial.printf("Heap: %i, free: %i, min free: %i, max block: %i\r\n", ESP.getHeapSize(), ESP.getFreeHeap(), ESP.getMinFreeHeap(), ESP.getMaxAllocHeap());
154154
if(psramFound()) {
@@ -449,7 +449,7 @@ static esp_err_t status_handler(httpd_req_t *req){
449449
p+=sprintf(p, "\"min_frame_time\":%d,", minFrameTime);
450450
p+=sprintf(p, "\"framesize\":%u,", s->status.framesize);
451451
p+=sprintf(p, "\"quality\":%u,", s->status.quality);
452-
p+=sprintf(p, "\"xclk\":%u,", xclk);
452+
p+=sprintf(p, "\"xclk\":%lu,", xclk);
453453
p+=sprintf(p, "\"brightness\":%d,", s->status.brightness);
454454
p+=sprintf(p, "\"contrast\":%d,", s->status.contrast);
455455
p+=sprintf(p, "\"saturation\":%d,", s->status.saturation);
@@ -598,7 +598,7 @@ static esp_err_t dump_handler(httpd_req_t *req){
598598

599599
d+= sprintf(d,"Up: %" PRId64 ":%02i:%02i:%02i (d:h:m:s)<br>\n", upDays, upHours, upMin, upSec);
600600
d+= sprintf(d,"Active streams: %i, Previous streams: %lu, Images captured: %lu<br>\n", streamCount, streamsServed, imagesServed);
601-
d+= sprintf(d,"CPU Freq: %i MHz, Xclk Freq: %i MHz<br>\n", ESP.getCpuFreqMHz(), xclk);
601+
d+= sprintf(d,"CPU Freq: %i MHz, Xclk Freq: %lu MHz<br>\n", ESP.getCpuFreqMHz(), xclk);
602602
d+= sprintf(d,"<span title=\"NOTE: Internal temperature sensor readings can be innacurate on the ESP32-c1 chipset, and may vary significantly between devices!\">");
603603
d+= sprintf(d,"MCU temperature : %i &deg;C, %i &deg;F</span>\n<br>", McuTc, McuTf);
604604
d+= sprintf(d,"Heap: %i, free: %i, min free: %i, max block: %i<br>\n", ESP.getHeapSize(), ESP.getFreeHeap(), ESP.getMinFreeHeap(), ESP.getMaxAllocHeap());

camsend.cpp

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
#include <HTTPClient.h>
2+
#include "cert.h"
3+
#include "myconfig2.h"
4+
#include <esp_camera.h>
5+
6+
7+
// Functions from the main .ino
8+
extern void flashLED(int flashtime);
9+
extern void setLamp(int newVal);
10+
11+
extern int lampVal;
12+
extern bool autoLamp;
13+
extern bool debugData;
14+
15+
/*
16+
17+
send weather data to villa using https
18+
19+
*/
20+
esp_err_t SendPictureHttp()
21+
{
22+
23+
camera_fb_t *fb = NULL;
24+
esp_err_t res = ESP_OK;
25+
26+
Serial.print("SendPictureHttp ");
27+
Serial.println(PICTURE);
28+
if (autoLamp && (lampVal != -1))
29+
{
30+
setLamp(lampVal);
31+
delay(75); // coupled with the status led flash this gives ~150ms for lamp to settle.
32+
}
33+
flashLED(75); // little flash of status LED
34+
35+
int64_t fr_start = esp_timer_get_time();
36+
37+
fb = esp_camera_fb_get();
38+
if (!fb)
39+
{
40+
Serial.println("CAPTURE: failed to acquire frame");
41+
if (autoLamp && (lampVal != -1))
42+
setLamp(0);
43+
esp_camera_return_all();
44+
return ESP_FAIL;
45+
}
46+
47+
size_t fb_len = 0;
48+
if (fb->format == PIXFORMAT_JPEG)
49+
{
50+
fb_len = fb->len;
51+
HTTPClient http;
52+
53+
http.begin(CAMSERVER, root_ca); // Specify the URL and certificate
54+
http.addHeader("Content-Type", "image/jpeg");
55+
http.addHeader("Content-Length", String(fb_len));
56+
http.addHeader("Filename", PICTURE);
57+
58+
int httpCode = http.POST(fb->buf, fb->len);
59+
60+
if (httpCode > 0)
61+
{ // Check for the returning code
62+
63+
String payload = http.getString();
64+
Serial.println(httpCode);
65+
}
66+
else
67+
{
68+
Serial.println("Error on HTTP request " + String(httpCode));
69+
res = ESP_FAIL;
70+
}
71+
http.end(); // Free the resources
72+
}
73+
else
74+
{
75+
res = ESP_FAIL;
76+
Serial.println("Capture Error: Non-JPEG image returned by camera module");
77+
}
78+
esp_camera_fb_return(fb);
79+
fb = NULL;
80+
81+
int64_t fr_end = esp_timer_get_time();
82+
if (debugData)
83+
{
84+
Serial.printf("JPG: %uB %ums\r\n", (uint32_t)(fb_len), (uint32_t)((fr_end - fr_start) / 1000));
85+
}
86+
87+
if (autoLamp && (lampVal != -1))
88+
{
89+
setLamp(0);
90+
}
91+
92+
return res;
93+
}

cert.h

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#ifndef __CERTLETS__
2+
#define __CERTLETS__
3+
4+
// lets encrypt R3
5+
const char *root_ca =
6+
"-----BEGIN CERTIFICATE-----\n"
7+
"MIIFFjCCAv6gAwIBAgIRAJErCErPDBinU/bWLiWnX1owDQYJKoZIhvcNAQELBQAw\n"
8+
"TzELMAkGA1UEBhMCVVMxKTAnBgNVBAoTIEludGVybmV0IFNlY3VyaXR5IFJlc2Vh\n"
9+
"c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