Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix flow save #176

Merged
merged 7 commits into from Apr 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions data_source/version.json
@@ -1,4 +1,4 @@
{
"fw_version": "1.2.1-Alpha.4",
"fs_version": "1.2.1-Alpha.4"
"fw_version": "1.2.1-Alpha.6",
"fs_version": "1.2.1-Alpha.6"
}
4 changes: 2 additions & 2 deletions platformio.ini
Expand Up @@ -40,7 +40,7 @@ extra_scripts =
lib_ignore = ;ESPAsynTCP
lib_deps =
paulstoffregen/OneWire @ ~2.3.7
lbussy/LCBUrl @ ~1.1.8
https://github.com/lbussy/LCBUrl#main
bblanchon/ArduinoJson @ ~6.19.4
https://github.com/lbussy/DS18B20_RT @ ~0.1.4
https://github.com/lbussy/Arduino-Log @ ~1.0.3
Expand All @@ -55,7 +55,7 @@ lib_deps =
monitor_filters =
esp32_exception_decoder
; send_on_enter
log2file
; log2file
build_type = debug ; release

[env:lolin_d32]
Expand Down
3 changes: 1 addition & 2 deletions src/flowmeter.cpp
Expand Up @@ -141,14 +141,13 @@ void logFlow()
}
else
{ // Log a pour
Log.verbose(F("Debiting %d pulses from tap %d on pin %d." CR), pulseCount, i, flow.taps[i].pin);
float pour = (float)pulseCount / (float)flow.taps[i].ppu;
flow.taps[i].remaining = flow.taps[i].remaining - pour;
setDoSaveFlow();
setQueuePourReport(i, pour); // Queue upstream pour report
setQueuePulseReport(i, pulseCount); // Queue upstream pulse report
app.taplistio.update = true; // Queue TIO report
setDoSaveFlow();
Log.verbose(F("Debiting %d pulses from tap %d on pin %d." CR), pulseCount, i, flow.taps[i].pin);
}
}
else
Expand Down
44 changes: 22 additions & 22 deletions src/main.cpp
Expand Up @@ -51,25 +51,6 @@ void setup()
// Set LED pin
pinMode(LED, OUTPUT);

// Check if portal is requested
bool detectdrd = drd->detectDoubleReset();
if (!app.copconfig.nodrd && detectdrd)
{
Log.notice(F("DRD: Portal requested." CR));
doWiFi(true);
}
else if (digitalRead(RESETWIFI) == LOW)
{
Log.notice(F("Pin %d low, presenting portal." CR), RESETWIFI);
doWiFi(true);
}
else
{
Log.notice(F("Starting WiFi." CR));
app.copconfig.nodrd = false;
doWiFi();
}

// Set pins for relays
pinMode(SOLENOID, OUTPUT);
if (app.temps.tfancontrolenabled)
Expand All @@ -83,8 +64,6 @@ void setup()
pinMode(COOL, OUTPUT);
digitalWrite(COOL, (app.temps.coolonhigh) ? LOW : HIGH);

setClock(); // Set NTP Time

// Initialize flowmeters before checking for FILESYSTEM update
if (!initFlow())
{ // If flowmeter configuration does not load, sit and blink slowly like an idiot
Expand All @@ -109,6 +88,27 @@ void setup()
saveFlowConfig();
saveAppConfig();

// Check if portal is requested
bool detectdrd = drd->detectDoubleReset();
if (!app.copconfig.nodrd && detectdrd)
{
Log.notice(F("DRD: Portal requested." CR));
doWiFi(true);
}
else if (digitalRead(RESETWIFI) == LOW)
{
Log.notice(F("Pin %d low, presenting portal." CR), RESETWIFI);
doWiFi(true);
}
else
{
Log.notice(F("Starting WiFi." CR));
app.copconfig.nodrd = false;
doWiFi();
}

setClock(); // Set NTP Time

if (!app.ota.badfw)
execspiffs(); // Check for pending FILESYSTEM update

Expand All @@ -135,7 +135,6 @@ void setup()
{ loopTstat(TS_TYPE_CHAMBER); }); // Update temperature control loop
doFanControlTicker.attach(TEMPLOOP, []()
{ loopTstat(TS_TYPE_TOWER); }); // Update fan control loop
sendTIOTaps(); // Send initial Taplist.io keg levels

#if !defined(DISABLE_LOGGING)
if (app.copconfig.serial)
Expand All @@ -145,6 +144,7 @@ void setup()
#else
nullDoc("d");
#endif
sendTIOTaps(); // Send initial Taplist.io keg levels
}

void loop()
Expand Down
3 changes: 2 additions & 1 deletion src/rpintsclient.cpp
Expand Up @@ -57,7 +57,7 @@ void connectRPints()
app.rpintstarget.host,
app.rpintstarget.port);
LCBUrl url;
if (url.isMDNS(app.rpintstarget.host))
if (url.isMDNS(app.rpintstarget.host) && url.isValidIP(url.getIP(app.rpintstarget.host).toString().c_str()))
{
Log.verbose(F("MQTT: Resolved mDNS broker name: %s (%s)" CR),
app.rpintstarget.host,
Expand Down Expand Up @@ -148,6 +148,7 @@ void onRPintsConnect(bool sessionPresent)
void onRPintsDisconnect(AsyncMqttClientDisconnectReason reason)
{
Log.verbose(F("Disconnected from MQTT." CR));
setDoRPintsConnect();
}

void onRPintsPublish(uint16_t packetId)
Expand Down
10 changes: 3 additions & 7 deletions src/webpagehandler.cpp
Expand Up @@ -2341,7 +2341,6 @@ HANDLER_STATE handleSecret(AsyncWebServerRequest *request) // Handle checking se
didProcess = true;
AsyncWebHeader *bulkLoadHeader = request->getHeader(needHeader);
const char *headerVal = bulkLoadHeader->value().c_str();
// Log.notice(F("[DEBUG] Secret Check: Testing[%s]:[%s]." CR), app.copconfig.guid, headerVal);
if (strcmp(headerVal, app.copconfig.guid) == 0)
{
didPass = true;
Expand Down Expand Up @@ -2386,7 +2385,6 @@ HANDLER_STATE handleJson(AsyncWebServerRequest *request) // Handle checking JSON
const char *headerVal = bulkLoadHeader->value().c_str();
if (!strcmp(headerVal, "AppConfig") == 0)
{
Log.verbose(F("[DEBUG] handleJson() with %s" CR), bulkLoadHeader->value().c_str());
didPass = true;
bool oldImperial = app.copconfig.imperial;
const char *oldHostName = app.copconfig.hostname;
Expand All @@ -2401,7 +2399,7 @@ HANDLER_STATE handleJson(AsyncWebServerRequest *request) // Handle checking JSON
// Process any p->name().c_str() / p->value().c_str() pairs
const char *name = p->name().c_str();
const char *value = p->value().c_str();
Log.verbose(F("Processing [%s]:(%s) pair." CR), name, value); // DEBUG
Log.verbose(F("Processing [%s]:(%s) pair." CR), name, value);

// Bulk Load mode Set
//
Expand Down Expand Up @@ -2454,7 +2452,6 @@ HANDLER_STATE handleJson(AsyncWebServerRequest *request) // Handle checking JSON
}
else if (!strcmp(headerVal, "FlowConfig") == 0)
{
Log.verbose(F("[DEBUG] handleJson()) with %s" CR), bulkLoadHeader->value().c_str());
didPass = true;
bool oldImperial = flow.imperial;

Expand All @@ -2468,7 +2465,7 @@ HANDLER_STATE handleJson(AsyncWebServerRequest *request) // Handle checking JSON
// Process any p->name().c_str() / p->value().c_str() pairs
const char *name = p->name().c_str();
const char *value = p->value().c_str();
Log.verbose(F("Processing [%s]:(%s) pair." CR), name, value); // DEBUG
Log.verbose(F("Processing [%s]:(%s) pair." CR), name, value);

// Bulk Load mode Set
//
Expand Down Expand Up @@ -2522,13 +2519,12 @@ HANDLER_STATE handleJson(AsyncWebServerRequest *request) // Handle checking JSON
else
{
// No valid bulk load type passed
Log.verbose(F("[DEBUG] handleJson() No valid X-KegCop-BulkLoad-Type bulk load header passed: %s" CR), bulkLoadHeader->value().c_str());
send_not_allowed(request);
}
}
else
{
Log.verbose(F("[DEBUG] handleJson() No X-KegCop-BulkLoad-Type header passed." CR));
//
}

if (!didProcess)
Expand Down