Skip to content

Commit

Permalink
heartbeat improvements
Browse files Browse the repository at this point in the history
- Add debug level option ``#define DEBUG_LEVEL``
- A bug in the heartbeat send in the protocol library was fixed at the same time as this release.
- if heartbeat is enabled, deliberately send the command to server to start it. (I had previously assumed that this was not required.)
  • Loading branch information
flash62au committed Oct 16, 2024
1 parent 9602223 commit 94b09a5
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 4 deletions.
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ The instructions below are for using the Arduino IDE and GitHub Desktop. Visual
* Click ``Upload`` **-->**

Notes:
* WiTcontroller version 1.73 or later is recommended to use WiThrottleProtocol version 1.1.25 or later to address a bug in heartbeat send but only seen with JMRI WiThrottle
* WiTcontroller version 1.66 or later requires WiThrottleProtocol version 1.1.24
* WiTcontroller version 1.65 or later requires WiThrottleProtocol version 1.1.23
* WiTcontroller version 1.57 or later requires WiThrottleProtocol version 1.1.20 or later for the E_STOP and E_STOP_CURRENT_LOCO to work correctly.
Expand Down Expand Up @@ -432,6 +433,30 @@ If the battery does not show 100% when plugged into the charger, you may need to

``#define BATTERY_CONVERSION_FACTOR 1.7``

To help work out the correct BATTERY_CONVERSION_FACTOR, you can enable so serial monitor message that will assist.

In your ``config_buttons.h`` add (or uncomment) these defines:

#define WITCONTROLLER_DEBUG 0
#define DEBUG_LEVEL 2

DEBUG_LEVEL must be 2 or greater

a) Make sure your battery is fully charged.
b) Upload the code and open the serial monitor.
c) Wait. Don't connect.
You will see lines like...

BATTERY TestValue: 100 (10003)
BATTERY lastAnalogReadValue: 2491 (10003)
BATTERY If Battery full, BATTERY_CONVERSION_FACTOR should be: 1.69 (10014)

Let it run for a while.
d) Note one of the recommend values (it will vary a bit) and enter it into the define in your config_buttons.h
e) Re-upload code and connect to a server
f) Confirm that the battery reads 100% (repeat if not)
g) Run the HandCab on battery for few hours and confirm the battery level is droping at an expected rate. (adjust the conversion factor if not.)

*To show the calculated percentage*, set the following to ``true`` The default is ``false``.

``#define USE_BATTERY_PERCENT_AS_WELL_AS_ICON true``
Expand Down Expand Up @@ -465,6 +490,11 @@ Bei Interesse kontaktieren Sie mich bitte direkt für eine Anleitung.

## Change Log

### V1.73
- Add debug level option ``#define DEBUG_LEVEL``
- A bug in the heartbeat send in the protocol library was fixed at the same time as this release.
- if heartbeat is enabled, deliberately send the command to server to start it. (I had previously assumed that this was not required.)

### V1.72
- add the ability to sort the roster with the new define ``ROSTER_SORT_SEQUENCE``
- 0 = no sorting. As it comes from the server
Expand Down
9 changes: 8 additions & 1 deletion WiTcontroller.ino
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#define debug_println(...)
#define debug_printf(...)
#endif
int debugLevel = DEBUG_LEVEL;

// *********************************************************************************

Expand Down Expand Up @@ -928,6 +929,7 @@ void connectWitServer() {
wiThrottleProtocol.setDelegate(&myDelegate);
#if WITHROTTLE_PROTOCOL_DEBUG == 0
wiThrottleProtocol.setLogStream(&Serial);
wiThrottleProtocol.setLogLevel(DEBUG_LEVEL);
#endif

debug_println("Connecting to the server...");
Expand Down Expand Up @@ -958,6 +960,9 @@ void connectWitServer() {
wiThrottleProtocol.setDeviceName(deviceName);
wiThrottleProtocol.setDeviceID(String(deviceId));
wiThrottleProtocol.setCommandsNeedLeadingCrLf(commandsNeedLeadingCrLf);
if (HEARTBEAT_ENABLED) {
wiThrottleProtocol.requireHeartbeat(true);
}

witConnectionState = CONNECTION_STATE_CONNECTED;
setLastServerResponseTime(true);
Expand Down Expand Up @@ -1074,7 +1079,7 @@ void buildWitEntry() {
// *********************************************************************************

AiEsp32RotaryEncoder rotaryEncoder = AiEsp32RotaryEncoder(ROTARY_ENCODER_A_PIN, ROTARY_ENCODER_B_PIN, ROTARY_ENCODER_BUTTON_PIN, ROTARY_ENCODER_VCC_PIN, ROTARY_ENCODER_STEPS);
void IRAM_ATTR readEncoderISR() {
void IRAM_ATTR readEncoderISR(void) {
rotaryEncoder.readEncoder_ISR();
}

Expand Down Expand Up @@ -2449,8 +2454,10 @@ void toggleHeartbeatCheck() {
debug_print("Heartbeat Check: ");
if (heartbeatCheckEnabled) {
debug_println("Enabled");
wiThrottleProtocol.requireHeartbeat(true);
} else {
debug_println("Disabled");
wiThrottleProtocol.requireHeartbeat(false);
}
writeHeartbeatCheck();
}
Expand Down
5 changes: 5 additions & 0 deletions config_buttons_example.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,11 @@
// to enable to console messages, uncomment and set the following to 0 (i.e. 0 = on 1 = off)
// #define WITHROTTLE_PROTOCOL_DEBUG 1

// console debug messages are enabled with the defines above
// the default level is 1
// 0 = errors only 1 = default level 2 = verbose 3 = extreme
// #define DEBUG_LEVEL 1

// *******************************************************************************************************************
// Default function labels

Expand Down
4 changes: 2 additions & 2 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ lib_deps =
chris--a/Keypad@^3.1.1
igorantolic/Ai Esp32 Rotary Encoder@^1.4
olikraus/U8g2@^2.33.3
https://github.com/flash62au/WiThrottleProtocol@^1.1.24
https://github.com/flash62au/WiThrottleProtocol@^1.1.25
; lib_extra_dirs =
; C:\Users\akers\Documents\GitHub\WiThrottleProtocol
; C:\Users\akers\OneDrive\Documents\GitHub\WiThrottleProtocol
monitor_speed = 115200
monitor_echo = yes
build_flags =
Expand Down
6 changes: 5 additions & 1 deletion static.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const String appName = "WiTcontroller";
const String appVersion = "v1.72";
const String appVersion = "v1.73";

#ifndef DEVICE_NAME
#define DEVICE_NAME "WiTcontroller"
Expand Down Expand Up @@ -515,6 +515,10 @@ const char ssidPasswordBlankChar = 164;
#define WITHROTTLE_PROTOCOL_DEBUG 1
#endif

#ifndef DEBUG_LEVEL
#define DEBUG_LEVEL 1
#endif

// *******************************************************************************************************************

#ifndef AUTO_CONNECT_TO_FIRST_DEFINED_SERVER
Expand Down

0 comments on commit 94b09a5

Please sign in to comment.