mqtt icon indicating copy to clipboard operation
mqtt copied to clipboard

Stop mqtt_run from executing

Open lefec opened this issue 7 years ago • 2 comments

Hi, thanks for your making this package. I am playing around with MQTT for the first time today. I am trying to use shiny for displaying live sensor data.

This is the example you gave on the frontpage:

library(mqtt)

sensor <- function(id, topic, payload, qos, retain, con) {
  if (topic == "bbc/subtitles/bbc_two_england/raw") {
    cat(crayon::cyan(topic), crayon::blue(readBin(payload, "character")), "\n", sep=" ")
  }
}

# NOTE: Use a unique name vs `hrbrunique`
mqtt_broker("hrbrnique", "test.mosquitto.org", 1883L) %>%
  mqtt_silence(c("error", "log")) %>% 
  mqtt_subscribe(
    "bbc/subtitles/bbc_one_london/raw", 
    function(id, topic, payload, qos, retain, con) { # regular anonymous function
      if (topic == "bbc/subtitles/bbc_one_london/raw")
        cat(crayon::yellow(topic), crayon::green(readBin(payload, "character")), "\n", sep=" ")
    }) %>%
  mqtt_subscribe("bbc/subtitles/bbc_news24/raw", ~{ # tilde shortcut function (passing in named, pre-known params)
    if (topic == "bbc/subtitles/bbc_news24/raw")
      cat(crayon::yellow(topic), crayon::red(readBin(payload, "character")), "\n", sep=" ")
  }) %>%
  mqtt_subscribe("bbc/subtitles/bbc_two_england/raw", sensor) %>% # named function
  mqtt_run() -> res

I can't figure out how to stop it from executing (for me it is printing out the subtitles without an end). I set the 'times' argument in mqtt_run but it does not seem to have any effect.

I am not really interested in printing the results to the console but to save them in a vector to make some quick analysis.

lefec avatar Mar 03 '18 19:03 lefec