Skip to content

Commit

Permalink
V 4.65
Browse files Browse the repository at this point in the history
  • Loading branch information
InnuendoPi committed Oct 2, 2024
1 parent 8e864da commit 6941cdd
Show file tree
Hide file tree
Showing 26 changed files with 197 additions and 414 deletions.
6 changes: 2 additions & 4 deletions 0_SETUP.ino
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
void setup()
{
Serial.begin(DEF_SERIAL);

#ifdef ESP32
snprintf(mqtt_clientid, maxHostSign, "ESP32-%llX", ESP.getEfuseMac());
// Serial.printf("\n*** SYSINFO: MQTTDevice32 ID: %X\n", mqtt_clientid);
DEBUG_INFO("SYS", "\n*** SYSINFO: MQTTDevice32 ID: %X", mqtt_clientid);
// WLAN Events
WiFi.onEvent(WiFiEvent);
Expand All @@ -13,7 +12,6 @@ void setup()
WiFiEvent_t::ARDUINO_EVENT_WIFI_STA_DISCONNECTED);
#elif ESP8266
snprintf(mqtt_clientid, maxHostSign, "ESP8266-%08X", ESP.getChipId());
// Serial.printf("\n*** SYSINFO: start up MQTTDevice - device ID: %s\n", mqtt_clientid);
DEBUG_INFO("SYS", "\n*** SYSINFO: start up MQTTDevice - device ID: %s", mqtt_clientid);
// WLAN Events
wifiConnectHandler = WiFi.onStationModeGotIP(EM_WIFICONNECT);
Expand Down Expand Up @@ -121,7 +119,7 @@ void setupServer()
server.on("/reqMiscAlert", handleRequestMiscAlert); // Misc Infos für WebConfig
server.on("/reqFirm", handleRequestFirm); // Firmware version
server.on("/setMisc", handleSetMisc); // Misc ändern
server.on("/setMiscLang", handleSetMiscLang); // Misc ändern
server.on("/setMiscLang", handleSetMiscLang); // Misc ändern
server.on("/startHTTPUpdate", startHTTPUpdate); // Firmware WebUpdate
server.on("/channel", handleChannel); // Server Sent Events will be handled from this URI
server.on("/startSSE", startSSE); // Server Sent Events will be handled from this URI
Expand Down
16 changes: 8 additions & 8 deletions 1_LOOP.ino
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
void loop()
{
server.handleClient(); // Webserver handle
server.handleClient(); // Webserver handle
if (WiFi.status() == WL_CONNECTED)
{
TickerPUBSUB.update(); // Ticker PubSubClient
TickerPUBSUB.update(); // Ticker PubSubClient
#ifdef ESP8266
if (startMDNS) // ESP8266 mDNS handle
if (startMDNS) // ESP8266 mDNS handle
mdns.update();
#endif
}

TickerTime.update();

if (numberOfSensors > 0) // Ticker Sensoren
TickerSen.update();
if (numberOfActors > 0) // Ticker Aktoren
if (numberOfSensors > 0) // Ticker Sensoren
TickerSen.update();
if (numberOfActors > 0) // Ticker Aktoren
TickerAct.update();
if (inductionStatus) // Ticker Induktion
if (inductionStatus) // Ticker Induktion
TickerInd.update();
if (useDisplay) // Ticker Display
if (useDisplay) // Ticker Display
{
TickerDisp.update();
nextion.checkNex();
Expand Down
16 changes: 4 additions & 12 deletions 2_SENSOREN.ino
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public:
{
sensorsStatus = EM_DEVER;
if (old_state)
DEBUG_ERROR("SEN", "sensor address device error %s %s %s %s %s %s %s %s", sens_address[0], sens_address[1], sens_address[2], sens_address[3], sens_address[4], sens_address[5], sens_address[6], sens_address[7]);
DEBUG_ERROR("SEN", "sensor address device error");
sens_state = false;
old_state = sens_state;
}
Expand Down Expand Up @@ -106,7 +106,6 @@ public:
old_state = sens_state;
}
sens_err = sensorsStatus;
// DEBUG_VERBOSE("SEN", "Update value: %.03f type: %d id: %d", sens_value, sens_type, sens_ptid);
} // if senstyp pt100
else if (sens_type == 2)
{
Expand Down Expand Up @@ -269,12 +268,10 @@ public:
dtostrf(sens_value, -1, 1, buf);
return buf;
}

float getTotalValueFloat()
{
return round((calcOffset() - 0.05) * 10) / 10.0;
}

char *getTotalValueString()
{
if (sens_value == -127.00)
Expand All @@ -286,7 +283,6 @@ public:
}
return buf;
}

float calcOffset()
{
if (sens_value == -127.00)
Expand All @@ -307,7 +303,6 @@ public:
}
return sens_value;
}

String getSens_adress_string()
{
return SensorAddressToString(sens_address);
Expand Down Expand Up @@ -513,10 +508,7 @@ void handleRequestSensors()
{
JsonObject sensorsObj = doc.add<JsonObject>();
sensorsObj["name"] = sensors[i].getSensorName();
sensorsObj["type"] = sensors[id].getSensType();
// String str = sensors[i].getSensorName();
// str.replace(" ", "%20"); // Erstze Leerzeichen für URL Charts
// sensorsObj["namehtml"] = str;
sensorsObj["type"] = sensors[i].getSensType();
sensorsObj["offset1"] = sensors[i].getOffset1();
sensorsObj["offset2"] = sensors[i].getOffset2();
sensorsObj["sw"] = sensors[i].getSensorSwitch();
Expand All @@ -535,8 +527,8 @@ void handleRequestSensors()

sensorsObj["script"] = sensors[i].getSensorTopic();
sensorsObj["cbpiid"] = sensors[i].getId();
sensorsObj["type"] = sensors[id].getSensType();
sensorsObj["pin"] = sensors[id].getSensPin();
sensorsObj["type"] = sensors[i].getSensType();
sensorsObj["pin"] = sensors[i].getSensPin();
yield();
}
}
Expand Down
1 change: 0 additions & 1 deletion 3_AKTOREN.ino
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,6 @@ void actERR()
actors[i].Update();

DEBUG_ERROR("ACT", "ACT MQTT event handling - actor: %s state: %d isOnBeforeError: %d", actors[i].getActorName().c_str(), actors[i].getActorState(), actors[i].getIsOnBeforeError());

}
yield();
}
Expand Down
18 changes: 7 additions & 11 deletions 4_INDUKTION.ino
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ public:

if (isPin(PIN_INTERRUPT))
{
// Interrupt deaktivert
detachInterrupt(PIN_INTERRUPT);
pinMode(PIN_INTERRUPT, OUTPUT);
// digitalWrite(PIN_INTERRUPT, HIGH);
Expand Down Expand Up @@ -108,7 +107,6 @@ public:
PIN_INTERRUPT = pinblue; // off possible
if (isPin(PIN_INTERRUPT)) // D7
{
// Interrupt deaktivert
pinMode(PIN_INTERRUPT, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(PIN_INTERRUPT), readInputWrap, CHANGE);
pins_used[PIN_INTERRUPT] = true;
Expand All @@ -125,7 +123,7 @@ public:
{
char subscribemsg[50];
mqtttopic.toCharArray(subscribemsg, 50);
DEBUG_VERBOSE("IND", "Subscribing to %s", subscribemsg);
DEBUG_VERBOSE("IND", "Subscribing to %s", subscribemsg);
pubsubClient.subscribe(subscribemsg);
}
}
Expand All @@ -137,7 +135,7 @@ public:
{
char subscribemsg[50];
mqtttopic.toCharArray(subscribemsg, 50);
DEBUG_VERBOSE("IND", "Unsubscribing from %s", subscribemsg);
DEBUG_VERBOSE("IND", "Unsubscribing from %s", subscribemsg);
pubsubClient.unsubscribe(subscribemsg);
}
}
Expand Down Expand Up @@ -297,7 +295,7 @@ public:
// Glitch rausfiltern
if (signalTime > 10)
{
if (ishigh) // PIN ist auf Rising, Bit senden hat gestartet :)
if (ishigh) // PIN ist auf Rising, Bit senden hat gestartet
{
lastInterrupt = newInterrupt;
}
Expand Down Expand Up @@ -348,7 +346,7 @@ public:
if (isInduon && powerLevelOnError < 100 && induction_state) // powerlevelonerror == 100 -> kein event handling
{
powerLevelBeforeError = power;
DEBUG_VERBOSE("IND", "MQTT event handling induction - power level: %d event power level: %d", power, powerLevelOnError);
DEBUG_VERBOSE("IND", "MQTT event handling induction - power level: %d event power level: %d", power, powerLevelOnError);
if (powerLevelOnError == 0)
isInduon = false;
else
Expand Down Expand Up @@ -472,7 +470,6 @@ public:
induction inductionCooker = induction();

#ifdef ESP32
// Interrupt deaktivert
void ARDUINO_ISR_ATTR readInputWrap()
{
inductionCooker.readInput();
Expand Down Expand Up @@ -529,15 +526,15 @@ void handleRequestIndu()
{
case 0:
pinswitched = inductionCooker.getPinWhite();
tempNUMBEROFPINS = NUMBEROFPINS - 1; // without off
tempNUMBEROFPINS = NUMBEROFPINS - 1; // ohne aus (-)
break;
case 1:
pinswitched = inductionCooker.getPinYellow();
tempNUMBEROFPINS = NUMBEROFPINS - 1; // without off
tempNUMBEROFPINS = NUMBEROFPINS - 1;
break;
case 2:
pinswitched = inductionCooker.getPinInterrupt();
tempNUMBEROFPINS = NUMBEROFPINS; // with off
tempNUMBEROFPINS = NUMBEROFPINS; // mit aus (-)
break;
}
if (isPin(pinswitched))
Expand Down Expand Up @@ -570,7 +567,6 @@ void handleSetIndu()
replyServerError("Server error set induction");
return;
}
Serial.println(server.arg(0));
inductionCooker.change(StringToPin(doc["pinw"]), StringToPin(doc["piny"]), StringToPin(doc["pinb"]), doc["topic"], doc["enabled"], doc["pl"]);
saveConfig();
replyOK();
Expand Down
56 changes: 7 additions & 49 deletions 5_DISPLAY.ino
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ void readCustomCommand()
int tempID = nextion.cmdGroup;
int tempPage = nextion.cmdLength;

if (tempID == 102) // 0x66 -> receive page command from readcustomcommand
if (tempID == 102) // 0x66 -> page command empfangen
{
DEBUG_VERBOSE("DIS", "page command activePage: %d currentPage: %d lastcurrent: %d cmdLength: %d cmdGroup: %d", activePage, nextion.currentPageId, nextion.lastCurrentPageId, tempPage, tempID);
tickerDispCallback();
}
else // 0x65 -> receive component id from readcustomcommand
else // 0x65 -> component id empfangen
{
DEBUG_VERBOSE("DIS", "componentID: %d activePage: %d currentPage: %d lastcurrent: %d cmdLength: %d", tempID, activePage, nextion.currentPageId, nextion.lastCurrentPageId, tempPage);

Expand Down Expand Up @@ -46,7 +46,7 @@ void initDisplay()
break;
case 1:
nextion.writeStr("page 1");
nextion.currentPageId = 1; // setze currentPageId wenn Startseite nicht 0
nextion.currentPageId = 1; // setze currentPageId wenn Startseite nicht 0
nextion.lastCurrentPageId = 0;
break;
case 2:
Expand All @@ -61,7 +61,7 @@ void initDisplay()
nextion.lastCurrentPageId = 1;
break;
}

if (nextion.getDebug())
DEBUG_INFO("CFG", "activePage: %d startPage: %d currentPage: %d lastcurrent: %d", activePage, startPage, nextion.currentPageId, nextion.lastCurrentPageId);
tickerDispCallback();
Expand Down Expand Up @@ -134,31 +134,10 @@ void KettlePage() // Seite 1

void BrewPage() // Seite 2
{
// DEBUG_INFO("DIS", "BrewPage");
if (strlen(structKettles[0].sensor) != 0)
{
nextion.writeStr(p1temp_text, structKettles[0].current_temp);
nextion.writeStr(p1target_text, structKettles[0].target_temp);

// Serial.printf("KettlePage sensor %s current temp: %s\n", structKettles[0].sensor, structKettles[0].current_temp);

// if (sensors[0].getId() != "")
// {
// for (uint8_t i = 0; i < maxKettles; i++)
// {
// if (strcmp(structKettles[i].sensor, sensors[0].getId().c_str()) == 0)
// {
// p1temp_text.attribute("txt", structKettles[i].current_temp);
// p1target_text.attribute("txt", structKettles[i].target_temp);
// break;
// }
// }
// }
// else
// {
// p1temp_text.attribute("txt", structKettles[0].current_temp);
// p1target_text.attribute("txt", "na");
// }
}
else
{
Expand All @@ -174,15 +153,11 @@ void BrewPage() // Seite 2

void InductionPage()
{
// log_e("Disp: InductionPage activeBrew: %d kettleID0: %s", activeBrew, structKettles[0].id);
// p2uhrzeit_text
// p2slider
// p2temp_text
// 316 = 0°C - 360 = 44°C - 223 = 100°C -- 53,4 je 20°C

int32_t aktSlider = nextion.readNum(p2slider);
if (aktSlider >= 0 && aktSlider <= 100)
inductionCooker.inductionNewPower(aktSlider); // inductionCooker.handleInductionPage(aktSlider);
inductionCooker.inductionNewPower(aktSlider);

nextion.writeStr(p2temp_text, String(structKettles[0].current_temp).c_str());
if (sensors[0].calcOffset() < 16.0)
Expand Down Expand Up @@ -387,7 +362,6 @@ void cbpi4steps_handlemqtt(unsigned char *payload)

for (uint8_t i = 0; i < stepsCounter; i++)
{
// if (structSteps[i].id == doc["id"])
if (strcmp(structSteps[i].id, doc["id"]) == 0)
{
int minutes = props["Timer"].as<int>() | 0;
Expand Down Expand Up @@ -422,7 +396,6 @@ void cbpi4steps_handlemqtt(unsigned char *payload)
current_step = true;
for (uint8_t i = 0; i < stepsCounter; i++)
{
// if (structSteps[i].name == doc["name"])
if (strcmp(structSteps[i].name, doc["name"]) == 0)
{
if (stepsCounter >= i + 1)
Expand Down Expand Up @@ -527,7 +500,6 @@ void cbpi4steps_handlemqtt(unsigned char *payload)
}
else
{
// if (props.containsKey("Timer"))
if (props["Timer"].is<int>())
{
int minutes = props["Timer"].as<int>();
Expand Down Expand Up @@ -616,16 +588,8 @@ void cbpi4notification_handlemqtt(unsigned char *payload)
strlcpy(notify, doc["message"] | "", maxNotifySign);
}

// void cbpi4fermenter_handlemqtt(unsigned char *payload, unsigned int length)
void cbpi4fermenter_handlemqtt(unsigned char *payload)
{
// Serial.printf("Display ferm len: %d\n", length);
// for (unsigned int i = 0; i < length; i++)
// {
// Serial.print((char)payload[i]);
// }
// Serial.println();

JsonDocument doc;
JsonDocument filter;
filter["id"] = true;
Expand All @@ -635,13 +599,12 @@ void cbpi4fermenter_handlemqtt(unsigned char *payload)
filter["target_temp"] = true;
// filter["steps"]["name"] = true;
DeserializationError error = deserializeJson(doc, (const char *)payload, DeserializationOption::Filter(filter));
// DeserializationError error = deserializeJson(doc, (const char *)payload);
if (error)
{
DEBUG_ERROR("DIS", "handlemqtt fermenter deserialize Json error %s MemoryUsage %d", error.c_str());
return;
}

fermenterStatus = doc["state"] | false;

for (uint8_t i = 0; i < maxKettles; i++)
Expand All @@ -655,9 +618,6 @@ void cbpi4fermenter_handlemqtt(unsigned char *payload)
char sensorupdate[45];
sprintf(sensorupdate, "%s%s", cbpi4sensor_topic, structKettles[i].sensor);
pubsubClient.subscribe(sensorupdate);

// Serial.printf("#%d new kettle name %s kettle-id: %s sensor-id: %s target: %s update: %s\n", i, structKettles[i].name, structKettles[i].id, structKettles[i].sensor, structKettles[i].target_temp, sensorupdate);

switch (i)
{
case 0:
Expand All @@ -683,7 +643,6 @@ void cbpi4fermenter_handlemqtt(unsigned char *payload)
{
if (strcmp(structKettles[i].id, doc["id"]) == 0)
{
// Serial.printf("#%d old kettle name %s kettle-id: %s sensor-id: %s target: %s update: %s\n", i, structKettles[i].name, structKettles[i].id, structKettles[i].sensor, structKettles[i].target_temp, sensorupdate);
dtostrf(doc["target_temp"], -1, 1, structKettles[i].target_temp);
switch (i)
{
Expand Down Expand Up @@ -718,12 +677,11 @@ void cbpi4fermentersteps_handlemqtt(unsigned char *payload)
DEBUG_ERROR("DIS", "handlemqtt notification deserialize Json error %s MemoryUsage %d", error.c_str());
return;
}

if (fermenterStatus)
{
strlcpy(currentStepName, doc["name"] | "", maxStepSign);
sprintf(currentStepRemain, "%s", "");
// sprintf(currentStepRemain, "%02d:%02d:%02d", doc["props"]["TimerD"].as<int>(), doc["props"]["TimerH"].as<int>(), doc["props"]["TimerM"].as<int>());
}
else
{
Expand Down
Loading

0 comments on commit 6941cdd

Please sign in to comment.