In this article we will flash firmware into a Particle Photon module installed in a ControlEverything 8 channel relay controller. The firmware will detect the current time/date and execute relay control commands based on scheduled events we store into the controller. No programming is required for this tutorial, the application firmware can be loaded into the Particle WEB IDE(Build) and from there it can be flashed right into the controller.
What you need
8 channel Particle Photon relay controller
Step 1: Setup Your Particle Photon and Account
Install the Particle Photon module into the 1 channel relay controller if it is not already.
Apply a regulated 12VDC power source to the 2.1mm barrel connector or power supply input screw terminals. Follow instructions here to setup your Particle Photon module for your WiFi network and associate it with your Particle Account so we can interface with it and flash in firmware.
Step 2: Flash Some Firmware
Click the Target Icon on the left and make sure your Particle Photon module is connected and selected here. Click on the Libraries Icon on the left, then search Community Libraries for NCD8Relay. Make sure the Time_Activated_Relay.ino tab is selected, then click the Use this Example button. Now click the devices icon on the left(looks like a target) and make sure your controller is online and selected. Now click the Flash button on the left(looks like a lightning bolt) to flash the firmware into your controller. After the module is flashed with this firmware and reboots you are ready to set the controller's Time Zone and load a Time Event Schedule into the controller. The complete source for this firmware is available on our GitHub repo.
Step 3: Set Time Zone in Controller
Go to Mobicle.io
Click on the device you flashed the Time Activated Relay firmware into on the Devices list. On the next page you should see the functions the controller has available. Click on the setTimezone function. Here we need to enter our timezone id as the Argument. Eastern time = 5, Central time = 6, Mountain time = 7, Pacific time = 8. I would enter 6 since I am in the central time zone.
After entering your time zone id click the send button. The time zone is now set in the controller and stored to memory. You will not have to set this ever again as it will be read from memory on boot up, unless you move the controller to a different time zone.
Step 4: Store a Time Event Schedule Into the Controller
On Mobicle go back to the Device List. Now click the plus button to the right of Event Publisher to add a new Particle Cloud Event Publisher. This will open a dialog to configure the Event Publish button.
Enter a name for the button(this is arbitrary and can be anything you want).
For Event Name enter timeEventsDevice1 This is the event the controller is subscribed to in firmware.
For Event data we will enter a comma delimited string indicating the time and relay control command we want to execute. The first number will indicate the year, the second will indicate the month, the third will indicate the day of month, the fourth will indicate the day of week, the fifth will indicate the hour, the sixth will indicate the minute, the seventh will indicate the second, the eighth will indicate the command id, and the ninth will indicate the optional command data. Whew...
Here is the format in a readable outline:
- Year(number greater than 2016) enter 0 to ignore current year on this event
- Month(1-12) enter 0 to ignore current month on this event
- Day of Month(1-31) enter 0 to ignore current day of month on this event
- Day of Week(1-7) enter 0 to ignore current day of week on this event
- Hour(0-23) enter 24 to ignore current hour on this event
- Minute(0-59) enter 60 to ignore current minute on this event
- Second(0-59) enter 60 to ignore current second on this event
- Command ID(0-5)
- Optional command data(0-255)
The command IDs are as follows:
0 = Turn on all relays
1 = Turn off all relays
2 = set status of all relays, requires optional command data to set status of relays(0-255)
3 = Turn on individual relay, requires optional command data to indicate relay to turn on(1-8)
4 = Turn off individual relay, requires optional command data to indicate relay to turn off(1-8)
5 = Toggle individual relay state, requires optional command data to indicate relay to toggle(1-8)
Lets say we want to turn on relay 1 at 5:30 am on June 16th 2017. The event would look like this:
Another example. Lets say we want to turn on all relays every Friday at 9:45 am.
We entered 0 for year, month, and day but entered 6 for day of week which is Friday. Then we entered 9 for hour, 45 for minute, 0 for second, 0 for the command ID(Turn on all relays), and 0 for optional data since it is not required.
We can enter multiple events(up to 28). Every time we store these events to the controller it will overwrite the old stored events. So we always have to enter all the events we want. To enter both of the events above you would enter the following for Event Data:
Never enter spaces, just commas seperating the values. You must always make sure each of your events consists of 9 numbers.
Enter 60 for the TTL box(this is time to live this is how long the module will have to check in with the server and get this new event).
Finally click submit and a button will be added to the Event Publisher list. Now click the button to publish the event to the Particle cloud and the controller will see that and start executing the schedule you set. Watch as the magic unfolds.