Improved example plugins

This commit is contained in:
Mark Qvist 2024-05-06 15:00:19 +02:00
parent 3967a85ab0
commit 2da2fc26e7
6 changed files with 47 additions and 16 deletions

View File

@ -1,3 +1,7 @@
# This is a bare-minimum command plugin
# example that you can build upon to
# implement your own command plugins.
import RNS
class BasicCommandPlugin(SidebandCommandPlugin):

View File

@ -1,3 +1,7 @@
# This plugin example fetches an XKCD comic
# from an external URL and returns it as an
# embedded image in an LXMF message.
import io
import RNS
import requests

View File

@ -1,10 +1,14 @@
import RNS
import time
import threading
# This plugin allows using GPSd as a location
# telemetry provider on Linux systems.
# This plugin requires the "gpsdclient" pip
# package to be installed on your system.
# Install it with: pip install gpsdclient
import RNS
import time
import threading
from gpsdclient import GPSDClient
class GpsdLocationPlugin(SidebandTelemetryPlugin):
@ -50,19 +54,28 @@ class GpsdLocationPlugin(SidebandTelemetryPlugin):
RNS.log("Connected, streaming GPSd data", RNS.LOG_DEBUG)
self.client_connected = True
self.last_update = time.time()
self.latitude = result.get("lat", None)
self.longitude = result.get("lon", None)
self.altitude = result.get("altHAE", None)
self.speed = result.get("speed", None)
self.bearing = result.get("track", None)
epx = result.get("epx", None); epy = result.get("epy", None)
epv = result.get("epv", None)
if epx != None and epy != None and epv != None:
self.accuracy = max(epx, epy, epv)
else:
self.accuracy = None
gpsd_latitude = result.get("lat", None)
gpsd_longitude = result.get("lon", None)
gpsd_altitude = result.get("altHAE", None)
gpsd_speed = result.get("speed", None)
gpsd_bearing = result.get("track", None)
gpsd_required = [gpsd_latitude, gpsd_longitude, gpsd_altitude, gpsd_speed, gpsd_bearing]
if not None in gpsd_required:
self.last_update = time.time()
self.latitude = gpsd_latitude
self.longitude = gpsd_longitude
self.altitude = gpsd_altitude
self.speed = gpsd_speed
self.bearing = gpsd_bearing
epx = result.get("epx", None); epy = result.get("epy", None)
epv = result.get("epv", None)
if epx != None and epy != None and epv != None:
self.accuracy = max(epx, epy, epv)
else:
self.accuracy = None
except Exception as e:
RNS.log("Could not connect to local GPSd, retrying later", RNS.LOG_ERROR)

View File

@ -1,3 +1,7 @@
# This is a bare-minimum service plugin
# example that you can build upon to
# implement your own service plugins.
import RNS
import time
import threading

View File

@ -1,3 +1,7 @@
# This is a bare-minimum telemetry plugin
# example that you can build upon to
# implement your own telemetry plugins.
import RNS
class BasicTelemetryPlugin(SidebandTelemetryPlugin):

View File

@ -1,5 +1,7 @@
# This plugin lets you remotely query and view a
# number of different image sources in Sideband.
# number of different image sources in Sideband,
# including remote or local webcams, video sources
# or images stored in a filesystem.
#
# This plugin requires the "pillow" pip package.
#