Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop mqtt_run from executing #3

Open
lefec opened this issue Mar 3, 2018 · 2 comments
Open

Stop mqtt_run from executing #3

lefec opened this issue Mar 3, 2018 · 2 comments

Comments

@lefec
Copy link

lefec commented Mar 3, 2018

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.

@jorditruji
Copy link

Hello Lefec,

I had the same problem as you, sincerely the only thing I can recommend you is switching to python and use paho mqtt.

@JeremyBesson
Copy link

You can use the timeout parameter
Example:

 mqtt_run(timeout = 1) 

But be careful this timeout is an interval in minutes contrary to what you can read in documentation.
Also it is not really usable because the process is not really close, you only don't have new data coming after the timeout.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants