Revert "Integration page"

This reverts commit 3415b62d2d.
This commit is contained in:
cpq 2023-07-19 18:50:27 +01:00
parent 3415b62d2d
commit ea89a4afab
7 changed files with 2161 additions and 2465 deletions

View File

@ -10,15 +10,6 @@ static void signal_handler(int sig_num) {
s_sig_num = sig_num;
}
// Simulate LED
static bool s_led_status = true;
bool led_get(void) {
return s_led_status;
}
void led_set(bool val) {
s_led_status = val;
}
int main(void) {
struct mg_mgr mgr;

View File

@ -218,17 +218,6 @@ static void handle_settings_get(struct mg_connection *c) {
MG_ESC("device_name"), MG_ESC(s_settings.device_name));
}
static void handle_led_get(struct mg_connection *c) {
mg_http_reply(c, 200, s_json_header, "%s", led_get() ? "true" : "false");
}
static void handle_led_set(struct mg_connection *c, struct mg_str body) {
bool on = false;
mg_json_get_bool(body, "$.on", &on);
led_set(on);
mg_http_reply(c, 200, s_json_header, "true");
}
// HTTP request handler function
static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) {
if (ev == MG_EV_ACCEPT && fn_data != NULL) {
@ -254,10 +243,6 @@ static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) {
handle_settings_get(c);
} else if (mg_http_match_uri(hm, "/api/settings/set")) {
handle_settings_set(c, hm->body);
} else if (mg_http_match_uri(hm, "/api/led/get")) {
handle_led_get(c);
} else if (mg_http_match_uri(hm, "/api/led/set")) {
handle_led_set(c, hm->body);
} else {
struct mg_http_serve_opts opts;
memset(&opts, 0, sizeof(opts));

View File

@ -24,7 +24,4 @@ struct ui_event {
char text[10];
};
bool led_get(void);
void led_set(bool);
void web_init(struct mg_mgr *mgr);

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@ -155,18 +155,28 @@ function DeveloperNote({text}) {
};
function Main({}) {
const [led, setLed] = useState(false);
const refresh = () => fetch('api/led/get').then(r => r.json()).then(r => setLed(r));
const [stats, setStats] = useState(null);
const refresh = () => fetch('api/stats/get').then(r => r.json()).then(r => setStats(r));
useEffect(refresh, []);
const setled = v => fetch('api/led/set', {
method: 'post', body: JSON.stringify({on: !led})
}).then(refresh);
if (!stats) return '';
return html`
<div class="m-4 grid grid-cols-2 gap-4">
<div class="bg-white p-2 divide-y">
<h1>LED control<//>
<${Setting} title="My LED:" value=${led} setfn=${setled} type="switch" />
<div class="p-2">
<div class="p-4 sm:p-2 mx-auto grid grid-cols-2 lg:grid-cols-4 gap-4">
<${Stat} title="Temperature" text="${stats.temperature} °C" tipText="good" tipIcon=${Icons.ok} tipColors=${tipColors.green} />
<${Stat} title="Humidity" text="${stats.humidity} %" tipText="warn" tipIcon=${Icons.warn} tipColors=${tipColors.yellow} />
<div class="bg-white col-span-2 border rounded-md shadow-lg" role="alert">
<${DeveloperNote} text="Stats data is received from the Mongoose backend" />
<//>
<//>
<div class="p-4 sm:p-2 mx-auto grid grid-cols-1 lg:grid-cols-2 gap-4">
<${Chart} data=${stats.points} />
<div class="my-4 hx-24 bg-white border rounded-md shadow-lg" role="alert">
<${DeveloperNote}
text="This chart is an SVG image, generated on the fly from the
data returned by the api/stats/get API call" />
<//>
<//>
<//>`;
};

View File

@ -24,7 +24,7 @@ void mg_random(void *buf, size_t len) { // Use on-board RNG
}
static void timer_fn(void *arg) {
//gpio_toggle(LED); // Blink LED
gpio_toggle(LED); // Blink LED
struct mg_tcpip_if *ifp = arg; // And show
const char *names[] = {"down", "up", "req", "ready"}; // network stats
MG_INFO(("Ethernet: %s, IP: %M, rx:%u, tx:%u, dr:%u, er:%u",
@ -32,13 +32,6 @@ static void timer_fn(void *arg) {
ifp->ndrop, ifp->nerr));
}
bool led_get(void) {
return gpio_read(LED);
}
void led_set(bool val) {
gpio_write(LED, val);
}
int main(void) {
gpio_output(LED); // Setup green LED
uart_init(UART_DEBUG, 115200); // Initialise debug printf