# Sending MQTT Protobuf via Script

**URL:** <https://forum.cirrus-link.com/t/sending-mqtt-protobuf-via-script/104>\
**Category:** MQTT Modules\
**Tags:** mqtt-engine\
**Created:** [August 19, 2021, 11:16am UTC](https://forum.cirrus-link.com/t/sending-mqtt-protobuf-via-script/104 "2021-08-19T11:16:41Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![jacques\_za](https://yyz2.discourse-cdn.com/flex028/user_avatar/forum.cirrus-link.com/jacques_za/32/29_2.png) [@jacques\_za](https://forum.cirrus-link.com/u/jacques_za)\
**Post date:** [August 19, 2021, 11:16am UTC](https://forum.cirrus-link.com/t/sending-mqtt-protobuf-via-script/104/1 "2021-08-19T11:16:41Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![wes.johnson](https://avatars.discourse-cdn.com/v4/letter/w/f14d63/32.png) [@wes.johnson](https://forum.cirrus-link.com/u/wes.johnson)\
**Post date:** [August 19, 2021, 4:06pm UTC](https://forum.cirrus-link.com/t/sending-mqtt-protobuf-via-script/104/2 "2021-08-19T16:06:47Z")

</div>

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:

- [Importing and using 3rd party Python libraries in Ignition – Inductive Automation Help Center](https://support.inductiveautomation.com/hc/en-us/articles/360047136012-Importing-and-using-3rd-party-Python-libraries-in-Ignition)
- [Third Party Python Modules - Custom Libraries](https://inductiveuniversity.com/videos/third-party-python-modules/8.1)

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

- [tahu/client\_libraries/python at develop · eclipse/tahu · GitHub](https://github.com/eclipse/tahu/tree/develop/client_libraries/python)

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

- [tahu/example.py at develop · eclipse/tahu · GitHub](https://github.com/eclipse/tahu/blob/develop/sparkplug_b/stand_alone_examples/python/example.py)

---

<div class="post-metadata">

**Author:** ![jacques\_za](https://yyz2.discourse-cdn.com/flex028/user_avatar/forum.cirrus-link.com/jacques_za/32/29_2.png) [@jacques\_za](https://forum.cirrus-link.com/u/jacques_za)\
**Post date:** [August 21, 2023, 1:15pm UTC](https://forum.cirrus-link.com/t/sending-mqtt-protobuf-via-script/104/3 "2023-08-21T13:15:45Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![wes.johnson](https://avatars.discourse-cdn.com/v4/letter/w/f14d63/32.png) [@wes.johnson](https://forum.cirrus-link.com/u/wes.johnson)\
**Post date:** [August 21, 2023, 4:28pm UTC](https://forum.cirrus-link.com/t/sending-mqtt-protobuf-via-script/104/4 "2023-08-21T16:28:43Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jacques\_za](https://yyz2.discourse-cdn.com/flex028/user_avatar/forum.cirrus-link.com/jacques_za/32/29_2.png) [@jacques\_za](https://forum.cirrus-link.com/u/jacques_za)\
**Post date:** [August 22, 2023, 6:02am UTC](https://forum.cirrus-link.com/t/sending-mqtt-protobuf-via-script/104/5 "2023-08-22T06:02:21Z")

</div>

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:

```auto
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.

---

<div class="post-metadata">

**Author:** ![wes.johnson](https://avatars.discourse-cdn.com/v4/letter/w/f14d63/32.png) [@wes.johnson](https://forum.cirrus-link.com/u/wes.johnson)\
**Post date:** [August 22, 2023, 3:14pm UTC](https://forum.cirrus-link.com/t/sending-mqtt-protobuf-via-script/104/6 "2023-08-22T15:14:20Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://yyz2.discourse-cdn.com/flex028/user_avatar/forum.cirrus-link.com/justinedwards.jle/32/117_2.png) [@justinedwards.jle](https://forum.cirrus-link.com/u/justinedwards.jle)\
**Post date:** [August 23, 2023, 12:05am UTC](https://forum.cirrus-link.com/t/sending-mqtt-protobuf-via-script/104/7 "2023-08-23T00:05:43Z")

</div>

Cross linking the Ignition Forum thread:

> **[MQTT Sparkplug via Cirruslink MQTT Engine](https://forum.inductiveautomation.com/t/mqtt-sparkplug-via-cirruslink-mqtt-engine/78151?u=justinedwards.jle)**
>
> Hi all, I'm trying to use the function "system.cirruslink.engine.publish()" to publish sparkplug messages back to a gateway. The basic reason for this is that I'm using metadata properties on the tags for various things, and when these are...
