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

@sensebox/sketch-templater

v1.13.1

Published

nodejs library to create senseBox Arduino Sketches

Downloads

81

Readme

senseBox sketch-templater NPM Version

Arduino sketch templates used by the openSenseMap-API. The sketch-templater creates a Arduino Sketch (.ino) for the Arduino IDE based on the selected options and sensors during the registration process on openSenseMap.

Versioning

The version of templates should always match the corresponding Version of the Board Support Package

Changelog

See CHANGELOG.md

Releasing a new version

To create a new version, use npm version.

  1. Document your changes in CHANGELOG.md. Make sure there are no uncommited changes in the worktree.
  2. Run npm version [major | minor | patch] -m "[v%s] Your commit message"
  3. Type in the new version (to create a beta release include the word beta in the new version)
  4. git push --tags origin main
  5. npm publish

Usage

Install via npm install --save @sensebox/sketch-templater or yarn add @sensebox/sketch-templater


const Sketcher = require('@sensebox/sketch-templater');

const mySketcher = new Sketcher('<your api post domain>');

// generate Sketch
const mySketch = mySketcher.generateSketch(box);
const mySketchBase64 = mySketcher.generateSketch(box, { encoding: 'base64' });

Configuration

In order to fill in the correct ingress domain, you have to specify a valid hostname. Do not specify a protocol (http or https)!

You can do this either in code when calling the new Sketcher('your domain here') or through external configuration.

If your project is using lorenwest/node-config, you can specify the ingress domain in your config file of your project like this:

  {
    ... your other config

    "sketch-templater": {
      "ingress_domain": "ingress.example.com"
    }
  }

Adding new Templates

To add new templates, just create a new .tpl file in the templates directory. A template consists of two parts. The first line contains a JSON object for configuration. The second line until the end is used as the template text.

Example configuration in first line

Specify a single model:

{ "model": "homeEthernet" }

Specify multiple models:

{ "models": ["homeWifi", "homeWifiFeinstaub"] }

Templating values

The templater uses special transformers to process the templates. The transformers are applied through searching for @@SUB_TEMPLATE_KEY@@ occurrences in the template files. Each replacement starts and ends with a double @. To specify a transformer, append a pipe (|) and the transformer name. When no transformer is specified, it just returns the input variable. For adding new template transformers, see Adding Transformers.

As of writing this, the following replacements can be made:

| Template text | Replacement | |------------------|-------------| | @@SENSEBOX_ID@@ | the senseBox ID | | @@SENSEBOX_NAME@@ | the senseBox Name | | @@SENSOR_IDS@@ | sensor IDs | | @@NUM_SENSORS@@ | the number of sensors | | @@INGRESS_DOMAIN@@ | the domain of your ingress server | | @@SERIAL_PORT@@ | Serial port for connected SDS011 (only Feinstaub models) | | @@SSID@@ | your WiFi SSID (only homeV2Wifi models) | | @@PASSWORD@@ | your WiFi Password (only homeV2Wifi models) | | @@ACCESS_TOKEN@@ | the access_token of wifi / ethernet boxes |

Additionally, the following transformers are implemented:

| Transformer name | Description | |------------------|-------------| | as-is | Do nothing. | | toDefine | Transform an array of sensors to multiple #define statements. | | toProgmem | Transform an array of sensors to multiple const char xxSENSOR_ID[] PROGMEM = "<id>"; statements. | | digitalPortToPortNumber | Transform a digital port (A, B or C) to a port number. You can add a offset parameter. |

Adding Transformers

In order to add a new transformer, just add a function in src/transformers.js to the module.exports. The function should return a string.

Adding Replacements

Add your additional replacements in src/index.js in the method _cloneBox to the second parameter of the Object.assign call.

License

MIT 2022 Matthias Pfeil, Jan Wirwahn, Gerald Pape