Skip to content

Commit 94b09a5

Browse files
committed
heartbeat improvements
- 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.)
1 parent 9602223 commit 94b09a5

File tree

5 files changed

+50
-4
lines changed

5 files changed

+50
-4
lines changed

README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ The instructions below are for using the Arduino IDE and GitHub Desktop. Visual
163163
* Click ``Upload`` **-->**
164164

165165
Notes:
166+
* 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
166167
* WiTcontroller version 1.66 or later requires WiThrottleProtocol version 1.1.24
167168
* WiTcontroller version 1.65 or later requires WiThrottleProtocol version 1.1.23
168169
* 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.
@@ -432,6 +433,30 @@ If the battery does not show 100% when plugged into the charger, you may need to
432433

433434
``#define BATTERY_CONVERSION_FACTOR 1.7``
434435

436+
To help work out the correct BATTERY_CONVERSION_FACTOR, you can enable so serial monitor message that will assist.
437+
438+
In your ``config_buttons.h`` add (or uncomment) these defines:
439+
440+
#define WITCONTROLLER_DEBUG 0
441+
#define DEBUG_LEVEL 2
442+
443+
DEBUG_LEVEL must be 2 or greater
444+
445+
a) Make sure your battery is fully charged.
446+
b) Upload the code and open the serial monitor.
447+
c) Wait. Don't connect.
448+
You will see lines like...
449+
450+
BATTERY TestValue: 100 (10003)
451+
BATTERY lastAnalogReadValue: 2491 (10003)
452+
BATTERY If Battery full, BATTERY_CONVERSION_FACTOR should be: 1.69 (10014)
453+
454+
Let it run for a while.
455+
d) Note one of the recommend values (it will vary a bit) and enter it into the define in your config_buttons.h
456+
e) Re-upload code and connect to a server
457+
f) Confirm that the battery reads 100% (repeat if not)
458+
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.)
459+
435460
*To show the calculated percentage*, set the following to ``true`` The default is ``false``.
436461

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

466491
## Change Log
467492

493+
### V1.73
494+
- Add debug level option ``#define DEBUG_LEVEL``
495+
- A bug in the heartbeat send in the protocol library was fixed at the same time as this release.
496+
- if heartbeat is enabled, deliberately send the command to server to start it. (I had previously assumed that this was not required.)
497+
468498
### V1.72
469499
- add the ability to sort the roster with the new define ``ROSTER_SORT_SEQUENCE``
470500
- 0 = no sorting. As it comes from the server

WiTcontroller.ino

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
#define debug_println(...)
4343
#define debug_printf(...)
4444
#endif
45+
int debugLevel = DEBUG_LEVEL;
4546

4647
// *********************************************************************************
4748

@@ -928,6 +929,7 @@ void connectWitServer() {
928929
wiThrottleProtocol.setDelegate(&myDelegate);
929930
#if WITHROTTLE_PROTOCOL_DEBUG == 0
930931
wiThrottleProtocol.setLogStream(&Serial);
932+
wiThrottleProtocol.setLogLevel(DEBUG_LEVEL);
931933
#endif
932934

933935
debug_println("Connecting to the server...");
@@ -958,6 +960,9 @@ void connectWitServer() {
958960
wiThrottleProtocol.setDeviceName(deviceName);
959961
wiThrottleProtocol.setDeviceID(String(deviceId));
960962
wiThrottleProtocol.setCommandsNeedLeadingCrLf(commandsNeedLeadingCrLf);
963+
if (HEARTBEAT_ENABLED) {
964+
wiThrottleProtocol.requireHeartbeat(true);
965+
}
961966

962967
witConnectionState = CONNECTION_STATE_CONNECTED;
963968
setLastServerResponseTime(true);
@@ -1074,7 +1079,7 @@ void buildWitEntry() {
10741079
// *********************************************************************************
10751080

10761081
AiEsp32RotaryEncoder rotaryEncoder = AiEsp32RotaryEncoder(ROTARY_ENCODER_A_PIN, ROTARY_ENCODER_B_PIN, ROTARY_ENCODER_BUTTON_PIN, ROTARY_ENCODER_VCC_PIN, ROTARY_ENCODER_STEPS);
1077-
void IRAM_ATTR readEncoderISR() {
1082+
void IRAM_ATTR readEncoderISR(void) {
10781083
rotaryEncoder.readEncoder_ISR();
10791084
}
10801085

@@ -2449,8 +2454,10 @@ void toggleHeartbeatCheck() {
24492454
debug_print("Heartbeat Check: ");
24502455
if (heartbeatCheckEnabled) {
24512456
debug_println("Enabled");
2457+
wiThrottleProtocol.requireHeartbeat(true);
24522458
} else {
24532459
debug_println("Disabled");
2460+
wiThrottleProtocol.requireHeartbeat(false);
24542461
}
24552462
writeHeartbeatCheck();
24562463
}

config_buttons_example.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,11 @@
177177
// to enable to console messages, uncomment and set the following to 0 (i.e. 0 = on 1 = off)
178178
// #define WITHROTTLE_PROTOCOL_DEBUG 1
179179

180+
// console debug messages are enabled with the defines above
181+
// the default level is 1
182+
// 0 = errors only 1 = default level 2 = verbose 3 = extreme
183+
// #define DEBUG_LEVEL 1
184+
180185
// *******************************************************************************************************************
181186
// Default function labels
182187

platformio.ini

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ lib_deps =
2222
chris--a/Keypad@^3.1.1
2323
igorantolic/Ai Esp32 Rotary Encoder@^1.4
2424
olikraus/U8g2@^2.33.3
25-
https://github.com/flash62au/WiThrottleProtocol@^1.1.24
25+
https://github.com/flash62au/WiThrottleProtocol@^1.1.25
2626
; lib_extra_dirs =
27-
; C:\Users\akers\Documents\GitHub\WiThrottleProtocol
27+
; C:\Users\akers\OneDrive\Documents\GitHub\WiThrottleProtocol
2828
monitor_speed = 115200
2929
monitor_echo = yes
3030
build_flags =

static.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const String appName = "WiTcontroller";
2-
const String appVersion = "v1.72";
2+
const String appVersion = "v1.73";
33

44
#ifndef DEVICE_NAME
55
#define DEVICE_NAME "WiTcontroller"
@@ -515,6 +515,10 @@ const char ssidPasswordBlankChar = 164;
515515
#define WITHROTTLE_PROTOCOL_DEBUG 1
516516
#endif
517517

518+
#ifndef DEBUG_LEVEL
519+
#define DEBUG_LEVEL 1
520+
#endif
521+
518522
// *******************************************************************************************************************
519523

520524
#ifndef AUTO_CONNECT_TO_FIRST_DEFINED_SERVER

0 commit comments

Comments
 (0)