I don't know if what I am asking for can be done or not, but the topic is that right now I have a workflow using Automator to send a value to thingspeak each 5 minutes using the following code:

curl --data "api_key=XXXXXXXXXXXXXX&field3=1000" https://api.thingspeak.com/update.json

Maybe can be done some kind of script in the raspberry to send this values each a certain period of time. If someone have tried this before and can give me some advice to do it, it would be great.


You'll want to use cron for this. You need to add a line to the crontab, telling your Pi to run your command every 5 minutes. I think it's good practice to get into the habit of putting your commands into script files. In this case you could make a shell script file. Let's make it on your desktop (you could put this anywhere, and call it anything you like):

touch /home/pi/Desktop/script.sh
nano /home/pi/Desktop/script.sh

Now put the following into your script file (the first line just tells the Pi how to execute the following commands):



(ctrl-X, and "y" to save and exit when you're done)

Now we'll make that script executable

sudo chmod 755 /home/pi/Desktop/script.sh

Now we'll tell the Pi when to execute this. So go to your crontab file

sudo nano /etc/crontab

Then add a line at the bottom (you'll to press "ctrl-X", then "y" to save and exit after you've added this):

*/5 * * * * root /bin/sh /home/pi/Desktop/script.sh

Note that the first 5 values, separated by spaces, are values telling your Pi when to execute the command. The first value is the minutes variable, which would usually tell cron to call the command at a given number of minutes (let's say 20 as an example) after each specified hour (in the 20 example, 1:20, 2:20, 3:20, etc.). By adjusting that to "*/5" instead, it will execute every 5 minutes. For your example, all the other values should be "*"s, which will tell the Pi to execute this command regardless of the value of that variable.

The 5 values in order represent:

  • minutes
  • hours
  • day of the month
  • month of the year
  • day of the week

You can replace each these values with an appropriate numeric value to specify when to execute your command. For example, replacing the third value with a 3 would limit the execution of your command to only the third day of each month. If you also change the fourth value to a 6, your command would only execute on the 3rd of June.

The "root" in the crontab line tells the Pi who to be when running this command (you could put your "pi" username here if you like).

The "/bin/sh" tells cron how to execute the command (in this case it's a shell script).

I hope this helps, I find cron super useful, so it's worth learning the basics of how it works!

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.