Skip to content

beechwoods-software/lifx-c

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

lifx-c

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.

Features

  • 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

Integration / Build

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:

  1. Add the lifx-c folder as a library target (or add it as a Zephyr module) so sources under lifx-c/src are compiled into your image.
  2. Enable any required Kconfig options (see Kconfig below).

Note: This module uses Zephyr networking and logging APIs; ensure the application's prj.conf enables net and logging as needed.

Configuration (Kconfig)

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.

Public API (overview)

  • bool lifx_init(void) — initialize sockets, device map and listener
  • void lifx_discover(void) — broadcast discovery packet
  • void lifx_networkListener(void) — listener thread (K_THREAD_DEFINE)
  • void lifx_DecodePacket(void *buf, int buflen, struct sockaddr *saddr, int addrlen) — decode incoming UDP packet
  • lifxdevice_t * lifx_findByName(const char *name) — lookup by label
  • lifxdevice_t * lifx_findByMac(const uint8_t *target) — lookup by MAC target
  • lifxdevice_item_t * lifx_device_list_get(void) — return the head of the device list
  • lifxdevice_item_t * lifx_device_list_set(lifxdevice_item_t *iter) — set the head of the device list
  • lifxdevice_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.

Generating Documentation

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).

Common issues & notes

  • 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 strncpy usages and port endianness if you modify the stack.
  • If you change allocation semantics, use Zephyr allocators (k_malloc) and include <zephyr/kernel.h>.

Contributing

Please open a PR with focused changes. Add unit/board tests where possible and follow Zephyr driver/module patterns.

License & Authors

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).

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors