ymlr-mqtt
TypeScript icon, indicating that this package has built-in type declarations

1.2.1 • Public • Published

ymlr-mqtt

ymlr-mqtt for ymlr plugin


Tag details

Tags Description
ymlr-mqtt Declare a mqtt connector
ymlr-mqtt'pub Publish a message to topics in mqtt
ymlr-mqtt'sub Subscribe topics in mqtt

ymlr-mqtt

Declare a mqtt connector

Example:

  - name: "[mqtt] localhost"
    ymlr-mqtt:
      uri: mqtt://user:pass@mqtt            # Mqtt uri
      runs:                                 # When a message is received then it will runs them
        - echo: Mqtt is connected

Publish a message to topics

  - name: "[mqtt] localhost"
    ymlr-mqtt:
      uri: mqtt://user:pass@mqtt            # Mqtt uri
      runs:                                 # When a message is received then it will runs them
        - name: Publish a message
          ymlr-mqtt'pub:
            topics:
              - test
            data:
              msg: Hello world

ymlr-mqtt'pub

Publish a message to topics in mqtt

Example:

Publish a message to mqtt

  - name: "[mqtt] localhost"
    ymlr-mqtt'pub:
      uri: mqtt://user:pass@mqtt
      topic: topic1
      topics:
        - topic2
        - topic3
      pubOpts:
        qos?: 0 | 1 | 2
      data:
        name: thanh

Reuse mqtt connection to publish multiple times

  - name: "[mqtt] localhost"
    ymlr-mqtt:
      uri: mqtt://user:pass@mqtt
      runs:
        - ymlr-mqtt'pub:
            topics:
              - topic1
            pubOpts:
              qos?: 0 | 1 | 2
            data:
              name: thanh
        - ...
        # Other elements

Or reuse by global variable Reuse mqtt connection to publish multiple times

  - name: "[mqtt] localhost"
    ymlr-mqtt:
      uri: mqtt://user:pass@mqtt
    vars:
      mqtt1: ${this}

  - ymlr-mqtt'pub:
      mqtt: ${ $vars.mqtt1 }
      topics:
        - topic1
      pubOpts:
        qos?: 0 | 1 | 2
      data:
        name: thanh

ymlr-mqtt'sub

Subscribe topics in mqtt

Example:

  - name: "[mqtt] localhost"
    ymlr-mqtt'sub:
      uri: mqtt://user:pass@mqtt
      topic: topic1
      topics:                               # topics which is subscribed
        - topic1
        - topic2
      runs:                                 # When a message is received then it will runs them
        - ${ $parentState }                 # - Received data in a topic
        - ${ $parentState.topicName }       # - Topic name
        - ${ $parentState.topicData }       # - Received message which is cast to object
        - ${ $parentState.topicMsg }        # - Received message which is text

        - ...
        # Other elements

Used in global mqtt

  - name: Global MQTT
    ymlr-mqtt:
      uri: mqtt://user:pass@mqtt
      runs:
        - name: "[mqtt] localhost"
          ymlr-mqtt'sub:
            topic: topic1
            topics:                             # topics which is subscribed
              - topic1
              - topic2
            runs:                               # When a message is received then it will runs them
              - ${ $parentState }               # - Received data in a topic
              - ${ $parentState.topicName }     # - Topic name
              - ${ $parentState.topicData }     # - Received message which is cast to object
              - ${ $parentState.topicMsg }      # - Received message which is text

              - ...
              # Other elements

Or reuse by global variable

  - name: Global MQTT
    ymlr-mqtt:
      uri: mqtt://user:pass@mqtt
    vars:
      mqtt1: ${this}

  - name: "[mqtt] localhost"
    ymlr-mqtt'sub:
      mqtt: ${ $vars.mqtt1 }
      topic: topic1
      topics:                             # topics which is subscribed
        - topic1
        - topic2
      runs:                               # When a message is received then it will runs them
        - ${ $parentState }               # - Received data in a topic
        - ${ $parentState.topicName }     # - Topic name
        - ${ $parentState.topicData }     # - Received message which is cast to object
        - ${ $parentState.topicMsg }      # - Received message which is text

        - ...
        # Other elements

        - stop:                           # - Stop subscribing

Have fun :)

Dependents (0)

Package Sidebar

Install

npm i ymlr-mqtt

Weekly Downloads

0

Version

1.2.1

License

ISC

Unpacked Size

33.7 kB

Total Files

28

Last publish

Collaborators

  • circle2jt