Adding LUA library to SHAC/NAC

Discussion in 'C-Bus Automation Controllers' started by Damaxx, Apr 4, 2019.

  1. Damaxx

    Damaxx

    Joined:
    May 12, 2008
    Messages:
    167
    Likes Received:
    15
    Was going over some more ideas for scripts and come across this post from Daniel in Jan 2018

    So that go me wondering - The LUA MQTT library is a very simple library with standard dependencies.

    https://github.com/geekscape/mqtt_lua/blob/master/lua/mqtt_library.lua

    Before I go dive into the deep end and brick my controller, are there any known caveats with adding functions?
    If we could get simple MQTT implementation, it would open a trove of possibilities.
     
    Damaxx, Apr 4, 2019
    #1
    1. Advertisements

  2. Damaxx

    Pie Boy

    Joined:
    Nov 21, 2012
    Messages:
    18
    Likes Received:
    1
    Location:
    New Zealand
    Pie Boy, Apr 15, 2019 at 5:44 AM
    #2
    1. Advertisements

  3. Damaxx

    Damaxx

    Joined:
    May 12, 2008
    Messages:
    167
    Likes Received:
    15
    Can you elaborate on how you got MQTT going?
     
    Damaxx, Apr 16, 2019 at 6:37 AM
    #3
  4. Damaxx

    Pie Boy

    Joined:
    Nov 21, 2012
    Messages:
    18
    Likes Received:
    1
    Location:
    New Zealand
    What are you trying to achieve exactly? this will bring in messages from an all ready configured broker on the same network as the SHAC making the SHAC a Mqtt client, i have mqtt talking to cbus both ways like this with a few esp8266 units and such

    The lib is already loaded in the SHAC firmware somewhere so you just need to require it etc, i stumbled on this by accident...
    Create a resident script with 0 delay to connect to the broker and topics see below, the lib is well documented as per link above

    mqtt = require("mosquitto")
    client = mqtt.new()

    client.ON_CONNECT = function()
    log("MQTT connected")
    client:subscribe("Some Topic")
    local mid = client:subscribe(Some Topic", 2)
    end

    client.ON_MESSAGE = function(mid, topic, payload)

    if topic == "Some topic" then

    if payload == "Some Payload" then
    -- Do something
    end

    end

    log(topic, payload)
    end

    broker = 'xxx.xxx.xxx.xxx' -- Broker ip adress
    client:connect(broker)
    client:loop_forever()
     
    Pie Boy, Apr 17, 2019 at 2:58 AM
    #4
    Damaxx likes this.
  5. Damaxx

    Damaxx

    Joined:
    May 12, 2008
    Messages:
    167
    Likes Received:
    15
    Awesome - that's what I was looking for.
    I was trying different ways of mqtt - all of which required an "mqtt" library.
    Didn't even think to try mosquitto.
    Much appreciated.
     
    Damaxx, Apr 17, 2019 at 3:31 AM
    #5
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.