Skip to content

Commit

Permalink
Merge pull request #246 from thorrak/devel
Browse files Browse the repository at this point in the history
- Incorporates new data senders both for MQTT and HTTP endpoints
- Adds a number of other bug fixes and tweaks
  • Loading branch information
thorrak committed Mar 3, 2024
2 parents e067467 + 8542187 commit 7a5d7e8
Show file tree
Hide file tree
Showing 29 changed files with 670 additions and 797 deletions.
11 changes: 6 additions & 5 deletions .github/workflows/build.yml
Expand Up @@ -4,6 +4,7 @@ on:
push:
branches:
- master
- no_std_strings
# tags:
# - "v*"
# pull_request:
Expand All @@ -21,25 +22,25 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3.3.0
- uses: actions/checkout@v4.1.1
- run: git fetch --prune --unshallow

- name: Cache pip
uses: actions/cache@v3.2.2
uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Cache PlatformIO
uses: actions/cache@v3.2.2
uses: actions/cache@v4
with:
path: ~/.platformio
key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }}

- name: Set up Python
uses: actions/setup-python@v4.4.0
uses: actions/setup-python@v5

- name: Install PlatformIO
run: |
Expand Down Expand Up @@ -82,4 +83,4 @@ jobs:
LICENSE
bin/*.bin
env:
GITHUB_REPOSITORY: thorrak/tiltbridge
GITHUB_REPOSITORY: thorrak/tiltbridge
1 change: 1 addition & 0 deletions docs/source/hardware.rst
Expand Up @@ -82,6 +82,7 @@ OLED Cases
- `TiltBridge Heltec/TTGO ESP32 OLED Enclosure by Thorrak <https://www.thingiverse.com/thing:3515836>`_
- `Generic "OLED" Enclosure by Thorrak <https://www.thingiverse.com/thing:3604590>`_
- `HiLetGo Wifi 32 Tiltbridge Case by calandryll <https://www.thingiverse.com/thing:4444391>`_
- `Ideaspark OLED 0.96" ESP32 case <https://www.printables.com/model/773441-esp32-oled-box>`_



Expand Down
9 changes: 5 additions & 4 deletions platformio.ini
Expand Up @@ -27,7 +27,7 @@ monitor_rts = 1

build_flags = ; Do not use spaces around the "=" here, will give you a builder not found error
!python tools/git_rev.py ; Pick up git information for version (disabled), branch, and commit (in version.cpp)
-D PIO_SRC_TAG=1.2.1 ; Increment versions shown in about.htm page (from version.cpp)
-D PIO_SRC_TAG=1.2.2 ; Increment versions shown in about.htm page (from version.cpp)
; Async TCP Settings:
-D CONFIG_ASYNC_TCP_RUNNING_CORE=1 ; per: https://github.com/me-no-dev/ESPAsyncWebServer/issues/731#issuecomment-628163515
-D CONFIG_ASYNC_TCP_USE_WDT=1
Expand All @@ -40,6 +40,7 @@ build_flags = ; Do not use spaces around the "=" here,
-D PRINT_GRAV_UPDATES=0 ; Turn on and off gravity printing to serial log
-D CORE_DEBUG_LEVEL=0 ; Set core Arduino log level (5 = high)
-D ARDUINO_LOG_LEVEL=0 ; Set Serial log level (6 = high)
-D CONFIG_NIMBLE_CPP_LOG_LEVEL=0 ; Set NimBLE log level (4 = high)
;-D PARSE_DEBUG ; Turn main Parse debug logging on
;-D PARSE_DEBUG_RESPONSE ; Turn Parse response debugging on
-D DISABLE_LOGGING ; This will remove log lib from sketch
Expand All @@ -53,15 +54,15 @@ build_flags = ; Do not use spaces around the "=" here,
;-D FSEDIT=1 ; Use a filesystem editor
extra_scripts = tools/get_port.py ; Pick up port information based on OS
lib_deps =
bblanchon/ArduinoJson @ 6.21.2 ; https://github.com/bblanchon/ArduinoJson
bblanchon/ArduinoJson @ 6.21.5 ; https://github.com/bblanchon/ArduinoJson
; thijse/ArduinoLog @ 1.1.1 ; https://github.com/thijse/Arduino-Log.git
https://github.com/thorrak/Arduino-Log.git ; // Need this until ArduinoLog merges https://github.com/thijse/Arduino-Log/pull/23
https://github.com/lbussy/esptelnet.git
https://github.com/me-no-dev/ESPAsyncWebServer.git
https://github.com/thorrak/WiFiManager.git#feature_asyncwebserver
h2zero/NimBLE-Arduino @ 1.4.1 ; https://github.com/h2zero/NimBLE-Arduino
256dpi/MQTT @ 2.5.1 ; https://github.com/256dpi/arduino-mqtt
lbussy/LCBUrl @ ^1.1.7
256dpi/MQTT @ 2.5.2 ; https://github.com/256dpi/arduino-mqtt
lbussy/LCBUrl @ ^1.1.9
https://github.com/lbussy/Parse-SDK-Arduino.git#fix_warnings
espi_lib_deps =
bodmer/TFT_eSPI @ 2.4.79 ; https://github.com/Bodmer/TFT_eSPI.git
Expand Down
3 changes: 0 additions & 3 deletions src/OTAUpdate.h
@@ -1,9 +1,6 @@
#ifndef TILTBRIDGE_OTAUPDATE_H
#define TILTBRIDGE_OTAUPDATE_H

#include <WiFi.h>
#include <Update.h>

// Although this should be automatically done with build flags, OTA updates
// are explicitly not supported on the "legacy" OLED screen version due to
// flash constraints. TFT + 16MB flash only!
Expand Down
16 changes: 9 additions & 7 deletions src/bridge_lcd.cpp
@@ -1,13 +1,14 @@
#include "bridge_lcd.h"
#include "jsonconfig.h"
#include "tilt/tiltScanner.h"
#include <WiFi.h>
#include <ArduinoLog.h>
#include <WiFi.h>

#ifdef LCD_SSD1306
#include <Wire.h>
#endif

#include "jsonconfig.h"
#include "tilt/tiltScanner.h"
#include "bridge_lcd.h"

bridge_lcd lcd;

#if defined(LCD_SSD1306) || defined(LCD_TFT_ESPI)
Expand Down Expand Up @@ -498,9 +499,10 @@ void bridge_lcd::display_wifi_reconnect_failed() {
}

void bridge_lcd::print_tilt_to_line(tiltHydrometer *tilt, uint8_t line) {
char gravity[11], temp[8];
sprintf(gravity, "%s", tilt->converted_gravity(false).c_str());
sprintf(temp, "%s %s", tilt->converted_temp(false).c_str(), tilt->is_celsius() ? "C" : "F");
char gravity[11], temp[9], temp_str[6];
tilt->converted_gravity(gravity, 11, false);
tilt->converted_temp(temp_str, 6, false);
snprintf(temp, sizeof(temp), "%s %s", temp_str, tilt->is_celsius() ? "C" : "F");

#if defined(LCD_TFT_ESPI)
tft->setTextColor(tilt_text_colors[tilt->m_color]);
Expand Down
1 change: 1 addition & 0 deletions src/getGuid.cpp
@@ -1,4 +1,5 @@
#include <Arduino.h>

#include "getGuid.h"

void getGuid(char *str)
Expand Down
2 changes: 0 additions & 2 deletions src/getGuid.h
@@ -1,8 +1,6 @@
#ifndef _GET_GUID_H
#define _GET_GUID_H

#include <Arduino.h>

void getGuid(char *str);

#endif // _GET_GUID_H
39 changes: 14 additions & 25 deletions src/http_server.cpp
@@ -1,33 +1,22 @@

#include <LCBUrl.h>
#include <Arduino.h>
#include <WiFi.h>
#include <WiFiClient.h>
#include <AsyncTCP.h>
#include <ESPAsyncWebServer.h>
#include <AsyncJson.h>
#include <ArduinoLog.h>
#include <Ticker.h>

#include "resetreasons.h"
#include "uptime.h"
#include "version.h"
#include "http_server.h"
#include "jsonconfig.h"
#include "tilt/tiltScanner.h"
#include "sendData.h"

#include "http_server.h"


httpServer http_server;
Ticker sendNowTicker;

extern bool send_cloudTarget;
extern bool send_brewersFriend;
extern bool send_brewfather;
extern bool send_userTarget;
extern bool send_grainfather;
extern bool send_localTarget;
extern bool send_brewStatus;
extern bool send_gSheets;
extern bool send_mqtt;

AsyncWebServer server(WEBPORT);

// This is to simplify the redirects in processCalibration
Expand Down Expand Up @@ -220,7 +209,7 @@ bool processCloudTargetSettings(AsyncWebServerRequest *request) {
if (!config.cloudEnabled) {
config.cloudEnabled = true;
// Trigger a send to Cloud in 5 seconds
sendNowTicker.once(5, [](){send_cloudTarget = true;});
sendNowTicker.once(5, [](){data_sender.send_cloudTarget = true;});
}
Log.notice(F("Settings update, [%s]:(%s) applied.\r\n"), name, value);
} else if (strcmp(value, "false") == 0) {
Expand Down Expand Up @@ -269,7 +258,7 @@ bool processLocalTargetSettings(AsyncWebServerRequest *request) {
Log.notice(F("Settings update, [%s]:(%s) applied.\r\n"), name, value);
strlcpy(config.localTargetURL, value, 256);
// Trigger a send to Fermentrack/BPR in 5 seconds using the updated URL
sendNowTicker.once(5, [](){send_localTarget = true;});
sendNowTicker.once(5, [](){data_sender.send_localTarget = true;});
} else if (strcmp(value, "") == 0 || strlen(value) == 0) {
Log.notice(F("Settings update, [%s]:(%s) cleared.\r\n"), name, value);
strlcpy(config.localTargetURL, value, 256);
Expand Down Expand Up @@ -324,7 +313,7 @@ bool processGoogleSheetsSettings(AsyncWebServerRequest *request) {
strlcpy(config.scriptsURL, value, 256);
Log.notice(F("Settings update, [%s]:(%s) applied.\r\n"), name, value);
// Trigger a send in 5 seconds using the updated GSheets URL
sendNowTicker.once(5, [](){send_gSheets = true;});
sendNowTicker.once(5, [](){data_sender.send_gSheets = true;});
} else if (strcmp(value, "") == 0 || strlen(value) == 0) {
strlcpy(config.scriptsURL, value, 256);
Log.notice(F("Settings update, [%s]:(%s) cleared.\r\n"), name, value);
Expand Down Expand Up @@ -412,7 +401,7 @@ bool processBrewersFriendSettings(AsyncWebServerRequest *request) {
strlcpy(config.brewersFriendKey, value, 65);
Log.notice(F("Settings update, [%s]:(%s) applied.\r\n"), name, value);
// Trigger a send to Brewers Friend in 5 seconds using the updated key
sendNowTicker.once(5, [](){send_brewersFriend = true;});
sendNowTicker.once(5, [](){data_sender.send_brewersFriend = true;});
} else if (strcmp(value, "") == 0 || strlen(value) == 0) {
strlcpy(config.brewersFriendKey, value, 65);
Log.notice(F("Settings update, [%s]:(%s) cleared.\r\n"), name, value);
Expand Down Expand Up @@ -457,7 +446,7 @@ bool processBrewfatherSettings(AsyncWebServerRequest *request)
strlcpy(config.brewfatherKey, value, 65);
Log.notice(F("Settings update, [%s]:(%s) applied.\r\n"), name, value);
// Trigger a send to Brewfather in 5 seconds using the updated key
sendNowTicker.once(5, [](){send_brewfather = true;});
sendNowTicker.once(5, [](){data_sender.send_brewfather = true;});
} else if (strcmp(value, "") == 0 || strlen(value) == 0) {
strlcpy(config.brewfatherKey, value, 65);
Log.notice(F("Settings update, [%s]:(%s) cleared.\r\n"), name, value);
Expand Down Expand Up @@ -502,7 +491,7 @@ bool processUserTargetSettings(AsyncWebServerRequest *request)
strlcpy(config.userTargetURL, value, 65);
Log.notice(F("Settings update, [%s]:(%s) applied.\r\n"), name, value);
// Trigger a send to the user target in 5 seconds using the updated key
sendNowTicker.once(5, [](){send_userTarget = true;});
sendNowTicker.once(5, [](){data_sender.send_userTarget = true;});
} else if (strcmp(value, "") == 0 || strlen(value) == 0) {
strlcpy(config.userTargetURL, value, 128);
Log.notice(F("Settings update, [%s]:(%s) cleared.\r\n"), name, value);
Expand Down Expand Up @@ -557,7 +546,7 @@ bool processGrainfatherSettings(AsyncWebServerRequest *request)
if (GRAINFATHER_MIN_URL_LENGTH < strlen(value) && strlen(value) < 64) {
strlcpy(config.grainfatherURL[to_color].link, value, 64);
Log.notice(F("Settings update, [%s]:(%s) applied.\r\n"), name, value);
sendNowTicker.once(5, [](){send_grainfather = true;});
sendNowTicker.once(5, [](){data_sender.send_grainfather = true;});
} else if (strcmp(value, "") == 0 || strlen(value) == 0) {
strlcpy(config.grainfatherURL[to_color].link, value, 64);
Log.notice(F("Settings update, [%s]:(%s) cleared.\r\n"), name, value);
Expand Down Expand Up @@ -601,7 +590,7 @@ bool processBrewstatusSettings(AsyncWebServerRequest *request) {
strlcpy(config.brewstatusURL, value, 256);
Log.notice(F("Settings update, [%s]:(%s) applied.\r\n"), name, value);
// Trigger a send to Brewstatus in 5 seconds using the updated key
sendNowTicker.once(5, [](){send_brewStatus = true;});
sendNowTicker.once(5, [](){data_sender.send_brewStatus = true;});
} else if (strcmp(value, "") == 0 || strlen(value) == 0) {
strlcpy(config.brewstatusURL, value, 256);
Log.notice(F("Settings update, [%s]:(%s) cleared.\r\n"), name, value);
Expand Down Expand Up @@ -794,7 +783,7 @@ bool processMqttSettings(AsyncWebServerRequest *request) {
} else {
if (config.save()) {
// Trigger a send via MQTT in 5 seconds using the updated data
sendNowTicker.once(5, [](){send_mqtt = true;});
sendNowTicker.once(5, [](){data_sender.send_mqtt = true;});
return true;
} else {
Log.error(F("Error: Unable to save MQTT configuration data.\r\n"));
Expand Down
6 changes: 0 additions & 6 deletions src/http_server.h
@@ -1,12 +1,6 @@
#ifndef TILTBRIDGE_HTTP_SERVER_H
#define TILTBRIDGE_HTTP_SERVER_H

#include "wifi_setup.h"
#include "OTAUpdate.h"
#include "sendData.h"
#include "jsonconfig.h"
#include "parseTarget.h"

#ifdef FSEDIT
#include <SPIFFSEditor.h>
#endif
Expand Down
5 changes: 1 addition & 4 deletions src/jsonconfig.cpp
Expand Up @@ -6,13 +6,10 @@
#include <FS.h>
#endif


#include "main.h"
#include "getGuid.h"
#include "serialhandler.h"


#include "jsonconfig.h"
#include "bridge_lcd.h"


#define MAX_FILENAME_LENGTH 32
Expand Down
27 changes: 16 additions & 11 deletions src/main.cpp
Expand Up @@ -2,9 +2,20 @@
// Please note - This source code (along with other files) are provided under license.
// More details (including license details) can be found in the files accompanying this source code.

#include <ArduinoLog.h>

#include "main.h"
#include "watchButtons.h"
#include "tilt/tiltScanner.h"
#include "http_server.h"
#include "wifi_setup.h"
#include "sendData.h"
#include "parseTarget.h"
#include "jsonconfig.h"
#include "bridge_lcd.h"
#include "serialhandler.h"
#include "main.h"



#if (ARDUINO_LOG_LEVEL >= 5)
Ticker memCheck;
Expand All @@ -16,7 +27,7 @@ void printMem() {
const uint32_t free = ESP.getFreeHeap();
const uint32_t max = ESP.getMaxAllocHeap();
const uint8_t frag = 100 - (max * 100) / free;
Log.verbose(F("Free Heap: %d, Largest contiguous block: %d, Frag: %d%%\r\n"), free, max, frag);
Log.info(F("Free Heap: %d, Largest contiguous block: %d, Frag: %d%%\r\n"), free, max, frag);
}

void reboot()
Expand Down Expand Up @@ -52,7 +63,8 @@ void setup() {
initButtons(); // Initialize buttons

// Start independent timers
#if (ARDUINO_LOG_LEVEL >= 5) && !defined(DISABLE_LOGGING)
// ARDUINO_LOG_LOG_LEVEL_INFO is 4
#if (ARDUINO_LOG_LEVEL >= ARDUINO_LOG_LOG_LEVEL_INFO) && !defined(DISABLE_LOGGING)
memCheck.attach(30, printMem); // Memory debug print on timer
#endif

Expand All @@ -68,14 +80,7 @@ void loop() {
serialLoop(); // Service telnet and console commands
checkButtons(); // Check for reset calls

send_to_cloud();
data_sender.send_to_localTarget();
send_to_bf_and_bf();
data_sender.send_to_brewstatus();
data_sender.send_to_grainfather();
data_sender.send_to_taplistio();
data_sender.send_to_google();
data_sender.send_to_mqtt();
data_sender.process();

if (tilt_scanner.scan()) {
// The scans are done asynchronously, so we'll poke the scanner to see if
Expand Down
15 changes: 0 additions & 15 deletions src/main.h
@@ -1,21 +1,6 @@
#ifndef _MAIN_H
#define _MAIN_H

#include "watchButtons.h"
#include "http_server.h"
#include "sendData.h"
#include "bridge_lcd.h"
#include "wifi_setup.h"
#include "serialhandler.h"
#include "jsonconfig.h"
#include "parseTarget.h"
#include <Arduino.h>
#include <Ticker.h>
#include <esp_log.h>

#ifdef LOG_LOCAL_LEVEL
#include <esp_log.h>
#endif

void printMem();
void setup();
Expand Down

0 comments on commit 7a5d7e8

Please sign in to comment.