# Issuing NCMD/DCMD commands in Ignition

**URL:** <https://forum.inductiveautomation.com/t/issuing-ncmd-dcmd-commands-in-ignition/40136>\
**Category:** Ignition\
**Created:** [October 29, 2020, 3:11pm UTC](https://forum.inductiveautomation.com/t/issuing-ncmd-dcmd-commands-in-ignition/40136 "2020-10-29T15:11:23Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![aamrc](https://avatars.discourse-cdn.com/v4/letter/a/dfb087/32.png) [@aamrc](https://forum.inductiveautomation.com/u/aamrc)\
**Post date:** [October 29, 2020, 3:11pm UTC](https://forum.inductiveautomation.com/t/issuing-ncmd-dcmd-commands-in-ignition/40136/1 "2020-10-29T15:11:23Z")

</div>

Hi,

What is the best method for issuing Sparkplug `NCMD` and `DCMD` commands using Ignition scripting?

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [October 29, 2020, 3:16pm UTC](https://forum.inductiveautomation.com/t/issuing-ncmd-dcmd-commands-in-ignition/40136/2 "2020-10-29T15:16:29Z")

</div>

These are typically issued by the Sparkplug module providing the tags in Ignition in response to things like changing an MQTT tag value.

You might be able to use the `system.cirruslink.engine.publish` scripting function to accomplish this.

What are you doing that requires publishing to these topics manually?

---

<div class="post-metadata">

**Author:** ![aamrc](https://avatars.discourse-cdn.com/v4/letter/a/dfb087/32.png) [@aamrc](https://forum.inductiveautomation.com/u/aamrc)\
**Post date:** [October 29, 2020, 3:21pm UTC](https://forum.inductiveautomation.com/t/issuing-ncmd-dcmd-commands-in-ignition/40136/3 "2020-10-29T15:21:13Z")

</div>

Hi Kevin,

The cirruslink command sounds promising, thanks for the prompt response.

My architecture allows any MQTT client to request command execution (through NDATA/DDATA) for another client, but I plan to have ACLs and filter commands using Ignition so it is in control what commands actually get published to NCMD or DCMD

---

<div class="post-metadata">

**Author:** ![aamrc](https://avatars.discourse-cdn.com/v4/letter/a/dfb087/32.png) [@aamrc](https://forum.inductiveautomation.com/u/aamrc)\
**Post date:** [October 30, 2020, 9:17am UTC](https://forum.inductiveautomation.com/t/issuing-ncmd-dcmd-commands-in-ignition/40136/4 "2020-10-30T09:17:55Z")

</div>

Hi Kevin,

Does Ignition allow for Sparkplug Proto Bufs encoding with the `system.cirruslink.engine.publish` method?

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [October 30, 2020, 12:13pm UTC](https://forum.inductiveautomation.com/t/issuing-ncmd-dcmd-commands-in-ignition/40136/5 "2020-10-30T12:13:41Z")

</div>

The payload it accepts is an opaque byte[] but I don’t know if there is anything available to encode one with available on the class path.

Maybe @wes0johnson from Cirrus Link can tell you.

---

<div class="post-metadata">

**Author:** ![wes0johnson](https://avatars.discourse-cdn.com/v4/letter/w/7ab992/32.png) [@wes0johnson](https://forum.inductiveautomation.com/u/wes0johnson)\
**Post date:** [October 31, 2020, 3:36pm UTC](https://forum.inductiveautomation.com/t/issuing-ncmd-dcmd-commands-in-ignition/40136/6 "2020-10-31T15:36:39Z")

</div>

As Kevin noted the publish method will accept any byte[]. So, if you can import the protobuf library and Tahu Python library into the Ignition Python runtime it should work.

---

<div class="post-metadata">

**Author:** ![321liftoff](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/321liftoff/32/27544_2.png) [@321liftoff](https://forum.inductiveautomation.com/u/321liftoff)\
**Post date:** [May 18, 2021, 4:28pm UTC](https://forum.inductiveautomation.com/t/issuing-ncmd-dcmd-commands-in-ignition/40136/7 "2021-05-18T16:28:13Z")

</div>

Sorry to bring up an old thread, but running Ignition 8.1.5 I've done the following:

(1) paste the following files to "C:\Program Files\Inductive Automation\Ignition\user-lib\pylib"  
From here ([https://github.com/eclipse/tahu/tree/master/client\_libraries/python](https://github.com/eclipse/tahu/tree/master/client_libraries/python))

- sparkplug\_b.py
- sparkplug\_b\_pb2.py

from here ([protobuf/python/google at main · protocolbuffers/protobuf · GitHub](https://github.com/protocolbuffers/protobuf/tree/master/python/google))

- google/protobuf/\*

(2) I have a script with the following:

```auto
	import sparkplug_b_pb2

```

Below is the error I get when I run the script:

> File "C:\Program Files\Inductive Automation\Ignition\user-lib\pylib\sparkplug\_b\_pb2.py", line 6, in from google.protobuf import descriptor as \_descriptor File "C:\Program Files\Inductive Automation\Ignition\user-lib\pylib\google\protobuf\descriptor.py", line 39, in import six ImportError: No module named six

Before I go adding various dependencies manually, is there a better way?

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [May 18, 2021, 4:32pm UTC](https://forum.inductiveautomation.com/t/issuing-ncmd-dcmd-commands-in-ignition/40136/8 "2021-05-18T16:32:03Z")

</div>

> [@321liftoff](#):
>
> Before I go adding various dependencies manually, is there a better way?

Better way to do what? This thread was not discussing anything that required trying to use external Python libraries.

---

<div class="post-metadata">

**Author:** ![321liftoff](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/321liftoff/32/27544_2.png) [@321liftoff](https://forum.inductiveautomation.com/u/321liftoff)\
**Post date:** [May 18, 2021, 4:37pm UTC](https://forum.inductiveautomation.com/t/issuing-ncmd-dcmd-commands-in-ignition/40136/9 "2021-05-18T16:37:18Z")

</div>

To issue a NCMD or DCMD correctly (per sparkplug spec), a payload needs to be encoded using protobuf. To help the user scripting, the sparkplug\_b library also helps create the MQTT packet. Per @wes0johnson recommendation above, I am attempting to import these libraries into Ignition for my script.

It looks like google protobuf needs other dependencies (it’s not self-contained?). Hence, my question. For example, there is no “pip” process to grab all the dependencies that are needed?

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [May 18, 2021, 4:39pm UTC](https://forum.inductiveautomation.com/t/issuing-ncmd-dcmd-commands-in-ignition/40136/10 "2021-05-18T16:39:15Z")

</div>

Ah, gotcha… should have read this a little closer. I thought the `system.cirruslink.engine.publish` ending up being the solution here.

I think you actually can pip install into the pylib directory… haven’t tried it myself: [Procedure for installing python libraries from source - #2 by PGriffith](http://forum.inductiveautomation.com/t/procedure-for-installing-python-libraries-from-source/26022/2)

---

<div class="post-metadata">

**Author:** ![321liftoff](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/321liftoff/32/27544_2.png) [@321liftoff](https://forum.inductiveautomation.com/u/321liftoff)\
**Post date:** [May 20, 2021, 1:39am UTC](https://forum.inductiveautomation.com/t/issuing-ncmd-dcmd-commands-in-ignition/40136/11 "2021-05-20T01:39:43Z")

</div>

Below is what I get when I try and install the "protobuf" library.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/1/8/18c4e6284ffc7a8d9ec1d37898406e7464aa8bab.png)

I was able to run the same command using python 2.7 and it worked fine, but I get the following when I use the library that it created:

> File "C:\Program Files\Inductive Automation\Ignition\user-lib\pylib\google\protobuf\internal\decoder.py", line 92, in   
> _SURROGATE\_PATTERN = re.compile(six.u(r'[\ud800-\udfff]'))  
> File "C:\Program Files\Inductive Automation\Ignition\user-lib\pylib\site-packages\six.py", line 674, in u  
> return unicode(s.replace(r'\', r'\\'), "unicode\_escape")  
> File "user-lib\pylib\encodings\_init_.py", line 142, in search\_function  
> raise CodecRegistryError,  
> encodings.CodecRegistryError: incompatible codecs in module "encodings.unicode\_escape" (C:\Program Files\Inductive Automation\Ignition\user-lib\pylib\encodings\unicode\_escape$py.class)

Any suggestions?

---

<div class="post-metadata">

**Author:** ![justin.brzozoski](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justin.brzozoski/32/13452_2.png) [@justin.brzozoski](https://forum.inductiveautomation.com/u/justin.brzozoski)\
**Post date:** [September 9, 2021, 4:36am UTC](https://forum.inductiveautomation.com/t/issuing-ncmd-dcmd-commands-in-ignition/40136/12 "2021-09-09T04:36:45Z")

</div>

The failure to install protobuf via pip is because pip is no longer usable for Jython 2.7. [I was just fighting this earlier this week.](https://forum.inductiveautomation.com/t/python-jython-cpython-libraries-pip-and-python-2-7-vs-3-a-quick-primer/43201/25)

But for the bigger issue of generating NCMD/DCMD from Ignition, writing to the corresponding tag in Ignition has always worked fine for me. I don’t understand why you’re avoiding that and building raw MQTT payloads. Can you walk me through a simple use case flow of events that requires building a raw NCMD?

---

<div class="post-metadata">

**Author:** ![321liftoff](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/321liftoff/32/27544_2.png) [@321liftoff](https://forum.inductiveautomation.com/u/321liftoff)\
**Post date:** [September 9, 2021, 2:20pm UTC](https://forum.inductiveautomation.com/t/issuing-ncmd-dcmd-commands-in-ignition/40136/13 "2021-09-09T14:20:59Z")

</div>

Thanks Justin.

I suppose the original post was not making use of the additional MQTT Engine.

For my case, I didn’t realize that modifying a tag within Ignition’s MQTT Engine would translate to an NCMD being generated and sent. Going that route works for my use-case.

---

<div class="post-metadata">

**Author:** ![321liftoff](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/321liftoff/32/27544_2.png) [@321liftoff](https://forum.inductiveautomation.com/u/321liftoff)\
**Post date:** [September 9, 2021, 2:22pm UTC](https://forum.inductiveautomation.com/t/issuing-ncmd-dcmd-commands-in-ignition/40136/14 "2021-09-09T14:22:24Z")

</div>

By the way, it’s good to note that this feature of writing to a node is disabled by default within the MQTT Engine configuration:

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/7/b/7b6cab971db18c81a589d583a9b8ef65df30147f.png)
