Nira
Nira

Reputation: 317

Task schedule management

I am doing a pet feeder with React-Native app - Node.js server - Arduino (ESP32) but I can't figure it out how to make it work so it drops food at specific times.

I was looking into nodeJS libraries like node-schedule or cron but I can't figure it out or they don't seem to fit my needs.

At this moment I can make it drop food when I press a button in my app, but that would make it too simple (I want both manual AND automatized tasks). My intention is to schedule feeding hours for your pet to eat, for example at 9:00, at 15:00 and at 21:00 via app, with some sort of alarms, while also being able to check them on demand and edit/delete options.

Any ideas on how could I do it, please?

Upvotes: 1

Views: 774

Answers (1)

EGibson
EGibson

Reputation: 477

You don't necessarily have to trigger the "drop food" command from the node app. I've written firmware for a device that connects to wifi, updates its internal date/time from a NTP server, then wakes up at a specified time every data to connect to a server and get setting updates. Ours is a battery powered device, so it doesn't just stay connected to the server all the time, and I used the ESP-IDF but the code was simple enough. I did some research and you can do the same process with an ESP32 using the Arduino Core.

Basic Idea

You could:

  • Set the times you want the feeding to occur in the app, which then sends those times to the device through BLE or your node app and store them in Flash
  • Calculate the number of milliseconds until the next feeding
  • Set a FreeRTOS timer to interrupt after that number of milliseconds to trigger a feeding event

Then after a feeding event occurs:

  • Check Flash for the next feeding event
  • Calculate the number of milliseconds
  • Set a FreeRTOS timer to interrupt and trigger a feeding event
  • Repeat

Resources:

Setting Local Time on Arduino using NTP

Using FreeRTOS timer interrupts on Arduino

Upvotes: 1

Related Questions