# Count data, store it and send it by trigger

**URL:** <https://discourse.nodered.org/t/count-data-store-it-and-send-it-by-trigger/12424>\
**Category:** General\
**Created:** [20 June 2019 10:35 UTC](https://discourse.nodered.org/t/count-data-store-it-and-send-it-by-trigger/12424 "2019-06-20T10:35:38Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Carloj](https://avatars.discourse-cdn.com/v4/letter/c/91b2a8/32.png) [@Carloj](https://discourse.nodered.org/u/Carloj)\
**Post date:** [20 June 2019 10:35 UTC](https://discourse.nodered.org/t/count-data-store-it-and-send-it-by-trigger/12424/1 "2019-06-20T10:35:38Z")

</div>

I want to count the amount of messages, store them and then send the total every 10 seconds to the mqtt broker.  
Like the first signal on the broker is 0, then 50, then 100......

I got the following flow but it just send every 10 seconds a message of 1

```auto
[{"id":"64dc420.1dbabc","type":"debug","z":"45ce3f2c.e344e","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":910,"y":400,"wires":[]},{"id":"f2036a6d.357388","type":"trigger","z":"45ce3f2c.e344e","op1":"","op2":"","op1type":"pay","op2type":"pay","duration":"10","extend":false,"units":"s","reset":"","bytopic":"all","name":"","x":910,"y":340,"wires":[["a17e488c.2f29b8"]]},{"id":"a17e488c.2f29b8","type":"mqtt out","z":"45ce3f2c.e344e","name":"","topic":"pers77_slag","qos":"2","retain":"","broker":"d2d18b60.565bd8","x":1130,"y":340,"wires":[]},{"id":"95ce3366.3c73c","type":"function","z":"45ce3f2c.e344e","name":"count","func":"var count=context.get('count') || 1;\ncount +=1;\nmsg.payload = \"\"+msg.payload+\" \"+ count;\ncontext.set('count', count);\nreturn msg;","outputs":1,"noerr":0,"x":720,"y":340,"wires":[["f2036a6d.357388","64dc420.1dbabc"]]},{"id":"b290d349.2180d8","type":"counter","z":"45ce3f2c.e344e","name":"","init":"0","step":"1","lower":"","upper":"","mode":"increment","outputs":"2","x":460,"y":440,"wires":[["a370d054.b2849","712a82fb.8654dc","95ce3366.3c73c"],["638f49f0.d941e8"]]},{"id":"41121122.d792c","type":"switch","z":"45ce3f2c.e344e","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"str"},{"t":"eq","v":"0","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":290,"y":440,"wires":[["b290d349.2180d8"],[]]},{"id":"71ae4ba2.299c44","type":"rpi-gpio in","z":"45ce3f2c.e344e","name":"","pin":"35","intype":"down","debounce":"30","read":false,"x":120,"y":440,"wires":[["41121122.d792c"]]},{"id":"d2d18b60.565bd8","type":"mqtt-broker","z":"","name":"Mqtt_Broker","broker":"192.168.16.76","port":"1883","tls":"","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]

```

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [20 June 2019 10:38 UTC](https://discourse.nodered.org/t/count-data-store-it-and-send-it-by-trigger/12424/2 "2019-06-20T10:38:36Z")

</div>

You appear to be using a contrib node in your flow. What counter node are you using?

---

<div class="post-metadata">

**Author:** ![Carloj](https://avatars.discourse-cdn.com/v4/letter/c/91b2a8/32.png) [@Carloj](https://discourse.nodered.org/u/Carloj)\
**Post date:** [20 June 2019 10:39 UTC](https://discourse.nodered.org/t/count-data-store-it-and-send-it-by-trigger/12424/3 "2019-06-20T10:39:14Z")

</div>

```auto
node-red-contrib-counter

```

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [20 June 2019 10:55 UTC](https://discourse.nodered.org/t/count-data-store-it-and-send-it-by-trigger/12424/4 "2019-06-20T10:55:11Z")

</div>

Add more debug nodes along your flow to understand what messages are being passed along your flow.

---

<div class="post-metadata">

**Author:** ![Carloj](https://avatars.discourse-cdn.com/v4/letter/c/91b2a8/32.png) [@Carloj](https://discourse.nodered.org/u/Carloj)\
**Post date:** [20 June 2019 11:59 UTC](https://discourse.nodered.org/t/count-data-store-it-and-send-it-by-trigger/12424/5 "2019-06-20T11:59:00Z")

</div>

Yes, i found the problem. The payload was the message and the count so "1 300", "0 600"
