signalk-relay-windlass 0.0.1

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.
@@ -0,0 +1,37 @@
1
+ name: Publish to npm
2
+ on:
3
+ release:
4
+ types: [created]
5
+ permissions:
6
+ id-token: write # Required for OIDC
7
+ contents: read
8
+ jobs:
9
+ build:
10
+ runs-on: ubuntu-latest
11
+ steps:
12
+ - uses: actions/checkout@v4
13
+ - uses: actions/setup-node@v4
14
+ with:
15
+ node-version: '24.x'
16
+ registry-url: 'https://registry.npmjs.org'
17
+
18
+ - name: Install and build
19
+ run: |
20
+ npm cache clean -f
21
+ npm install
22
+ npm ci && npm cache clean --force
23
+ npm run build
24
+
25
+ - name: Set tag variable
26
+ id: vars
27
+ run: echo "tag=${GITHUB_REF#refs/*/}" >> $GITHUB_OUTPUT
28
+
29
+ - name: Publish
30
+ run: |
31
+ npm ci && npm cache clean --force
32
+ if [[ "${{ steps.vars.outputs.tag }}" == *beta* ]];
33
+ then
34
+ npm publish --tag beta
35
+ else
36
+ npm publish --access public
37
+ fi
@@ -0,0 +1,30 @@
1
+ name: 'Release on tag'
2
+ on:
3
+ push:
4
+ tags:
5
+ - '*'
6
+
7
+ jobs:
8
+ release:
9
+ permissions:
10
+ contents: write
11
+ if: startsWith(github.ref, 'refs/tags/')
12
+ runs-on: ubuntu-latest
13
+ steps:
14
+ - name: Build Changelog
15
+ id: github_release
16
+ uses: mikepenz/release-changelog-builder-action@v5
17
+ with:
18
+ ignorePreReleases: 'true'
19
+ env:
20
+ GITHUB_TOKEN: ${{ secrets.RELEASE_PAT }}
21
+
22
+ - name: Create Release
23
+ uses: actions/create-release@v1
24
+ with:
25
+ tag_name: ${{ github.ref }}
26
+ release_name: ${{ github.ref }}
27
+ prerelease: ${{ contains(github.ref, 'beta') }}
28
+ body: ${{steps.github_release.outputs.changelog}}
29
+ env:
30
+ GITHUB_TOKEN: ${{ secrets.RELEASE_PAT }}
@@ -0,0 +1,13 @@
1
+ name: Pull Request Labels
2
+ on:
3
+ pull_request:
4
+ types: [opened, labeled, unlabeled, synchronize]
5
+ jobs:
6
+ label:
7
+ runs-on: ubuntu-latest
8
+ steps:
9
+ - uses: mheap/github-action-required-labels@v1
10
+ with:
11
+ mode: exactly
12
+ count: 1
13
+ labels: 'fix, feature, doc, chore, test, ignore, other, dependencies, refactor'
@@ -0,0 +1,27 @@
1
+ # This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
2
+ # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs
3
+
4
+ name: Node.js CI & Test
5
+
6
+ on:
7
+ push:
8
+ branches: ['master']
9
+ pull_request:
10
+ branches: ['master']
11
+
12
+ jobs:
13
+ build:
14
+ runs-on: ubuntu-latest
15
+
16
+ strategy:
17
+ matrix:
18
+ node-version: [20.x, 22.x, 24.x]
19
+
20
+ steps:
21
+ - uses: actions/checkout@v3
22
+ - name: Use Node.js ${{ matrix.node-version }}
23
+ uses: actions/setup-node@v3
24
+ with:
25
+ node-version: ${{ matrix.node-version }}
26
+ - run: npm install
27
+ - run: npm run ci-test
package/.mocharc.json ADDED
@@ -0,0 +1,5 @@
1
+ {
2
+ "extension": ["ts"],
3
+ "spec": "test/*.ts",
4
+ "require": "tsx"
5
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "semi": false,
3
+ "singleQuote": true,
4
+ "trailingComma": "none"
5
+ }
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,112 @@
1
+ # SignalK Relay Windlass Plugin
2
+
3
+ A Signal K server plugin that provides safe control of an electric windlass (anchor winch) using two relay switches. This plugin allows you to raise and lower your anchor through Signal K while providing important safety features like automatic timeout protection.
4
+
5
+ ## Features
6
+
7
+ - **Dual Relay Control**: Controls windlass up/down operation using separate relays
8
+ - **Safety Timeout**: Configurable automatic shutoff to prevent motor damage from extended operation
9
+ - **Real-time Status**: Live monitoring of windlass state based on relay feedback
10
+ - **Notification System**: Alert notifications when safety timeout is triggered
11
+ - **PUT Handler**: Control windlass through Signal K PUT requests
12
+
13
+ ## Configuration
14
+
15
+ The plugin requires configuration of three main parameters:
16
+
17
+ ### Settings
18
+
19
+ - **Windlass State Path**: Signal K path for windlass control state (default: `electrical.windlass.control.state`)
20
+ - **Up Relay Path**: Path to relay that controls windlass up operation (default: `electrical.windlass.up.state`)
21
+ - **Down Relay Path**: Path to relay that controls windlass down operation (default: `electrical.windlass.down.state`)
22
+ - **Safety Timeout**: Maximum continuous operation time in seconds (default: 30, range: 0-300, 0 = disabled)
23
+ - **Direction Switch Delay**: Minimum delay when switching between up and down directions in seconds (default: 2, range: 0-30, 0 = disabled)
24
+
25
+ ## Usage
26
+
27
+ ### Control Methods
28
+
29
+ The windlass can be controlled through several methods:
30
+
31
+ 1. **Signal K Web Interface**: Use the controls in the web interface
32
+ 2. **PUT Requests**: Send HTTP PUT requests to the windlass path
33
+ 3. **WebSocket**: Send delta messages via WebSocket
34
+ 4. **Node-RED**: Use Signal K nodes in Node-RED flows
35
+
36
+ ### Control Values
37
+
38
+ - `"up"` - Raise the anchor (activates up relay, deactivates down relay)
39
+ - `"down"` - Lower the anchor (activates down relay, deactivates up relay)
40
+ - `"off"` - Stop operation (deactivates both relays)
41
+
42
+ ### PUT Request Example
43
+
44
+ ```bash
45
+ curl -X PUT \
46
+ http://localhost:3000/signalk/v1/api/vessels/self/electrical/windlass/control/state \
47
+ -H 'Content-Type: application/json' \
48
+ -d '{"value": "up"}'
49
+ ```
50
+
51
+ ## Safety Features
52
+
53
+ ### Automatic Timeout Protection
54
+
55
+ The plugin includes configurable timeout protection to prevent windlass motor damage:
56
+
57
+ - **Configurable Duration**: Set maximum run time (0-300 seconds)
58
+ - **Automatic Shutoff**: Both relays automatically deactivated when timeout reached
59
+ - **Visual/Audio Alerts**: Notifications sent through Signal K alert system
60
+ - **Debug Logging**: Timeout events logged for troubleshooting
61
+
62
+ ### Direction Switch Delay Protection
63
+
64
+ To prevent motor and gearbox damage from rapid direction changes:
65
+
66
+ - **Configurable Delay**: Set minimum time between opposite direction commands (0-30 seconds)
67
+ - **Smart Timing**: Only applies when switching from up→down or down→up
68
+ - **Immediate Stop**: Off commands execute immediately for safety
69
+ - **Queue Management**: Direction changes are delayed and automatically executed when safe
70
+
71
+ ### State Monitoring
72
+
73
+ - **Real-time Feedback**: Windlass state automatically updates based on relay positions
74
+ - **Conflict Detection**: System detects invalid relay combinations
75
+ - **Subscription-based**: Uses Signal K subscriptions for efficient monitoring
76
+
77
+ ## Signal K Paths
78
+
79
+ ### Output Paths
80
+
81
+ | Path | Description | Values |
82
+ | ----------------------------------- | ---------------------- | ------------------------- |
83
+ | `electrical.windlass.control.state` | Current windlass state | `"up"`, `"down"`, `"off"` |
84
+
85
+ ### Input Paths (Monitored)
86
+
87
+ | Path | Description | Values |
88
+ | -------------------------------- | ---------------- | --------------------------- |
89
+ | `electrical.windlass.up.state` | Up relay state | `true` (on) / `false` (off) |
90
+ | `electrical.windlass.down.state` | Down relay state | `true` (on) / `false` (off) |
91
+
92
+ ### Notification Paths
93
+
94
+ | Path | Description |
95
+ | -------------------------------- | --------------------------- |
96
+ | `notifications.windlass.timeout` | Timeout alert notifications |
97
+
98
+ ## License
99
+
100
+ Licensed under the Apache License 2.0. See LICENSE file for details.
101
+
102
+ ## Contributing
103
+
104
+ Issues and pull requests welcome! Please ensure:
105
+
106
+ - Code follows existing style (run `npm run format`)
107
+ - Tests pass (`npm test`)
108
+ - Documentation is updated for new features
109
+
110
+ ## Author
111
+
112
+ Scott Bender <scott@scottbender.net>
@@ -0,0 +1,4 @@
1
+ import { ServerAPI, Plugin } from '@signalk/server-api';
2
+ declare const start: (app: ServerAPI) => Plugin;
3
+ export default start;
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAiBA,OAAO,EACL,SAAS,EACT,MAAM,EAKP,MAAM,qBAAqB,CAAA;AAsB5B,QAAA,MAAM,KAAK,GAAI,KAAK,SAAS,WAkY5B,CAAA;AAGD,eAAe,KAAK,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,373 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright 2025 Scott Bender <scott@scottbender.net>
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ var WindlassState;
18
+ (function (WindlassState) {
19
+ WindlassState["Up"] = "up";
20
+ WindlassState["Off"] = "off";
21
+ WindlassState["Down"] = "down";
22
+ })(WindlassState || (WindlassState = {}));
23
+ const error = {
24
+ state: 'COMPLETED',
25
+ statusCode: 500
26
+ };
27
+ const completed = {
28
+ state: 'COMPLETED',
29
+ statusCode: 200
30
+ };
31
+ const pending = {
32
+ state: 'PENDING'
33
+ };
34
+ const start = (app) => {
35
+ let props;
36
+ let onStop = [];
37
+ let started = false;
38
+ let upRelayState = false;
39
+ let downRelayState = false;
40
+ let currentState = WindlassState.Off;
41
+ let timeoutTimer = null;
42
+ function clearTimeoutTimer() {
43
+ if (timeoutTimer) {
44
+ app.debug('Clearing windlass timeout timer');
45
+ clearTimeout(timeoutTimer);
46
+ timeoutTimer = null;
47
+ }
48
+ }
49
+ function forceWindlassOff() {
50
+ app.debug('Windlass timeout reached - forcing off');
51
+ clearTimeoutTimer();
52
+ // Turn off both relays
53
+ app.debug('Forcing relay states: up=false, down=false');
54
+ app.putSelfPath(props.upRelayPath, false);
55
+ app.putSelfPath(props.downRelayPath, false);
56
+ // Send notification about timeout
57
+ const timeoutNotification = {
58
+ updates: [
59
+ {
60
+ values: [
61
+ {
62
+ path: 'notifications.windlass.timeout',
63
+ value: {
64
+ state: 'alert',
65
+ method: ['visual', 'sound'],
66
+ message: `Windlass automatically stopped after ${props.timeoutSeconds} seconds`,
67
+ timestamp: new Date().toISOString()
68
+ }
69
+ }
70
+ ]
71
+ }
72
+ ]
73
+ };
74
+ app.handleMessage(plugin.id, timeoutNotification);
75
+ }
76
+ function updateWindlassState() {
77
+ if (!started)
78
+ return;
79
+ let newState;
80
+ if (upRelayState && !downRelayState) {
81
+ newState = WindlassState.Up;
82
+ }
83
+ else if (!upRelayState && downRelayState) {
84
+ newState = WindlassState.Down;
85
+ }
86
+ else {
87
+ newState = WindlassState.Off;
88
+ }
89
+ // Handle timeout logic
90
+ if (newState !== currentState) {
91
+ app.debug(`Windlass state changing: ${currentState} -> ${newState} (up: ${upRelayState}, down: ${downRelayState})`);
92
+ clearTimeoutTimer();
93
+ // Start timeout timer for active states
94
+ if ((newState === WindlassState.Up || newState === WindlassState.Down) &&
95
+ props.timeoutSeconds > 0) {
96
+ app.debug(`Starting timeout timer: ${props.timeoutSeconds} seconds`);
97
+ timeoutTimer = setTimeout(() => {
98
+ forceWindlassOff();
99
+ }, props.timeoutSeconds * 1000);
100
+ }
101
+ currentState = newState;
102
+ sendState(newState);
103
+ }
104
+ }
105
+ const plugin = {
106
+ start: (properties, _restartPluginParam) => {
107
+ props = properties;
108
+ started = true;
109
+ app.debug('Starting windlass plugin with configuration:');
110
+ app.debug(` windlassPath: ${props.windlassPath}`);
111
+ app.debug(` upRelayPath: ${props.upRelayPath}`);
112
+ app.debug(` downRelayPath: ${props.downRelayPath}`);
113
+ app.debug(` timeoutSeconds: ${props.timeoutSeconds}`);
114
+ const subscriptionOptions = {
115
+ context: 'vessels.self',
116
+ subscribe: [
117
+ {
118
+ path: props.upRelayPath,
119
+ period: 100
120
+ },
121
+ {
122
+ path: props.downRelayPath,
123
+ period: 100
124
+ }
125
+ ]
126
+ };
127
+ app.debug('Setting up subscriptions for relay monitoring');
128
+ app.subscriptionmanager.subscribe(subscriptionOptions, onStop, (error) => {
129
+ app.error('Subscription error: ' + JSON.stringify(error));
130
+ }, (delta) => {
131
+ delta.updates?.forEach((update) => {
132
+ update.values?.forEach((value) => {
133
+ if (value.path === props.upRelayPath) {
134
+ app.debug(`Up relay state changed: ${upRelayState} -> ${Boolean(value.value)}`);
135
+ upRelayState = Boolean(value.value);
136
+ updateWindlassState();
137
+ }
138
+ else if (value.path === props.downRelayPath) {
139
+ app.debug(`Down relay state changed: ${downRelayState} -> ${Boolean(value.value)}`);
140
+ downRelayState = Boolean(value.value);
141
+ updateWindlassState();
142
+ }
143
+ });
144
+ });
145
+ });
146
+ app.debug('Registering PUT handler for windlass control');
147
+ app.registerPutHandler('vessels.self', props.windlassPath, (context, path, value, cb) => {
148
+ app.debug(`PUT request received: ${path} = ${value}`);
149
+ if (value === WindlassState.Up) {
150
+ app.debug('Processing windlass UP command');
151
+ setWindlassUp(cb);
152
+ return pending;
153
+ }
154
+ else if (value === WindlassState.Down) {
155
+ app.debug('Processing windlass DOWN command');
156
+ setWindlassDown(cb);
157
+ return pending;
158
+ }
159
+ else if (value === WindlassState.Off) {
160
+ app.debug('Processing windlass OFF command');
161
+ setWindlassOff(cb);
162
+ return pending;
163
+ }
164
+ else {
165
+ app.debug(`Unknown windlass command: ${value}`);
166
+ return error;
167
+ }
168
+ });
169
+ app.handleMessage(plugin.id, {
170
+ updates: [
171
+ {
172
+ meta: [
173
+ {
174
+ path: props.windlassPath,
175
+ value: {
176
+ displayName: 'Windlass',
177
+ possibleValues: [
178
+ {
179
+ title: 'Up',
180
+ value: 'up'
181
+ },
182
+ {
183
+ title: 'Off',
184
+ value: 'off'
185
+ },
186
+ {
187
+ title: 'Down',
188
+ value: 'down'
189
+ }
190
+ ]
191
+ }
192
+ }
193
+ ]
194
+ }
195
+ ]
196
+ });
197
+ sendState(WindlassState.Off);
198
+ app.debug('Windlass plugin started successfully');
199
+ },
200
+ stop: function () {
201
+ app.debug('Stopping windlass plugin');
202
+ started = false;
203
+ clearTimeoutTimer();
204
+ onStop.forEach((f) => f());
205
+ onStop = [];
206
+ app.debug('Windlass plugin stopped');
207
+ },
208
+ id: 'signalk-relay-windlass',
209
+ name: 'Signal K Relay Windlass',
210
+ description: 'Signal K Plugin to control a windlass using two relay switches',
211
+ schema: {
212
+ type: 'object',
213
+ required: ['windlassPath', 'upRelayPath', 'downRelayPath'],
214
+ properties: {
215
+ windlassPath: {
216
+ type: 'string',
217
+ title: 'Windlass State Path',
218
+ description: 'The path to use for the windlass state',
219
+ default: 'electrical.windlass.control.state'
220
+ },
221
+ upRelayPath: {
222
+ type: 'string',
223
+ title: 'Up Relay Path',
224
+ description: 'The path to the up relay switch',
225
+ default: 'electrical.windlass.up.state'
226
+ },
227
+ downRelayPath: {
228
+ type: 'string',
229
+ title: 'Down Relay Path',
230
+ description: 'The path to the down relay switch',
231
+ default: 'electrical.windlass.down.state'
232
+ },
233
+ timeoutSeconds: {
234
+ type: 'number',
235
+ title: 'Safety Timeout (seconds)',
236
+ description: 'Maximum time windlass can run continuously before automatic shutoff (0 = no timeout)',
237
+ default: 10
238
+ },
239
+ switchingDelaySeconds: {
240
+ type: 'number',
241
+ title: 'Direction Switch Delay (seconds)',
242
+ description: 'Delay when switching between up and down directions (0 = no delay)',
243
+ default: 5
244
+ }
245
+ }
246
+ }
247
+ /*
248
+ uiSchema: () => {
249
+ const uiSchema: any = {}
250
+
251
+ Object.values(devices).forEach((device: any) => {
252
+ uiSchema[`Device ID ${deviceKey(device)}`] = {
253
+ password: {
254
+ 'ui:widget': 'password'
255
+ }
256
+ }
257
+ })
258
+
259
+ return uiSchema
260
+ },
261
+ */
262
+ //registerWithRouter: (router) => {}
263
+ };
264
+ function sendState(state) {
265
+ app.debug(`Sending windlass state: ${state}`);
266
+ app.handleMessage(plugin.id, {
267
+ updates: [
268
+ {
269
+ values: [
270
+ {
271
+ path: props.windlassPath,
272
+ value: state
273
+ }
274
+ ]
275
+ }
276
+ ]
277
+ });
278
+ }
279
+ function setWindlassUp(cb) {
280
+ app.debug('Executing windlass UP: turning off down relay first');
281
+ app.putSelfPath(props.downRelayPath, false, (reply) => {
282
+ if (reply.state === 'COMPLETED') {
283
+ if (reply.statusCode === 200) {
284
+ app.debug('Down relay turned off, now turning on up relay');
285
+ setTimeout(() => {
286
+ ;
287
+ app.putSelfPath(props.upRelayPath, true, (reply) => {
288
+ if (reply.state === 'COMPLETED') {
289
+ if (reply.statusCode === 200) {
290
+ app.debug('Up relay activated successfully');
291
+ sendState(WindlassState.Up);
292
+ cb(completed);
293
+ }
294
+ else {
295
+ app.debug(`Up relay activation failed: ${reply.statusCode}`);
296
+ cb({ ...error, message: reply.message });
297
+ }
298
+ }
299
+ });
300
+ }, currentState === WindlassState.Down
301
+ ? props.switchingDelaySeconds * 1000
302
+ : 0);
303
+ }
304
+ else {
305
+ app.debug(`Up relay PUT failed: ${reply.statusCode}`);
306
+ cb({ ...error, message: reply.message });
307
+ }
308
+ }
309
+ });
310
+ }
311
+ function setWindlassDown(cb) {
312
+ app.debug('Executing windlass DOWN: turning off up relay first');
313
+ app.putSelfPath(props.upRelayPath, false, (reply) => {
314
+ if (reply.state === 'COMPLETED') {
315
+ if (reply.statusCode === 200) {
316
+ app.debug('Up relay turned off, now turning on down relay');
317
+ setTimeout(() => {
318
+ ;
319
+ app.putSelfPath(props.downRelayPath, true, (reply) => {
320
+ if (reply.state === 'COMPLETED') {
321
+ if (reply.statusCode === 200) {
322
+ app.debug('Down relay activated successfully');
323
+ sendState(WindlassState.Down);
324
+ cb(completed);
325
+ }
326
+ else {
327
+ app.debug(`Down relay activation failed: ${reply.statusCode}`);
328
+ cb({ ...error, message: reply.message });
329
+ }
330
+ }
331
+ });
332
+ }, currentState === WindlassState.Up
333
+ ? props.switchingDelaySeconds * 1000
334
+ : 0);
335
+ }
336
+ else {
337
+ app.debug(`Up relay deactivation failed: ${reply.statusCode}`);
338
+ cb({ ...error, message: reply.message });
339
+ }
340
+ }
341
+ });
342
+ }
343
+ function setWindlassOff(cb) {
344
+ app.debug('Executing windlass OFF: turning off both relays');
345
+ app.putSelfPath(props.upRelayPath, false, (reply) => {
346
+ if (reply.state === 'COMPLETED') {
347
+ if (reply.statusCode !== 200) {
348
+ app.debug(`Up relay deactivation failed: ${reply.statusCode}`);
349
+ cb({ ...error, message: reply.message });
350
+ return;
351
+ }
352
+ app.debug('Up relay turned off, now turning off down relay');
353
+ app.putSelfPath(props.downRelayPath, false, (reply) => {
354
+ if (reply.state === 'COMPLETED') {
355
+ if (reply.statusCode === 200) {
356
+ app.debug('Both relays turned off successfully');
357
+ sendState(WindlassState.Off);
358
+ cb(completed);
359
+ }
360
+ else {
361
+ app.debug(`Down relay deactivation failed: ${reply.statusCode}`);
362
+ cb({ ...error, message: reply.message });
363
+ }
364
+ }
365
+ });
366
+ }
367
+ });
368
+ }
369
+ return plugin;
370
+ };
371
+ module.exports = start;
372
+ exports.default = start;
373
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;GAaG;;AAaH,IAAK,aAIJ;AAJD,WAAK,aAAa;IAChB,0BAAS,CAAA;IACT,4BAAW,CAAA;IACX,8BAAa,CAAA;AACf,CAAC,EAJI,aAAa,KAAb,aAAa,QAIjB;AAED,MAAM,KAAK,GAAiB;IAC1B,KAAK,EAAE,WAAW;IAClB,UAAU,EAAE,GAAG;CAChB,CAAA;AAED,MAAM,SAAS,GAAiB;IAC9B,KAAK,EAAE,WAAW;IAClB,UAAU,EAAE,GAAG;CAChB,CAAA;AAED,MAAM,OAAO,GAAiB;IAC5B,KAAK,EAAE,SAAS;CACjB,CAAA;AAED,MAAM,KAAK,GAAG,CAAC,GAA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,EAAE,CAAC,KAAU,EAAE,EAAE;YACjE,IAAI,KAAK,CAAC,KAAK,KAAK,WAAW,EAAE,CAAC;gBAChC,IAAI,KAAK,CAAC,UAAU,KAAK,GAAG,EAAE,CAAC;oBAC7B,GAAG,CAAC,KAAK,CAAC,iCAAiC,KAAK,CAAC,UAAU,EAAE,CAAC,CAAA;oBAC9D,EAAE,CAAC,EAAE,GAAG,KAAK,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC,CAAA;oBACxC,OAAM;gBACR,CAAC;gBACD,GAAG,CAAC,KAAK,CAAC,iDAAiD,CAAC,CAC3D;gBAAC,GAAW,CAAC,WAAW,CAAC,KAAK,CAAC,aAAa,EAAE,KAAK,EAAE,CAAC,KAAU,EAAE,EAAE;oBACnE,IAAI,KAAK,CAAC,KAAK,KAAK,WAAW,EAAE,CAAC;wBAChC,IAAI,KAAK,CAAC,UAAU,KAAK,GAAG,EAAE,CAAC;4BAC7B,GAAG,CAAC,KAAK,CAAC,qCAAqC,CAAC,CAAA;4BAChD,SAAS,CAAC,aAAa,CAAC,GAAG,CAAC,CAAA;4BAC5B,EAAE,CAAC,SAAS,CAAC,CAAA;wBACf,CAAC;6BAAM,CAAC;4BACN,GAAG,CAAC,KAAK,CAAC,mCAAmC,KAAK,CAAC,UAAU,EAAE,CAAC,CAAA;4BAChE,EAAE,CAAC,EAAE,GAAG,KAAK,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC,CAAA;wBAC1C,CAAC;oBACH,CAAC;gBACH,CAAC,CAAC,CAAA;YACJ,CAAC;QACH,CAAC,CAAC,CAAA;IACJ,CAAC;IAED,OAAO,MAAM,CAAA;AACf,CAAC,CAAA;AAED,MAAM,CAAC,OAAO,GAAG,KAAK,CAAA;AACtB,kBAAe,KAAK,CAAA"}
@@ -0,0 +1,65 @@
1
+ const { defineConfig, globalIgnores } = require('eslint/config')
2
+ const js = require('@eslint/js')
3
+ const globals = require('globals')
4
+ const tseslint = require('typescript-eslint')
5
+ const prettier = require('eslint-config-prettier/flat')
6
+
7
+ module.exports = defineConfig([
8
+ globalIgnores([
9
+ '**/public',
10
+ '**/dist',
11
+ '**/test',
12
+ '**/docs',
13
+ '**/web',
14
+ 'src/test.ts'
15
+ ]),
16
+
17
+ // TypeScript options
18
+ {
19
+ files: ['**/*.ts'],
20
+ extends: [common('@typescript-eslint/'), tseslint.configs.recommended],
21
+ languageOptions: {
22
+ parser: tseslint.parser,
23
+ globals: globals.node
24
+ },
25
+ rules: {
26
+ // '@typescript-eslint/no-empty-object-type': 'off'
27
+ '@typescript-eslint/no-explicit-any': 'off'
28
+ }
29
+ },
30
+
31
+ // JavasScript-only options
32
+ {
33
+ files: ['**/*.js'],
34
+ extends: [common(), js.configs.recommended],
35
+ languageOptions: {
36
+ globals: globals.node
37
+ }
38
+ },
39
+
40
+ // Disable rules that prettier handles
41
+ prettier
42
+ ])
43
+
44
+ // Common rules for all files
45
+ function common(prefix = '') {
46
+ return {
47
+ rules: {
48
+ [`${prefix}no-unused-vars`]: [
49
+ 'error',
50
+ {
51
+ argsIgnorePattern: '^_',
52
+ varsIgnorePattern: '^_',
53
+ caughtErrorsIgnorePattern: '^_'
54
+ }
55
+ ],
56
+ [`${prefix}no-unused-expressions`]: [
57
+ 'error',
58
+ {
59
+ allowShortCircuit: true,
60
+ allowTernary: true
61
+ }
62
+ ]
63
+ }
64
+ }
65
+ }
package/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "signalk-relay-windlass",
3
+ "version": "0.0.1",
4
+ "description": "Signal K Plugin to control a windlass using two relay switches",
5
+ "main": "dist/index.js",
6
+ "scripts": {
7
+ "test": "mocha --require ts-node/register",
8
+ "prettier": "prettier --write .",
9
+ "lint": "eslint --fix --format compact .",
10
+ "ci-lint": "eslint && prettier --check .",
11
+ "ci-test": "npm run build && npm run build:web && npm run test && npm run ci-lint",
12
+ "format": "npm run prettier && npm run lint",
13
+ "build": "tsc",
14
+ "watch": "npm run build -- -w"
15
+ },
16
+ "keywords": [
17
+ "signalk-node-server-plugin",
18
+ "signalk-category-hardware"
19
+ ],
20
+ "author": "scott@scottbender.net",
21
+ "license": "Apache-2.0",
22
+ "dependencies": {
23
+ "node-hid": "^3.3.0"
24
+ },
25
+ "repository": {
26
+ "type": "git",
27
+ "url": "https://github.com/sbender9/signalk-relay-windlass"
28
+ },
29
+ "devDependencies": {
30
+ "@signalk/server-api": "^2.7.2",
31
+ "@tsconfig/node20": "^20.1.6",
32
+ "@types/chai": "^5.2.2",
33
+ "@types/mocha": "^10.0.10",
34
+ "@types/node": "^24.0.4",
35
+ "chai": "^5.2.1",
36
+ "eslint": "^9.33.0",
37
+ "eslint-config-prettier": "^10.1.8",
38
+ "eslint-formatter-compact": "^8.40.0",
39
+ "file-loader": "^6.1.1",
40
+ "mocha": "^11.7.1",
41
+ "prettier": "^3.6.2",
42
+ "style-loader": "^2.0.0",
43
+ "ts-node": "^10.9.2",
44
+ "tsx": "^4.20.3",
45
+ "typescript": "^5.9.2",
46
+ "typescript-eslint": "^8.40.0"
47
+ }
48
+ }
Binary file