@noforeignland/signalk-to-noforeignland 1.0.1-beta.8 → 1.1.0-beta.3

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/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ 1.1.0
2
+ * CHANGE: Refactored Project structure, see PROJECT_STRUCTURE.md
3
+ * CHANGE: Use phrase GNSS instead of GPS - Thanks Piotr
4
+
1
5
  1.0.1
2
6
  * CHANGE: Cleanup previous installs and migrate plugin config, removes depricated old plugins.
3
7
 
@@ -24,17 +28,17 @@ The "new" one has to be installed once manually, after that everything is back t
24
28
  0.1.29-beta.1
25
29
  * CHANGE: After talking to Treppo from Sugnal K core team we should use the data path "noforeignland.*", code and docs changed.
26
30
  * CHANGE: README.md info added and format optimized
27
- * CHANGE: GPS source at the end for setPluginStatus - Cerbo has a long source name and truncates it.
31
+ * CHANGE: GNSS source at the end for setPluginStatus - Cerbo has a long source name and truncates it.
28
32
  * CHANGE: Use "npm install instead" of "npm ci" to push from Github to npmjs using OIDC authentication
29
33
  * CHANGE: Moved navigation.position source from path noforeignland.status to noforeignland.source
30
34
 
31
35
  0.1.28
32
- * BUGFIX: No GPS data found - introduced in 0.1.27 - Thanks Piotr
36
+ * BUGFIX: No GNSS data found - introduced in 0.1.27 - Thanks Piotr
33
37
 
34
38
  0.1.28-beta.2
35
39
  * EXPERIMENTAL: Signal K data path to visualize the plugin behaviour or error in Node Red, KIP, etc. Using plugin.signalk-to-noforeignland.* for now. See README.md for details.
36
40
  * CHANGE: Using app.getDataDirPath() to store transient data, thanks Jeremy, they are now in "plugin-config-data/signalk-to-noforeignland/nfl-track" and renamed to pending.json1 and sent.json1
37
- * CHANGE: Optimize GPS detection if multiple navigation.position from different sources exist.
41
+ * CHANGE: Optimize GNSS detection if multiple navigation.position from different sources exist.
38
42
  * CHANGE: PluginStatus optimized for limited space available.
39
43
  * CHANGE: doc/beta_install.md changed for new file structure.
40
44
 
@@ -46,13 +50,13 @@ The "new" one has to be installed once manually, after that everything is back t
46
50
 
47
51
  0.1.27-beta.1
48
52
  * NEW: NPMJS requires new method for publishing. The old tokens will expire Nov 19th, 2025, so moving to OIDC authentication.
49
- * NEW: Check the GPS status in navigation.position, else retry and throw PluginError on Dashboard
53
+ * NEW: Check the GNSS status in navigation.position, else retry and throw PluginError on Dashboard
50
54
  * CHANGE: Keep track data on disk rewritten and migrate old files to new structure, so nfl-track-sent.jsonl becomes a continuous archive of all sent track data over time, when enabled. New Logic:
51
55
  * New points accumulate in nfl-track-pending.jsonl
52
56
  * Send succeeds → API confirms receipt
53
57
  * If keepFiles=true: The content of pending file is appended to nfl-track-sent.jsonl (line 588)
54
58
  * Pending file is deleted
55
- * Next GPS points → create a new pending file
59
+ * Next GNSS points → create a new pending file
56
60
  * Next successful send → appends again to the same nfl-track-sent.jsonl
57
61
 
58
62
  0.1.26
@@ -0,0 +1,357 @@
1
+ # Project Structure
2
+
3
+ This document describes the architecture and organization of the SignalK to Noforeignland plugin.
4
+
5
+ ## Overview
6
+
7
+ This plugin follows a modular architecture where each responsibility is encapsulated in a dedicated module. The main orchestrator ([index.js](index.js)) coordinates all modules through a class-based approach.
8
+
9
+ ## Directory Layout
10
+
11
+ ```
12
+ nfl-signalk/
13
+ index.js # Main plugin entry point & orchestrator
14
+ cleanup-old-plugin.js # Postinstall script for removing old versions
15
+ package.json # NPM package configuration
16
+ lib/ # Core modules directory
17
+ ConfigManager.js # Configuration handling & migration
18
+ TrackLogger.js # Position subscription & logging
19
+ TrackSender.js # API communication & track sending
20
+ HealthMonitor.js # Position data health checks
21
+ PluginCleanup.js # Runtime cleanup of old plugins
22
+ TrackMigration.js # Track file migration utilities
23
+ DataPathEmitter.js # SignalK delta emission
24
+ DirectoryUtils.js # File system utilities
25
+ README.md # User documentation
26
+ CHANGELOG.md # Version history
27
+ PROJECT_STRUCTURE.md # This file
28
+ ```
29
+
30
+ ## Module Responsibilities
31
+
32
+ ### Core Orchestrator
33
+
34
+ #### [index.js](index.js)
35
+ **Purpose**: Main plugin class that orchestrates all modules and implements SignalK plugin lifecycle.
36
+
37
+ **Key Responsibilities**:
38
+ - Exports SignalK plugin object with `start()` and `stop()` methods
39
+ - Initializes all module instances in correct order
40
+ - Manages plugin state (options, upSince, cron, lastSuccessfulTransfer)
41
+ - Coordinates between modules during startup sequence
42
+ - Handles plugin status and error reporting to SignalK UI
43
+ - Implements CRON-based interval for data sending
44
+
45
+ **Key Methods**:
46
+ - `start(options, restartPlugin)`: 13-step startup sequence
47
+ - `stop()`: Cleanup and shutdown
48
+ - `interval()`: CRON job handler for sending tracks
49
+ - `handleSavePoint(lastPosition)`: Callback when track point is saved
50
+ - `handleHealthy()`: Callback when health check passes
51
+ - `setPluginStatus(status)`: Update UI status
52
+ - `setPluginError(error)`: Report error to UI
53
+
54
+ ### Configuration & Migration
55
+
56
+ #### [lib/ConfigManager.js](lib/ConfigManager.js)
57
+ **Purpose**: Handles plugin configuration, schema definition, and config migration.
58
+
59
+ **Key Responsibilities**:
60
+ - Defines plugin schema (mandatory/advanced/expert settings groups)
61
+ - Migrates old flat config structure to new nested structure
62
+ - Flattens nested config back to internal format with defaults
63
+ - Validates boat API key
64
+ - Resolves track directory paths (absolute vs relative)
65
+ - Randomizes CRON schedule to avoid server load spikes
66
+
67
+ **Config Structure**:
68
+ ```javascript
69
+ {
70
+ mandatory: { boatApiKey: string },
71
+ advanced: { minMove, minSpeed, sendWhileMoving, ping_api_every_24h },
72
+ expert: { filterSource, trackDir, keepFiles, trackFrequency, apiCron,
73
+ internetTestTimeout, apiTimeout }
74
+ }
75
+ ```
76
+
77
+ ### Position Tracking
78
+
79
+ #### [lib/TrackLogger.js](lib/TrackLogger.js)
80
+ **Purpose**: Subscribes to position updates and logs them to disk.
81
+
82
+ **Key Responsibilities**:
83
+ - Subscribes to `navigation.position` and optionally `navigation.speedOverGround`
84
+ - Implements GNSS source auto-selection (stick to one source unless stale)
85
+ - Supports manual source filtering via `filterSource` config
86
+ - Validates positions (rejects coordinates near 0,0)
87
+ - Applies movement filters (minSpeed, minMove, trackFrequency)
88
+ - Implements 24-hour keepalive ping
89
+ - Saves track points to JSONL file (`pending.jsonl`)
90
+ - Calculates distances using equirectangular approximation
91
+
92
+ **GNSS Source Logic**:
93
+ - If `filterSource` is set: only accept that specific source
94
+ - If not set: auto-select first source, switch only if stale (>5 min)
95
+ - Prevents position jumps when multiple GNSS devices are present
96
+
97
+ **Track Point Format**:
98
+ ```json
99
+ {"lat": 37.8136, "lon": -122.4784, "t": "2025-01-15T10:30:00.000Z"}
100
+ ```
101
+
102
+ #### [lib/TrackSender.js](lib/TrackSender.js)
103
+ **Purpose**: Sends accumulated track data to the Noforeignland API.
104
+
105
+ **Key Responsibilities**:
106
+ - Reads track points from `pending.jsonl`
107
+ - Tests internet connectivity via DNS lookups (8.8.8.8, 1.1.1.1)
108
+ - Checks if boat is moving (based on last position timestamp)
109
+ - Sends track data to NFL API with retry logic (3 attempts)
110
+ - Handles successful sends (archive to `sent.jsonl` or delete)
111
+ - Validates position coordinates before sending
112
+
113
+ **API Request Format**:
114
+ ```javascript
115
+ POST https://www.noforeignland.com/home/api/v1/boat/tracking/track
116
+ Headers: { 'X-NFL-API-Key': pluginApiKey }
117
+ Body: {
118
+ timestamp: ms,
119
+ track: [[ms, lat, lon], [ms, lat, lon], ...],
120
+ boatApiKey: userBoatApiKey
121
+ }
122
+ ```
123
+
124
+ **Retry Logic**:
125
+ - Attempt 1: base timeout (default 30s)
126
+ - Attempt 2: 2x timeout + 2s delay
127
+ - Attempt 3: 3x timeout + 4s delay
128
+
129
+ ### Health & Monitoring
130
+
131
+ #### [lib/HealthMonitor.js](lib/HealthMonitor.js)
132
+ **Purpose**: Monitors GNSS position data freshness and reports issues.
133
+
134
+ **Key Responsibilities**:
135
+ - Initial check: 2 minutes after startup
136
+ - Periodic checks: every 5 minutes
137
+ - Detects stale position data (>5 minutes old)
138
+ - Detects missing position data
139
+ - Provides context-aware error messages (filtered vs auto-selected source)
140
+ - Calls error/healthy callbacks to update plugin status
141
+
142
+ **Health States**:
143
+ - Healthy: Position received within last 5 minutes
144
+ - Warning: No position for >5 minutes
145
+ - Error: No position ever received (or 2+ min after startup)
146
+
147
+ ### Cleanup & Migration
148
+
149
+ #### [lib/PluginCleanup.js](lib/PluginCleanup.js)
150
+ **Purpose**: Runtime cleanup of old plugin versions.
151
+
152
+ **Key Responsibilities**:
153
+ - Detects Victron Cerbo vs standard SignalK paths
154
+ - Migrates config from old `signalk-to-noforeignland` to new scoped name
155
+ - Removes old plugin directories (`signalk-to-noforeignland`, `signalk-to-nfl`)
156
+ - Multiple retry attempts (immediate, 5s, 15s, 30s delays)
157
+ - Falls back to manual instructions if removal fails
158
+ - Returns promise resolving to 'all_removed' or 'partial_removal'
159
+
160
+ **Old Plugins Removed**:
161
+ - `signalk-to-noforeignland` (unscoped predecessor)
162
+ - `signalk-to-nfl` (deprecated alias)
163
+
164
+ #### [cleanup-old-plugin.js](cleanup-old-plugin.js)
165
+ **Purpose**: Postinstall script for immediate cleanup during npm install.
166
+
167
+ **Key Responsibilities**:
168
+ - Runs via `npm postinstall` hook
169
+ - Uses direct `fs.rmSync()` instead of npm uninstall (safer during install)
170
+ - 2-second delay to allow npm to complete current operation
171
+ - Detects Victron Cerbo vs standard SignalK paths
172
+ - Migrates config files
173
+ - Provides fallback manual instructions
174
+
175
+ **Why Two Cleanup Mechanisms?**
176
+ 1. **Postinstall**: Runs during installation, removes old plugins immediately
177
+ 2. **Runtime**: Handles cases where postinstall failed (permissions, timing)
178
+
179
+ #### [lib/TrackMigration.js](lib/TrackMigration.js)
180
+ **Purpose**: Migrates track files from old naming/location schemes.
181
+
182
+ **Key Responsibilities**:
183
+ - Migrates old file names to new naming scheme:
184
+ - `nfl-track.jsonl` -> `pending.jsonl`
185
+ - `nfl-track-pending.jsonl` -> `pending.jsonl`
186
+ - `nfl-track-sent.jsonl` -> `sent.jsonl`
187
+ - Migrates track files from old plugin directory to new data directory
188
+ - Removes old track directory if empty
189
+ - Non-destructive: only migrates if target doesn't exist
190
+
191
+ ### SignalK Integration
192
+
193
+ #### [lib/DataPathEmitter.js](lib/DataPathEmitter.js)
194
+ **Purpose**: Creates and updates SignalK data paths for external integrations.
195
+
196
+ **Key Responsibilities**:
197
+ - Emits SignalK deltas to create data paths
198
+ - Updates status paths on state changes
199
+ - Manages error state independently
200
+ - Provides both ISO8601 and locale-formatted timestamps
201
+
202
+ **Data Paths Created**:
203
+ ```
204
+ noforeignland.savepoint # ISO8601 timestamp of last save
205
+ noforeignland.savepoint_local # Locale string of last save
206
+ noforeignland.sent_to_api # ISO8601 timestamp of last API transfer
207
+ noforeignland.sent_to_api_local # Locale string of last API transfer
208
+ noforeignland.status # Status string (save/transfer/source info)
209
+ noforeignland.status_boolean # 0 = OK, 1 = error
210
+ noforeignland.source # Active GNSS source name
211
+ ```
212
+
213
+ **Usage**: These paths can be consumed by Node-RED, KIP dashboards, or other SignalK consumers.
214
+
215
+ #### [lib/DirectoryUtils.js](lib/DirectoryUtils.js)
216
+ **Purpose**: File system utilities with proper error handling.
217
+
218
+ **Key Responsibilities**:
219
+ - Creates directories recursively
220
+ - Checks read/write permissions
221
+ - Provides context-specific error messages
222
+ - Handles common error codes (EACCES, EPERM, ETIMEDOUT)
223
+
224
+ ## Data Flow
225
+
226
+ ### Startup Sequence
227
+ ```
228
+ 1. ConfigManager: Migrate old config -> flatten -> validate
229
+ 2. DirectoryUtils: Create track directory
230
+ 3. PluginCleanup: Remove old plugins (async, non-blocking)
231
+ 4. TrackMigration: Migrate old track files
232
+ 5. Initialize: TrackLogger, TrackSender, HealthMonitor
233
+ 6. ConfigManager: Randomize CRON schedule
234
+ 7. TrackLogger: Start position subscription
235
+ 8. CRON: Start interval job
236
+ 9. HealthMonitor: Start health checks
237
+ ```
238
+
239
+ ### Position Logging Flow
240
+ ```
241
+ navigation.position delta
242
+ -> TrackLogger.doOnValue()
243
+ -> handleSourceSelection() [filter/auto-select]
244
+ -> isValidPosition() [validate lat/lon]
245
+ -> shouldLogPosition() [check distance/frequency]
246
+ -> savePoint() [append to pending.jsonl]
247
+ -> callback to index.handleSavePoint()
248
+ -> DataPathEmitter.emitSavepoint()
249
+ -> setPluginStatus()
250
+ ```
251
+
252
+ ### Track Sending Flow (CRON Interval)
253
+ ```
254
+ CRON trigger
255
+ -> index.interval()
256
+ -> TrackSender.isBoatMoving() [check last position age]
257
+ -> TrackSender.hasTrackData() [check pending.jsonl exists]
258
+ -> TrackSender.testInternet() [DNS lookup test]
259
+ -> TrackSender.sendTrack()
260
+ -> createTrackFromFile() [read pending.jsonl]
261
+ -> sendWithRetry() [POST to API, 3 attempts]
262
+ -> handleSuccessfulSend() [archive or delete]
263
+ -> DataPathEmitter.emitApiTransfer()
264
+ -> setPluginStatus()
265
+ ```
266
+
267
+ ### Health Monitoring Flow
268
+ ```
269
+ HealthMonitor timer (every 5 min)
270
+ -> performHealthCheck()
271
+ -> check lastPositionReceived timestamp
272
+ -> if stale/missing: call onError callback
273
+ -> index.setPluginError()
274
+ -> DataPathEmitter.setError()
275
+ -> app.setPluginError()
276
+ -> if healthy: call onHealthy callback
277
+ -> index.handleHealthy()
278
+ -> setPluginStatus() [clear error if needed]
279
+ ```
280
+
281
+ ## File Locations
282
+
283
+ ### Victron Cerbo GX
284
+ - SignalK directory: `/data/conf/signalk`
285
+ - Plugin installed at: `/data/conf/signalk/node_modules/@noforeignland/signalk-to-noforeignland`
286
+ - Config: `/data/conf/signalk/plugin-config-data/@noforeignland-signalk-to-noforeignland.json`
287
+ - Track files: `/data/conf/signalk/plugin-config-data/@noforeignland-signalk-to-noforeignland/nfl-track/`
288
+
289
+ ### Standard SignalK
290
+ - SignalK directory: `~/.signalk`
291
+ - Plugin installed at: `~/.signalk/node_modules/@noforeignland/signalk-to-noforeignland`
292
+ - Config: `~/.signalk/plugin-config-data/@noforeignland-signalk-to-noforeignland.json`
293
+ - Track files: `~/.signalk/plugin-config-data/@noforeignland-signalk-to-noforeignland/nfl-track/`
294
+
295
+ ## Development Notes
296
+
297
+ ### Adding New Features
298
+ 1. Create module in `lib/` if it's a distinct responsibility
299
+ 2. Instantiate in [index.js](index.js) constructor
300
+ 3. Initialize in `start()` method at appropriate step
301
+ 4. Clean up in `stop()` method
302
+ 5. Update this document
303
+
304
+ ### Configuration Changes
305
+ 1. Update schema in [ConfigManager.js](lib/ConfigManager.js) `getSchema()`
306
+ 2. Add migration logic in `migrateOldConfig()` if breaking change
307
+ 3. Update `flattenConfig()` to include new fields with defaults
308
+ 4. Test both old and new config formats
309
+
310
+ ### Track File Format Changes
311
+ 1. Update `TrackLogger.savePoint()` for writing
312
+ 2. Update `TrackSender.createTrackFromFile()` for reading
313
+ 3. Add migration logic in [TrackMigration.js](lib/TrackMigration.js) if needed
314
+
315
+ ### Testing Checklist
316
+ - [ ] Test on Victron Cerbo GX (path detection, limited storage)
317
+ - [ ] Test on standard SignalK installation
318
+ - [ ] Test config migration from old versions
319
+ - [ ] Test with multiple GNSS sources (auto-selection)
320
+ - [ ] Test with filtered source
321
+ - [ ] Test with no internet connection
322
+ - [ ] Test with slow internet (timeout scenarios)
323
+ - [ ] Test cleanup of old plugins
324
+ - [ ] Test track file migration
325
+
326
+ ## Dependencies
327
+
328
+ ```json
329
+ {
330
+ "cron": "^2.1.0", // CRON job scheduling
331
+ "fs-extra": "^10.1.0", // Enhanced file system operations
332
+ "node-fetch": "^2.6.7" // HTTP requests to API
333
+ }
334
+ ```
335
+
336
+ ## Version History Notes
337
+
338
+ - **1.1.0**: Refactored to modular structure
339
+ - **1.0.x**: Scoped package name, cleanup mechanism
340
+ - **0.1.x**: Original flat structure (deprecated)
341
+
342
+ ## Known Technical Debt
343
+
344
+ 1. **Empty process.exit()**: [cleanup-old-plugin.js](cleanup-old-plugin.js) setTimeout may not complete
345
+ 2. **Error timing**: [PluginCleanup.js](lib/PluginCleanup.js) shows error before retries complete
346
+ 3. **No test suite**: Manual testing only, no automated tests
347
+
348
+ ## SignalK Plugin Conventions
349
+
350
+ This plugin follows SignalK plugin conventions:
351
+ - Exports function returning `{id, name, schema, start, stop}`
352
+ - Uses `app.debug()` for logging
353
+ - Uses `app.setPluginStatus()` and `app.setPluginError()` for UI feedback
354
+ - Subscribes via `app.subscriptionmanager.subscribe()`
355
+ - Emits deltas via `app.handleMessage(pluginId, delta)`
356
+ - Config stored in `plugin-config-data/` directory
357
+ - Data stored in plugin's data directory
package/README.md CHANGED
@@ -2,8 +2,7 @@
2
2
  Effortlessly log your boat's movement to **noforeignland.com**
3
3
 
4
4
  ## Important for 0.1.x users
5
- Since 1.0.0 this package now released unter npmjs org noforeignland in version 1.0.0 due to deployment changes in npmjs and the need of trustworthy sources. All npmjs keys will be revoked Nov 19th, 2025.
6
- Users of the old (depricated) 0.1.x versions need to install this new package once manually using the Signal K Appstore. The Plugin Configuration will be kept from the 0.1.x install.
5
+ Upgrade to >1.1.0 by installing this plugin from the Appstore again. Your old config will be migrated and old plugins will be automatically removed.
7
6
 
8
7
  ## Features
9
8
  * Automatically log your position to noforeignland.com
@@ -20,7 +19,7 @@ Users of the old (depricated) 0.1.x versions need to install this new package on
20
19
 
21
20
  ## Requirements
22
21
  * An internet connection is required in order to update noforeignland.com
23
- * A navigation.position data path inside Signal K for self, which is your current GPS position
22
+ * A navigation.position data path inside Signal K for self, which is your current GNSS position
24
23
  * A **noforeignland.com** account
25
24
  * Your Boat API Key from the **noforeignland.com** website:
26
25
  * Account > Settings > Boat tracking > API Key
@@ -43,4 +42,15 @@ noforeignland.status - string - Status & Error
43
42
  noforeignland.status_boolean - number - 0 = normal operation, 1 = error
44
43
  noforeignland.source - string - string - data source of navigation.position
45
44
  notifications.noforeignland.status_boolean - json object - auto created
46
- ```
45
+ ```
46
+
47
+ https://github.com/noforeignland/nfl-signalk/issues
48
+
49
+ # Virctron Cerbo GX Users
50
+
51
+ ## Limited storage
52
+ Signal K can quickly exhaust the small onboard storage of the device, especially when a lot of logging is enabled and not properly configured. Even concider to not enable "Keep track files on disk" if you are moving a lot.
53
+
54
+ Vicron Energy addressed this here:
55
+ https://www.victronenergy.com/live/venus-os:large#disk_space_issues_data_partition_full
56
+
@@ -55,11 +55,14 @@ cd /data/conf/signalk
55
55
 
56
56
  npm i @noforeignland/signalk-to-noforeignland@beta
57
57
 
58
+ # reset owner properly, else package belongs to root
59
+ chown -R signalk:signalk /data/conf/signalk/*
60
+
58
61
  ```
59
62
 
60
63
  2. Restart Server & Check logs
61
64
  ```
62
- Restart Server vom Webgui and check logs in Webgui
65
+ svc -t /service/signalk-server
63
66
  ```
64
67
 
65
68
 
@@ -70,10 +73,14 @@ cd /data/conf/signalk
70
73
 
71
74
  # Here use the beta version you want to install
72
75
  npm i @noforeignland/signalk-to-noforeignland@1.0.1-beta.5
76
+
77
+ # reset owner properly, else package belongs to root
78
+ chown -R signalk:signalk /data/conf/signalk/*
79
+
73
80
  ```
74
81
  2. Restart Server & Check logs
75
82
  ```
76
- Restart Server vom Webgui and check logs in Webgui
83
+ svc -t /service/signalk-server
77
84
  ```
78
85
 
79
86
 
@@ -98,9 +105,12 @@ npm pack
98
105
  cd /data/conf/signalk
99
106
  npm install ~/dev/nfl-signalk-main/<your_npm_pack.tgz>
100
107
 
108
+ # reset owner properly, else package belongs to root
109
+ chown -R signalk:signalk /data/conf/signalk/*
110
+
101
111
  ```
102
112
 
103
113
  3. Restart Server & Check logs
104
114
  ```
105
- Restart Server vom Webgui and check logs in Webgui
115
+ svc -t /service/signalk-server
106
116
  ```
package/doc/dev CHANGED
@@ -1,17 +0,0 @@
1
-
2
- INTERNAL NOTES ONLY, IGNORE.
3
-
4
-
5
- cd ~/dirk/nfl-signalk
6
-
7
- # Aktuelle Version zu Beta machen
8
- npm version 1.0.1-beta.1 --no-git-tag-version
9
-
10
- # Package bauen
11
- npm pack
12
-
13
- # Mit beta tag publishen (nicht als 'latest')
14
- npm publish --tag beta
15
-
16
- # Falls du noch nicht eingeloggt bist:
17
- npm login