Lightweight LIFX LAN protocol stack implemented in C for Zephyr RTOS.
This module implements discovery, packet decoding, and per-device state management for LIFX-compatible lights on a local network. It is intended to be built as a Zephyr library and consumed by an application that needs to discover and control LIFX devices.
- Broadcast discovery (GetService)
- UDP listener and packet dispatch
- Per-device state (
lifxdevice_t) with helpers for label, power, color, zones and firmware information - Small API to send LIFX commands and wait for responses
Add lifx-c to your Zephyr project's CMakeLists (the repository already
provides a CMakeLists.txt for building as a library). Typical usage from
an application CMakeLists looks like:
- Add the
lifx-cfolder as a library target (or add it as a Zephyr module) so sources underlifx-c/srcare compiled into your image. - Enable any required Kconfig options (see
Kconfigbelow).
Note: This module uses Zephyr networking and logging APIs; ensure the
application's prj.conf enables net and logging as needed.
The number of supported lifx lights can be changed by setting the CONFIG_NUM_LIFX_DEVICES.
The default is 8.
There is an anomaly in the lifx light bulb where it will nat on the local land and this advertising the local gateway as its address. A reboot of the light clears this condition. A reboot request can automaitcially be generated whin this anomaly occures by setting CONFIG_LIFX_REBOOT_LIGHT_ON_GW_ADDRESS to true.
To expose the module logging options in your project's Kconfig, add the
following snippet to your application Kconfig (or include lifx-c's
Kconfig):
module = LIFX
module-str = "LIFX"
module-help = "Enable logging for LIFX protocol"
source "subsys/logging/Kconfig.template.log_config"
Then set the desired log level in prj.conf, e.g. CONFIG_LIFX_LOG_LEVEL_DBG=y.
bool lifx_init(void)— initialize sockets, device map and listenervoid lifx_discover(void)— broadcast discovery packetvoid lifx_networkListener(void)— listener thread (K_THREAD_DEFINE)void lifx_DecodePacket(void *buf, int buflen, struct sockaddr *saddr, int addrlen)— decode incoming UDP packetlifxdevice_t * lifx_findByName(const char *name)— lookup by labellifxdevice_t * lifx_findByMac(const uint8_t *target)— lookup by MAC targetlifxdevice_item_t * lifx_device_list_get(void)— return the head of the device listlifxdevice_item_t * lifx_device_list_set(lifxdevice_item_t *iter)— set the head of the device listlifxdevice_item_t * lifx_device_list_add(lifxdevice_t *dev)— add a device to the device list
See lifx-c/include/*.h for full API details and Doxygen comments.
The repository includes Doxygen comments in the headers. To generate HTML documentation:
cd lifx-c/doc
doxygen Doxyfile
Output is placed in lifx-c/doc/html (unless the Doxyfile is changed).
- The module depends on Zephyr socket wrappers (
zsock_*) and expects IPv4 to be present. - Some string-handling and byte-order semantics are documented in the
headers — please audit
strncpyusages and port endianness if you modify the stack. - If you change allocation semantics, use Zephyr allocators (
k_malloc) and include<zephyr/kernel.h>.
Please open a PR with focused changes. Add unit/board tests where possible and follow Zephyr driver/module patterns.
See top-level LICENSE (if present) and the VERSION file for project
metadata. Original author: Brad Kemp brad@beechwoods.com (as noted in
source headers).