|
| 1 | +# LifeTrac v25 - Mode Switch Feature Changelog |
| 2 | + |
| 3 | +## Version 25 - Mode Switch Implementation |
| 4 | + |
| 5 | +**Date:** December 2024 |
| 6 | +**Feature:** MQTT/OFF/BLE Mode Selection Switch |
| 7 | + |
| 8 | +### Summary |
| 9 | + |
| 10 | +Added support for a HONEYWELL 2NT1-1 On/Off/On switch that allows users to select between: |
| 11 | +1. **Position 1 (MQTT mode)** - Traditional WiFi/MQTT control via broker |
| 12 | +2. **Position 2 (OFF mode)** - Complete power cutoff at center (hardware switch disconnects 12V) |
| 13 | +3. **Position 3 (BLE mode)** - Direct Bluetooth Low Energy control from DroidPad app (default) |
| 14 | + |
| 15 | +### Key Features |
| 16 | + |
| 17 | +- **Default BLE Mode**: If no switch is installed, controller defaults to BLE mode |
| 18 | +- **Hardware Power Cutoff**: OFF position physically disconnects 12V power |
| 19 | +- **Automatic Mode Detection**: Controller reads switch position on startup |
| 20 | +- **DroidPad Direct Control**: BLE mode enables direct connection without WiFi/broker |
| 21 | +- **Backward Compatible**: Existing MQTT functionality preserved |
| 22 | + |
| 23 | +### Hardware Changes |
| 24 | + |
| 25 | +#### Pin Assignments |
| 26 | +- **D9 (MODE_SWITCH_PIN_A)**: First switch position pin |
| 27 | +- **D10 (MODE_SWITCH_PIN_B)**: Second switch position pin (unused but available for future expansion) |
| 28 | + |
| 29 | +#### Switch Logic (HONEYWELL 2NT1-1) |
| 30 | +``` |
| 31 | +Position 1 (MQTT): D9=HIGH, D10=LOW -> MQTT mode |
| 32 | +Position 2 (OFF): Hardware power cutoff at center (no power to controller) |
| 33 | +Position 3 (BLE): D9=LOW, D10=LOW -> BLE mode (default when switch not installed) |
| 34 | +``` |
| 35 | + |
| 36 | +#### Recommended Switch |
| 37 | +- **HONEYWELL 2NT1-1** On/Off/On switch |
| 38 | +- Part: https://www.grainger.com/product/HONEYWELL-Toggle-Switch-3-Position-24D402 |
| 39 | +- Type: 3-position DPDT (On/Off/On type) |
| 40 | +- Pole 1: Controls 12V power to Arduino Opta VIN |
| 41 | +- Pole 2: Controls D9 signal pin for mode detection |
| 42 | +- Center position provides hardware power cutoff |
| 43 | + |
| 44 | +### Software Changes |
| 45 | + |
| 46 | +#### Modified Files |
| 47 | + |
| 48 | +1. **lifetrac_v25_controller.ino** |
| 49 | + - Added `#include <ArduinoBLE.h>` for BLE support |
| 50 | + - Added mode switch pin definitions (D9, D10) |
| 51 | + - Added `ControlMode` enum (MODE_BLE, MODE_MQTT) |
| 52 | + - Added BLE service and characteristic definitions |
| 53 | + - Modified `setup()` to read mode switch and initialize appropriate mode |
| 54 | + - Modified `loop()` to handle both MQTT and BLE control paths |
| 55 | + - Added new functions: |
| 56 | + - `readModeSwitch()` - Detects switch position |
| 57 | + - `setupBLE()` - Initializes BLE service |
| 58 | + - `readBLEJoystickData()` - Reads joystick data from BLE characteristics |
| 59 | + |
| 60 | +2. **arduino_libraries.txt** |
| 61 | + - Added ArduinoBLE library requirement |
| 62 | + |
| 63 | +3. **INSTALLATION_GUIDE.md** |
| 64 | + - Added mode switch hardware connections |
| 65 | + - Added mode selection instructions |
| 66 | + - Updated pin reference table |
| 67 | + - Added BLE troubleshooting section |
| 68 | + |
| 69 | +4. **WIRING_DIAGRAM.md** |
| 70 | + - Added mode switch wiring diagram |
| 71 | + - Updated digital I/O pin assignments |
| 72 | + - Added mode switch logic explanation |
| 73 | + |
| 74 | +5. **DROIDPAD_INTEGRATION.md** |
| 75 | + - Added control mode selection section |
| 76 | + - Added BLE direct control setup instructions |
| 77 | + - Added BLE data format and characteristic UUIDs |
| 78 | + - Added comparison between BLE and MQTT modes |
| 79 | + |
| 80 | +6. **README.md** |
| 81 | + - Updated features list to highlight mode selection |
| 82 | + - Added BLE as primary/simplest control option |
| 83 | + - Updated quick start guide with BLE option first |
| 84 | + |
| 85 | +#### New Documentation Files |
| 86 | + |
| 87 | +1. **DROIDPAD_BLE_SETUP.md** (8.4 KB) |
| 88 | + - Complete step-by-step BLE setup guide |
| 89 | + - Hardware configuration instructions |
| 90 | + - DroidPad configuration with UUIDs |
| 91 | + - Control mapping reference |
| 92 | + - Troubleshooting guide |
| 93 | + - Advantages and limitations of BLE mode |
| 94 | + |
| 95 | +2. **MODE_SWITCH_WIRING.md** (9.8 KB) |
| 96 | + - Detailed switch wiring diagrams |
| 97 | + - Bill of materials for switch |
| 98 | + - Recommended switch models |
| 99 | + - Installation steps |
| 100 | + - Testing procedures |
| 101 | + - Troubleshooting |
| 102 | + - Alternative simplified wiring methods |
| 103 | + |
| 104 | +### BLE Implementation Details |
| 105 | + |
| 106 | +#### Service UUID |
| 107 | +``` |
| 108 | +19B10000-E8F2-537E-4F6C-D104768A1214 |
| 109 | +``` |
| 110 | + |
| 111 | +#### Characteristics |
| 112 | + |
| 113 | +**Left Joystick Characteristic:** |
| 114 | +- UUID: `19B10001-E8F2-537E-4F6C-D104768A1214` |
| 115 | +- Properties: Read + Write |
| 116 | +- Format: 8 bytes (2 x float32) |
| 117 | + - Bytes 0-3: left_x (-1.0 to 1.0) |
| 118 | + - Bytes 4-7: left_y (-1.0 to 1.0) |
| 119 | + |
| 120 | +**Right Joystick Characteristic:** |
| 121 | +- UUID: `19B10002-E8F2-537E-4F6C-D104768A1214` |
| 122 | +- Properties: Read + Write |
| 123 | +- Format: 8 bytes (2 x float32) |
| 124 | + - Bytes 0-3: right_x (-1.0 to 1.0) |
| 125 | + - Bytes 4-7: right_y (-1.0 to 1.0) |
| 126 | + |
| 127 | +#### BLE Device Name |
| 128 | +``` |
| 129 | +LifeTrac-v25 |
| 130 | +``` |
| 131 | + |
| 132 | +### Code Statistics |
| 133 | + |
| 134 | +- **Total Lines Added**: ~160 lines in controller |
| 135 | +- **New Functions**: 3 (readModeSwitch, setupBLE, readBLEJoystickData) |
| 136 | +- **Documentation Added**: ~18 KB in new/updated files |
| 137 | + |
| 138 | +### Safety Features Maintained |
| 139 | + |
| 140 | +All existing safety features work in both modes: |
| 141 | +- **Deadzone**: 10% (0.1) deadzone on all inputs |
| 142 | +- **Safety Timeout**: 1 second timeout stops all movement |
| 143 | +- **Emergency Stop**: Send all zeros or disconnect to stop |
| 144 | +- **Input Validation**: Values outside ±1.0 are clamped |
| 145 | + |
| 146 | +### Benefits of This Implementation |
| 147 | + |
| 148 | +1. **Simplicity**: BLE mode requires no network setup |
| 149 | +2. **Lower Latency**: BLE typically 20-50ms vs 100-200ms for MQTT |
| 150 | +3. **Mobile-First**: Perfect for smartphone/tablet control |
| 151 | +4. **Backward Compatible**: Existing MQTT setups continue to work |
| 152 | +5. **Flexible**: Easy to switch between modes with hardware switch |
| 153 | +6. **Safe Default**: BLE mode is default if switch not installed |
| 154 | +7. **Power Saving**: OFF mode provides complete shutdown |
| 155 | + |
| 156 | +### Testing Recommendations |
| 157 | + |
| 158 | +1. **Mode Detection Test** |
| 159 | + - Test with switch in each position |
| 160 | + - Verify Serial Monitor shows correct mode |
| 161 | + - Test with no switch installed (should default to BLE) |
| 162 | + |
| 163 | +2. **BLE Functionality Test** |
| 164 | + - Scan for "LifeTrac-v25" from mobile device |
| 165 | + - Connect and verify characteristic UUIDs |
| 166 | + - Send test data and verify movement |
| 167 | + - Test safety timeout |
| 168 | + - Test emergency stop |
| 169 | + |
| 170 | +3. **MQTT Functionality Test** |
| 171 | + - Verify WiFi connection in MQTT mode |
| 172 | + - Test MQTT message reception |
| 173 | + - Verify existing ESP32 remote still works |
| 174 | + - Test web interface compatibility |
| 175 | + |
| 176 | +4. **Switch Reliability Test** |
| 177 | + - Test switching between modes |
| 178 | + - Verify power cutoff in OFF position |
| 179 | + - Test mode persistence across power cycles |
| 180 | + |
| 181 | +### Known Limitations |
| 182 | + |
| 183 | +1. **BLE Range**: Typically 30-100 feet (10-30m) vs potentially unlimited with WiFi |
| 184 | +2. **Single Connection**: BLE mode supports only one connected device at a time |
| 185 | +3. **No Status Publishing**: BLE mode doesn't publish status to MQTT (not connected) |
| 186 | +4. **Compilation Requirement**: Requires ArduinoBLE library (built-in for Arduino Opta) |
| 187 | + |
| 188 | +### Future Enhancements |
| 189 | + |
| 190 | +Possible future improvements: |
| 191 | +1. Add BLE status characteristic for reading system state |
| 192 | +2. Support multiple simultaneous BLE connections |
| 193 | +3. Add BLE battery level reporting |
| 194 | +4. Implement BLE security (pairing/encryption) |
| 195 | +5. Add mode switching via serial command (without hardware switch) |
| 196 | +6. Add visual LED indicators for mode selection |
| 197 | + |
| 198 | +### Migration Guide |
| 199 | + |
| 200 | +For existing installations: |
| 201 | +1. Update Arduino Opta firmware to include BLE support |
| 202 | +2. Optionally install mode switch hardware |
| 203 | +3. If no switch installed, controller defaults to BLE mode |
| 204 | +4. To continue using MQTT only, connect D9 to 12V permanently |
| 205 | + |
| 206 | +### Required Libraries |
| 207 | + |
| 208 | +- ArduinoBLE (v1.3.0 or newer) - Arduino official library |
| 209 | +- OptaController - Arduino Opta official library |
| 210 | +- PubSubClient (v2.8 or newer) - For MQTT |
| 211 | +- ArduinoJson (v6.21 or newer) - For JSON parsing |
| 212 | +- WiFi - Built-in ESP32 library |
| 213 | + |
| 214 | +### Compatibility |
| 215 | + |
| 216 | +- **Arduino Board**: Arduino Opta WiFi |
| 217 | +- **Arduino IDE**: 2.0 or newer |
| 218 | +- **DroidPad**: Android/iOS versions with BLE support |
| 219 | +- **Mobile OS**: Android 5.0+ or iOS 10.0+ (BLE 4.0+ required) |
| 220 | + |
| 221 | +### Related Documentation |
| 222 | + |
| 223 | +- [DROIDPAD_BLE_SETUP.md](DROIDPAD_BLE_SETUP.md) - Complete BLE setup guide |
| 224 | +- [MODE_SWITCH_WIRING.md](MODE_SWITCH_WIRING.md) - Hardware wiring instructions |
| 225 | +- [DROIDPAD_INTEGRATION.md](DROIDPAD_INTEGRATION.md) - General DroidPad guide |
| 226 | +- [INSTALLATION_GUIDE.md](INSTALLATION_GUIDE.md) - Complete installation guide |
| 227 | +- [WIRING_DIAGRAM.md](WIRING_DIAGRAM.md) - System wiring diagrams |
| 228 | + |
| 229 | +### Support |
| 230 | + |
| 231 | +For issues or questions: |
| 232 | +- GitHub Issues: https://github.com/OpenSourceEcology/LifeTrac/issues |
| 233 | +- Documentation: See README.md and linked guides above |
| 234 | + |
| 235 | +### Contributors |
| 236 | + |
| 237 | +This feature was developed to simplify mobile control while maintaining flexibility for network-based operations. |
| 238 | + |
| 239 | +--- |
| 240 | + |
| 241 | +**Note**: This implementation provides a foundation for direct mobile control. Users can choose the mode that best fits their use case: simple BLE for mobile operation, or MQTT for network integration and multiple control interfaces. |
0 commit comments