Have ideas to improve npm?Join in the discussion! »

    weatherlink

    1.2.1 • Public • Published

    https://nodei.co/npm/weatherlink.png?downloads=true&downloadRank=true&stars=true

    Weatherlink

    Unofficial js wrapper library for WeatherLink v2 API

    Install

    npm install weatherlink

    or

    yarn add weatherlink

    Usage

    const Weatherlink = require('weatherlink');
    
    const apiKey = '<replace with your api key>';
    const apiSecret = '<replace with your api secret>';
    
    const weatherLink = WeatherLink({apiKey, apiSecret});

    Methods

    Metadata about the weather stations and sensors, as well as the different types of sensors

    GET/stations Get all weather stations associated with your API Key

    weatherLink.getAllStations().then(console.log).catch(console.error);

    GET /stations​/{station-ids} Get weather stations for one or more station IDs provided

    weatherLink
      .getStations({stationIds: ['102882']})
      .then(console.log)
      .catch(console.error);

    GET /sensors Get all sensors attached to all weather stations associated with your API Key

    weatherLink.getAllSensors().then(console.log).catch(console.error);

    GET /sensors​/{sensor-ids} Get sensors for one or more sensor IDs provided

    weatherLink
      .getSensors({sensorIds: ['371124', '371125']})
      .then(console.log)
      .catch(console.error);

    GET /sensor-catalog Get a catalog of all types of sensors

    weatherLink.getSensorCatalog().then(console.log).catch(console.error);

    This call is not in the official weatherlink documentation

    This returns all sensors attached to all weather stations associated with your API Key with their very own specs from sensor catalog. It's just a mix of /sensors + /sensor-catalog

    weatherLink
      .getAllSensorsWithSpecs()
      .then((data) => console.log(JSON.stringify(data, null, 2)))
      .catch(console.error);

    Weather Data

    Weather sensor observation data

    GET /current​/{station-id} Get current conditions data for one station

    weatherLink
      .getCurrent({stationId: '102882'})
      .then(console.log)
      .catch(console.error);

    GET /historic​/{station-id} Get historic data for one station ID within a given timerange

    Using date-fns

    const subDays = require('date-fns/subDays');
    const getUnixTime = require('date-fns/getUnixTime');
    
    const now = new Date();
    const yesterday = subDays(now, 1);
    const startTimestamp = getUnixTime(yesterday);
    const endTimestamp = getUnixTime(now);
    
    weatherLink
      .getHistoric({stationId: '102882', startTimestamp, endTimestamp})
      .then((r) => console.log(JSON.stringify(r, null, 2)))
      .catch(console.log);

    Examples

    Here

    Install

    npm i weatherlink

    DownloadsWeekly Downloads

    0

    Version

    1.2.1

    License

    MIT License

    Unpacked Size

    11.3 kB

    Total Files

    7

    Last publish

    Collaborators

    • avatar