Skip to content

Instantly share code, notes, and snippets.

@yoggy
Created May 17, 2015 13:32
Show Gist options
  • Save yoggy/ec89461b5a48e7354c8b to your computer and use it in GitHub Desktop.
Save yoggy/ec89461b5a48e7354c8b to your computer and use it in GitHub Desktop.
#!/usr/bin/ruby
require 'mathn'
$host = 'mqtt.example.com'
$port = 1883
$user = 'username'
$pass = 'password'
def usage
puts "#{$0} topic"
exit 0
end
usage if ARGV.size == 0
$topic = ARGV[0]
loop do
t = Time.now.to_i % 10000
num = sprintf("segd%04d", t)
num += "." if t.prime?
cmd = "mosquitto_pub -h #{$host} -p #{$port} -u #{$user} -P #{$pass} -t #{$topic} -m #{num}"
puts cmd
system cmd
sleep 1
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment