aboutsummaryrefslogtreecommitdiff
path: root/main
diff options
context:
space:
mode:
authorJan200101 <sentrycraft123@gmail.com>2024-04-22 01:26:46 +0200
committerJan200101 <sentrycraft123@gmail.com>2024-04-22 01:26:46 +0200
commitaccf08f86a636f59dad3af110a8e914f12f59498 (patch)
treea2a066565215f25e54bb19b5c235cadab0bce74c /main
parent47335617dc6804dd2b948e7ab691e36f17e7bce3 (diff)
downloadShelSP-accf08f86a636f59dad3af110a8e914f12f59498.tar.gz
ShelSP-accf08f86a636f59dad3af110a8e914f12f59498.zip
update
Diffstat (limited to 'main')
-rw-r--r--main/http.c2
-rw-r--r--main/net.c3
-rw-r--r--main/routes/routes.h26
-rw-r--r--main/routes/settings.c35
-rw-r--r--main/routes/shelly.c1
-rw-r--r--main/routes/status.c2
6 files changed, 52 insertions, 17 deletions
diff --git a/main/http.c b/main/http.c
index 22077a5..6e3b33a 100644
--- a/main/http.c
+++ b/main/http.c
@@ -27,7 +27,7 @@ httpd_handle_t start_webserver(void)
while (handler->uri)
{
- ESP_LOGI(TAG, "Registering URI handler %s", handler->uri);
+ ESP_LOGI(TAG, "Registering URI handler %i %s", handler->method, handler->uri);
httpd_register_uri_handler(server, handler);
++handler;
}
diff --git a/main/net.c b/main/net.c
index 6d9ec7b..43a07c8 100644
--- a/main/net.c
+++ b/main/net.c
@@ -191,6 +191,9 @@ esp_err_t net_connect(void)
}
bool s = wifi_init_sta();
+ if (s)
+ ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA));
+
ESP_ERROR_CHECK(esp_wifi_start());
setup_mdns();
diff --git a/main/routes/routes.h b/main/routes/routes.h
index 34986f7..f81b298 100644
--- a/main/routes/routes.h
+++ b/main/routes/routes.h
@@ -20,45 +20,43 @@ static const httpd_uri_t handlers[] = {
{
.uri = "/shelly",
.method = HTTP_GET,
- .handler = shelly_get_handler,
- .user_ctx = NULL
+ .handler = shelly_get_handler
},
{
.uri = "/status",
.method = HTTP_GET,
- .handler = status_handler,
- .user_ctx = NULL
+ .handler = status_handler
},
{
.uri = "/settings",
.method = HTTP_GET,
- .handler = settings_handler,
- .user_ctx = NULL
+ .handler = settings_handler
},
{
.uri = "/settings/cloud",
.method = HTTP_GET,
- .handler = settings_cloud_handler,
- .user_ctx = NULL
+ .handler = settings_cloud_handler
},
{
.uri = "/settings/sta",
.method = HTTP_GET,
- .handler = settings_sta_handler,
- .user_ctx = NULL
+ .handler = settings_sta_handler
},
{
.uri = "/settings/relay/0",
.method = HTTP_GET,
- .handler = settings_relay_handler,
- .user_ctx = NULL
+ .handler = settings_relay_handler
},
{
.uri = "/relay/0",
.method = HTTP_GET,
- .handler = relay_handler,
- .user_ctx = NULL
+ .handler = relay_handler
+ },
+ {
+ .uri = "/relay/0",
+ .method = HTTP_POST,
+ .handler = relay_handler
},
{ NULL },
};
diff --git a/main/routes/settings.c b/main/routes/settings.c
index 88ca6de..c93b50f 100644
--- a/main/routes/settings.c
+++ b/main/routes/settings.c
@@ -73,6 +73,10 @@ char* settings_json(void)
if (!sta_data)
sta_data = "{}";
+ char* relay_data = settings_relay_json();
+ if (!relay_data)
+ relay_data = "{}";
+
char* resp = NULL;
int rc = asprintf(
@@ -154,14 +158,35 @@ char* settings_json(void)
"\"led_status_disable\":false,"
"\"debug_enable\":false,"
"\"allow_cross_origin\":false,"
- "\"wifirecovery_reboot_enabled\":true"
+ "\"wifirecovery_reboot_enabled\":true,"
+
+ "\"factory_reset_from_switch\":false,"
+ "\"mode\":\"relay\","
+ "\"longpush_time\":1000,"
+ "\"actions\":{"
+ "\"active\":false,"
+ "\"names\":[]"
+ "},"
+ "\"relays\":["
+ "%s"
+ "],"
+ "\"ext_sensors\":{},"
+ "\"ext_temperature\":{},"
+ "\"ext_humidity\":{},"
+ "\"ext_switch_enable\":1,"
+ "\"ext_switch\":{"
+ "\"0\":{"
+ "\"relay_num\":0"
+ "}"
+ "}"
"}",
CONFIG_SHELLSP_MODEL, MAC2STR(get_wifi_mac()),
CONFIG_SHELLSP_MODEL, MAC2STR(get_wifi_mac()),
CONFIG_SHELLSP_MODEL, MAC2STR(get_wifi_mac()),
sta_data,
CONFIG_SHELLSP_MODEL, MAC2STR(get_wifi_mac()),
- CONFIG_SHELLSP_MODEL, MAC2STR(get_wifi_mac())
+ CONFIG_SHELLSP_MODEL, MAC2STR(get_wifi_mac()),
+ relay_data
);
ESP_RETURN_ON_FALSE(resp && rc, NULL, TAG, "buffer alloc failed");
@@ -171,6 +196,8 @@ char* settings_json(void)
esp_err_t settings_handler(httpd_req_t *req)
{
+ ESP_LOGI(TAG, "settings_handler %s", req->uri);
+
char *resp = settings_json();
ESP_RETURN_ON_FALSE(resp, ESP_ERR_NO_MEM, TAG, "buffer alloc failed");
@@ -181,6 +208,8 @@ esp_err_t settings_handler(httpd_req_t *req)
esp_err_t settings_cloud_handler(httpd_req_t *req)
{
+ ESP_LOGI(TAG, "settings_cloud_handler %s", req->uri);
+
httpd_resp_set_type(req, "application/json");
httpd_resp_sendstr(req, "{\"enabled\":false}");
return ESP_OK;
@@ -188,6 +217,8 @@ esp_err_t settings_cloud_handler(httpd_req_t *req)
esp_err_t settings_sta_handler(httpd_req_t *req)
{
+ ESP_LOGI(TAG, "settings_sta_handler %s", req->uri);
+
size_t query_len = httpd_req_get_url_query_len(req) + 1;
if (query_len > 1)
diff --git a/main/routes/shelly.c b/main/routes/shelly.c
index 80c0675..dd1e2d4 100644
--- a/main/routes/shelly.c
+++ b/main/routes/shelly.c
@@ -8,6 +8,7 @@ static const char *TAG = "routes/shelly";
esp_err_t shelly_get_handler(httpd_req_t *req)
{
+ ESP_LOGI(TAG, "shelly_get_handler %s", req->uri);
char* resp = NULL;
int rc = asprintf(
diff --git a/main/routes/status.c b/main/routes/status.c
index eb7853f..8463f09 100644
--- a/main/routes/status.c
+++ b/main/routes/status.c
@@ -8,6 +8,8 @@ static const char *TAG = "routes/status";
esp_err_t status_handler(httpd_req_t *req)
{
+ ESP_LOGI(TAG, "status_handler %s", req->uri);
+
char* resp = NULL;
char* relay_resp = relay_json();