This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm whether you accept or reject these cookies being set.

Azure IoT Hub - MQTT
#21
(10.01.2019, 09:55)admin Wrote: Thanks!

First, you need to update MQTT library packages:

New CPU:
http://dl.openrb.com/pkg/libmosquitto_1.4.15-1_imx6.ipk
http://dl.openrb.com/pkg/luamosquitto_0.3-2_imx6.ipk

Old CPU:
http://dl.openrb.com/pkg/libmosquitto_1.4.15-1_mxs.ipk
http://dl.openrb.com/pkg/luamosquitto_0.3-2_mxs.ipk

Here's a minimal example that you can use, don't forget to change device_id, broker, username and password parameters. You also need to upload azure.crt via FTP (using ftp username, upload to root directory). Certificate file contents: https://gist.github.com/jsopenrb/5873b20...d6b950151f
Code:
device_id = 'DEV_TEST'
broker = 'DEV.azure-devices.net'
port = 8883
username = 'DEV.azure-devices.net/DEV_TEST'
password = 'SharedAccessSignature ...'

mqtt = require('mosquitto')
client = mqtt.new(device_id)

client.ON_CONNECT = function(...)
 log('ON_CONNECT', ...)
 client:publish('devices/' .. device_id .. '/messages/events/', '{id=456}')
end

client.ON_PUBLISH = function(...)
 log('ON_PUBLISH', ...)
end

client.ON_LOG = function(...)
 log('ON_LOG', ...)
end

client.ON_DISCONNECT = function(...)
 log('ON_DISCONNECT', ...)
end

client:version_set(mqtt.PROTOCOL_V311)
client:tls_set('/home/ftp/azure.crt')
client:login_set(username, password)
client:connect(broker, port)

while true do
 res, err, code = client:loop()
 if not res then
   log('loop error', res, err, code)
   os.sleep(1)
 end
end

Is there a typo in the filename or is the package removed from your downloads? 

libmosquitto_1.4.15-1_imx6.ipk
Reply
#22
Updated package: http://dl.openrb.com/pkg/libmosquitto_1.6.2-1_imx6.ipk
Reply


Forum Jump: