Skip to content

Commit

Permalink
"reset" renamed to "restart" in the websocket API and the REST API. A…
Browse files Browse the repository at this point in the history
…dditional its available now via MQTT too.

Attention, the URL changed from "/rest/api/v1/reset" to "/rest/api/v1/device/restart".
  • Loading branch information
BlueAndi committed Jan 5, 2025
1 parent 90cd03c commit 2628967
Show file tree
Hide file tree
Showing 15 changed files with 103 additions and 104 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ Use the following default credentials to get access to the PIXELIX web interface
Connect PIXELIX with your PC via usb and start a terminal. Use the following commands to set the wifi SSID and passphrase of your home wifi network:
* Write wifi passphrase: ```write wifi passphrase <your-passphrase>```
* Write wifi SSID: ```write wifi ssid <your-ssid>```
* Restart PIXELIX: ```reset```
* Restart PIXELIX: ```restart```
* Get IP-address: ```get ip```
* Get status: ```get status```
* A status of 0 means everything is ok.
Expand Down
14 changes: 7 additions & 7 deletions data/debug.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ <h1 class="mt-5">Debug</h1>
<ul class="nav nav-tabs" role="tablist">
<li class="nav-item" role="presentation"><a class="nav-link active" id="logging-tab" data-bs-toggle="tab" role="tab" href="#logging" aria-controls="logging" aria-selected="true">Logging</a></li>
<li class="nav-item" role="presentation"><a class="nav-link" id="measurement-tab" data-bs-toggle="tab" role="tab" href="#measurement" aria-controls="measurement" aria-selected="false">Measurement</a></li>
<li class="nav-item" role="presentation"><a class="nav-link" id="reset-tab" data-bs-toggle="tab" role="tab" href="#reset" aria-controls="reset" aria-selected="false">Reset</a></li>
<li class="nav-item" role="presentation"><a class="nav-link" id="restart-tab" data-bs-toggle="tab" role="tab" href="#restart" aria-controls="restart" aria-selected="false">Reset</a></li>
</ul>
<div class="tab-content" id="myTabContent">
<div class="tab-pane fade show active" id="logging" role="tabpanel" aria-labelledby="logging-tab">
Expand Down Expand Up @@ -96,9 +96,9 @@ <h1 class="mt-5">Debug</h1>
<button class="btn btn-light" id="buttonMeasurement" type="button" onclick="toggleMeasurement();" disabled>Start</button>
</p>
</div>
<div class="tab-pane fade" id="reset" role="tabpanel" aria-labelledby="reset-tab">
<p>Reset the system now: </p>
<p><button class="btn btn-light" type="button" onclick="reset();" disabled>Reset</button></p>
<div class="tab-pane fade" id="restart" role="tabpanel" aria-labelledby="restart-tab">
<p>Restart the system now: </p>
<p><button class="btn btn-light" type="button" onclick="restart();" disabled>Reset</button></p>
</div>
</div>
</div>
Expand Down Expand Up @@ -262,11 +262,11 @@ <h1 class="mt-5">Debug</h1>
});
}

/* Reset device */
function reset() {
/* Restart device */
function restart() {
disableUI();

wsClient.reset().then(function(rsp) {
wsClient.restart().then(function(rsp) {
return dialog.showInfo("<p>Ok.</p>");
}).catch(function(err) {
return dialog.showError("<p>Error: " + err + "</p>");
Expand Down
12 changes: 12 additions & 0 deletions data/extra/restart.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"ha": {
"component": "button",
"discovery": {
"name": "Restart",
"ic": "mdi:restart",
"ent_cat": "config",
"dev_cla": "restart",
"pl_prs": "{}"
}
}
}
6 changes: 3 additions & 3 deletions data/js/rest.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,10 @@ pixelix.rest.Client.prototype.setSetting = function(key, value) {
return promise;
};

pixelix.rest.Client.prototype.reset = function() {
pixelix.rest.Client.prototype.restart = function() {
return utils.makeRequest({
method: "GET",
url: "/rest/api/v1/reset",
method: "POST",
url: "/rest/api/v1/device/restart",
isJsonResponse: true
});
};
Expand Down
4 changes: 2 additions & 2 deletions data/js/ws.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,13 +289,13 @@ pixelix.ws.Client.prototype.getSlots = function() {
}.bind(this));
};

pixelix.ws.Client.prototype.reset = function() {
pixelix.ws.Client.prototype.restart = function() {
return new Promise(function(resolve, reject) {
if (null === this._socket) {
reject();
} else {
this._sendCmd({
name: "RESET",
name: "RESTART",
par: null,
resolve: resolve,
reject: reject
Expand Down
4 changes: 2 additions & 2 deletions data/update.html
Original file line number Diff line number Diff line change
Expand Up @@ -344,12 +344,12 @@ <h1 class="mt-5">Update</h1>
progress = 90;
updateProgressBar("progressBarRestore", progress);
}).then(function() {
return restClient.reset();
return restClient.restart();
}).then(function() {
progress = 100;
updateProgressBar("progressBarRestore", progress);

return dialog.showInfo("<p>Reset performed to apply restored configuration.</p>");
return dialog.showInfo("<p>Restart performed to apply restored configuration.</p>");
}).catch(function() {
dialog.showError("<p>Restore failed.</p>");
});
Expand Down
6 changes: 3 additions & 3 deletions doc/WEBSOCKET.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

* [Get display pixel colors](#get-display-pixel-colors)
* [Get slots information](#get-slots-information)
* [Reset](#reset)
* [Restart](#restart)
* [Brightness](#brightness)
* [Get brightness information](#get-brightness-information)
* [Set brightness](#set-brightness)
Expand Down Expand Up @@ -62,8 +62,8 @@ Response:
* Failed:
* ```NACK```

# Reset
Command: ```RESET```
# Restart
Command: ```RESTART```

Parameter:
* N/A
Expand Down
2 changes: 1 addition & 1 deletion lib/TopicHandlerService/src/TopicHandlerService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ void TopicHandlerService::registerTopic(const String& deviceId, const String& en
isReadAccess = true;
}

if ((nullptr != setTopicFunc) &&
if ((nullptr != setTopicFunc) ||
(nullptr != uploadReqFunc))
{
isWriteAccess = true;
Expand Down
51 changes: 25 additions & 26 deletions src/General/MiniTerminal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,31 +61,31 @@
* Local Variables
*****************************************************************************/

/** Command: reset */
static const char RESET[] = "reset";
/** Command: restart */
static const char RESTART[] = "restart";

/** Command: write wifi passphrase */
static const char WRITE_WIFI_PASSPHRASE[] = "write wifi passphrase ";
static const char WRITE_WIFI_PASSPHRASE[] = "write wifi passphrase ";

/** Command: write wifi ssid */
static const char WRITE_WIFI_SSID[] = "write wifi ssid ";
static const char WRITE_WIFI_SSID[] = "write wifi ssid ";

/** Command: get ip */
static const char GET_IP[] = "get ip";
static const char GET_IP[] = "get ip";

/** Command: status */
static const char GET_STATUS[] = "get status";
static const char GET_STATUS[] = "get status";

/** Command: help */
static const char HELP[] = "help";
static const char HELP[] = "help";

const MiniTerminal::CmdTableEntry MiniTerminal::m_cmdTable[] = {
{ RESET, &MiniTerminal::cmdReset },
{ WRITE_WIFI_PASSPHRASE, &MiniTerminal::cmdWriteWifiPassphrase },
{ WRITE_WIFI_SSID, &MiniTerminal::cmdWriteWifiSSID },
{ GET_IP, &MiniTerminal::cmdGetIPAddress },
{ GET_STATUS, &MiniTerminal::cmdGetStatus },
{ HELP, &MiniTerminal::cmdHelp },
{ RESTART, &MiniTerminal::cmdRestart },
{ WRITE_WIFI_PASSPHRASE, &MiniTerminal::cmdWriteWifiPassphrase },
{ WRITE_WIFI_SSID, &MiniTerminal::cmdWriteWifiSSID },
{ GET_IP, &MiniTerminal::cmdGetIPAddress },
{ GET_STATUS, &MiniTerminal::cmdGetStatus },
{ HELP, &MiniTerminal::cmdHelp },
};

/******************************************************************************
Expand All @@ -94,21 +94,21 @@ const MiniTerminal::CmdTableEntry MiniTerminal::m_cmdTable[] = {

void MiniTerminal::process()
{
char buffer[LOCAL_BUFFER_SIZE];
size_t read = m_stream.readBytes(buffer, LOCAL_BUFFER_SIZE);
size_t idx = 0U;
char buffer[LOCAL_BUFFER_SIZE];
size_t read = m_stream.readBytes(buffer, LOCAL_BUFFER_SIZE);
size_t idx = 0U;

/* Process the read input data. */
while(read > idx)
while (read > idx)
{
char currentChar = buffer[idx];

/* Command finished? */
if (ASCII_LF == currentChar)
{
/* Don't echo mechanism, because its too late in case the
* command may write a result too.
*/
* command may write a result too.
*/
(void)m_stream.write(currentChar);

m_input[m_writeIndex] = '\0';
Expand All @@ -118,9 +118,9 @@ void MiniTerminal::process()
{
executeCommand(m_input);
}

/* Reset command line buffer */
m_writeIndex = 0U;
m_writeIndex = 0U;
m_input[m_writeIndex] = '\0';
}
/* Remove the last character from command line? */
Expand All @@ -129,8 +129,7 @@ void MiniTerminal::process()
{
if (0 < m_writeIndex)
{
static const char removeSeq[] =
{
static const char removeSeq[] = {
ASCII_BS,
ASCII_SP,
ASCII_BS
Expand Down Expand Up @@ -192,7 +191,7 @@ void MiniTerminal::executeCommand(const char* cmdLine)
for (idx = 0U; UTIL_ARRAY_NUM(m_cmdTable) > idx; ++idx)
{
const CmdTableEntry entry = m_cmdTable[idx];
const size_t len = strlen(entry.cmdStr);
const size_t len = strlen(entry.cmdStr);

if (0 == strncmp(cmdLine, entry.cmdStr, len))
{
Expand All @@ -207,7 +206,7 @@ void MiniTerminal::executeCommand(const char* cmdLine)
}
}

void MiniTerminal::cmdReset(const char* par)
void MiniTerminal::cmdRestart(const char* par)
{
UTIL_NOT_USED(par);
m_isRestartRequested = true;
Expand Down Expand Up @@ -282,7 +281,7 @@ void MiniTerminal::cmdGetStatus(const char* par)
{
UTIL_NOT_USED(par);

ErrorState::ErrorId status = ErrorState::getInstance().getErrorId();
ErrorState::ErrorId status = ErrorState::getInstance().getErrorId();
String result;

result += static_cast<int32_t>(status);
Expand Down
4 changes: 2 additions & 2 deletions src/General/MiniTerminal.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,11 @@ class MiniTerminal
void executeCommand(const char* cmdLine);

/**
* Reset the device.
* Restart the device.
*
* @param[in] par Parameter
*/
void cmdReset(const char* par);
void cmdRestart(const char* par);

/**
* Write wifi passphrase.
Expand Down
28 changes: 27 additions & 1 deletion src/Topics/Topics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include <TopicHandlerService.h>
#include <Util.h>
#include "DisplayMgr.h"
#include "UpdateMgr.h"

/******************************************************************************
* Compiler Switches
Expand Down Expand Up @@ -69,6 +70,7 @@ typedef struct
static bool getDisplayState(const String& topic, JsonObject& value);
static bool hasDisplayStateChanged(const String& topic);
static bool setDisplayState(const String& topic, const JsonObjectConst& value);
static bool restart(const String& topic, const JsonObjectConst& value);

/******************************************************************************
* Local Variables
Expand All @@ -83,7 +85,8 @@ static String gDeviceId;
* List of topics.
*/
static TopicElem gTopicList[] = {
{ "display", "/power", getDisplayState, hasDisplayStateChanged, setDisplayState, "/extra/display.json" }
{ "display", "/power", getDisplayState, hasDisplayStateChanged, setDisplayState, "/extra/display.json" },
{ "device", "/restart", nullptr, nullptr, restart, "/extra/restart.json" }
};

/**
Expand Down Expand Up @@ -263,3 +266,26 @@ static bool setDisplayState(const String& topic, const JsonObjectConst& value)

return isSuccessful;
}

/**
* Restart the device.
*
* @param[in] topic Topic
* @param[in] value Value
*
* @return If successful, it will return true otherwise false.
*/
static bool restart(const String& topic, const JsonObjectConst& value)
{
const uint32_t RESTART_DELAY = 100U; /* ms */

UTIL_NOT_USED(topic);
UTIL_NOT_USED(value);

/* To ensure that a positive response will be sent before the device restarts,
* a short delay is necessary.
*/
UpdateMgr::getInstance().reqRestart(RESTART_DELAY);

return true;
}
38 changes: 0 additions & 38 deletions src/Web/RestApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
#include "RestUtil.h"
#include "SlotList.h"
#include "ButtonActions.h"
#include "UpdateMgr.h"

#include <Util.h>
#include <WiFi.h>
Expand Down Expand Up @@ -120,7 +119,6 @@ static void handleSlot(AsyncWebServerRequest* request);
static void handlePluginInstall(AsyncWebServerRequest* request);
static void handlePluginUninstall(AsyncWebServerRequest* request);
static void handlePlugins(AsyncWebServerRequest* request);
static void handleReset(AsyncWebServerRequest* request);
static void handleSensors(AsyncWebServerRequest* request);
static void handleSettings(AsyncWebServerRequest* request);
static void handleSetting(AsyncWebServerRequest* request);
Expand Down Expand Up @@ -178,7 +176,6 @@ void RestApi::init(AsyncWebServer& srv)
(void)srv.on("/rest/api/v1/plugin/install", handlePluginInstall);
(void)srv.on("/rest/api/v1/plugin/uninstall", handlePluginUninstall);
(void)srv.on("/rest/api/v1/plugins", handlePlugins);
(void)srv.on("/rest/api/v1/reset", handleReset);
(void)srv.on("/rest/api/v1/sensors", handleSensors);
(void)srv.on("/rest/api/v1/settings", handleSettings);
(void)srv.on("/rest/api/v1/setting", handleSetting);
Expand Down Expand Up @@ -780,41 +777,6 @@ static void handlePlugins(AsyncWebServerRequest* request)
RestUtil::sendJsonRsp(request, jsonDoc, httpStatusCode);
}

/**
* Perform a reset request.
* GET \c "/api/v1/reset"
*
* @param[in] request HTTP request
*/
static void handleReset(AsyncWebServerRequest* request)
{
const size_t JSON_DOC_SIZE = 512U;
DynamicJsonDocument jsonDoc(JSON_DOC_SIZE);
uint32_t httpStatusCode = HttpStatus::STATUS_CODE_OK;

if (nullptr == request)
{
return;
}

if (HTTP_GET != request->method())
{
RestUtil::prepareRspErrorHttpMethodNotSupported(jsonDoc);
httpStatusCode = HttpStatus::STATUS_CODE_NOT_FOUND;
}
else
{
/* To ensure the positive response will be sent. */
const uint32_t RESTART_DELAY = 100U; /* ms */

(void)RestUtil::prepareRspSuccess(jsonDoc);

UpdateMgr::getInstance().reqRestart(RESTART_DELAY);
}

RestUtil::sendJsonRsp(request, jsonDoc, httpStatusCode);
}

/**
* List all sensors.
* GET \c "/api/v1/sensors"
Expand Down
Loading

0 comments on commit 2628967

Please sign in to comment.