Skip to content

Commit

Permalink
✨ feat: Add ESP32 firmware version on website
Browse files Browse the repository at this point in the history
In this commit, we added a new feature that allows the website to
retrieve the ESP32 firmware version.
  • Loading branch information
Hsun1031 committed Mar 17, 2023
1 parent 1c7307c commit 1719c5b
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/platformIO.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ jobs:
echo -e "\n" >> commit_msg.txt
fi
- name: Change Version
run: |
sed -i "s/0\.0\.0/$(git describe --tags)/" ./include/version.h
- name: Install PlatformIO python
uses: actions/setup-python@v4
with:
Expand Down
3 changes: 0 additions & 3 deletions include/header.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
#ifndef __CLEANER_HEADER_H__
#define __CLEANER_HEADER_H__

// cleaner version
#define CLEANER_VERSION "0.0.1"

// I2C
#define CLEANER_DEFAULT_I2C_SDA 21
#define CLEANER_DEFAULT_I2C_SCL 22
Expand Down
7 changes: 7 additions & 0 deletions include/version.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#ifndef __CLEANER_VERSION_H__
#define __CLEANER_VERSION_H__

// cleaner version
#define CLEANER_VERSION "0.0.0"

#endif
15 changes: 15 additions & 0 deletions src/components/network/my_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <WiFi.h>
#include <Update.h>

#include "version.h"
#include "components/website.h"
#include "components/setting.h"

Expand Down Expand Up @@ -332,6 +333,20 @@ void setup_api() {
ESP.deepSleep(100000);
});

// [POST] http://cleaner/api/esp/verion- Get ESP32 version
server.on("/api/esp/verion", HTTP_POST, [] (AsyncWebServerRequest *request) {
char *json_str = (char *)malloc( sizeof(char) * 70 );
if(json_str != NULL) {
sprintf(json_str,
"{\"url\":\"/api/esp/verion\",\"version\":\"%s\",\"status\":\"susses\"}",
CLEANER_VERSION
);
request->send(200, "application/json", json_str);
} else {
request->send(400, "application/json", "{\"url\":\"/api/esp/version\",\"status\":\"error\",\"message\":\"The ESP verion was null\"}");
}
});

// [POST] http://cleaner/api/esp/info- Get ESP32 info
server.on("/api/esp/info", HTTP_POST, [] (AsyncWebServerRequest *request) {
char *json_str = (char *)malloc( sizeof(char) * 500 );
Expand Down

0 comments on commit 1719c5b

Please sign in to comment.