1.13.1 • Published 1 year ago

@sensebox/sketch-templater v1.13.1

Weekly downloads
52
License
MIT
Repository
github
Last release
1 year ago

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. 1. Run npm version [major | minor | patch] -m "[v%s] Your commit message" 1. Type in the new version (to create a beta release include the word beta in the new version) 1. git push --tags origin main 1. 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 textReplacement
@@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 nameDescription
as-isDo nothing.
toDefineTransform an array of sensors to multiple #define statements.
toProgmemTransform an array of sensors to multiple const char xxSENSOR_ID[] PROGMEM = "<id>"; statements.
digitalPortToPortNumberTransform 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

1.13.1

1 year ago

1.13.1-beta.0

1 year ago

1.13.1-beta.1

1 year ago

1.13.0

1 year ago

1.12.1

2 years ago

1.12.0

2 years ago

1.11.0

2 years ago

1.11.2

2 years ago

1.11.1

2 years ago

1.10.5

3 years ago

1.10.4

3 years ago

1.10.3

3 years ago

1.10.2

3 years ago

1.10.1

3 years ago

1.10.0

3 years ago

1.9.0

3 years ago

1.8.3-beta.4

4 years ago

1.8.3

4 years ago

1.8.3-beta.2

4 years ago

1.8.3-beta.1

4 years ago

1.8.3-beta.3

4 years ago

1.8.3-beta.0

4 years ago

1.8.2

4 years ago

1.8.1

4 years ago

1.8.0

4 years ago

1.7.0

4 years ago

1.7.0-beta2

4 years ago

1.7.0-beta

4 years ago

1.6.1

4 years ago

1.6.0

4 years ago

1.5.5

4 years ago

1.5.4

4 years ago

1.5.2

4 years ago

1.5.1

4 years ago

1.5.0

4 years ago

1.4.0

5 years ago

1.4.0-beta.4

5 years ago

1.4.0-beta.3

5 years ago

1.4.0-beta.2

5 years ago

1.4.0-beta.1

5 years ago

1.4.0-beta

5 years ago

1.3.0

6 years ago

1.2.0

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.10

6 years ago

1.0.9

7 years ago

1.0.8

7 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago