va_end(args);
}
+static void mqtt_publish_ephemeral(const char *topic, const char *fmt, ...)
+{
+ va_list args;
+ va_start(args, fmt);
+ char m[256];
+ int l = vsnprintf(m, sizeof(m), fmt, args);
+ if (mosquitto_publish(mosq, NULL, topic, l, m, 0, false) != MOSQ_ERR_SUCCESS)
+ msg(L_ERROR, "Mosquitto: publish failed");
+ va_end(args);
+}
+
+static void mqtt_log_callback(struct mosquitto *mosq UNUSED, void *obj UNUSED, int level, const char *message)
+{
+ msg(L_DEBUG, "MQTT(%d): %s", level, message);
+}
+
static void mqtt_conn_callback(struct mosquitto *mosq UNUSED, void *obj UNUSED, int status)
{
if (!status) {
die("Mosquitto: initialization failed");
mosquitto_connect_callback_set(mosq, mqtt_conn_callback);
+ mosquitto_log_callback_set(mosq, mqtt_log_callback);
if (mosquitto_will_set(mosq, "status/clock", 4, "dead", 0, true) != MOSQ_ERR_SUCCESS)
die("Mosquitto: unable to set will");
- if (mosquitto_connect_async(mosq, "10.32.184.5", 1883, 60) != MOSQ_ERR_SUCCESS)
- die("Mosquitto: connect failed");
+ if (mosquitto_tls_set(mosq, "/etc/burrow-mqtt/ca.crt", NULL, "/etc/burrow-mqtt/client.crt", "/etc/burrow-mqtt/client.key", NULL) != MOSQ_ERR_SUCCESS)
+ die("Mosquitto: Unable to set TLS parameters");
+
+ if (mosquitto_connect_async(mosq, "burrow-mqtt", 8883, 60) != MOSQ_ERR_SUCCESS)
+ die("Mosquitto: Unable to connect");
if (mosquitto_loop_start(mosq))
die("Mosquitto: cannot start service thread");
}
+/*** IR remote ***/
+
+static const struct {
+ u32 code;
+ const char * const name;
+} key_table[] = {
+ { 0x4bc0ab54, "1" },
+ { 0x4bc06b94, "2" },
+ { 0x4bc0eb14, "3" },
+ { 0x4bc01be4, "4" },
+ { 0x4bc09b64, "5" },
+ { 0x4bc05ba4, "6" },
+ { 0x4bc0db24, "7" },
+ { 0x4bc03bc4, "8" },
+ { 0x4bc0bb44, "9" },
+ { 0x4bc0fb04, ">10" },
+ { 0x4bc07b84, "10/0" },
+ { 0x4bc07986, "clr" },
+ { 0x4b2010ef, "play-mode" },
+ { 0x4b20817e, "group/search" },
+ { 0x4bc0926d, "memory" },
+ { 0x4b20629d, "enter" },
+ { 0x4b2051ae, "band" },
+ { 0x4b90cb34, "fm-mode" },
+ { 0x4bc000ff, "preset+" },
+ { 0x4bc0807f, "preset-" },
+ { 0x4b9002fd, "tuning-up" },
+ { 0x4b90827d, "tuning-down" },
+ { 0x4b207887, "input-up" },
+ { 0x4b20f807, "input-down" },
+ { 0x4bc0a956, "dimmer" },
+ { 0x4bc040bf, "volume-up" },
+ { 0x4bc0c03f, "volume-down" },
+ { 0x4b20aa55, "display" },
+ { 0x4bc0a05f, "muting" },
+ { 0x4bc0f807, "pause" },
+ { 0x4bc0d827, "play" },
+ { 0x4bc038c7, "stop" },
+ { 0x4bc0d12e, "rewind" },
+ { 0x4bc051ae, "ffwd" },
+ { 0x4bc07887, "prev-song" },
+ { 0x4bc0b847, "next-song" },
+ { 0x4b20ea15, "random" },
+ { 0x4b206a95, "repeat" },
+ { 0x4b2048b7, "scroll" },
+ { 0x4b904ab5, "playlist-up" },
+ { 0x4b90ca35, "playlist-down" },
+ { 0x4b900af5, "album-up" },
+ { 0x4b908a75, "album-down" },
+ { 0x4b905aa5, "menu" },
+ { 0x4b90da25, "select" },
+ { 0x4b9041be, "list-up" },
+ { 0x4b90c13e, "list-down" },
+};
+
+static void report_ir_key(u32 key_code)
+{
+ for (uint i = 0; i < (uint) ARRAY_SIZE(key_table); i++) {
+ if (key_table[i].code == key_code) {
+ msg(L_DEBUG, "IR key %08x: %s", key_code, key_table[i].name);
+ mqtt_publish_ephemeral("burrow/control/catarium-ir", key_table[i].name);
+ return;
+ }
+ }
+
+ msg(L_WARN, "IR key %08x not recognized", key_code);
+}
+
/*** USB ***/
static void clock_timer_handler(struct main_timer *timer);
msg(L_ERROR, "Short RX transfer");
} else {
u32 key = get_u32_be(dev->rx_buffer);
- msg(L_INFO, "IR key %08x", key);
+ report_ir_key(key);
}
rx_submit(dev);