Files
t-embed-insecam-widget/main/httpstream.h
T
Juli 65a391940b insecam desk widget for the LilyGO T-Embed
ESP-IDF 5.5 + LVGL 9 firmware that plays random public cameras from
insecam.org on the T-Embed's 320x170 screen, live MJPEG where available,
a new camera every 20 seconds. Knob steps through cameras, LED ring shows
the countdown. Auto-detects the original vs CC1101 board, reuses Wi-Fi
credentials from NVS and falls back to a captive-portal setup hotspot.
2026-09-17 00:38:09 +02:00

35 lines
1.1 KiB
C

#pragma once
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include "esp_err.h"
// Small blocking HTTP/1.x GET client on raw sockets. Unlike esp_http_client it
// happily streams bodies with no Content-Length (MJPEG cameras, HTTP/1.0 servers),
// de-chunks chunked bodies and follows a few redirects.
typedef struct {
int fd;
int status;
bool chunked;
int64_t content_length; // -1 when unknown
int64_t body_read;
char content_type[80];
char host[128];
uint16_t port;
uint8_t *buf; // receive buffer
size_t cap, len, pos;
int64_t chunk_left;
bool eof;
int rx_timeout_ms;
} httpstream_t;
#define HTTPSTREAM_EOF 0
#define HTTPSTREAM_ERR (-1)
#define HTTPSTREAM_TIMEOUT (-2)
esp_err_t httpstream_open(httpstream_t *s, const char *url, const char *user_agent,
int connect_timeout_ms, int rx_timeout_ms);
// Returns bytes copied (>0), HTTPSTREAM_EOF, HTTPSTREAM_ERR or HTTPSTREAM_TIMEOUT.
int httpstream_read(httpstream_t *s, uint8_t *out, size_t n);
void httpstream_close(httpstream_t *s);