Skip to content

Commit

Permalink
Merge pull request #598 from visualapproach/development_v4
Browse files Browse the repository at this point in the history
Development v4
  • Loading branch information
visualapproach authored Aug 16, 2023
2 parents 02ab869 + 9115d33 commit 8c770d6
Show file tree
Hide file tree
Showing 24 changed files with 111 additions and 19 deletions.
26 changes: 22 additions & 4 deletions Code/data/config.html
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ <h2>Command queue</h2>
<td colspan="2" class="center"><button id="resetq" class="button_red" onclick="buttonConfirm(this);resetCommandQueue()">Clear queue</button></td>
</tr>
<tr>
<td colspan="2" class="center"><button id="saveq" class="button" onclick="savetofile()" disabled>Save to file</button></td>
<td colspan="2" class="center"><button id="loadq" class="button" onclick="buttonConfirm(this);loadfromfile()" disabled>Load from file</button></td>
<td colspan="2" class="center"><button id="saveq" class="button" onclick="savetofile()">Save to file</button></td>
<td colspan="2" class="center"><button id="loadq" class="button" onclick="buttonConfirm(this);loadfromfile()">Load from file</button></td>
</tr>
</table>
</section>
Expand Down Expand Up @@ -356,12 +356,30 @@ <h2>Command queue</h2>

function savetofile()
{

var filename=prompt("Please enter a filename","mycommandqueue1");
if(filename == null) return;
var req = new XMLHttpRequest();
req.open('POST', '/cmdq_file/');
var json = {
'ACT':'save',
'NAME':filename
};
req.send(JSON.stringify(json));
console.log(json);
}

function loadfromfile()
{

var filename=prompt("Please enter a filename","mycommandqueue1");
if(filename == null) return;
var req = new XMLHttpRequest();
req.open('POST', '/cmdq_file/');
var json = {
'ACT':'load',
'NAME':filename
};
req.send(JSON.stringify(json));
console.log(json);
}

function editCommandQueue(index)
Expand Down
Binary file modified Code/datazip/calib.html.gz
Binary file not shown.
Binary file modified Code/datazip/chkupdatefw.html.gz
Binary file not shown.
Binary file modified Code/datazip/config.html.gz
Binary file not shown.
Binary file modified Code/datazip/favicon.ico.gz
Binary file not shown.
Binary file modified Code/datazip/function.js.gz
Binary file not shown.
Binary file modified Code/datazip/hwconfig.html.gz
Binary file not shown.
Binary file modified Code/datazip/hwtestinfo.html.gz
Binary file not shown.
Binary file modified Code/datazip/index.html.gz
Binary file not shown.
Binary file modified Code/datazip/index.js.gz
Binary file not shown.
Binary file modified Code/datazip/main.css.gz
Binary file not shown.
Binary file modified Code/datazip/mqtt.html.gz
Binary file not shown.
Binary file modified Code/datazip/remove.html.gz
Binary file not shown.
Binary file modified Code/datazip/success.html.gz
Binary file not shown.
Binary file modified Code/datazip/upload.html.gz
Binary file not shown.
Binary file modified Code/datazip/webconfig.html.gz
Binary file not shown.
Binary file modified Code/datazip/wifi.html.gz
Binary file not shown.
Binary file modified Code/fw/firmware.bin
Binary file not shown.
2 changes: 1 addition & 1 deletion Code/fw/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2023-08-11-1232
2023-08-16-1957
2 changes: 1 addition & 1 deletion Code/lib/BWC_unified/bwc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1311,7 +1311,7 @@ void BWC::loadCommandQueue(){
file.close();
return;
}

_command_que.clear();
// Set the values in the variables
for(int i = 0; i < doc[F("LEN")]; i++){
command_que_item item;
Expand Down
2 changes: 1 addition & 1 deletion Code/src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <WiFi.h>
#endif
#define DEVICE_NAME "layzspa"
#define FW_VERSION "2023-08-11-1232"
#define FW_VERSION "2023-08-16-1957"

#define HA_PREFIX "homeassistant"
#define PROM_NAMESPACE "layzspa"
Expand Down
3 changes: 2 additions & 1 deletion Code/src/ha.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

void setupHA()
{
HeapSelectIram ephemeral;
//HeapSelectIram ephemeral;
//HeapSelectDram ephemeral;

const char* _dev = "dev";
Expand All @@ -33,6 +33,7 @@
*/
String topic;
String payload;
payload.reserve(1300);
#if defined(ESP8266)
String mychipid = String((unsigned int)ESP.getChipId());
#elif defined(ESP32)
Expand Down
93 changes: 82 additions & 11 deletions Code/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,21 @@ DallasTemperature tempSensors(&oneWire);

void setup()
{
HeapSelectIram ephemeral;

// init record of stack
char stack;
stack_start = &stack;

Serial.begin(115200);
Serial.println(F("\nStart"));
bwc = new BWC;
bwc->setup();
bwc->loop();
{
HeapSelectIram ephemeral;
Serial.printf("IRamheap %d\n", ESP.getFreeHeap());
bwc = new BWC;
bwc->setup();
bwc->loadCommandQueue();
bwc->loop();
}
periodicTimer.attach(periodicTimerInterval, []{ periodicTimerFlag = true; });
// delayed mqtt start
startComplete.attach(61, []{ if(useMqtt) enableMqtt = true; startComplete.detach(); });
Expand All @@ -85,8 +89,12 @@ void setup()
loadWebConfig();
startWiFi();
startNTP();
startOTA();
startHttpServer();
{
HeapSelectIram ephemeral;
Serial.printf("IRamheap %d\n", ESP.getFreeHeap());
startOTA();
startHttpServer();
}
startWebSocket();
startMqtt();
if(bwc->hasTempSensor)
Expand All @@ -102,7 +110,6 @@ void setup()
Serial.println(F("End of setup()"));
heap_water_mark = ESP.getFreeHeap();
Serial.println(ESP.getFreeHeap()); //26216
bwc->loadCommandQueue();
}

void loop()
Expand Down Expand Up @@ -221,10 +228,13 @@ void loop()
*/
void sendWS()
{
HeapSelectIram ephemeral;

// HeapSelectIram ephemeral;
// Serial.printf("IRamheap %d\n", ESP.getFreeHeap());
// send states
String json;
json.reserve(320);

bwc->getJSONStates(json);
webSocket->broadcastTXT(json);
// send times
Expand Down Expand Up @@ -281,6 +291,7 @@ void getOtherInfo(String &rtn)
void sendMQTT()
{
HeapSelectIram ephemeral;
Serial.printf("IRamheap %d\n", ESP.getFreeHeap());
String json;
json.reserve(320);

Expand All @@ -294,7 +305,7 @@ void sendMQTT()
{
//Serial.println(F("MQTT > message not published"));
}
delay(2);
// delay(2);

// send times
json.clear();
Expand All @@ -307,7 +318,7 @@ delay(2);
{
//Serial.println(F("MQTT > times not published"));
}
delay(2);
// delay(2);

//send other info
json.clear();
Expand Down Expand Up @@ -626,6 +637,7 @@ void startHttpServer()
server->on(F("/getversions/"), handleGetVersions);
server->on(F("/debug-on/"), [](){bwc->BWC_DEBUG = true; server->send(200, F("text/plain"), "ok");});
server->on(F("/debug-off/"), [](){bwc->BWC_DEBUG = false; server->send(200, F("text/plain"), "ok");});
server->on(F("/cmdq_file/"), handle_cmdq_file);
// server->on(F("/getfiles/"), updateFiles);

// if someone requests any other file or page, go to function 'handleNotFound'
Expand Down Expand Up @@ -925,6 +937,64 @@ void handleDelCommand()
server->send(200, F("text/plain"), "");
}

void handle_cmdq_file()
{
if (!checkHttpPost(server->method())) return;

// DynamicJsonDocument doc(256);
StaticJsonDocument<256> doc;
String message = server->arg(0);
DeserializationError error = deserializeJson(doc, message);
if (error)
{
server->send(400, F("text/plain"), F("Error deserializing message"));
return;
}

String action = doc[F("ACT")].as<String>();;
String filename = "/";
filename += doc[F("NAME")].as<String>();;

if(action.equals("load"))
{
copyFile("/cmdq.json", "/cmdq.backup");
copyFile(filename, "/cmdq.json");
bwc->reloadCommandQueue();
}
if(action.equals("save"))
{
copyFile("/cmdq.json", filename);
}

server->send(200, F("text/plain"), "");
}

void copyFile(String source, String dest)
{
char ibuffer[64]; //declare a buffer

File f_source = LittleFS.open(source, "r"); //open source file to read
if (!f_source)
{
return;
}

File f_dest = LittleFS.open(dest, "w"); //open destination file to write
if (!f_dest)
{
return;
}

while (f_source.available() > 0)
{
byte i = f_source.readBytes(ibuffer, 64); // i = number of bytes placed in buffer from file f_source
f_dest.write(ibuffer, i); // write i bytes from buffer to file f_dest
}

f_dest.close(); // done, close the destination file
f_source.close(); // done, close the source file
}

/**
* load "Web Config" json configuration from "webconfig.json"
*/
Expand Down Expand Up @@ -1918,7 +1988,8 @@ void updateError(int err){
*/
void startMqtt()
{
HeapSelectIram ephemeral;
// HeapSelectIram ephemeral;
// Serial.printf("IRamheap %d\n", ESP.getFreeHeap());

Serial.println("startmqtt");
// if(!aWifiClient) aWifiClient = new WiFiClient;
Expand Down
2 changes: 2 additions & 0 deletions Code/src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ void handleGetCommandQueue();
void handleAddCommand();
void handleEditCommand();
void handleDelCommand();
void handle_cmdq_file();
void copyFile(String source, String dest);
void loadWebConfig();
void saveWebConfig();
void handleGetWebConfig();
Expand Down

0 comments on commit 8c770d6

Please sign in to comment.