Test about how to get MQTT working
library(mqtt)
mqtt_broker("bbf928f8-ef46-4614-893f-d36c43f7b8ce", "test.mosquitto.org", 1883L) %>%
mqtt_silence(c("error", "log", "publish")) %>%
mqtt_subscribe("cvmartin", ~{
if (topic == "cvmartin") {
payload <- readBin(payload, "character")
cat(crayon::cyan(topic), crayon::white(payload), "\n", sep=" ")
# Here is where the magig happens. Modify the response!
resp <- 8 * (as.numeric(payload))
resp <- as.character(resp)
con$publish_chr(0, "cvmartintest", resp, 0, FALSE)
}
}) %>%
mqtt_run() -> res
# Then, in a Pi (or wherever terminal)
# mosquitto_pub -h test.mosquitto.org -t cvmartin -m "50"
# In another terminal, receive the message back:
# mosquitto_sub -d -h test.mosquitto.org -t cvmartintest