Skip to content

Commit

Permalink
Merge branch 'devel'
Browse files Browse the repository at this point in the history
  • Loading branch information
lbussy committed Jul 29, 2020
2 parents 83ee6a2 + b492861 commit 60e025a
Show file tree
Hide file tree
Showing 12 changed files with 100 additions and 79 deletions.
Binary file modified firmware/firmware.bin
Binary file not shown.
1 change: 1 addition & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ build_flags =
-D BAUD=${common_env_data.monitor_speed}
; -DDEBUG_ESP_PORT=Serial
; -DDEBUG_ESP_WIFI
; -DDEBUG_ESP_HTTP_UPDATE
; -DDEBUG_ESP_CORE
; -DPIO_FRAMEWORK_ARDUINO_LWIP2_LOW_MEMORY ; v2 Lower Memory (default)
; -DPIO_FRAMEWORK_ARDUINO_LWIP2_HIGHER_BANDWIDTH ; v2 Higher Bandwidth
Expand Down
7 changes: 4 additions & 3 deletions src/execota.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ SOFTWARE. */

void execfw() {
Log.notice(F("Starting the Firmware OTA pull, will reboot without notice." CR));
_delay(5000); // Let page finish loading

// Stop web server before OTA update - will restart on reset
stopWebServer();
Expand All @@ -37,8 +36,8 @@ void execfw() {

ESPhttpUpdate.setLedPin(LED, LOW);
// "http://www.brewbubbles.com/firmware/firmware.bin"
WiFiClient client;
t_httpUpdate_return ret = ESPhttpUpdate.update(client, F(FIRMWAREURL), "");
WiFiClient _client;
t_httpUpdate_return ret = ESPhttpUpdate.update(_client, F(FIRMWAREURL), "0");

switch(ret) {
case HTTP_UPDATE_FAILED:
Expand All @@ -48,6 +47,7 @@ void execfw() {
config.dospiffs2 = false;
config.didupdate = false;
saveConfig();
ESP.restart();
break;

case HTTP_UPDATE_NO_UPDATES:
Expand All @@ -57,6 +57,7 @@ void execfw() {
config.dospiffs2 = false;
config.didupdate = false;
saveConfig();
ESP.restart();
break;

case HTTP_UPDATE_OK:
Expand Down
2 changes: 0 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,6 @@ void loop() {
config.brewfather.update = false;
}

_delay(50); // Required to "loosen up" the loop so mDNS and webpages are responsive

yield();
}
}
4 changes: 2 additions & 2 deletions src/ntp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ void setClock() {
#ifdef LOG_LEVEL
Serial.println();
#endif
Log.verbose(F("Re-requesting time hack." CR));
Log.verbose(F("Re-requesting time hack."));
configTime(GMT, 0, "pool.ntp.org", "time.nist.gov");
startSecs = time(nullptr);
cycle++;
}
#ifdef LOG_LEVEL
Serial.print(F("."));
#endif
_delay(1000);
delay(1000);
yield();
nowSecs = time(nullptr);
}
Expand Down
63 changes: 0 additions & 63 deletions src/pushhelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,66 +143,3 @@ bool pushToTarget(PushTarget *target, IPAddress targetIP, int port) {
return false;
}
}

void setDoURLTarget() {
doURLTarget = true; // Semaphore required for Ticker + radio event
}

void setDoBFTarget() {
doBFTarget = true; // Semaphore required for Ticker + radio event
}

void setDoBrewfTarget() {
doBrewfTarget = true; // Semaphore required for Ticker + radio event
}

void setDoReset() {
doReset = true; // Semaphore required for reset in callback
}

void tickerLoop() {
Target *target = Target::getInstance();
BFTarget *bfTarget = BFTarget::getInstance();
BrewfTarget *brewfTarget = BrewfTarget::getInstance();

// Trigger Bubble check
//
if (doBubble) {
doBubble = false;
if (bubbles.update())
Log.verbose(F("Current BPM is %D. Averages (%l in sample): BPM = %D, Ambient = %D, Vessel = %D." CR),
bubbles.lastBpm,
bubbles.sampleSize,
bubbles.getAvgBpm(),
bubbles.getAvgAmbient(),
bubbles.getAvgVessel()
);
}

// Handle JSON posts
//
// Do URL Target post
if (doURLTarget) {
doURLTarget = false;
target->push();
}
//
// Do Brewer's Friend Post
if (doBFTarget) { // Do BF post
doBFTarget = false;
bfTarget->push();
}
//
// Do Brewfather Post
if (doBrewfTarget) { // Do BF post
doBrewfTarget = false;
brewfTarget->push();
}

// Check for Reset Pending
// Necessary because we cannot delay in a callback
if (doReset) {
doReset = false;
resetController();
}
}
7 changes: 1 addition & 6 deletions src/pushhelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ SOFTWARE. */
#include "target.h"
#include "brewfather.h"
#include "brewersfriend.h"
#include "execota.h"
#include <ESP8266WiFi.h>

IPAddress resolveHost(const char hostname[129]);
bool pushToTarget(PushTarget*, IPAddress, int);
void tickerLoop();
void updateLoop();
void setDoURLTarget();
void setDoBFTarget();
Expand All @@ -41,9 +41,4 @@ void setDoReset();
extern volatile bool doBubble;
extern struct Bubbles bubbles;

static bool __attribute__((unused)) doURLTarget = false; // Semaphore for Target timer
static bool __attribute__((unused)) doBFTarget = false; // Semaphore for BF timer
static bool __attribute__((unused)) doBrewfTarget = false; // Semaphore for BRF timer
static bool __attribute__((unused)) doReset = false; // Semahore for reset

#endif // _PUSHHELPER_H
2 changes: 1 addition & 1 deletion src/serial_setup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ SOFTWARE. */
#ifndef DISABLE_LOGGING

void setSerial() { // Start serial with auto-detected rate (default to BAUD)
_delay(3000); // Delay to allow monitor to start
delay(2000); // Delay to allow monitor to start
Serial.begin(BAUD);
// Serial.setDebugOutput(true);
Serial.flush();
Expand Down
73 changes: 73 additions & 0 deletions src/tools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ SOFTWARE. */
#include "tools.h"

void _delay(unsigned long ulDelay) {
Log.verbose(F("DEBUG: In _delay()." CR));
// Safe semi-blocking delay
#ifdef ESP32
vTaskDelay(ulDelay); // Builtin to ESP32
Expand Down Expand Up @@ -94,3 +95,75 @@ void saveBpm() {
}
}
}

void setDoURLTarget() {
doURLTarget = true; // Semaphore required for Ticker + radio event
}

void setDoBFTarget() {
doBFTarget = true; // Semaphore required for Ticker + radio event
}

void setDoBrewfTarget() {
doBrewfTarget = true; // Semaphore required for Ticker + radio event
}

void setDoReset() {
doReset = true; // Semaphore required for reset in callback
}

void setDoOTA() {
doOTA = true; // Semaphore required for OTA in callback
}

void tickerLoop() {
Target *target = Target::getInstance();
BFTarget *bfTarget = BFTarget::getInstance();
BrewfTarget *brewfTarget = BrewfTarget::getInstance();

// Trigger Bubble check
//
if (doBubble) {
doBubble = false;
if (bubbles.update())
Log.verbose(F("Current BPM is %D. Averages (%l in sample): BPM = %D, Ambient = %D, Vessel = %D." CR),
bubbles.lastBpm,
bubbles.sampleSize,
bubbles.getAvgBpm(),
bubbles.getAvgAmbient(),
bubbles.getAvgVessel()
);
}

// Handle JSON posts
//
// Do URL Target post
if (doURLTarget) {
doURLTarget = false;
target->push();
}
//
// Do Brewer's Friend Post
if (doBFTarget) { // Do BF post
doBFTarget = false;
bfTarget->push();
}
//
// Do Brewfather Post
if (doBrewfTarget) { // Do BF post
doBrewfTarget = false;
brewfTarget->push();
}

// Check for Reset Pending
// Necessary because we cannot delay in a callback
if (doReset) {
doReset = false;
resetController();
}

if (doOTA) {
doOTA = false;
execfw();
}
}
15 changes: 15 additions & 0 deletions src/tools.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ SOFTWARE. */
#define _TOOLS_H

#include "bubbles.h"
#include "brewersfriend.h"
#include "brewfather.h"
#include "target.h"
#include <LittleFS.h>
#include <ArduinoLog.h>
#include <ArduinoJson.h>
Expand All @@ -36,6 +39,18 @@ void _delay(unsigned long);
void resetController();
void loadBpm();
void saveBpm();
void tickerLoop();
void setDoURLTarget();
void setDoBFTarget();
void setDoBrewfTarget();
void setDoReset();
void setDoOTA();

static bool __attribute__((unused)) doURLTarget = false; // Semaphore for Target timer
static bool __attribute__((unused)) doBFTarget = false; // Semaphore for BF timer
static bool __attribute__((unused)) doBrewfTarget = false; // Semaphore for BRF timer
static bool __attribute__((unused)) doReset = false; // Semahore for reset
static bool __attribute__((unused)) doOTA = false; // Semahore for reset

extern struct Bubbles bubbles;

Expand Down
4 changes: 2 additions & 2 deletions src/webserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ void setActionPageHandlers()

server.on("/otastart/", HTTP_GET, [](AsyncWebServerRequest *request) {
Log.verbose(F("Processing /otastart/." CR));
request->send(200, F("text/plain"), F("200: OTA started."));
execfw(); // Trigger the OTA update
request->send(200, F("text/plain"), F("200: OTA queued."));
setDoOTA();
});

server.on("/clearupdate/", HTTP_GET, [](AsyncWebServerRequest *request) {
Expand Down
1 change: 1 addition & 0 deletions src/webserver.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ SOFTWARE. */
#include "config.h"
#include "thatVersion.h"
#include "pushhelper.h"
#include "tools.h"
#include <ArduinoLog.h>
#include <ArduinoJson.h>
#include <AsyncJson.h>
Expand Down

0 comments on commit 60e025a

Please sign in to comment.