How to use the Golioth Settings Service with Zephyr

Originally published at: How to use the Golioth Settings Service with Zephyr - Golioth

Controlling 10 devices is easy, controlling 10,000 is a different story. The trick is to plan for scale, which is what we specialize in here at Golioth. A few weeks ago we announced the Golioth Device Settings Service that enables you to change settings for your entire fleet at the click of a button. Of course, you can drill down to groups of devices and single devices too. While the announcement post showed the Settings Service using our ESP-IDF SDK, today we’ll look at this setting service from the device point of view with Zephyr RTOS. Device-side building blocks The good news is that the Golioth Zephyr SDK has done all the hard work for you. We just need to do three things to start using the settings service in any Zephyr firmware project: Enable the settings service in KConfig Register a callback function when the device connects to Golioth Validate the data and do something useful when a new setting arrives Code walk-through Golioth’s settings sample code is a great starting point. It watches for a settings key named LOOP_DELAY_S to remotely adjust the delay between sending messages back to the server. Let’s walk through the important parts of that code for a better understanding of what is involved. 1. Enable settings in KConfig CONFIG_GOLIOTH_SETTINGS=y To turn the settings service on, the CONFIG_GOLIOTH_SETTINGS symbol needs to be selected. Add the code above to your prj.conf file. 2. Register a callback for settings updates static void golioth_on_connect(struct golioth_client *client) { if (IS_ENABLED(CONFIG_GOLIOTH_SETTINGS)) { int err = golioth_settings_register_callback(client, on_setting); if (err) { LOG_ERR(“Failed to register settings callback: %d”, err); } } } To do anything useful with the settings service, we…