Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect handling of STATE messages #11

Open
carloslockward opened this issue Oct 15, 2024 · 2 comments
Open

Incorrect handling of STATE messages #11

carloslockward opened this issue Oct 15, 2024 · 2 comments

Comments

@carloslockward
Copy link

carloslockward commented Oct 15, 2024

Acording to the Sparkplug B Spec section 5.13:

The MQTT Will Message’s topic MUST be of the form spBv1.0/STATE/sparkplug_host_id where host_id is the unique identifier of the Sparkplug Host Application

Currently in the _mqtt_on_message method of the MqttSpbEntity class you have:

        # Check that the namespace and group are correct
        # NOTE: Should not be because we are subscribed to an specific topic, but good to check.
        if topic.namespace != "spBv1.0" or topic.group_name != self._spb_group_name:
            logger.error("%s - Incorrect MQTT spBv1.0 namespace and topic. Message ignored !" % self._entity_domain)
            return

        # Check if it is a STATE message from the SCADA application
        if topic.message_type == "STATE":
            # Execute the callback function if it is not None
            if self.on_message is not None:
                self.on_message(topic, msg.payload.decode("utf-8"))
            return

and since the message topic is divided like this:

        topic_fields = topic_str.split('/')  # Get the topic

        self.topic = topic_str

        self.namespace = topic_fields[0]
        self.group_name = topic_fields[1]
        self.message_type = topic_fields[2]
        self.eon_name = None
        self.eon_device_name = None

The on_message callback will never capture state messages because the MqttSpbTopic class assumes the group always comes after the spBv1.0 part of the message topic, which is true for most topics but not true for STATE messages.

@carloslockward
Copy link
Author

Created PR #12

@carloslockward
Copy link
Author

Could you take a look at this? @javier-fg

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant