npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

msp-webhook

v1.0.5

Published

A plugin to send data to a website/webhook. Stores data locally if connection fails, then uploads later.

Downloads

55

Readme

MSP Webhook

A plugin to send data from SignalK to a webhook. If the server looses connection to the webhook the plugin will store the entry in a local file as JSON data; once the connection is restored it will send the stored data to the hook for processing (at the next scheduled attempt) and if successfully sent delete the record.

Sends the following SignalK data streams:

  • position: "navigation.position",
  • speed: "navigation.speedOverGround",
  • heading: "navigation.headingTrue",
  • log: "navigation.trip.log",
  • depth: "environment.depth.belowTransducer",
  • wTemp: "environment.water.temperature",
  • windSpeed: "environment.wind.speedApparent",
  • windDir: "environment.wind.angleApparent",
  • pressure: "environment.pressure"

User selectable time frame for sending data, sends on the hour following the specified period e.g. if set at 10 minutes will be on the hour, ten-past and so on.

Authentication token sent as a URL parameter to allow a basic security check on the website

For an example of processing the data online, in PHP you can use the following code:

    // Check if the request method is POST
    if ($_SERVER['REQUEST_METHOD'] === 'POST') {
        // Retrieve the JSON payload from the request body
        $jsonPayload = file_get_contents('php://input');

        // Decode the JSON payload into an associative array
        $data = json_decode($jsonPayload, true);

        // Check if the 'Authorization' header is set and contains the correct authentication key
        $authKey = 'Your Authentication key here';
        if (!isset($_GET['auth_key']) || $_GET['auth_key'] !== $authKey) {
            http_response_code(401); // Unauthorized
            echo json_encode(array('error' => $_GET['auth_key']));
            exit;
        }

        // Ensure navigation.position exists and contains latitude and longitude
        if (isset($data['position']['value']['latitude']) && isset($data['position']['value']['longitude'])) {

            $latitude = filter_var($data['position']['value']['latitude'], FILTER_SANITIZE_SPECIAL_CHARS);
            $longitude = filter_var($data['position']['value']['longitude'], FILTER_SANITIZE_SPECIAL_CHARS);
            $speed = isset($data['speed']['value']) ? filter_var($data['speed']['value'], FILTER_SANITIZE_SPECIAL_CHARS) : null;

            // Check if heading is in radians and convert to degrees
            if (isset($data['heading']['value'])) {
                $headingRadians = filter_var($data['heading']['value'], FILTER_SANITIZE_SPECIAL_CHARS);
                $headingDegrees = $headingRadians * (180 / M_PI);  // Convert radians to degrees
            } else {
                $headingDegrees = null;
            }

            $depth = isset($data['depth']['value']) ? filter_var($data['depth']['value'], FILTER_SANITIZE_SPECIAL_CHARS) : null;
            $windSpeed = isset($data['windSpeed']['value']) ? filter_var($data['windSpeed']['value'], FILTER_SANITIZE_SPECIAL_CHARS) : null;

            // Check if windDirection is in radians and convert to degrees
            if (isset($data['windDir']['value'])) {
                $windDirRadians = filter_var($data['windDir']['value'], FILTER_SANITIZE_SPECIAL_CHARS);
                $windDirDegrees = $windDirRadians * (180 / M_PI);  // Convert radians to degrees
            } else {
                $windDirDegrees = null;
            }

            $pressure = isset($data['pressure']) ? filter_var($data['pressure'], FILTER_SANITIZE_SPECIAL_CHARS) : null;
            $dateTime = isset($data['datetime']) ? filter_var($data['datetime'], FILTER_SANITIZE_SPECIAL_CHARS) : date('Y-m-d H:i:s');

            $responseData = [
                'timeStamp'     => $dateTime,
                'latitude'      => $latitude,
                'longitude'     => $longitude,
                'heading'       => $headingDegrees,
                'depth'         => $depth,
                'speed'         => $speed,
                'windSpeed'     => $windSpeed,
                'windDirection' => $windDirDegrees,
                'temp'          => '',
                'barometer'     => $pressure,
            ];

            // Add your processing here, you can use the array above to send onto a database query or something similar.
        }            

        http_response_code(200); // OK
        echo json_encode(array('message' => 'Data processed successfully', 'message' => 'Webhook received and processed'));
        exit();

    } else {

        // Respond with an error for unsupported request methods
        http_response_code(405); // Method Not Allowed
        echo json_encode(array('message' => 'Method Not Allowed'));
        exit();

    }