@meri-imperiumi/signalk-meshtastic 1.0.0
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/.eslintrc.json +6 -0
- package/.github/workflows/publish.yml +30 -0
- package/.github/workflows/test.yml +21 -0
- package/README.md +92 -0
- package/doc/config-crew-role.png +0 -0
- package/doc/meshtastic-bequia.png +0 -0
- package/doc/telemetry.png +0 -0
- package/package.json +35 -0
- package/plugin/commands/index.js +37 -0
- package/plugin/commands/ping.js +6 -0
- package/plugin/commands/switching.js +33 -0
- package/plugin/commands/waypoint.js +56 -0
- package/plugin/index.js +1037 -0
- package/plugin/telemetry.js +69 -0
- package/plugin/waypoint.js +29 -0
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
function median(arr) {
|
|
2
|
+
if (!arr.length) {
|
|
3
|
+
return undefined;
|
|
4
|
+
}
|
|
5
|
+
const s = [...arr].sort((a, b) => a - b);
|
|
6
|
+
const mid = Math.floor(s.length / 2);
|
|
7
|
+
return s.length % 2 ? s[mid] : ((s[mid - 1] + s[mid]) / 2);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
class Telemetry {
|
|
11
|
+
constructor() {
|
|
12
|
+
this.data = {};
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
toMeshtastic() {
|
|
16
|
+
const values = {};
|
|
17
|
+
if (this.data['environment.outside.temperature']) {
|
|
18
|
+
values.temperature = this.data['environment.outside.temperature'] - 273.15;
|
|
19
|
+
}
|
|
20
|
+
if (this.data['environment.outside.relativeHumidity']) {
|
|
21
|
+
values.relativeHumidity = this.data['environment.outside.relativeHumidity'] * 100;
|
|
22
|
+
}
|
|
23
|
+
if (this.data['environment.outside.pressure']) {
|
|
24
|
+
values.barometricPressure = this.data['environment.outside.pressure'] / 100;
|
|
25
|
+
}
|
|
26
|
+
if (this.data['environment.wind.directionTrue']) {
|
|
27
|
+
values.windDirection = Math.floor(this.data['environment.wind.directionTrue'] * (180 / Math.PI));
|
|
28
|
+
}
|
|
29
|
+
if (this.data['environment.wind.speedOverGround'] && this.data['environment.wind.speedOverGround'].length) {
|
|
30
|
+
values.windSpeed = median(this.data['environment.wind.speedOverGround']);
|
|
31
|
+
values.windGust = this.data['environment.wind.speedOverGround'].reduce((prev, current) => (current > prev ? current : prev), 0);
|
|
32
|
+
values.windLull = this.data['environment.wind.speedOverGround'].reduce((prev, current) => {
|
|
33
|
+
if (!prev) {
|
|
34
|
+
return current;
|
|
35
|
+
}
|
|
36
|
+
return current < prev ? current : prev;
|
|
37
|
+
}, 0);
|
|
38
|
+
// Clear wind history
|
|
39
|
+
this.data['environment.wind.speedOverGround'] = [];
|
|
40
|
+
}
|
|
41
|
+
if (this.data['electrical.batteries.house.voltage']) {
|
|
42
|
+
values.voltage = this.data['electrical.batteries.house.voltage'];
|
|
43
|
+
}
|
|
44
|
+
if (this.data['electrical.batteries.house.current']) {
|
|
45
|
+
values.current = this.data['electrical.batteries.house.current'] * 1000;
|
|
46
|
+
}
|
|
47
|
+
if (this.data['navigation.anchor.distanceFromBow']) {
|
|
48
|
+
// Using distance is a bit silly here as the unit is mm, but what can we do
|
|
49
|
+
values.distance = this.data['navigation.anchor.distanceFromBow'] * 1000;
|
|
50
|
+
} else if (this.data['environment.depth.belowSurface']) {
|
|
51
|
+
// If not anchored, report depth as distance. Still mm.
|
|
52
|
+
values.distance = this.data['environment.depth.belowSurface'] * 1000;
|
|
53
|
+
}
|
|
54
|
+
return values;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
updateWindSpeed(windSpeed) {
|
|
58
|
+
if (!this.data['environment.wind.speedOverGround']) {
|
|
59
|
+
this.data['environment.wind.speedOverGround'] = [];
|
|
60
|
+
}
|
|
61
|
+
this.data['environment.wind.speedOverGround'].push(windSpeed);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
update(path, value) {
|
|
65
|
+
this.data[path] = value;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
module.exports = Telemetry;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
exports.vesselIcon = (vessel) => {
|
|
2
|
+
let icon = 128741; // Motorboat
|
|
3
|
+
if (String(vessel.mmsi).substr(0, 3) === '972'
|
|
4
|
+
|| String(vessel.mmsi).substr(0, 3) === '974'
|
|
5
|
+
|| String(vessel.mmsi).substr(0, 3) === '970') {
|
|
6
|
+
icon = 128735; // MOB, EPIRB, or SART
|
|
7
|
+
return icon;
|
|
8
|
+
}
|
|
9
|
+
if (vessel.sensors
|
|
10
|
+
&& vessel.sensors.ais
|
|
11
|
+
&& vessel.sensors.ais.class
|
|
12
|
+
&& vessel.sensors.ais.class.value === 'A') {
|
|
13
|
+
icon = 128674; // Ship
|
|
14
|
+
}
|
|
15
|
+
if (vessel.design
|
|
16
|
+
&& vessel.design.aisShipType
|
|
17
|
+
&& vessel.design.aisShipType.value) {
|
|
18
|
+
switch (vessel.design.aisShipType.value.id) {
|
|
19
|
+
case 36: {
|
|
20
|
+
icon = 9973; // Sailboat
|
|
21
|
+
break;
|
|
22
|
+
}
|
|
23
|
+
default: {
|
|
24
|
+
break;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return icon;
|
|
29
|
+
};
|