+ led_begin_update();
+ struct led *led = &leds[index];
+ struct client *client = find_client(sender);
+ if (client->status < 0) {
+ msg(L_ERROR, "LED update from a dead client %s", client->name);
+ } else {
+ led->r = r;
+ led->g = g;
+ led->b = b;
+ led->sender = client;
+ }
+ led_end_update();
+}
+
+static void mqtt_msg_callback(struct mosquitto *mosq UNUSED, void *obj UNUSED, const struct mosquitto_message *m)
+{
+ char val[256];
+ if (m->payloadlen >= sizeof(val) - 1) {
+ msg(L_ERROR, "Invalid value for topic %s", m->topic);
+ return;
+ }
+ memcpy(val, m->payload, m->payloadlen);
+ val[m->payloadlen] = 0;
+ msg(L_DEBUG, "MQTT < %s %s", m->topic, val);
+
+ static const char px_status[] = "status/";
+ static const char px_rainbow[] = "burrow/lights/rainbow/";
+ if (str_has_prefix(m->topic, px_status))
+ msg_status(m->topic, m->topic + strlen(px_status), val);
+ else if (str_has_prefix(m->topic, px_rainbow))
+ msg_rainbow(m->topic, m->topic + strlen(px_rainbow), val);