Giter Site home page Giter Site logo

node-red-counter's Introduction

node-red-contrib-counter

GitHub version NPM version Dependencies Status

A Node-RED node to create a counter with messages.


Table of Contents


Install

Run the following command in your Node-RED user directory - typically ~/.node-red:

npm install node-red-contrib-counter

Usage

By default the counter will be incremented for every inbound message and append the current count to msg.count.

Configuration

  • Initial Count: The initial count can be set in the configuration. By default it will be zero at start.
  • Default Step: Default amount that will be incremented or decremented on every incoming message.
  • Lower Limit: Optional limitation of the lower count limit. Will add countLowerLimitReached to msg if reached.
  • Upper Limit: Optional limitation of the upper count limit. Will add countUpperLimitReached to msg if reached.
  • Mode: Determine if count value should be incremented or decremented on every incoming message.
  • Outputs: Selects the output format of the counter. For more info read below.

Output

There are two output options for the counter value:

  • single: The actual count will be appended to msg.count of the original msg.
  • split: The node will become two outputs, first will return the count as msg.payload and possible limitation info, the second returns the untouched original msg.

Control

It's possible to control the counter with incoming msg properties:

  • msg.increment: counter will be incremented by the given value.
  • msg.decrement: counter will be decremented by the given value.
  • msg.reset: resets the counter to it's initial count, or to the given value, when it's a number.

Example Flows

Simple example showing how to use the counter and it's output.

example1.png

[{"id":"25b6280d.1ecf6","type":"inject","z":"327d23e5.bb5924","name":"decrement","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":380,"y":160,"wires":[["8a41c1.6006b64"]]},{"id":"285e0e19.b9680a","type":"inject","z":"327d23e5.bb5924","name":"increment","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":380,"y":120,"wires":[["ce8d952f.18666"]]},{"id":"fda0a334.bc9588","type":"inject","z":"327d23e5.bb5924","name":"reset","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":370,"y":200,"wires":[["17cce981.975686"]]},{"id":"ce8d952f.18666","type":"function","z":"327d23e5.bb5924","name":"msg object","func":"msg.increment = 2;\nreturn msg;","outputs":1,"noerr":0,"x":550,"y":120,"wires":[["ac65bf94.6e609"]]},{"id":"17cce981.975686","type":"function","z":"327d23e5.bb5924","name":"msg object","func":"msg.reset = true;\nreturn msg;","outputs":1,"noerr":0,"x":550,"y":200,"wires":[["ac65bf94.6e609"]]},{"id":"8a41c1.6006b64","type":"function","z":"327d23e5.bb5924","name":"msg object","func":"msg.decrement = 1;\nreturn msg;","outputs":1,"noerr":0,"x":550,"y":160,"wires":[["ac65bf94.6e609"]]},{"id":"ac65bf94.6e609","type":"counter","z":"327d23e5.bb5924","name":"","init":"0","step":1,"lower":null,"upper":null,"mode":"increment","outputs":"1","x":740,"y":140,"wires":[["988afc3c.a08f98"]]},{"id":"370626a8.22216a","type":"inject","z":"327d23e5.bb5924","name":"normal msg without control parameter","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":470,"y":80,"wires":[["ac65bf94.6e609"]]},{"id":"988afc3c.a08f98","type":"debug","z":"327d23e5.bb5924","name":"message","active":true,"console":"false","complete":"true","x":900,"y":140,"wires":[]}]

example2.png

[{"id":"4f41c5a1.85426c","type":"inject","z":"327d23e5.bb5924","name":"decrement","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":380,"y":380,"wires":[["e9085587.2d19c"]]},{"id":"afb267a8.63739","type":"inject","z":"327d23e5.bb5924","name":"increment","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":380,"y":340,"wires":[["4a35e3c7.3dbd0c"]]},{"id":"f066adf1.21ba","type":"inject","z":"327d23e5.bb5924","name":"reset","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":370,"y":420,"wires":[["523f8e05.d5537"]]},{"id":"4a35e3c7.3dbd0c","type":"function","z":"327d23e5.bb5924","name":"msg object","func":"msg.increment = 3;\nreturn msg;","outputs":1,"noerr":0,"x":550,"y":340,"wires":[["f33ad4bd.777a5"]]},{"id":"523f8e05.d5537","type":"function","z":"327d23e5.bb5924","name":"msg object","func":"msg.reset = 10;\nreturn msg;","outputs":1,"noerr":0,"x":550,"y":420,"wires":[["f33ad4bd.777a5"]]},{"id":"e9085587.2d19c","type":"function","z":"327d23e5.bb5924","name":"msg object","func":"msg.decrement = 1;\nreturn msg;","outputs":1,"noerr":0,"x":550,"y":380,"wires":[["f33ad4bd.777a5"]]},{"id":"9b40b088.73732","type":"debug","z":"327d23e5.bb5924","name":"count","active":true,"console":"false","complete":"payload","x":890,"y":340,"wires":[]},{"id":"f33ad4bd.777a5","type":"counter","z":"327d23e5.bb5924","name":"","init":"100","step":"1","lower":null,"upper":null,"mode":"increment","outputs":"2","x":740,"y":360,"wires":[["9b40b088.73732"],["876cc69d.d4b438"]]},{"id":"99b73d63.9fdb","type":"inject","z":"327d23e5.bb5924","name":"normal msg without control parameter","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":470,"y":300,"wires":[["f33ad4bd.777a5"]]},{"id":"876cc69d.d4b438","type":"debug","z":"327d23e5.bb5924","name":"message","active":false,"console":"false","complete":"true","x":900,"y":380,"wires":[]}]

Bugs / Feature request

Please report bugs and feel free to ask for new features directly on GitHub.

License

This project is licensed under Apache 2.0 license.

Donation

You like to support me?
You appreciate my work?
You use it in commercial projects?

Feel free to make a little donation! ๐Ÿ˜‰

node-red-counter's People

Contributors

dkern avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.