Skip to content

Commit

Permalink
Merge pull request #318 from visualapproach/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
visualapproach authored Jul 2, 2022
2 parents cbf7b8e + b6d85db commit 4ddb436
Show file tree
Hide file tree
Showing 20 changed files with 316 additions and 213 deletions.
Binary file modified Build-instructions-Bestway-WiFi-remote.pdf
Binary file not shown.
10 changes: 7 additions & 3 deletions Code/4-wire-version/data/WebSocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,14 @@ function handlemsg(e)
]
document.getElementById('mqtt').innerHTML = "MQTT: " + mqtt_states[msgobj.MQTT + 4];

// hydro jets available
document.getElementById('jetstitle').style.display = (msgobj.HASJETS ? 'table-row' : 'none');
document.getElementById('jetsbutton').style.display = (msgobj.HASJETS ? 'table-row' : 'none');

document.getElementById('jetstitle').style.display = (msgobj.HASJETS ? 'inherit' : 'none');
document.getElementById('jetsbutton').style.display = (msgobj.HASJETS ? 'inherit' : 'none');
document.getElementById('jetstotals').style.display = (msgobj.HASJETS ? 'table-row' : 'none');

document.getElementById('airtitle').style.display = (msgobj.HASAIR ? 'inherit' : 'none');
document.getElementById('airbutton').style.display = (msgobj.HASAIR ? 'inherit' : 'none');
document.getElementById('airtotals').style.display = (msgobj.HASAIR ? 'table-row' : 'none');

document.getElementById('ciotx').innerHTML = 'CIO TX: ' + (msgobj.CIOTX ? 'Active' : 'Dead');
document.getElementById('dsptx').innerHTML = 'DSP TX: ' + (msgobj.DSPTX ? 'Active' : 'Dead');
Expand Down
9 changes: 5 additions & 4 deletions Code/4-wire-version/data/config.html
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,9 @@
<option value="2">Set air bubbles</option>
<option value="3">Set heater</option>
<option value="4">Set filter pump</option>
<!--
<option value="11">Set hydrojets</option>
-->
<option value="6">Reboot ESP</option>
<option value="12">Take Control</option>
</select>
</td>
</tr>
Expand Down Expand Up @@ -129,7 +128,9 @@ <h2>Command queue</h2>
const rebootesp = 6;
const gettarget = 7;
const setjets = 11;
const commandlist = ["Set target", "Set unit", "Set bubbles", "Set heat", "Set pump", "Reset queue", "Reboot ESP", "Internal cmd", "Set jets"];
const setgodmode = 12;
const commandlist = ["Set target", "Set unit", "Set bubbles", "Set heat", "Set pump", "Reset queue", "Reboot ESP", "Internal cmd", "resetTotals:", "resetTimerChlorine", "resetTimerFilter", "Set jets", "Take Control"];


function loadconfig(){
const Http = new XMLHttpRequest();
Expand Down Expand Up @@ -195,7 +196,7 @@ <h2>Command queue</h2>
"FINT":parseInt(document.getElementById("finterval").value),
"CLINT":parseInt(document.getElementById("clinterval").value),
"AUDIO":document.getElementById("audio").checked//,
//"RESTORE":document.getElementById("restore").value
//"RESTORE":parseInt(document.getElementById("restore").value)
}
Http.send(JSON.stringify(msgobj));
console.log(msgobj);
Expand Down
14 changes: 8 additions & 6 deletions Code/4-wire-version/data/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,14 @@ <h2>Control:</h2>
</table>
<table class="fixed">
<tr>
<td>Bubbles</td>
<td><div id="airtitle">Bubbles</div></td>
<td>
<label class="switch">
<input type="checkbox" id="AIR" onchange="sendCommand('toggleBubbles')">
<span class="slider round"></span>
</label>
<div id="airbutton">
<label class="switch">
<input type="checkbox" id="AIR" onchange="sendCommand('toggleBubbles')">
<span class="slider round"></span>
</label>
</div>
</td>
<td>Heater</td>
<td>
Expand Down Expand Up @@ -156,7 +158,7 @@ <h2>Totals:</h2>
<td>Heating:</td>
<td><span id="heatingtime">n/a</span></td>
</tr>
<tr>
<tr id="airtotals">
<td>Air:</td>
<td><span id="airtime">n/a</span></td>
</tr>
Expand Down
12 changes: 8 additions & 4 deletions Code/4-wire-version/lib/BWC4W/BWC_8266_4w.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@ void CIO::loop(void) {
{
msglen = cio_serial.readBytes(from_CIO_buf, PAYLOADSIZE);
//copy from_CIO_buf -> to_DSP_buf
if(msglen == PAYLOADSIZE){
if(msglen == PAYLOADSIZE)
{
//discard message if checksum is wrong
uint8_t calculatedChecksum;
calculatedChecksum = from_CIO_buf[1]+from_CIO_buf[2]+from_CIO_buf[3]+from_CIO_buf[4];
if(from_CIO_buf[CIO_CHECKSUMINDEX] == calculatedChecksum){
if(from_CIO_buf[CIO_CHECKSUMINDEX] == calculatedChecksum)
{
for(int i = 0; i < PAYLOADSIZE; i++){
if(to_DSP_buf[i] != from_CIO_buf[i]) dataAvailable = true;
to_DSP_buf[i] = from_CIO_buf[i];
Expand All @@ -48,7 +50,8 @@ void CIO::loop(void) {
states[CHAR1] = ' ';
states[CHAR2] = ' ';
states[CHAR3] = ' ';
if(states[ERROR]){
if(states[ERROR])
{
to_CIO_buf[COMMANDINDEX] = 0; //clear any commands
GODMODE = false;
states[CHAR1] = 'E';
Expand Down Expand Up @@ -83,7 +86,8 @@ void CIO::loop(void) {
{
msglen = dsp_serial.readBytes(from_DSP_buf, PAYLOADSIZE);
//copy from_DSP_buf -> to_CIO_buf
if(msglen == PAYLOADSIZE){
if(msglen == PAYLOADSIZE)
{
//discard message if checksum is wrong
uint8_t calculatedChecksum;
calculatedChecksum = from_DSP_buf[1]+from_DSP_buf[2]+from_DSP_buf[3]+from_DSP_buf[4];
Expand Down
48 changes: 48 additions & 0 deletions Code/4-wire-version/lib/BWC4W/BWC_8266_4w_globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -255,4 +255,52 @@ const bool HASJETS = false;
const String MYMODEL = "NO54154";
#endif

#ifdef NO54144

//what row in allowedstates to go to when pressing Bubbles, Jets, Pump, Heat (columns in that order)
//Example: We are in state zero (first row). If we press Bubbles (first column) then there is a 6
//meaning current state (row) is now 6. According to ALLOWEDSTATES table, we turn on Bubbles and keep
//everything else off. (1,0,0,0)
const uint8_t JUMPTABLE[][4] = {
// b,j,p,h
{1,2,3,4},
{0,2,3,4},
{1,0,3,4},
{1,2,0,4},
{1,2,0,3}
};
//Bubbles, Jets, Pump, Heat
const uint8_t ALLOWEDSTATES[][4] = {
{0,0,0,0},
{1,0,0,0},
{0,1,0,0},
{0,0,1,0},
{0,0,1,2} //the "2" means both heater elements
};

//cio
const uint8_t TEMPINDEX = 2;
const uint8_t ERRORINDEX = 3;
const uint8_t CIO_CHECKSUMINDEX = 5;
//dsp
const uint8_t COMMANDINDEX = 2;
const uint8_t DSP_CHECKSUMINDEX = 5;

const uint8_t PAYLOADSIZE = 7;

const uint8_t PUMPBITMASK = B00000101; //5
const uint8_t BUBBLESBITMASK = B00000010; //2
const uint8_t JETSBITMASK = B00001000; //8
// const uint8_t HEATBITMASK1 = B00000000; //0 heater stage 1 = off
// const uint8_t HEATBITMASK2 = B00110000; //48 heater stage 2 = on
//lines below should be tested. It would be consistent with 54173 model.
//If heating is slow this is probably the cause but I don't want to change it before someone tests it.
const uint8_t HEATBITMASK1 = B00110000; //48 heater stage 1 = 50%
const uint8_t HEATBITMASK2 = B01000000; //64 heater stage 2 = 100%
const uint8_t POWERBITMASK = B10000000; //128
const bool HASJETS = true;
const bool HASAIR = false;
const String MYMODEL = "NO54144";
#endif

#endif
9 changes: 7 additions & 2 deletions Code/4-wire-version/lib/BWC4W/model.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@
//#define NO54173 //this is same as 54138 but can run heater on 50% when bubbles are on.
//#define NO54123 //not tested. ref https://github.com/mrQ000/layz-rc link to presentation slides
//#define NO54154 //no jets. Works for Palm Springs 54129
//#define NO54144 //with jets, but no bubbles. Palm Springs 54144


//WARNING: DEVICES HAVE DIFFERENT PINOUTS!!! CHECK BEFORE USING
//The 54123 should work also for 54112 judging from a comment from @jenswalit in the forum

//If using/testing the new PCB choose PCB_V2
#define PCB_V1
//#define PCB_V2 //The PCB with rounded corners
//#define PCB_V1
#define PCB_V2 //The PCB with rounded corners

#ifdef PCB_V2
#warning "USING PINOUT FOR PCB V2. EDIT lib/BWC/model.h IF USING OTHER PCB"
#endif
4 changes: 3 additions & 1 deletion Code/4-wire-version/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ lib_deps =
knolleary/PubSubClient@^2.8
tzapu/WiFiManager@^0.16
plerup/EspSoftwareSerial@^6.15.2
me-no-dev/ESPAsyncTCP
board_build.filesystem = littlefs
monitor_speed = 115200
;Set upload speed to 115200 if you get transfer errors
;upload_speed = 921600
;board_build.f_cpu = 160000000L

build_flags =
-DWEBSOCKETS_NETWORK_TYPE="NETWORK_ESP8266_ASYNC"
; Uncomment the lines below by removing semicolons and edit IP for OTA upload.
; You have to upload via USB cable the first time. (upload_protocol = esptool)
; Make sure to use a data-USB cable. There is power only cables that wont work.
Expand Down
2 changes: 1 addition & 1 deletion Code/4-wire-version/src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include <ESP8266WiFi.h>

#define LEGACY_NAME "layzspa"
#define FW_VERSION "4W_2022-05-20"
#define FW_VERSION "4W_2022-06-27"

/*
* Miscellaneous
Expand Down
42 changes: 36 additions & 6 deletions Code/4-wire-version/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,17 @@ void setup()

void loop()
{
// calc looptime
static bool firstloopdone = false;
unsigned long ms = millis();
unsigned long looptime;
if(ms>prevlooptime && firstloopdone){
looptime = ms - prevlooptime;
looptime_min = min(looptime, looptime_min);
looptime_max = max(looptime, looptime_max);
}
prevlooptime = ms;
firstloopdone = true;
// We need this self-destructing info several times, so save it locally
bool newData = bwc.newData();
// Fiddle with the pump computer
Expand Down Expand Up @@ -125,9 +136,6 @@ void loop()
}
if (WiFi.status() == WL_CONNECTED)
{
// could be interesting to display the IP
//bwc.print(WiFi.localIP().toString());

if (!DateTime.isTimeValid())
{
Serial.println(F("NTP > Start synchronisation"));
Expand Down Expand Up @@ -208,14 +216,18 @@ String getOtherInfo()
String json = "";
// Set the values in the document
doc["CONTENT"] = "OTHER";
doc["MQTT"] = mqttClient.state();
doc["CIOTX"] = bwc.cio_tx_ok;
doc["DSPTX"] = bwc.dsp_tx_ok;
doc["HASJETS"] = HASJETS;
doc["HASAIR"] = HASAIR;
doc["RSSI"] = WiFi.RSSI();
doc["IP"] = WiFi.localIP().toString();
doc["SSID"] = WiFi.SSID();
doc["FW"] = FW_VERSION;
doc["MODEL"] = MYMODEL;
doc["LOOPMAX"] = looptime_max;
doc["LOOPMIN"] = looptime_min;

// Serialize JSON to string
if (serializeJson(doc, json) == 0)
Expand Down Expand Up @@ -258,6 +270,18 @@ void sendMQTT()
{
//Serial.println(F("MQTT > times not published"));
}


//send other info
json = getOtherInfo();
if (mqttClient.publish((String(mqttBaseTopic) + "/other").c_str(), String(json).c_str(), true))
{
//Serial.println(F("MQTT > other published"));
}
else
{
//Serial.println(F("MQTT > other not published"));
}
}


Expand Down Expand Up @@ -1016,10 +1040,10 @@ void handleDir()
while (root.next())
{
Serial.println(root.fileName());
mydir += root.fileName() + F(" \t Size: ");
mydir += String(root.fileSize()) + F(" Bytes\r\n");
mydir += "<a href=\"/" + root.fileName() + "\">" + root.fileName() + "</a>" + F(" \t Size: ");
mydir += String(root.fileSize()) + F(" Bytes<br>");
}
server.send(200, "text/plain", mydir);
server.send(200, "text/html", mydir);
}

/**
Expand Down Expand Up @@ -1244,6 +1268,12 @@ void mqttConnect()
// Watch the 'command' topic for incoming MQTT messages
mqttClient.subscribe((String(mqttBaseTopic) + "/command").c_str());
mqttClient.loop();

mqttClient.publish((String(mqttBaseTopic) + "/reboot_time").c_str(), DateTime.format(DateFormatter::ISO8601).c_str(), true);
mqttClient.publish((String(mqttBaseTopic) + "/reboot_reason").c_str(), ESP.getResetReason().c_str(), true);
mqttClient.loop();
sendMQTT();
//setupHA(); //Setup MQTT Device
}
else
{
Expand Down
3 changes: 2 additions & 1 deletion Code/4-wire-version/src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ bool runonce = true;
const int solarpin = D0;
/** pulled to GND. Boot fails if pulled HIGH. */
const int myoutputpin = D8;

/** track loop times */
unsigned long prevlooptime, looptime_max, looptime_min;


void handleAUX();
Expand Down
2 changes: 1 addition & 1 deletion Code/6-wire-version/data/config.html
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ <h2>Command queue</h2>
"FINT":parseInt(document.getElementById("finterval").value),
"CLINT":parseInt(document.getElementById("clinterval").value),
"AUDIO":document.getElementById("audio").checked,
"RESTORE":document.getElementById("restore").value
"RESTORE":parseInt(document.getElementById("restore").value)
}
Http.send(JSON.stringify(msgobj));
console.log(msgobj);
Expand Down
Loading

0 comments on commit 4ddb436

Please sign in to comment.