Skip to content

Adding basic suport for MQTT client #667

@refaktor

Description

@refaktor

We got proposal on the email to add support for mqtt protocol. This was already in longterm plan so basic MQTT client should be added to Rye.

It's always much more motivating to work with real examples, so this is a first target example from the request. Using Rye to do the timing will also be interesting.

#!/usr/local/bin/lua54

function measureRespTime()
       local sum = 0.0
        for i=1,3,1 do
        local handle = io.popen("curl -so /dev/null -w '%{time_total}\n' https://url/")
        local result = handle:read("*a")
	local res = result
        local resp = res:gsub("[\n\r]", " ")
	sum = sum + resp
									                   
	handle:close()
	end
	local avg = sum/3
--print(avg)
       publishMessage(avg)
end

function publishMessage(measurement)
      local resptime = measurement
      --local response = resptime:gsub("[-h]", " ")
      local str1 = "nanomq_cli pub -t \"website/monitoring\" -q 2 -u ohab_client --password **** -m "
      local str2 = " -h HOSTNAME -p PORT"
      local str3 = str1 .. tostring(resptime) 
    
      local rtime = str3 .. str2
    
      local handle = io.popen(rtime)
      local result = handle:read("*a")
      handle:close()
end

measureRespTime()

Thanks to mr. Serge for request and example.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions