IPWorks IoT 2020 Node.js Edition

Questions / Feedback?

MessageIn Event

Fired when an incoming message has been received and/or fully acknowledged.

Syntax

mqttsn.on('MessageIn', [callback])

Callback

The 'callback' is called when the 'MessageIn' event is emited.

function(e){ }

The argument 'e' has the following properties:

e.msgId
e.topicId
e.topicIdType
e.QOS
e.message (buffer)
e.retained
e.duplicate
e.returnCode

Remarks

Fired on reception of a PUBLISH packet for QoS 0 and 1 messages, and reception of a PUBREL packet for QoS 2 messages.

  • MsgId: a unique (among currently unacknowledged incoming messages) identifier attached to messages of QoS 1 and 2. Otherwise value will be 0.
  • TopicId: topic id of type TopicIdType.
  • TopicIdType: 0 = registered topic id, 1 = pre-defined topic id, 2 = short topic name.
  • QOS: The message's QoS level.
  • Message: The message data.
  • Retained: Whether or not this message was received as a result of subscribing to a topic.
  • Duplicate: Whether or not the server has indicated that this message is a duplicate of another message sent previously.
  • ReturnCode: QoS 1 messages can be accepted or rejected by setting the ReturnCode to a value listed below.
    • 0: accepted
    • 1: rejected - congestion
    • 2: rejected - invalid topic id
    • 3: rejected - not supported

Inbound Message Processing

Incoming messages with a QoS of 1 follow these steps:

  1. The TopicInfo event is fired (if the gateway sends a REGISTER packet because it needs to inform the client name and assigned topic id it will use in a PUBLISH message).
  2. The class sends a REGACK (register acknowledgment) packet in response (if a REGISTER packet was received).
  3. The MessageIn event is fired.
  4. The class sends a PUBACK (publish acknowledgment) packet in response (with the return code from the MessageIn event if one is set).

Incoming messages with a QoS of 2 follow these steps:

  1. The TopicInfo event is fired (if the gateway sends a REGISTER packet because it needs to inform the client name and assigned topic id it will use in a PUBLISH message).
  2. The class sends a REGACK (register acknowledgment) packet in response (if a REGISTER packet was received).
  3. The class sends a PUBREC (publish received) packet in response.
  4. The class waits to receive a PUBREL (publish release) packet.
  5. The class sends a PUBCOMP (publish complete) packet in response.
  6. The MessageIn event is fired.

Copyright (c) 2022 /n software inc. - All rights reserved.
IPWorks IoT 2020 Node.js Edition - Version 20.0 [Build 8265]