feat: REST-API mit Routing, Auth und Handlern
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
#ifndef NL_API_H
|
||||
#define NL_API_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "board/nl_board.h"
|
||||
#include "config/nl_settings.h"
|
||||
#include "light/nl_control.h"
|
||||
#include "light/nl_light_types.h"
|
||||
#include "net/nl_http.h"
|
||||
|
||||
#define NL_API_BODY_MAX 1024
|
||||
|
||||
typedef struct {
|
||||
char mac[18];
|
||||
char name[NL_NAME_LEN];
|
||||
const char *wifi_mode; /* "sta" | "ap" | "apsta" */
|
||||
char ssid[NL_SSID_LEN];
|
||||
int rssi; /* dBm, 0 when not connected */
|
||||
char ip[16]; /* address the device answers on, "" if none */
|
||||
char sta_ip[16]; /* station address, "" when not connected (reported as null) */
|
||||
const char *wifi_error; /* NULL | "auth" | "not_found" | "timeout" */
|
||||
uint32_t uptime_s;
|
||||
uint32_t free_heap;
|
||||
const char *last_ota_error; /* NULL until OTA exists */
|
||||
} nl_sys_info_t;
|
||||
|
||||
/* Everything the API needs from the application; implemented by src/sys/nl_app_api.c. */
|
||||
typedef struct {
|
||||
const nl_board_t *board;
|
||||
const char *fw_version;
|
||||
const char *build_date;
|
||||
void (*get_state)(nl_light_state_t *out);
|
||||
nl_ctrl_err_t (*apply)(const nl_light_change_t *c);
|
||||
void (*get_settings)(nl_settings_t *out);
|
||||
int (*save_settings)(const nl_settings_t *s); /* 0 = ok; wifi fields are ignored */
|
||||
int (*wifi_configure)(const char *ssid, const char *pass); /* 0 = onboarding test started */
|
||||
bool (*open_access)(void); /* unconfigured onboarding AP */
|
||||
void (*get_info)(nl_sys_info_t *out);
|
||||
void (*factory_reset)(void); /* request only */
|
||||
void (*ping)(void);
|
||||
int (*fw_update)(const char *url); /* 0 = started, <0 = unavailable */
|
||||
} nl_api_ctx_t;
|
||||
|
||||
typedef enum { NL_API_AFTER_NONE = 0, NL_API_AFTER_REBOOT } nl_api_after_t;
|
||||
|
||||
typedef struct {
|
||||
int status;
|
||||
nl_api_after_t after; /* action for the server once the response has been sent */
|
||||
char body[NL_API_BODY_MAX];
|
||||
} nl_api_response_t;
|
||||
|
||||
void nl_api_handle(const nl_api_ctx_t *ctx, const nl_http_request_t *req, nl_api_response_t *resp);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user