Lighting events
A device configures its lights based on lighting events. Such a lighting event may be a nearby PIR sensor detecting movement, or a pre-configured schedule. From an implementation perspective, a lighting event is a request to configure the 3 lighting dim-levels: red, green, and blue. A lighting event further contains a timestamp and a priority.
Each light device stores up to 5 concurrent lighting events with different priorities, ranging from 0 (lowest priority) to 4 (highest priority). When a high priority event expires, any lower priority event takes over and is allowed to configure the lights. For example, when a high priority PIR event expires, a lower priority schedule again takes control of the lights.
Zones
Lighting events are typically communicated to one or multiple zones. A device is assigned to a zone using the device variable zone
. Lighting events may be sent to multiple zones using comma-separation. The reserved zone name all
affects all network devices, even if they are not specifically configured to belong to any particular zone.
Smart phone control event
A smart phone control event is received and forwarded to the zone(s) by the access point. Smart phone control events may either be sent remotely via the backend server or via UDP from the local area network. Remotely, the event is sent as a regular device command to the lights' network access point, or when via the local area network using UDP on port 898.
# Shell example: turn lights to 100% in zones 5 and 6 via local area network UDP.
# The Thingsquare access point has IP address 192.168.0.100 (server variable local-addr)
$ echo -n "5,6:lc646464" | nc -u 192.168.0.100 898
The light devices configure the priority and duration of smart phone control events using the thsq_lighting_set_default_lc
function.
/* Firmware example: Light device configures smart phone control events to have priority 3 and last for 3600 seconds. */
void thsq_lighting_set_default_lc(thsq_lighting_prio_t prio, uint32_t duration);
thsq_lighting_set_default_lc(3, 3600);
Light switch event
A light switch event is generated and broadcasted from a battery-driven network device and contains light dimlevels.
/* Firmware example: Broadcast light switch event from deadleaf device.
Below event requests devices in zone 101 to configure red dim-level to 10%, green to 20%, and blue to 30% */
uint8_t rgb[] = { 10, 20, 30 };
thsq_lighting_send(THSQ_LIGHTING_SWITCH, (uint8_t*)"101", 3, rgb, 3, 1);
The light devices configure the priority and duration of light switch events using the thsq_lighting_set_default_switch
function.
/* Firmware example: Light device configures light switch events to have priority 3 and last for 3600 seconds. */
void thsq_lighting_set_default_switch(thsq_lighting_prio_t prio, uint32_t duration);
thsq_lighting_set_default_switch(3, 3600);
PIR event
A PIR event is generated and broadcasted from a battery-driven network device and contains no argument.
/* Firmware example: Broadcast PIR event from deadleaf device.
Below event notifies devices in zone 102 that movement was detected. */
thsq_lighting_send(THSQ_LIGHTING_PIR, "102", 3, NULL, 0, 1);
The light devices configure the priority, duration, and dim-levels of PIR events using the thsq_lighting_set_default_pir
function.
/* Firmware example: Light device configures PIR events to have priority 2, last for 120 seconds, and fully turn on the lights. */
void thsq_lighting_set_default_pir(thsq_lighting_prio_t prio, uint32_t duration, int red, int green, int blue);
thsq_lighting_set_default_pir(2, 120, 100, 100, 100);
Schedule event
Schedule events are automatically generated internally in a light device when there is an active schedule configured.
/* Firmware example: Light device configures schedule priority to 1. */
void thsq_lighting_set_default_schedule(thsq_lighting_prio_t prio);
thsq_lighting_set_default_schedule(1);
Overriding event configurations
For testing purposes, the lighting event configurations may be overridden using device variables pir
, switch
, lc
, and schedule
.
-
lc
format [prio],[duration]
lc
example "3,3600" -
switch
variable [prio],[duration]
switch
example "3,3600" -
pir
variable [prio],[duration],[red],[green],[blue]
pir
example "2,120,100,100,100" -
schedule
variable [prio]
schedule
example "1"