Skip to content

Commit

Permalink
Fixed a few bugs regarding upload baud rates and when to start proces…
Browse files Browse the repository at this point in the history
…sing incomming MQTT messages.
  • Loading branch information
tpanajott committed Sep 21, 2023
1 parent ae70b1a commit 8ae9745
Show file tree
Hide file tree
Showing 18 changed files with 196 additions and 81 deletions.
3 changes: 3 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
FROM python:latest

RUN apt-get update \
&& apt-get -y upgrade

RUN apt-get update \
&& apt-get install -y --no-install-recommends \
postgresql-client curl inotify-tools net-tools \
Expand Down
Binary file modified docker/web/nspanelmanager/data_file.bin
Binary file not shown.
Binary file modified docker/web/nspanelmanager/firmware.bin
Binary file not shown.
Binary file modified docker/web/nspanelmanager/merged_flash.bin
Binary file not shown.
1 change: 1 addition & 0 deletions docker/web/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ gevent==22.10.2
greenlet==2.0.2
idna==3.4
paho-mqtt==1.6.1
pip-upgrade==0.0.6
psutil==5.9.4
pytz==2023.3
requests==2.28.2
Expand Down
9 changes: 5 additions & 4 deletions firmware/NSPanelManagerFirmware/data/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ <h5 class="title is-5">NSPanel TFT upload</h5>
<div class="field">
<label class="label">Upload baud rate</label>
<div class="notification is-warning">
The upload baud rate that this specific NSPanel can can not be
The upload baud rate that this specific NSPanel is able to perform at can not be
calculated. This is something you will have to experiment with if
you wish to have different value than default. Chaning this from
default may cause the NSPanel to fail to update the screen TFT.
Expand All @@ -331,12 +331,13 @@ <h5 class="title is-5">NSPanel TFT upload</h5>
<option value="4800">4800</option>
<option value="9600">9600</option>
<option value="19200">19200</option>
<option value="31250">31250</option>
<option value="38400">38400</option>
<option value="57600">57600</option>
<option value="115200">115200 (default)</option>
<option value="230400">230400</option>
<option value="460800">460800</option>
<option value="576000">576000</option>
<option value="250000">250000</option>
<option value="260000">260000</option>
<option value="512000">512000</option>
<option value="921600">921600</option>
</select>
</div>
Expand Down
84 changes: 84 additions & 0 deletions firmware/NSPanelManagerFirmware/data/static/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ html {
background-color: #101410;
}

body {
color: #4a4a4a;
font-size: 1em;
font-weight: 400;
line-height: 1.5;
}

#page-title {
color: #ffffff;
}
Expand Down Expand Up @@ -41,3 +48,80 @@ html {
.hidden {
display: none;
}

.title {
color: #363636;
font-size: 2rem;
font-weight: 600;
line-height: 1.125;
}

.subtitle {
word-break: break-word;
}

@media screen and (min-width: 1408px) {
.container:not(.is-max-desktop):not(.is-max-widescreen) {
max-width: 1344px;
}
}
@media screen and (min-width: 1216px) {
.container:not(.is-max-desktop) {
max-width: 1152px;
}
}
.container {
margin: 0 auto;
position: relative;
width: auto;
}
@media screen and (min-width: 1024px) {
.container {
max-width: 960px;
}
}

.modal {
align-items: center;
display: none;
flex-direction: column;
justify-content: center;
overflow: hidden;
position: fixed;
z-index: 40;
}

.section {
padding: 3rem 3rem;
}

.box {
background-color: #fff;
border-radius: 6px;
box-shadow: 0 .5em 1em -.125em rgba(10,10,10,.1),0 0 0 1px rgba(10,10,10,.02);
color: #4a4a4a;
display: block;
padding: 1.25rem;
}

.label {
color: #363636;
display: block;
font-size: 1rem;
font-weight: 700;
}

.notification {
border-radius: 4px;
position: relative;
padding: 1.25rem 2.5rem 1.25rem 1.5rem;
}

.mt-4 {
margin-top: 1rem !important;
}

.is-warning {
background-color: #ffe08a;
color: rgba(0,0,0,.7);
}
2 changes: 1 addition & 1 deletion firmware/NSPanelManagerFirmware/include/nspm-bin-version.h
Original file line number Diff line number Diff line change
@@ -1 +1 @@
#define NSPanelManagerFirmwareVersion "0.0.1442"
#define NSPanelManagerFirmwareVersion "0.0.1483"
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,12 @@ bool ChunkDownloader::_downloadChunks() {
uint read_chunks = 0;
while (read_chunks < this->_download_chunks) {
if (!httpClient.getStreamPtr()->available()) { // No data avilable from WiFi, wait 1000ms and try again
vTaskDelay(1000 / portTICK_PERIOD_MS);
vTaskDelay(500 / portTICK_PERIOD_MS);
num_failed_reads++;

if (num_failed_reads >= 10) {
return false;
}
continue;
}

Expand All @@ -58,7 +62,7 @@ bool ChunkDownloader::_downloadChunks() {
uint16_t num_read_bytes = 0;
while (num_read_bytes < next_read_chunk_size) {
while (httpClient.getStreamPtr()->available() <= 0) {
vTaskDelay(250 / portTICK_PERIOD_MS);
vTaskDelay(500 / portTICK_PERIOD_MS);
num_failed_reads++;
if (num_failed_reads >= 10) {
// We have had 10 failed reads in a row for a total of 2.5 seconds, cancel this request and try again.
Expand Down
12 changes: 9 additions & 3 deletions firmware/NSPanelManagerFirmware/lib/HttpLib/HttpLib.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <HTTPClient.h>
#include <HttpLib.hpp>
#include <MqttLog.hpp>
#include <cstdint>

size_t HttpLib::GetFileSize(const char *url) {
HTTPClient httpClient;
Expand Down Expand Up @@ -45,11 +46,16 @@ size_t HttpLib::DownloadChunk(uint8_t *buffer, const char *address, size_t offse
}

size_t sizeReceived = 0;
uint8_t num_retries = 0;
while (sizeReceived < size) {
if (!httpClient.getStreamPtr()->available()) { // No data avilable from WiFi, wait 100ms and try again
vTaskDelay(500 / portTICK_PERIOD_MS);
LOG_DEBUG("Still waiting for data from address '", address, "'.");
continue;
vTaskDelay(50 / portTICK_PERIOD_MS);
num_retries++;
if (num_retries >= 5) {
break;
} else {
continue;
}
}
sizeReceived += httpClient.getStreamPtr()->readBytes(&buffer[sizeReceived], httpClient.getStreamPtr()->available() >= size - sizeReceived ? size - sizeReceived : httpClient.getStreamPtr()->available());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,13 @@ void InterfaceManager::_taskLoadConfigAndInit(void *param) {
NSPanel::attachSleepCallback(InterfaceManager::processSleepEvent);
NSPanel::attachWakeCallback(InterfaceManager::processWakeEvent);

// Attach screen clock MQTT callback if configured from manager.
if (InterfaceConfig::show_screensaver_clock) {
PageManager::GetScreensaverPage()->attachMqttTimeCallback();
} else {
LOG_DEBUG("Not attaching MQTT clock callback is panel is confiugred to now show clock on screensaver.");
}

LOG_INFO("Config initialized. Closing taskLoadConfigAndInit");
vTaskDelete(NULL); // Delete task, we are done
}
Expand Down Expand Up @@ -181,8 +188,8 @@ void InterfaceManager::handleNSPanelCommand(char *topic, byte *payload, unsigned
} else if (command.compare("firmware_update") == 0) {
WebManager::startOTAUpdate();
} else if (command.compare("tft_update") == 0) {
InterfaceManager::stop();
NSPanel::instance->startOTAUpdate();
InterfaceManager::stop();
} else {
LOG_WARNING("Received unknown command on MQTT: ", command.c_str());
}
Expand Down Expand Up @@ -220,11 +227,6 @@ void InterfaceManager::subscribeToMqttTopics() {
// Subscribe to command to wake/put to sleep the display
vTaskDelay(100 / portTICK_PERIOD_MS);
MqttManager::subscribeToTopic(NSPMConfig::instance->mqtt_screen_cmd_topic.c_str(), &InterfaceManager::mqttCallback);
if (InterfaceConfig::show_screensaver_clock) {
PageManager::GetScreensaverPage()->attachMqttTimeCallback();
} else {
LOG_DEBUG("Not attaching MQTT clock callback is panel is confiugred to now show clock on screensaver.");
}

MqttManager::subscribeToTopic(NSPMConfig::instance->mqtt_panel_cmd_topic.c_str(), &InterfaceManager::handleNSPanelCommand);
MqttManager::subscribeToTopic(NSPMConfig::instance->mqtt_panel_screen_brightness_topic.c_str(), &InterfaceManager::handleNSPanelScreenBrightnessCommand);
Expand Down
Loading

0 comments on commit 8ae9745

Please sign in to comment.