Sending MQTT Protobuf via Script

Hi,

I want to send mqtt messages from a script using the existing MQTT Engine connection to field devices. For this purpose, system.cirruslink.engine.publish() looks like the right tool for the job, but it doesn’t seem to encode the message with Protobuf.

All messages currently sent to / from the MQTT Engine connection is already encoded with Protobuf, but messages sent manually using this script is not.

Is there a function or feature or option that I’m not aware of to help us do this?

Kind regards,
J

There isn’t anything built into the MQTT Engine scripting API to support publishing of Sparkplug/protobuf messages. However, Ignition does support importing custom Python libraries. See the following links:

Using this method, you could add ‘Tahu’ to Ignition:

This would allow you to write scripts such the one below in Ignition:

Thanks, Wes

This actually solved my problem for a while, but recently Ignition dropped the gwtime() function from their prebuilt python binary, which broke the google protobuf libraries I imported.

Has there been any development on this? The drive must already use these functions itself?

Kind regards,
J

There hasn’t been much development on the Tahu/Python front. All of the committers on Tahu currently are Java focused. So, there hasn’t been much traction yet on other languages.

The only option I can think of for you is to update the Tahu/Python library or add the required dependencies using the same method you used to import that Tahu library to begin with.

Our MQTT modules are written in Java and use the Ignition Java SDK - not the Python one. So, the dependencies are completely different.

Thank you for the background, Wes. I understand now that it’s not possible to make these functions available to me.

I did of course looking at providing the missing functions in the way you describe, but this is the error:

Traceback (most recent call last):
  File "<input>", line 7, in <module>
  File "/home/user/.ignition/cache/gwscada.example.com_8088/C1/pylib/sparkplug_b/__init__.py", line 13, in <module>
    import sparkplug_b_pb2
  File "/home/user/.ignition/cache/gwscada.example.com_8088/C1/pylib/sparkplug_b/sparkplug_b_pb2.py", line 8, in <module>
    from google.protobuf import reflection as _reflection
  File "/home/user/.ignition/cache/gwscada.example.com_8088/C1/pylib/google/protobuf/reflection.py", line 51, in <module>
    from google.protobuf import message_factory
  File "/home/user/.ignition/cache/gwscada.example.com_8088/C1/pylib/google/protobuf/message_factory.py", line 49, in <module>
    from google.protobuf.internal import python_message as message_impl
  File "/home/user/.ignition/cache/gwscada.example.com_8088/C1/pylib/google/protobuf/internal/python_message.py", line 70, in <module>
    from google.protobuf.internal import well_known_types
  File "/home/user/.ignition/cache/gwscada.example.com_8088/C1/pylib/google/protobuf/internal/well_known_types.py", line 99, in <module>
    _EPOCH_DATETIME = datetime.utcfromtimestamp(0)
  File "/home/user/.ignition/cache/gwscada.example.com_8088/C1/pylib/datetime.py", line 1623, in utcfromtimestamp
    y, m, d, hh, mm, ss, weekday, jday, dst = _time.gmtime(t)
AttributeError: 'builtin_function_or_method' object has no attribute 'gmtime'

It looks like the missing function is gmtime(), normally provided by the time library, which is pre-built into the python binary. I don’t know why this was removed from the version of python used by Ignition, and I haven’t been able to find an external python library to replace that function.

Perhaps I just lack the knowledge of how to do this. I’ve made a similar post at the Ignition forums, hopefully someone can come up with a solution.

I think the Ignition forum may be more fruitful than this one. If you are able to find a solution there, can you link it here?

Cross linking the Ignition Forum thread: