signalk-rec-bms 1.1.4 → 1.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -44,3 +44,15 @@ Run the following command:
44
44
  ```bash
45
45
  npm install signalk-rec-bms
46
46
  ```
47
+
48
+ ## Victron Cerbo GX / Venus OS
49
+
50
+ VenusOS claims all serial devices by default and attempts to pair them with a pre-defined service. This script works by telling VenusOS to ignore your usb to serial device & allowing you to use it with SignalK.
51
+
52
+ ```bash
53
+ curl -o /home/root/signalk-rec-bms-venusOS.sh https://raw.githubusercontent.com/ofernander/signalk-rec-bms/main/venus-os/signalk-rec-bms-venusOS.sh && bash /home/root/signalk-rec-bms-venusOS.sh
54
+ ```
55
+
56
+ The script will list your connected USB serial devices, you select which one is the usb to serial converter for your REC-BMS. Once complete, unplug and replug your RS485 adapter, then reboot the Cerbo device.
57
+
58
+ To uninstall: `bash /home/root/signalk-rec-bms-venusOS.sh --uninstall` or select the last option in the script menu.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "signalk-rec-bms",
3
- "version": "1.1.4",
3
+ "version": "1.1.5",
4
4
  "description": "SignalK plugin for REC-BMS",
5
5
  "main": "plugin/index.js",
6
6
  "scripts": {
@@ -366,7 +366,7 @@
366
366
  "expectedPackets": 1,
367
367
  "payloadSizes": [null],
368
368
  "parser": "parseERRLResponse",
369
- "timeout": 3,
369
+ "timeout": 100,
370
370
  "description": "ERRL? returns error log data",
371
371
  "module": "erro"
372
372
  },
@@ -0,0 +1,283 @@
1
+ #!/bin/bash
2
+ # signalk-rec-bms-setup.sh
3
+ # Venus OS setup script for signalk-rec-bms
4
+ #
5
+ # Reserves the REC-BMS serial adapter so Venus OS serial-starter
6
+ # leaves it alone and SignalK can own it cleanly.
7
+ #
8
+ # Usage:
9
+ # Interactive install: bash setup.sh
10
+ # Uninstall: bash setup.sh --uninstall
11
+ # Silent boot mode: bash setup.sh --boot (called by rc.local, not for manual use)
12
+
13
+ # exit on unhandled errors
14
+ set -e
15
+
16
+ # trap unexpected exits and inform the user
17
+ trap 'echo ""; echo "ERROR: Setup was interrupted unexpectedly. Run the script again to retry."; exit 1' ERR
18
+
19
+ STORED_SERIAL="/data/conf/signalk-rec-bms"
20
+ UDEV_RULES="/etc/udev/rules.d/zz-signalk-rec-bms.rules"
21
+ RC_LOCAL="/data/rc.local"
22
+ SELF="/home/root/signalk-rec-bms-venusOS.sh"
23
+
24
+
25
+ # -------------------------------------------------------
26
+ # BOOT MODE
27
+ # Called by rc.local on every boot.
28
+ # Silent - re-applies the udev rule after firmware updates
29
+ # restore the read-only filesystem.
30
+ # -------------------------------------------------------
31
+ if [ "$1" = "--boot" ]; then
32
+ if [ ! -f "$STORED_SERIAL" ]; then
33
+ exit 0
34
+ fi
35
+
36
+ stored=$(cat "$STORED_SERIAL")
37
+ if [ -z "$stored" ]; then
38
+ exit 0
39
+ fi
40
+
41
+ if [ ! -f "/opt/victronenergy/swupdate-scripts/remount-rw.sh" ]; then
42
+ exit 0
43
+ fi
44
+ bash /opt/victronenergy/swupdate-scripts/remount-rw.sh
45
+
46
+ echo "# signalk-rec-bms: reserve device for SignalK" > "$UDEV_RULES"
47
+ echo "ACTION==\"add\", ENV{ID_BUS}==\"usb\", ATTRS{serial}==\"${stored}\", ENV{VE_SERVICE}=\"ignore\"" >> "$UDEV_RULES"
48
+
49
+ udevadm control --reload-rules
50
+
51
+ exit 0
52
+ fi
53
+
54
+
55
+ # -------------------------------------------------------
56
+ # UNINSTALL MODE
57
+ # -------------------------------------------------------
58
+ if [ "$1" = "--uninstall" ]; then
59
+ echo ""
60
+ echo "signalk-rec-bms Venus OS Uninstall"
61
+ echo "===================================="
62
+ echo ""
63
+
64
+ read -p "Remove signalk-rec-bms device reservation? [y/N]: " confirm
65
+ if [[ ! "$confirm" =~ ^[Yy]$ ]]; then
66
+ echo "Aborted."
67
+ exit 0
68
+ fi
69
+
70
+ echo "Remounting filesystem read-write..."
71
+ bash /opt/victronenergy/swupdate-scripts/remount-rw.sh
72
+
73
+ # remove udev rules file
74
+ if [ -f "$UDEV_RULES" ]; then
75
+ rm -f "$UDEV_RULES"
76
+ echo "Removed udev rules file."
77
+ fi
78
+
79
+ # remove rc.local entry
80
+ if [ -f "$RC_LOCAL" ]; then
81
+ sed -i "\|bash $SELF --boot|d" "$RC_LOCAL"
82
+ echo "Removed boot hook from rc.local."
83
+ fi
84
+
85
+ # remove stored serial
86
+ if [ -f "$STORED_SERIAL" ]; then
87
+ rm -f "$STORED_SERIAL"
88
+ echo "Removed stored device serial."
89
+ fi
90
+
91
+ # remove self from persistent location
92
+ if [ -f "$SELF" ]; then
93
+ rm -f "$SELF"
94
+ echo "Removed setup script from /data/conf."
95
+ fi
96
+
97
+ # reload udev — does not affect other devices
98
+ udevadm control --reload-rules
99
+
100
+ # restart serial-starter so it resumes managing the device
101
+ svc -t /service/serial-starter
102
+
103
+ echo ""
104
+ echo "Uninstall complete."
105
+ echo "Unplug and replug your RS485 adapter for serial-starter to resume managing the device."
106
+ echo ""
107
+ exit 0
108
+ fi
109
+
110
+
111
+ # -------------------------------------------------------
112
+ # INTERACTIVE INSTALL MODE
113
+ # -------------------------------------------------------
114
+ echo ""
115
+ echo "signalk-rec-bms Venus OS Setup"
116
+ echo "================================"
117
+ echo ""
118
+
119
+
120
+ # -------------------------------------------------------
121
+ # STEP 1 - Check we are on Venus OS
122
+ # -------------------------------------------------------
123
+ if [ ! -f "/opt/victronenergy/version" ]; then
124
+ echo "ERROR: This script is for Venus OS only."
125
+ exit 1
126
+ fi
127
+
128
+ echo "Venus OS $(head -n 1 /opt/victronenergy/version) detected."
129
+ echo ""
130
+
131
+
132
+ # -------------------------------------------------------
133
+ # STEP 2 - Scan for USB serial devices
134
+ # -------------------------------------------------------
135
+ echo "Scanning for USB serial devices..."
136
+ echo ""
137
+
138
+ devices=()
139
+ serials=()
140
+ descriptions=()
141
+
142
+ for tty in /dev/ttyUSB* /dev/ttyACM*; do
143
+ [ -e "$tty" ] || continue
144
+ name=$(basename $tty)
145
+ serial=$(udevadm info -q property -n $tty 2>/dev/null | grep "^ID_SERIAL_SHORT=" | cut -d= -f2)
146
+ product=$(udevadm info -q property -n $tty 2>/dev/null | grep "^ID_MODEL=" | cut -d= -f2 | tr '_' ' ')
147
+ vendor=$(udevadm info -q property -n $tty 2>/dev/null | grep "^ID_VENDOR=" | cut -d= -f2 | tr '_' ' ')
148
+ devices+=("$name")
149
+ serials+=("$serial")
150
+ descriptions+=("$vendor $product [serial: ${serial:-unknown}]")
151
+ done
152
+
153
+ if [ ${#devices[@]} -eq 0 ]; then
154
+ echo "ERROR: No USB serial devices found."
155
+ echo "Connect your RS485 adapter and run this script again."
156
+ exit 1
157
+ fi
158
+
159
+ echo "Found the following USB serial devices:"
160
+ echo ""
161
+ for i in "${!devices[@]}"; do
162
+ echo " [$((i+1))] ${devices[$i]} - ${descriptions[$i]}"
163
+ done
164
+ uninstall_option=$(( ${#devices[@]} + 1 ))
165
+ echo " [$uninstall_option] Uninstall signalk-rec-bms Venus OS setup"
166
+ echo ""
167
+
168
+
169
+ # -------------------------------------------------------
170
+ # STEP 3 - User selects the BMS device
171
+ # -------------------------------------------------------
172
+ read -p "Enter the number of the device connected to your REC-BMS: " selection
173
+
174
+ # handle uninstall option
175
+ if [ "$selection" = "$uninstall_option" ]; then
176
+ exec bash "$0" --uninstall
177
+ fi
178
+
179
+ if ! [[ "$selection" =~ ^[0-9]+$ ]] || \
180
+ [ "$selection" -lt 1 ] || \
181
+ [ "$selection" -gt "${#devices[@]}" ]; then
182
+ echo "Invalid selection. Exiting."
183
+ exit 1
184
+ fi
185
+
186
+ idx=$((selection-1))
187
+ selected_tty="${devices[$idx]}"
188
+ selected_serial="${serials[$idx]}"
189
+ selected_desc="${descriptions[$idx]}"
190
+
191
+ echo ""
192
+ echo "Selected: $selected_tty - $selected_desc"
193
+ echo ""
194
+
195
+ if [ -z "$selected_serial" ]; then
196
+ echo "ERROR: Could not read USB serial number for this device."
197
+ echo "The reservation requires a USB serial number to survive reboots."
198
+ echo "Try a different adapter or check dmesg for device details."
199
+ exit 1
200
+ fi
201
+
202
+
203
+ # -------------------------------------------------------
204
+ # STEP 4 - Confirm
205
+ # -------------------------------------------------------
206
+ read -p "Reserve $selected_tty for signalk-rec-bms? [y/N]: " confirm
207
+ if [[ ! "$confirm" =~ ^[Yy]$ ]]; then
208
+ echo "Aborted."
209
+ exit 0
210
+ fi
211
+
212
+
213
+ # -------------------------------------------------------
214
+ # STEP 5 - Store USB serial number persistently
215
+ # -------------------------------------------------------
216
+ echo ""
217
+ echo "Storing device serial number..."
218
+ echo "$selected_serial" > "$STORED_SERIAL"
219
+
220
+
221
+ # -------------------------------------------------------
222
+ # STEP 6 - Remount root filesystem read-write
223
+ # -------------------------------------------------------
224
+ echo "Remounting filesystem read-write..."
225
+ bash /opt/victronenergy/swupdate-scripts/remount-rw.sh
226
+
227
+
228
+ # -------------------------------------------------------
229
+ # STEP 7 - Write udev rule targeting this specific device
230
+ # VE_SERVICE=ignore tells serial-starter to leave it alone
231
+ # -------------------------------------------------------
232
+ echo "Writing udev rule..."
233
+
234
+ echo "# signalk-rec-bms: reserve device for SignalK" > "$UDEV_RULES"
235
+ echo "ACTION==\"add\", ENV{ID_BUS}==\"usb\", ATTRS{serial}==\"${selected_serial}\", ENV{VE_SERVICE}=\"ignore\"" >> "$UDEV_RULES"
236
+
237
+ echo "Reloading udev rules..."
238
+ udevadm control --reload-rules
239
+ udevadm trigger
240
+
241
+
242
+ # -------------------------------------------------------
243
+ # STEP 8 - Persist across Venus OS firmware updates
244
+ # Firmware updates restore the read-only filesystem,
245
+ # wiping the udev rule. rc.local re-applies it on boot.
246
+ # This script copies itself to /data/conf so it survives
247
+ # and is called from rc.local on every boot.
248
+ # -------------------------------------------------------
249
+ echo "Installing boot hook..."
250
+
251
+ if [ "$(realpath $0)" != "$(realpath $SELF)" ]; then
252
+ cp "$0" "$SELF"
253
+ chmod +x "$SELF"
254
+ fi
255
+
256
+ if [ ! -f "$RC_LOCAL" ]; then
257
+ echo "#!/bin/bash" > "$RC_LOCAL"
258
+ chmod 755 "$RC_LOCAL"
259
+ fi
260
+
261
+ grep -qxF "bash $SELF --boot" "$RC_LOCAL" || \
262
+ echo "bash $SELF --boot" >> "$RC_LOCAL"
263
+
264
+
265
+ # -------------------------------------------------------
266
+ # STEP 9 - Restart serial-starter to pick up the change
267
+ # -------------------------------------------------------
268
+ echo "Restarting serial-starter..."
269
+ svc -t /service/serial-starter
270
+
271
+
272
+ echo ""
273
+ echo "Done."
274
+ echo ""
275
+ echo " Device: $selected_tty"
276
+ echo " Serial: $selected_serial"
277
+ echo " Status: Reserved for signalk-rec-bms"
278
+ echo ""
279
+ echo "Serial-starter will not probe or claim this device."
280
+ echo "Unplug and replug your RS485 adapter now, then start the SignalK plugin."
281
+ echo ""
282
+ echo "To undo this at any time: bash $SELF --uninstall"
283
+ echo ""