# How to make a cron with node inject

**URL:** https://discourse.nodered.org/t/how-to-make-a-cron-with-node-inject/66487
**Category:** General
**Tags:** function-node
**Created:** [16 August 2022 11:28 UTC](https://discourse.nodered.org/t/how-to-make-a-cron-with-node-inject/66487 "2022-08-16T11:28:10Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![mykerinos1](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mykerinos1/32/46877_2.png) [@mykerinos1](https://discourse.nodered.org/u/mykerinos1)
#### Post date: [16 August 2022 11:28 UTC](https://discourse.nodered.org/t/how-to-make-a-cron-with-node-inject/66487/1 "2022-08-16T11:28:10Z")

</div>

Hllo i'm using inject node to send data every 10 minutes for my chart but i'd prefered to add a cron to send data at specific minutes like 00,10,20,30,40,50 but i don't know hoxw to set it.  
Can you help me.  
Thanks

---

<div class="post-metadata">

### Author: ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)
#### Post date: [16 August 2022 11:35 UTC](https://discourse.nodered.org/t/how-to-make-a-cron-with-node-inject/66487/2 "2022-08-16T11:35:51Z")

</div>

Use the [node-red-contrib-cron-plus](https://flows.nodered.org/node/node-red-contrib-cron-plus) node

Configure it to

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/3/234b43b7f998d71c5e8cea1cc88971a4fb45a5a9.png)

---

<div class="post-metadata">

### Author: ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)
#### Post date: [16 August 2022 11:44 UTC](https://discourse.nodered.org/t/how-to-make-a-cron-with-node-inject/66487/3 "2022-08-16T11:44:03Z")

</div>

From the inject help notes

> **Note** : The _"Interval between times"_ and _"at a specific time"_ options use the standard cron system. This means that 20 minutes will be at the next hour, 20 minutes past and 40 minutes past - not in 20 minutes time.

So if you select Interval Between Times and set times to between 00:00 and 00:00 and interval every 10min it should inject on hour and every 10 mins.

---

<div class="post-metadata">

### Author: ![mykerinos1](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mykerinos1/32/46877_2.png) [@mykerinos1](https://discourse.nodered.org/u/mykerinos1)
#### Post date: [16 August 2022 11:56 UTC](https://discourse.nodered.org/t/how-to-make-a-cron-with-node-inject/66487/4 "2022-08-16T11:56:53Z")

</div>

thanks a lot 😉 thanks also to UnborN . i was too slowly for test your help

---

<div class="post-metadata">

### Author: ![mykerinos1](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mykerinos1/32/46877_2.png) [@mykerinos1](https://discourse.nodered.org/u/mykerinos1)
#### Post date: [17 August 2022 17:47 UTC](https://discourse.nodered.org/t/how-to-make-a-cron-with-node-inject/66487/5 "2022-08-17T17:47:15Z")

</div>

i would try your soluce but it doesn t work. i don't know what to insert for payload outpout. if i just set like you payload doesn't arrived but cron is working

---

<div class="post-metadata">

### Author: ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)
#### Post date: [17 August 2022 19:30 UTC](https://discourse.nodered.org/t/how-to-make-a-cron-with-node-inject/66487/6 "2022-08-17T19:30:13Z")

</div>

> [@mykerinos1](#):
>
> i don't know what to insert for payload outpout

You can select any of the options to determine what Cron+ will output when it triggers.  
 ![choice](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/0/804f9b61a35b81224f4230a7da5edc6af96d740e.jpeg)

But in the first instance, try setting the payload to string

 ![output](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/8/184491eb57470236f90fd164cf6559f5fff5bc2f.jpeg)

It will then output a payload string of "Go"  
 ![go](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/4/0439218e246f3a262ba27d9432269c2b04f76747.jpeg)

OR

set the payload to 'Timestamp', which will output a timestamp (similar to the inject node)

---

<div class="post-metadata">

### Author: ![mykerinos1](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mykerinos1/32/46877_2.png) [@mykerinos1](https://discourse.nodered.org/u/mykerinos1)
#### Post date: [18 August 2022 05:27 UTC](https://discourse.nodered.org/t/how-to-make-a-cron-with-node-inject/66487/7 "2022-08-18T05:27:12Z")

</div>

Thanks for answering.  
i tried all ou told to me .  
with string i only have the payload (name) that i said.  
with time stamp i only have time stamp  
**without cron plus**  
 ![without cronplus](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/c/0cdfd8649f1a07fa11d8d72993417bd7a6d8989c.jpeg)  
**withcronplus**

 ![with cronplus](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/4/04957566b75046a7b4c47a8d5f316bdf3f5f5c20.jpeg)

---

<div class="post-metadata">

### Author: ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)
#### Post date: [18 August 2022 07:48 UTC](https://discourse.nodered.org/t/how-to-make-a-cron-with-node-inject/66487/8 "2022-08-18T07:48:19Z")

</div>

From what is see from your bottom screenshot ... the problem is that you have wired the Cron plus node **after** your http request node. Usually Cron plus is used at the beginning of a flow to trigger the execution of a flow (In your case to the **left** of the http request node )

Ofcourse you can trigger flows with the node-red Inject node .. the difference is that Cron plus has more advanced scheduling capabilities (if you need them)

---

<div class="post-metadata">

### Author: ![mykerinos1](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mykerinos1/32/46877_2.png) [@mykerinos1](https://discourse.nodered.org/u/mykerinos1)
#### Post date: [18 August 2022 07:54 UTC](https://discourse.nodered.org/t/how-to-make-a-cron-with-node-inject/66487/10 "2022-08-18T07:54:58Z")

</div>

yes but i can change inject node by cron plus but will i can set 1 second cron for one and 10 minute for other one ?

---

<div class="post-metadata">

### Author: ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)
#### Post date: [18 August 2022 08:05 UTC](https://discourse.nodered.org/t/how-to-make-a-cron-with-node-inject/66487/11 "2022-08-18T08:05:17Z")

</div>

No, Cron+ will send both the 1 second cron AND the 10 minute cron.  
There would be no need to use an inject node.

---

<div class="post-metadata">

### Author: ![mykerinos1](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mykerinos1/32/46877_2.png) [@mykerinos1](https://discourse.nodered.org/u/mykerinos1)
#### Post date: [18 August 2022 08:13 UTC](https://discourse.nodered.org/t/how-to-make-a-cron-with-node-inject/66487/12 "2022-08-18T08:13:20Z")

</div>

So can i set it ?

---

<div class="post-metadata">

### Author: ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)
#### Post date: [18 August 2022 08:23 UTC](https://discourse.nodered.org/t/how-to-make-a-cron-with-node-inject/66487/13 "2022-08-18T08:23:14Z")

</div>

Set what exactly?

The inject node and Cron node can both be configured to send a message at a regular interval.

The payload will be whatever you configure the node to send. If you want a different payload each time, you'll need to add a Function node with some logic to set the payload to whatever value you want.

---

<div class="post-metadata">

### Author: ![mykerinos1](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mykerinos1/32/46877_2.png) [@mykerinos1](https://discourse.nodered.org/u/mykerinos1)
#### Post date: [18 August 2022 08:38 UTC](https://discourse.nodered.org/t/how-to-make-a-cron-with-node-inject/66487/14 "2022-08-18T08:38:18Z")

</div>

set cron plus to inject to 1second complete msg.payload and also each 10 minutes to inject some msg.payload

---

<div class="post-metadata">

### Author: ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)
#### Post date: [18 August 2022 09:05 UTC](https://discourse.nodered.org/t/how-to-make-a-cron-with-node-inject/66487/15 "2022-08-18T09:05:57Z")

</div>

what you mean with complete msg.payload ? .. as mentioned the msg when Cron or Inject nodes execute can be configured by you to whatever you want (depending of what you want to send to the next node).

Here is an example with Cron plus .. that you can have two schedules from the same node ..  
schedule1 is configured every second  
schedule2 is configured every 10 minutes  
i have changed the payload for both, from the default, to something custom

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/8/d8f58cfa902a04cca4e4c3c3088a5738c0d86bda.png)

and can also changed Cron outputs to Fan out .. so each schedule will output separately

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/9/796b6fa9b1b64580a50bb8e511d67102bac6ff78.png)

**Demo Flow:**

```auto
[{"id":"7c73ecd0459ce0ac","type":"cronplus","z":"54efb553244c241f","name":"","outputField":"payload","timeZone":"","persistDynamic":false,"commandResponseMsgOutput":"fanOut","outputs":4,"options":[{"name":"schedule1","topic":"everySecond","payloadType":"json","payload":"{\"payload\":\"This is a payload every 1 second\",\"color\":\"blue\",\"age\":12}","expressionType":"cron","expression":"* * * * * * *","location":"","offset":"0","solarType":"all","solarEvents":"sunrise,sunset"},{"name":"schedule2","topic":"every10Min","payloadType":"json","payload":"{\"payload\":\"This is a payload every 10 minutes\",\"color\":\"red\",\"age\":33}","expressionType":"cron","expression":"0 0/10 * * * * *","location":"","offset":"0","solarType":"all","solarEvents":"sunrise,sunset"}],"x":420,"y":2520,"wires":[["157eecc61d0ec722"],["ab3fc018775141c5"],[],[]]},{"id":"157eecc61d0ec722","type":"debug","z":"54efb553244c241f","name":"schedule1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":670,"y":2460,"wires":[]},{"id":"ab3fc018775141c5","type":"debug","z":"54efb553244c241f","name":"schedule2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":670,"y":2500,"wires":[]}]

```

---

<div class="post-metadata">

### Author: ![mykerinos1](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mykerinos1/32/46877_2.png) [@mykerinos1](https://discourse.nodered.org/u/mykerinos1)
#### Post date: [18 August 2022 10:45 UTC](https://discourse.nodered.org/t/how-to-make-a-cron-with-node-inject/66487/16 "2022-08-18T10:45:13Z")

</div>

I m sorry but i have no success  
i set this in the json  
{"payload":"payload.data.conditions[0].temp"} look the debug.

 ![node](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/2/f208b0494975a5f2948c689f579138222dfd26b5.jpeg)

---

<div class="post-metadata">

### Author: ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)
#### Post date: [18 August 2022 11:25 UTC](https://discourse.nodered.org/t/how-to-make-a-cron-with-node-inject/66487/17 "2022-08-18T11:25:15Z")

</div>

Why do you have a wire connected to Cron plus ? what is the purpose of that ?  
Cron node should be **at the start** of your flow line (to trigger the next node based on its set schedules)

> [@mykerinos1](#):
>
> i'd prefered to add a cron to send data at specific minutes like 00,10,20,30,40,50

**Cron-plus** ➡ **Nodes to get data for chart** ➡ **Chart node**

---

<div class="post-metadata">

### Author: ![mykerinos1](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mykerinos1/32/46877_2.png) [@mykerinos1](https://discourse.nodered.org/u/mykerinos1)
#### Post date: [18 August 2022 13:22 UTC](https://discourse.nodered.org/t/how-to-make-a-cron-with-node-inject/66487/18 "2022-08-18T13:22:45Z")

</div>

if i do like that all data are going to debug. i set a payload in cron plus without succes.

 ![nodered](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/4/948a2048bf28514e951d462938b32f7a65248344.jpeg)

---

<div class="post-metadata">

### Author: ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)
#### Post date: [18 August 2022 13:51 UTC](https://discourse.nodered.org/t/how-to-make-a-cron-with-node-inject/66487/19 "2022-08-18T13:51:50Z")

</div>

You havent explained much of your flow but i can see from that image that you have it wired to an http-request. Is that **http-request** node a GET or a POST request ?

If its a GET then the `msg.payload` of the Cron node doesnt really matter .. it could be anything .. just a msg to trigger the actual request.

If its a POST then `msg.payload` does matter and it will be the body for the request. In that case you have to configure it to be whatever the request body needs to be.

---

<div class="post-metadata">

### Author: ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)
#### Post date: [21 August 2022 11:55 UTC](https://discourse.nodered.org/t/how-to-make-a-cron-with-node-inject/66487/20 "2022-08-21T11:55:12Z")

</div>

Topic closed to try and keep conversation in just one topic.

> [@How to set 2 timestamp for the same request?](https://discourse.nodered.org/t/how-to-set-2-timestamp-for-the-same-request/66535/8):
>
> Another user has already given you advice about the layout of your flow... [How to make a cron with node inject - #17 by UnborN](https://discourse.nodered.org/t/how-to-make-a-cron-with-node-inject/66487/17) NOTE - Please stick to just one forum topic, and avoid opening new topics for the same problems!!

---

<div class="post-metadata">

### Author: ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)
#### Post date: [21 August 2022 11:55 UTC](https://discourse.nodered.org/t/how-to-make-a-cron-with-node-inject/66487/21 "2022-08-21T11:55:24Z")

</div>


