Update multi-cam.ino

This commit is contained in:
andri 2026-04-09 06:44:15 +00:00
parent 1b8745a144
commit 3beaad3e57
1 changed files with 9 additions and 15 deletions

View File

@ -8,9 +8,10 @@ const char* ssid = "3";
const char* password = "12345678"; const char* password = "12345678";
const char* server_backend = "http://iotcam.appku.asia/api/register"; // Ganti IP Node.js kamu const char* server_backend = "http://iotcam.appku.asia/api/register"; // Ganti IP Node.js kamu
// --- IDENTITAS KAMERA (GANTI UNTUK TIAP ESP32) --- // --- IDENTITAS KAMERA ---
const char* cam_id = "CCTV_01"; // GANTI ID INI UNTUK SETIAP ESP32 YANG BERBEDA (Misal: CCTV_01, CCTV_02)
const char* cam_name = "Kamera Depan"; const String cam_id = "CCTV_01";
const String cam_name = "Kamera Mobile";
#define PART_BOUNDARY "123456789000000000000987654321" #define PART_BOUNDARY "123456789000000000000987654321"
static const char* _STREAM_CONTENT_TYPE = "multipart/x-mixed-replace;boundary=" PART_BOUNDARY; static const char* _STREAM_CONTENT_TYPE = "multipart/x-mixed-replace;boundary=" PART_BOUNDARY;
@ -20,7 +21,6 @@ static const char* _STREAM_PART = "Content-Type: image/jpeg\r\nContent-Length: %
httpd_handle_t api_httpd = NULL; httpd_handle_t api_httpd = NULL;
httpd_handle_t stream_httpd = NULL; httpd_handle_t stream_httpd = NULL;
// Definisi Pin untuk Board AI-Thinker
#define PWDN_GPIO_NUM 32 #define PWDN_GPIO_NUM 32
#define RESET_GPIO_NUM -1 #define RESET_GPIO_NUM -1
#define XCLK_GPIO_NUM 0 #define XCLK_GPIO_NUM 0
@ -41,7 +41,6 @@ httpd_handle_t stream_httpd = NULL;
unsigned long lastRegistration = 0; unsigned long lastRegistration = 0;
const unsigned long registrationInterval = 30000; const unsigned long registrationInterval = 30000;
// --- HANDLER: Video Stream (Port 81) ---
static esp_err_t stream_handler(httpd_req_t *req){ static esp_err_t stream_handler(httpd_req_t *req){
camera_fb_t * fb = NULL; camera_fb_t * fb = NULL;
esp_err_t res = ESP_OK; esp_err_t res = ESP_OK;
@ -70,7 +69,6 @@ static esp_err_t stream_handler(httpd_req_t *req){
return res; return res;
} }
// --- HANDLER: Snapshot (Port 80) ---
static esp_err_t snapshot_handler(httpd_req_t *req) { static esp_err_t snapshot_handler(httpd_req_t *req) {
camera_fb_t * fb = esp_camera_fb_get(); camera_fb_t * fb = esp_camera_fb_get();
if (!fb) { httpd_resp_send_500(req); return ESP_FAIL; } if (!fb) { httpd_resp_send_500(req); return ESP_FAIL; }
@ -82,19 +80,17 @@ static esp_err_t snapshot_handler(httpd_req_t *req) {
return res; return res;
} }
// --- HANDLER: Info Perangkat (Port 80) ---
static esp_err_t info_handler(httpd_req_t *req) { static esp_err_t info_handler(httpd_req_t *req) {
char json_response[400]; char json_response[300];
snprintf(json_response, sizeof(json_response), snprintf(json_response, sizeof(json_response),
"{\"id\":\"%s\",\"name\":\"%s\",\"ssid\":\"%s\",\"rssi\":%d,\"ip\":\"%s\",\"mac\":\"%s\",\"free_heap\":%u,\"cpu_freq\":%u}", "{\"ssid\":\"%s\",\"rssi\":%d,\"ip\":\"%s\",\"mac\":\"%s\",\"free_heap\":%u,\"cpu_freq\":%u}",
cam_id, cam_name, WiFi.SSID().c_str(), WiFi.RSSI(), WiFi.localIP().toString().c_str(), WiFi.macAddress().c_str(), ESP.getFreeHeap(), ESP.getCpuFreqMHz() WiFi.SSID().c_str(), WiFi.RSSI(), WiFi.localIP().toString().c_str(), WiFi.macAddress().c_str(), ESP.getFreeHeap(), ESP.getCpuFreqMHz()
); );
httpd_resp_set_hdr(req, "Connection", "close"); httpd_resp_set_hdr(req, "Connection", "close");
httpd_resp_set_type(req, "application/json"); httpd_resp_set_type(req, "application/json");
return httpd_resp_send(req, json_response, strlen(json_response)); return httpd_resp_send(req, json_response, strlen(json_response));
} }
// --- HANDLER: Pengaturan Kamera (Port 80) ---
static esp_err_t cmd_handler(httpd_req_t *req) { static esp_err_t cmd_handler(httpd_req_t *req) {
char* buf; char* buf;
size_t buf_len; size_t buf_len;
@ -141,8 +137,8 @@ void registerToBackend() {
http.begin(server_backend); http.begin(server_backend);
http.addHeader("Content-Type", "application/json"); http.addHeader("Content-Type", "application/json");
// Payload sekarang mencakup ID dan Nama // --> HANYA INI YANG DIUBAH: Penambahan id dan name ke Payload
String payload = "{\"id\":\"" + String(cam_id) + "\",\"name\":\"" + String(cam_name) + "\",\"ip\":\"" + WiFi.localIP().toString() + "\",\"mac\":\"" + WiFi.macAddress() + "\",\"status\":\"online\"}"; String payload = "{\"id\":\"" + cam_id + "\",\"name\":\"" + cam_name + "\",\"ip\":\"" + WiFi.localIP().toString() + "\",\"mac\":\"" + WiFi.macAddress() + "\",\"status\":\"online\"}";
int httpResponseCode = http.POST(payload); int httpResponseCode = http.POST(payload);
http.end(); http.end();
@ -187,7 +183,6 @@ void setup() {
registerToBackend(); registerToBackend();
lastRegistration = millis(); lastRegistration = millis();
// Server API (Port 80)
httpd_config_t config_api = HTTPD_DEFAULT_CONFIG(); httpd_config_t config_api = HTTPD_DEFAULT_CONFIG();
config_api.server_port = 80; config_api.server_port = 80;
config_api.ctrl_port = 32768; config_api.ctrl_port = 32768;
@ -201,7 +196,6 @@ void setup() {
httpd_register_uri_handler(api_httpd, &uri_cmd); httpd_register_uri_handler(api_httpd, &uri_cmd);
} }
// Server Video (Port 81)
httpd_config_t config_stream = HTTPD_DEFAULT_CONFIG(); httpd_config_t config_stream = HTTPD_DEFAULT_CONFIG();
config_stream.server_port = 81; config_stream.server_port = 81;
config_stream.ctrl_port = 32769; config_stream.ctrl_port = 32769;