aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan200101 <sentrycraft123@gmail.com>2024-04-22 16:26:50 +0200
committerJan200101 <sentrycraft123@gmail.com>2024-04-22 16:26:50 +0200
commit2da71ab755d1f444f2867b4dd75fe3e21e2c7395 (patch)
tree37ffdda6c59746dc9980b90b7bcab950e9577a47
parentaccf08f86a636f59dad3af110a8e914f12f59498 (diff)
downloadShelSP-2da71ab755d1f444f2867b4dd75fe3e21e2c7395.tar.gz
ShelSP-2da71ab755d1f444f2867b4dd75fe3e21e2c7395.zip
cleanup
-rw-r--r--main/CMakeLists.txt23
-rw-r--r--main/Kconfig.projbuild5
-rw-r--r--main/http.cpp (renamed from main/http.c)4
-rw-r--r--main/main.cpp (renamed from main/main.c)4
-rw-r--r--main/net.cpp (renamed from main/net.c)6
-rw-r--r--main/relay.cpp29
-rw-r--r--main/relay.h8
-rw-r--r--main/routes/relay.cpp (renamed from main/routes/relay.c)36
-rw-r--r--main/routes/routes.h72
-rw-r--r--main/routes/settings.cpp94
-rw-r--r--main/routes/shelly.cpp (renamed from main/routes/shelly.c)6
-rw-r--r--main/routes/status.cpp (renamed from main/routes/status.c)3
-rw-r--r--main/settings.cpp (renamed from main/routes/settings.c)97
-rw-r--r--main/settings.h8
-rw-r--r--main/utils.cpp (renamed from main/utils.c)0
-rw-r--r--main/utils.h4
16 files changed, 251 insertions, 148 deletions
diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt
index 103cb88..d2f174e 100644
--- a/main/CMakeLists.txt
+++ b/main/CMakeLists.txt
@@ -1,14 +1,21 @@
list(APPEND
SOURCES
- "main.c"
- "net.c"
- "http.c"
- "utils.c"
+ "main.cpp"
+ "net.cpp"
+ "net.h"
+ "http.cpp"
+ "http.h"
+ "relay.cpp"
+ "relay.h"
+ "settings.cpp"
+ "settings.h"
+ "utils.cpp"
+ "utils.h"
- "routes/relay.c"
- "routes/settings.c"
- "routes/shelly.c"
- "routes/status.c"
+ "routes/relay.cpp"
+ "routes/settings.cpp"
+ "routes/shelly.cpp"
+ "routes/status.cpp"
)
idf_component_register(
diff --git a/main/Kconfig.projbuild b/main/Kconfig.projbuild
index a94ccce..a3811c6 100644
--- a/main/Kconfig.projbuild
+++ b/main/Kconfig.projbuild
@@ -18,5 +18,10 @@ menu "ShelSP Configuration"
help
Set static netmask address for AP mode.
+ config SHELLSP_RELAY_PIN
+ int "relay pin"
+ default 4
+ help
+ The pin to be used to run the relay
endmenu \ No newline at end of file
diff --git a/main/http.c b/main/http.cpp
index 6e3b33a..82ed4ec 100644
--- a/main/http.c
+++ b/main/http.cpp
@@ -2,6 +2,7 @@
#include "esp_log.h"
#include "http.h"
+#include "utils.h"
#include "routes/routes.h"
static const char* TAG = "http";
@@ -18,6 +19,7 @@ httpd_handle_t start_webserver(void)
config.server_port = 8001;
#endif // !CONFIG_IDF_TARGET_LINUX
config.lru_purge_enable = true;
+ config.max_uri_handlers = ARRLEN(handlers);
// Start the httpd server
ESP_LOGI(TAG, "Starting server on port: '%d'", config.server_port);
@@ -27,7 +29,7 @@ httpd_handle_t start_webserver(void)
while (handler->uri)
{
- ESP_LOGI(TAG, "Registering URI handler %i %s", handler->method, handler->uri);
+ ESP_LOGD(TAG, "Registering URI handler %i %s", handler->method, handler->uri);
httpd_register_uri_handler(server, handler);
++handler;
}
diff --git a/main/main.c b/main/main.cpp
index 498639e..4fecc09 100644
--- a/main/main.c
+++ b/main/main.cpp
@@ -19,6 +19,10 @@
#include "net.h"
#include "http.h"
+extern "C" {
+ void app_main(void);
+}
+
static const char *TAG = "main";
void app_main(void)
diff --git a/main/net.c b/main/net.cpp
index 43a07c8..eeef7d9 100644
--- a/main/net.c
+++ b/main/net.cpp
@@ -72,7 +72,7 @@ static void setup_mdns()
char* id;
asprintf(
&id,
- "shelly%s-%02X%02X%02X%02X%02X%02X",
+ "shelly%s-"MACFMT"",
CONFIG_SHELLSP_MODEL, MAC2STR(get_wifi_mac())
);
@@ -98,8 +98,8 @@ static bool wifi_init_softap(void)
wifi_config_t wifi_ap_config = {
.ap = {
.channel = 1,
- .max_connection = 5,
.authmode = WIFI_AUTH_OPEN,
+ .max_connection = 5,
.pmf_cfg = {
.required = false,
},
@@ -109,7 +109,7 @@ static bool wifi_init_softap(void)
char* ssid = (char*)wifi_ap_config.ap.ssid;
snprintf(
ssid, 32,
- "shelly%s-%02X%02X%02X%02X%02X%02X",
+ "shelly%s-"MACFMT"",
CONFIG_SHELLSP_MODEL, MAC2STR(get_wifi_mac())
);
wifi_ap_config.ap.ssid_len = strlen(ssid);
diff --git a/main/relay.cpp b/main/relay.cpp
new file mode 100644
index 0000000..701701f
--- /dev/null
+++ b/main/relay.cpp
@@ -0,0 +1,29 @@
+#include "esp_check.h"
+
+#include "relay.h"
+
+static const char *TAG = "relay";
+
+int state = 0;
+
+char* relay_json(void)
+{
+ char* resp = NULL;
+
+ int rc = asprintf(
+ &resp,
+ "{"
+ "\"ison\":%s,"
+ "\"has_timer\":false,"
+ "\"timer_started\":0,"
+ "\"timer_duration\":0,"
+ "\"timer_remaining\":0,"
+ "\"source\":\"http\""
+ "}",
+ state ? "true" : "false"
+ );
+
+ ESP_RETURN_ON_FALSE(resp && rc, NULL, TAG, "buffer alloc failed");
+
+ return resp;
+}
diff --git a/main/relay.h b/main/relay.h
new file mode 100644
index 0000000..c15946b
--- /dev/null
+++ b/main/relay.h
@@ -0,0 +1,8 @@
+#ifndef RELAY_H
+#define RELAY_H
+
+char* relay_json(void);
+
+extern int state;
+
+#endif \ No newline at end of file
diff --git a/main/routes/relay.c b/main/routes/relay.cpp
index 460e139..8dbeb02 100644
--- a/main/routes/relay.c
+++ b/main/routes/relay.cpp
@@ -1,11 +1,12 @@
#include "esp_log.h"
#include "esp_check.h"
+#include "relay.h"
#include "routes.h"
static const char *TAG = "routes/relay";
-#define GPIO_RELAY_PIN 4
+#define GPIO_RELAY_PIN (gpio_num_t)CONFIG_SHELLSP_RELAY_PIN
#if !CONFIG_IDF_TARGET_LINUX
#include "driver/gpio.h"
@@ -21,7 +22,7 @@ static gpio_config_t* get_gpio(void)
//set as output mode
io_conf.mode = GPIO_MODE_OUTPUT;
//bit mask of the pins that you want to set,e.g. GPIO4
- io_conf.pin_bit_mask = (1ULL<<GPIO_RELAY_PIN);
+ io_conf.pin_bit_mask = (1ULL << GPIO_RELAY_PIN);
//disable pull-down mode
io_conf.pull_down_en = GPIO_PULLDOWN_DISABLE;
//disable pull-up mode
@@ -39,29 +40,7 @@ static gpio_config_t* get_gpio(void)
#endif
-int state = 0;
-char* relay_json(void)
-{
- char* resp = NULL;
-
- int rc = asprintf(
- &resp,
- "{"
- "\"ison\":%s,"
- "\"has_timer\":false,"
- "\"timer_started\":0,"
- "\"timer_duration\":0,"
- "\"timer_remaining\":0,"
- "\"source\":\"http\""
- "}",
- state ? "true" : "false"
- );
-
- ESP_RETURN_ON_FALSE(resp && rc, NULL, TAG, "buffer alloc failed");
-
- return resp;
-}
esp_err_t relay_handler(httpd_req_t *req)
{
@@ -74,31 +53,30 @@ esp_err_t relay_handler(httpd_req_t *req)
size_t query_len = httpd_req_get_url_query_len(req) + 1;
if (query_len > 1)
{
- char* buf = malloc(query_len);
+ char* buf = (char*)malloc(query_len);
ESP_RETURN_ON_FALSE(buf, ESP_ERR_NO_MEM, TAG, "buffer alloc failed");
if (httpd_req_get_url_query_str(req, buf, query_len) == ESP_OK) {
char param[8];
if (httpd_query_key_value(buf, "turn", param, sizeof(param)) == ESP_OK) {
- ESP_LOGI(TAG, "Found URL query parameter => turn=%s", param);
if (!strcmp("on", param))
{
- ESP_LOGI(TAG, "Turned %i on", GPIO_RELAY_PIN);
+ ESP_LOGI(TAG, "Turned GPIO %i on", GPIO_RELAY_PIN);
state = 1;
gpio_set_level(GPIO_RELAY_PIN, state);
}
else if (!strcmp("off", param))
{
- ESP_LOGI(TAG, "Turned %i off", GPIO_RELAY_PIN);
+ ESP_LOGI(TAG, "Turned GPIO %i off", GPIO_RELAY_PIN);
state = 0;
gpio_set_level(GPIO_RELAY_PIN, state);
}
else if (!strcmp("toggle", param))
{
state = !state;
- ESP_LOGI(TAG, "Toggled %i", GPIO_RELAY_PIN);
+ ESP_LOGI(TAG, "Toggled GPIO %i", GPIO_RELAY_PIN);
gpio_set_level(GPIO_RELAY_PIN, state);
}
else
diff --git a/main/routes/routes.h b/main/routes/routes.h
index f81b298..1beed29 100644
--- a/main/routes/routes.h
+++ b/main/routes/routes.h
@@ -3,60 +3,104 @@
#include <esp_http_server.h>
-esp_err_t echo_post_handler(httpd_req_t *req);
-esp_err_t shelly_get_handler(httpd_req_t *req);
+esp_err_t shelly_handler(httpd_req_t *req);
esp_err_t status_handler(httpd_req_t *req);
esp_err_t settings_handler(httpd_req_t *req);
esp_err_t settings_cloud_handler(httpd_req_t *req);
esp_err_t settings_sta_handler(httpd_req_t *req);
esp_err_t settings_relay_handler(httpd_req_t *req);
-
esp_err_t relay_handler(httpd_req_t *req);
-extern int state;
-char* relay_json(void);
-
static const httpd_uri_t handlers[] = {
{
.uri = "/shelly",
.method = HTTP_GET,
- .handler = shelly_get_handler
+ .handler = shelly_handler,
+ .user_ctx = NULL
+ },
+ {
+ .uri = "/shelly",
+ .method = HTTP_POST,
+ .handler = shelly_handler,
+ .user_ctx = NULL
},
+
{
.uri = "/status",
.method = HTTP_GET,
- .handler = status_handler
+ .handler = status_handler,
+ .user_ctx = NULL
+ },
+ {
+ .uri = "/status",
+ .method = HTTP_POST,
+ .handler = status_handler,
+ .user_ctx = NULL
},
+
{
.uri = "/settings",
.method = HTTP_GET,
- .handler = settings_handler
+ .handler = settings_handler,
+ .user_ctx = NULL
},
{
+ .uri = "/settings",
+ .method = HTTP_POST,
+ .handler = settings_handler,
+ .user_ctx = NULL
+ },
+
+ {
.uri = "/settings/cloud",
.method = HTTP_GET,
- .handler = settings_cloud_handler
+ .handler = settings_cloud_handler,
+ .user_ctx = NULL
+ },
+ {
+ .uri = "/settings/cloud",
+ .method = HTTP_POST,
+ .handler = settings_cloud_handler,
+ .user_ctx = NULL
},
+
{
.uri = "/settings/sta",
.method = HTTP_GET,
- .handler = settings_sta_handler
+ .handler = settings_sta_handler,
+ .user_ctx = NULL
},
{
+ .uri = "/settings/sta",
+ .method = HTTP_POST,
+ .handler = settings_sta_handler,
+ .user_ctx = NULL
+ },
+
+ {
.uri = "/settings/relay/0",
.method = HTTP_GET,
- .handler = settings_relay_handler
+ .handler = settings_relay_handler,
+ .user_ctx = NULL
+ },
+ {
+ .uri = "/settings/relay/0",
+ .method = HTTP_POST,
+ .handler = settings_relay_handler,
+ .user_ctx = NULL
},
{
.uri = "/relay/0",
.method = HTTP_GET,
- .handler = relay_handler
+ .handler = relay_handler,
+ .user_ctx = NULL
},
{
.uri = "/relay/0",
.method = HTTP_POST,
- .handler = relay_handler
+ .handler = relay_handler,
+ .user_ctx = NULL
},
{ NULL },
};
diff --git a/main/routes/settings.cpp b/main/routes/settings.cpp
new file mode 100644
index 0000000..0d03eba
--- /dev/null
+++ b/main/routes/settings.cpp
@@ -0,0 +1,94 @@
+#include "esp_mac.h"
+#include "esp_log.h"
+#include "esp_check.h"
+#include "esp_wifi.h"
+
+#include "relay.h"
+#include "settings.h"
+#include "utils.h"
+#include "routes.h"
+
+static const char *TAG = "routes/settings";
+
+esp_err_t settings_handler(httpd_req_t *req)
+{
+ ESP_LOGD(TAG, "settings_handler %s", req->uri);
+
+ char *resp = settings_json();
+ ESP_RETURN_ON_FALSE(resp, ESP_ERR_NO_MEM, TAG, "buffer alloc failed");
+
+ httpd_resp_set_type(req, "application/json");
+ httpd_resp_sendstr(req, resp);
+ return ESP_OK;
+}
+
+esp_err_t settings_cloud_handler(httpd_req_t *req)
+{
+ ESP_LOGD(TAG, "settings_cloud_handler %s", req->uri);
+
+ httpd_resp_set_type(req, "application/json");
+ httpd_resp_sendstr(req, "{\"enabled\":false}");
+ return ESP_OK;
+}
+
+esp_err_t settings_sta_handler(httpd_req_t *req)
+{
+ ESP_LOGD(TAG, "settings_sta_handler %s", req->uri);
+
+ size_t query_len = httpd_req_get_url_query_len(req) + 1;
+
+ if (query_len > 1)
+ {
+ char* buf = (char*)malloc(query_len);
+ ESP_RETURN_ON_FALSE(buf, ESP_ERR_NO_MEM, TAG, "buffer alloc failed");
+
+ if (httpd_req_get_url_query_str(req, buf, query_len) == ESP_OK)
+ {
+ char param[64];
+ wifi_config_t wifi_cfg;
+ ESP_ERROR_CHECK(esp_wifi_get_config(WIFI_IF_STA, &wifi_cfg));
+
+ if (httpd_query_key_value(buf, "ssid", param, sizeof(param)) == ESP_OK)
+ {
+ ESP_LOGI(TAG, "Found URL query parameter => ssid=%s", param);
+ ESP_LOGD(TAG, "Configured ssid %s", param);
+
+ size_t s = sizeof(wifi_cfg.sta.ssid);
+ strncpy((char*)wifi_cfg.sta.ssid, param, s);
+ wifi_cfg.sta.ssid[s] = '\0';
+ ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_STA, &wifi_cfg));
+ }
+
+ if (httpd_query_key_value(buf, "key", param, sizeof(param)) == ESP_OK) {
+ ESP_LOGD(TAG, "Configured psk");
+
+ size_t s = sizeof(wifi_cfg.sta.password) - 1;
+ strncpy((char*)wifi_cfg.sta.password, param, s);
+ wifi_cfg.sta.password[s] = '\0';
+ wifi_cfg.sta.threshold.authmode = WIFI_AUTH_WPA2_PSK;
+ ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_STA, &wifi_cfg));
+ }
+ }
+
+ free(buf);
+ }
+
+ char* resp = settings_sta_json();
+ ESP_RETURN_ON_FALSE(resp, ESP_ERR_NO_MEM, TAG, "buffer alloc failed");
+
+ httpd_resp_set_type(req, "application/json");
+ httpd_resp_sendstr(req, resp);
+
+ return ESP_OK;
+}
+
+esp_err_t settings_relay_handler(httpd_req_t *req)
+{
+ char *resp = settings_relay_json();
+ ESP_RETURN_ON_FALSE(resp, ESP_ERR_NO_MEM, TAG, "buffer alloc failed");
+
+ httpd_resp_set_type(req, "application/json");
+ httpd_resp_sendstr(req, resp);
+
+ return ESP_OK;
+}
diff --git a/main/routes/shelly.c b/main/routes/shelly.cpp
index dd1e2d4..269a3bb 100644
--- a/main/routes/shelly.c
+++ b/main/routes/shelly.cpp
@@ -6,16 +6,16 @@
static const char *TAG = "routes/shelly";
-esp_err_t shelly_get_handler(httpd_req_t *req)
+esp_err_t shelly_handler(httpd_req_t *req)
{
- ESP_LOGI(TAG, "shelly_get_handler %s", req->uri);
+ ESP_LOGD(TAG, "shelly_get_handler %s", req->uri);
char* resp = NULL;
int rc = asprintf(
&resp,
"{"
"\"type\":\"SHSW-%s\","
- "\"mac\":\"%02X%02X%02X%02X%02X%02X\","
+ "\"mac\":\""MACFMT"\","
"\"auth\":false,"
"\"fw\":\"20230913-112003/v1.14.0-gcb84623\","
"\"discoverable\":true,"
diff --git a/main/routes/status.c b/main/routes/status.cpp
index 8463f09..d44ae47 100644
--- a/main/routes/status.c
+++ b/main/routes/status.cpp
@@ -2,13 +2,14 @@
#include "esp_log.h"
#include "esp_check.h"
+#include "relay.h"
#include "routes.h"
static const char *TAG = "routes/status";
esp_err_t status_handler(httpd_req_t *req)
{
- ESP_LOGI(TAG, "status_handler %s", req->uri);
+ ESP_LOGD(TAG, "status_handler %s", req->uri);
char* resp = NULL;
char* relay_resp = relay_json();
diff --git a/main/routes/settings.c b/main/settings.cpp
index c93b50f..7f002e2 100644
--- a/main/routes/settings.c
+++ b/main/settings.cpp
@@ -3,10 +3,11 @@
#include "esp_check.h"
#include "esp_wifi.h"
-#include "routes.h"
+#include "relay.h"
+#include "settings.h"
#include "utils.h"
-static const char *TAG = "routes/settings";
+static const char *TAG = "settings";
char* settings_sta_json(void)
{
@@ -84,12 +85,12 @@ char* settings_json(void)
"{"
"\"device\":{"
"\"type\":\"SHSW-%s\","
- "\"mac\":\"%02X%02X%02X%02X%02X%02X\","
- "\"hostname\":\"shelly%s-%02X%02X%02X%02X%02X%02X\""
+ "\"mac\":\""MACFMT"\","
+ "\"hostname\":\"shelly%s-"MACFMT"\""
"},"
"\"wifi_ap\":{"
"\"enabled\":false,"
- "\"ssid\":\"shelly%s-%02X%02X%02X%02X%02X%02X\","
+ "\"ssid\":\"shelly%s-"MACFMT"\","
"\"key\":\"\""
"},"
"\"wifi_sta\":%s,"
@@ -110,7 +111,7 @@ char* settings_json(void)
"\"enable\":false,"
"\"server\":\"192.168.33.3:1883\","
"\"user\":\"\","
- "\"id\":\"shelly%s-%02X%02X%02X%02X%02X%02X\","
+ "\"id\":\"shelly%s-"MACFMT"\","
"\"reconnect_timeout_max\":60,"
"\"reconnect_timeout_min\":2,"
"\"clean_session\":true,"
@@ -134,7 +135,7 @@ char* settings_json(void)
"\"username\":\"admin\""
"},"
"\"pin_code\":\"123456\","
- "\"name\":\"shelly%s-%02X%02X%02X%02X%02X%02X\","
+ "\"name\":\"shelly%s-"MACFMT"\","
"\"fw\":\"20170427-114337/master@79dbb397\","
"\"discoverable\":true,"
"\"build_info\":{"
@@ -193,85 +194,3 @@ char* settings_json(void)
return resp;
}
-
-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");
-
- httpd_resp_set_type(req, "application/json");
- httpd_resp_sendstr(req, resp);
- return ESP_OK;
-}
-
-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;
-}
-
-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)
- {
- char* buf = malloc(query_len);
- ESP_RETURN_ON_FALSE(buf, ESP_ERR_NO_MEM, TAG, "buffer alloc failed");
-
- if (httpd_req_get_url_query_str(req, buf, query_len) == ESP_OK)
- {
- char param[64];
- wifi_config_t wifi_cfg;
- ESP_ERROR_CHECK(esp_wifi_get_config(WIFI_IF_STA, &wifi_cfg));
-
- if (httpd_query_key_value(buf, "ssid", param, sizeof(param)) == ESP_OK)
- {
- ESP_LOGI(TAG, "Found URL query parameter => ssid=%s", param);
-
- size_t s = sizeof(wifi_cfg.sta.ssid);
- strncpy((char*)wifi_cfg.sta.ssid, param, s);
- wifi_cfg.sta.ssid[s] = '\0';
- ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_STA, &wifi_cfg));
- }
-
- if (httpd_query_key_value(buf, "key", param, sizeof(param)) == ESP_OK) {
- ESP_LOGI(TAG, "Found URL query parameter => key=%s", param);
-
- size_t s = sizeof(wifi_cfg.sta.password) - 1;
- strncpy((char*)wifi_cfg.sta.password, param, s);
- wifi_cfg.sta.password[s] = '\0';
- wifi_cfg.sta.threshold.authmode = WIFI_AUTH_WPA2_PSK;
- ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_STA, &wifi_cfg));
- }
- }
-
- free(buf);
- }
-
- char* resp = settings_sta_json();
- ESP_RETURN_ON_FALSE(resp, ESP_ERR_NO_MEM, TAG, "buffer alloc failed");
-
- httpd_resp_set_type(req, "application/json");
- httpd_resp_sendstr(req, resp);
-
- return ESP_OK;
-}
-
-esp_err_t settings_relay_handler(httpd_req_t *req)
-{
- char *resp = settings_relay_json();
- ESP_RETURN_ON_FALSE(resp, ESP_ERR_NO_MEM, TAG, "buffer alloc failed");
-
- httpd_resp_set_type(req, "application/json");
- httpd_resp_sendstr(req, resp);
-
- return ESP_OK;
-}
diff --git a/main/settings.h b/main/settings.h
new file mode 100644
index 0000000..1cad8cd
--- /dev/null
+++ b/main/settings.h
@@ -0,0 +1,8 @@
+#ifndef SETTINGS_H
+#define SETTINGS_H
+
+char* settings_sta_json(void);
+char* settings_relay_json(void);
+char* settings_json(void);
+
+#endif \ No newline at end of file
diff --git a/main/utils.c b/main/utils.cpp
index 6ec78ac..6ec78ac 100644
--- a/main/utils.c
+++ b/main/utils.cpp
diff --git a/main/utils.h b/main/utils.h
index 605f1f4..d6a864c 100644
--- a/main/utils.h
+++ b/main/utils.h
@@ -1,6 +1,10 @@
#ifndef UTILS_H
#define UTILS_H
+#define ARRLEN(arr) sizeof(arr) / sizeof(arr[0])
+
+#define MACFMT "%02X%02X%02X%02X%02X%02X"
+
uint8_t* get_wifi_mac(void);
#endif