Skip to content
Snippets Groups Projects
Commit 29ceaa5c authored by echicken's avatar echicken :chicken:
Browse files

wx

parent 579ad72c
Branches
No related tags found
No related merge requests found
...@@ -16031,7 +16031,7 @@ ...@@ -16031,7 +16031,7 @@
}, { }, {
key: "sendText", key: "sendText",
value: function sendText(_ref3) { value: function sendText(_ref3) {
var text = _ref3.text, _ref3$to = _ref3.to, to = _ref3$to === void 0 ? _BROADCAST : _ref3$to, _ref3$channel = _ref3.channel, channel = _ref3$channel === void 0 ? 0 : _ref3$channel, _ref3$wantAck = _ref3.wantAck, wantAck = _ref3$wantAck === void 0 ? true : _ref3$wantAck, ackHandler = _ref3.ackHandler; var text = _ref3.text, _ref3$to = _ref3.to, to = _ref3$to === void 0 ? _BROADCAST : _ref3$to, _ref3$channel = _ref3.channel, channel = _ref3$channel === void 0 ? 0 : _ref3$channel, _ref3$wantAck = _ref3.wantAck, wantAck = _ref3$wantAck === void 0 ? true : _ref3$wantAck, ackHandler = _ref3.ackHandler, replyId = _ref3.replyId, hopLimit = _ref3.hopLimit;
var enc = new TextEncoder(); var enc = new TextEncoder();
var payload = enc.encode(text); var payload = enc.encode(text);
if (payload.length > _MAX_PAYLOAD) if (payload.length > _MAX_PAYLOAD)
...@@ -16042,7 +16042,9 @@ ...@@ -16042,7 +16042,9 @@
to: to, to: to,
channel: channel, channel: channel,
wantAck: wantAck, wantAck: wantAck,
ackHandler: ackHandler ackHandler: ackHandler,
replyId: replyId,
hopLimit: hopLimit
}); });
} }
/** /**
...@@ -16630,9 +16632,10 @@ ...@@ -16630,9 +16632,10 @@
}; };
} }
var Module = /* @__PURE__ */ function() { var Module = /* @__PURE__ */ function() {
function Module2(config) { function Module2(config, devices) {
_classCallCheck(this, Module2); _classCallCheck(this, Module2);
this.config = config; this.config = config;
this.devices = devices;
} }
return _createClass(Module2, [{ return _createClass(Module2, [{
key: "log", key: "log",
...@@ -16647,9 +16650,9 @@ ...@@ -16647,9 +16650,9 @@
}]); }]);
}(); }();
var Echo = /* @__PURE__ */ function(_Module) { var Echo = /* @__PURE__ */ function(_Module) {
function Echo2(config) { function Echo2(config, devices) {
_classCallCheck(this, Echo2); _classCallCheck(this, Echo2);
return _callSuper(this, Echo2, [config]); return _callSuper(this, Echo2, [config, devices]);
} }
_inherits(Echo2, _Module); _inherits(Echo2, _Module);
return _createClass(Echo2, [{ return _createClass(Echo2, [{
...@@ -16665,16 +16668,17 @@ ...@@ -16665,16 +16668,17 @@
device.sendText({ device.sendText({
text: echo, text: echo,
to: replyTo, to: replyTo,
channel: packet.channel channel: packet.channel,
replyId: packet.id
}); });
return true; return true;
} }
}]); }]);
}(Module); }(Module);
var Weather = /* @__PURE__ */ function(_Module2) { var Weather = /* @__PURE__ */ function(_Module2) {
function Weather2(config) { function Weather2(config, devices) {
_classCallCheck(this, Weather2); _classCallCheck(this, Weather2);
return _callSuper(this, Weather2, [config]); return _callSuper(this, Weather2, [config, devices]);
} }
_inherits(Weather2, _Module2); _inherits(Weather2, _Module2);
return _createClass(Weather2, [{ return _createClass(Weather2, [{
...@@ -16684,7 +16688,7 @@ ...@@ -16684,7 +16688,7 @@
return false; return false;
var dec = new TextDecoder(); var dec = new TextDecoder();
var msg = dec.decode(packet.payloadVariant.value.payload); var msg = dec.decode(packet.payloadVariant.value.payload);
if (!msg.startsWith(".weather")) if (!msg.startsWith(".wx"))
return false; return false;
try { try {
var weather = openWeatherMap.call_api_v3({ var weather = openWeatherMap.call_api_v3({
...@@ -16700,12 +16704,15 @@ ...@@ -16700,12 +16704,15 @@
ws += "\r\n".concat(weather.current.temp, "\xB0C, feels like ").concat(weather.current.feels_like, "\xB0C"); ws += "\r\n".concat(weather.current.temp, "\xB0C, feels like ").concat(weather.current.feels_like, "\xB0C");
ws += "\r\nUVI: ".concat(weather.current.uvi); ws += "\r\nUVI: ".concat(weather.current.uvi);
ws += "\r\nHumidity: ".concat(weather.current.humidity, "%"); ws += "\r\nHumidity: ".concat(weather.current.humidity, "%");
ws += "\r\nWind: ".concat(weather.current.wind_speed, " KPH ").concat(wd, ", Gust: ").concat(weather.current.wind_gust, " KPH"); ws += "\r\nWind: ".concat(weather.current.wind_speed, " km/h ").concat(wd);
if (weather.current.wind_gust !== void 0)
ws += ", Gust: ".concat(weather.current.wind_gust, " km/h");
ws += "\r\n".concat(weather.current.clouds, "% cloudy"); ws += "\r\n".concat(weather.current.clouds, "% cloudy");
device.sendText({ device.sendText({
text: ws, text: ws,
to: replyTo, to: replyTo,
channel: packet.channel channel: packet.channel,
replyId: packet.id
}); });
return true; return true;
} catch (err) { } catch (err) {
...@@ -16717,34 +16724,21 @@ ...@@ -16717,34 +16724,21 @@
}(Module); }(Module);
function init() { function init() {
var config = getConfig(); var config = getConfig();
var devices = {};
var modules = []; var modules = [];
for (var module in config.modules) {
switch (config.modules[module].path) {
case "echo":
modules.push(new Echo(config.modules[module]));
break;
case "weather":
modules.push(new Weather(config.modules[module]));
break;
default:
var m = js.global.load({}, config.modules[module].path);
modules.push(new m(config.modules[module]));
break;
}
}
var _loop3 = function _loop32() { var _loop3 = function _loop32() {
var dev = void 0; var dev = void 0;
if (config.devices[device].type === "serial") { if (config.devices[device].type === "serial") {
var cfg = config.devices[device]; var cfg = config.devices[device];
dev = new SerialDevice(cfg.port, cfg.baud, void 0, void 0, cfg.debug, cfg.id); dev = new SerialDevice(cfg.port, cfg.baud, void 0, void 0, cfg.debug, cfg.id);
dev.on("ready", function() { dev.on("ready", function() {
return js.global.log(sbbsdefs.LOG_DEBUG, "".concat(cfg.type, " device ").concat(cfg.port, " is ready")); return js.global.log(sbbsdefs.LOG_INFO, "".concat(cfg.type, " device ").concat(cfg.port, " is ready"));
}); });
} else if (config.devices[device].type === "socket") { } else if (config.devices[device].type === "socket") {
var _cfg = config.devices[device]; var _cfg = config.devices[device];
dev = new SocketDevice(_cfg.host, _cfg.port, _cfg.debug, _cfg.id); dev = new SocketDevice(_cfg.host, _cfg.port, _cfg.debug, _cfg.id);
dev.on("ready", function() { dev.on("ready", function() {
return js.global.log(sbbsdefs.LOG_DEBUG, "".concat(_cfg.type, " device ").concat(_cfg.host, ":").concat(_cfg.port, " is ready")); return js.global.log(sbbsdefs.LOG_INFO, "".concat(_cfg.type, " device ").concat(_cfg.host, ":").concat(_cfg.port, " is ready"));
}); });
} }
if (dev === void 0) if (dev === void 0)
...@@ -16775,11 +16769,31 @@ ...@@ -16775,11 +16769,31 @@
} }
}); });
dev.connect(); dev.connect();
devices[config.devices[device].id] = dev;
}; };
for (var device in config.devices) { for (var device in config.devices) {
if (_loop3()) if (_loop3())
continue; continue;
} }
for (var module in config.modules) {
var devs = [];
for (var devId in config.modules[module].devices) {
if (devices[devId] !== void 0)
devs.push(devices[devId]);
}
switch (config.modules[module].path) {
case "echo":
modules.push(new Echo(config.modules[module], devs));
break;
case "weather":
modules.push(new Weather(config.modules[module], devs));
break;
default:
var m = js.global.load({}, config.modules[module].path);
modules.push(new m(config.modules[module]));
break;
}
}
} }
init(); init();
js.do_callbacks = true; js.do_callbacks = true;
......
...@@ -2243,7 +2243,7 @@ ...@@ -2243,7 +2243,7 @@
}, },
"node_modules/@swag/ts4s": { "node_modules/@swag/ts4s": {
"version": "1.0.0", "version": "1.0.0",
"resolved": "git+https://gitlab.synchro.net/swag/ts4s.git#855160cd0b428a0327232c19c8e99b9895cfd0e8", "resolved": "git+https://gitlab.synchro.net/swag/ts4s.git#c6be266b47b4d14bd26f2a36949f9e3f22f61f34",
"dev": true, "dev": true,
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
...@@ -5245,7 +5245,7 @@ ...@@ -5245,7 +5245,7 @@
} }
}, },
"@swag/ts4s": { "@swag/ts4s": {
"version": "git+https://gitlab.synchro.net/swag/ts4s.git#855160cd0b428a0327232c19c8e99b9895cfd0e8", "version": "git+https://gitlab.synchro.net/swag/ts4s.git#c6be266b47b4d14bd26f2a36949f9e3f22f61f34",
"dev": true, "dev": true,
"from": "@swag/ts4s@git+https://gitlab.synchro.net/swag/ts4s.git", "from": "@swag/ts4s@git+https://gitlab.synchro.net/swag/ts4s.git",
"requires": { "requires": {
......
import { protobuf, Device } from '@sota/meshtastic'; import { protobuf, Device } from '@sota/meshtastic';
import { sbbsdefs, openWeatherMap } from '@swag/ts4s'; import { openWeatherMap } from '@swag/ts4s';
import Module from '../lib/module'; import Module from '../lib/module';
import { IModuleConfig } from '../lib/config'; import { IModuleConfig } from '../lib/config';
...@@ -14,7 +14,7 @@ export default class Weather extends Module { ...@@ -14,7 +14,7 @@ export default class Weather extends Module {
// @ts-expect-error It's ambient // @ts-expect-error It's ambient
const dec = new TextDecoder(); const dec = new TextDecoder();
const msg = dec.decode(packet.payloadVariant.value.payload); const msg = dec.decode(packet.payloadVariant.value.payload);
if (!msg.startsWith('.weather')) return false; if (!msg.startsWith('.wx')) return false;
try { try {
// To do: lat/lon should be based on requester's known pos if in node DB, or on the BBS position (from device config?) // To do: lat/lon should be based on requester's known pos if in node DB, or on the BBS position (from device config?)
const weather = openWeatherMap.call_api_v3({ lat: 43.7554870, lon: -79.4384880, exclude: ['minutely', 'hourly', 'daily', 'alerts'], units: 'metric' }); const weather = openWeatherMap.call_api_v3({ lat: 43.7554870, lon: -79.4384880, exclude: ['minutely', 'hourly', 'daily', 'alerts'], units: 'metric' });
...@@ -24,7 +24,8 @@ export default class Weather extends Module { ...@@ -24,7 +24,8 @@ export default class Weather extends Module {
ws += `\r\n${weather.current.temp}°C, feels like ${weather.current.feels_like}°C`; ws += `\r\n${weather.current.temp}°C, feels like ${weather.current.feels_like}°C`;
ws += `\r\nUVI: ${weather.current.uvi}`; ws += `\r\nUVI: ${weather.current.uvi}`;
ws += `\r\nHumidity: ${weather.current.humidity}%`; ws += `\r\nHumidity: ${weather.current.humidity}%`;
ws += `\r\nWind: ${weather.current.wind_speed} KPH ${wd}, Gust: ${weather.current.wind_gust} KPH`; ws += `\r\nWind: ${weather.current.wind_speed} km/h ${wd}`;
if (weather.current.wind_gust !== undefined) ws += `, Gust: ${weather.current.wind_gust} km/h`;
ws += `\r\n${weather.current.clouds}% cloudy`; ws += `\r\n${weather.current.clouds}% cloudy`;
device.sendText({ text: ws, to: replyTo, channel: packet.channel, replyId: packet.id }); device.sendText({ text: ws, to: replyTo, channel: packet.channel, replyId: packet.id });
return true; return true;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment