# How to get value from rpi into Igntion

**URL:** <https://forum.inductiveautomation.com/t/how-to-get-value-from-rpi-into-igntion/40374>\
**Category:** Maker\
**Created:** [November 5, 2020, 8:51pm UTC](https://forum.inductiveautomation.com/t/how-to-get-value-from-rpi-into-igntion/40374 "2020-11-05T20:51:54Z")\
**Posts on this page:** 18\
**Page:** 2

<div class="post-metadata">

**Author:** ![tordvd](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/tordvd/32/11525_2.png) [@tordvd](https://forum.inductiveautomation.com/u/tordvd)\
**Post date:** [December 11, 2020, 12:51pm UTC](https://forum.inductiveautomation.com/t/how-to-get-value-from-rpi-into-igntion/40374/21 "2020-12-11T12:51:29Z")

</div>

Hi the examples from git are python v2.9 i think.

> [@tordvd](#):
>
> When you get that to work, you should try the sparkplug example. If ur running python 3.5 I can send you an 3.5 modified sparkplug library.

You have to go through all the code and search replace the print statements and give them brackets.

From my requirements.txt :

```auto
paho-mqtt==1.5.1
protobuf==3.13.0

```

From my sparkplug code:

```auto
  

import sys
sys.path.insert(0, "tahu_python3/client_libraries/python/")
#print(sys.path)

import paho.mqtt.client as mqtt
import sparkplug_b as sparkplug
import time
import random
import string

from sparkplug_b import *

```

As you can see i have renamed the sparkplug lib `tahu_python3` after i did the search replace

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [December 12, 2020, 9:05pm UTC](https://forum.inductiveautomation.com/t/how-to-get-value-from-rpi-into-igntion/40374/22 "2020-12-12T21:05:45Z")

</div>

> [@Kyle\_Chase](#):
>
> I have a python mqtt project I have been working on

Hey Kyle, were you using sparkplug B, any luck you've had a chance to finish this off? I got the sparkplug B client working, but there's a bit involved to get it into a user-friendly state!

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [December 12, 2020, 9:07pm UTC](https://forum.inductiveautomation.com/t/how-to-get-value-from-rpi-into-igntion/40374/23 "2020-12-12T21:07:45Z")

</div>

Sweet, I got the example working. Turns out I was 1) using an older library version and 2) didn’t realise the library was in the client\_libraries folder. Cheers! As I said to Kyle, there’s a bit involved to convert this into a user-friendly library to use on generic projects 😕

---

<div class="post-metadata">

**Author:** ![tordvd](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/tordvd/32/11525_2.png) [@tordvd](https://forum.inductiveautomation.com/u/tordvd)\
**Post date:** [December 14, 2020, 7:50am UTC](https://forum.inductiveautomation.com/t/how-to-get-value-from-rpi-into-igntion/40374/24 "2020-12-14T07:50:41Z")

</div>

Nice!  
I agree with that. I find node-red to be more user friendly that way, but node-red is not always applicable.

Im currently struggling a bit with the Python library regarding death messages. If you disconnect your client, are the data in Ignition marked as “Stale”?

---

<div class="post-metadata">

**Author:** ![nader.chinichian](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nader.chinichian/32/9261_2.png) [@nader.chinichian](https://forum.inductiveautomation.com/u/nader.chinichian)\
**Post date:** [December 15, 2020, 4:38am UTC](https://forum.inductiveautomation.com/t/how-to-get-value-from-rpi-into-igntion/40374/25 "2020-12-15T04:38:29Z")

</div>

Is anyone mange to read gpio from python script in ignition itself?

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [December 15, 2020, 1:07pm UTC](https://forum.inductiveautomation.com/t/how-to-get-value-from-rpi-into-igntion/40374/26 "2020-12-15T13:07:11Z")

</div>

Jython cannot load the shared libraries that provide full access to the GPIO pins. The `pigpiod` service is your best bet, but no-one has taken the time to test/deploy in jython yet.

> [@Maker and Rasbery pi & Jetson nano GPIO access](http://forum.inductiveautomation.com/t/maker-and-rasbery-pi-jetson-nano-gpio-access/36344/2):
>
> I recommend running the [pigpiod](https://github.com/joan2937/pigpio) daemon and connecting to its socket interface from a long-lived asynchronous thread. The client-side python module for that project looks jython-compatible, but you might want to optimize it. Python’s socket module is notoriously laggy in jython.

---

<div class="post-metadata">

**Author:** ![Kyle\_Chase](https://avatars.discourse-cdn.com/v4/letter/k/9de0a6/32.png) [@Kyle\_Chase](https://forum.inductiveautomation.com/u/Kyle_Chase)\
**Post date:** [December 17, 2020, 3:12am UTC](https://forum.inductiveautomation.com/t/how-to-get-value-from-rpi-into-igntion/40374/27 "2020-12-17T03:12:30Z")

</div>

I am using Sparkplug B, let’s get a time to sync up today or tomorrow and I’ll work on getting it up to GH eventually. Not comfortable posting it yet, but can get you access.

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [December 18, 2020, 12:06am UTC](https://forum.inductiveautomation.com/t/how-to-get-value-from-rpi-into-igntion/40374/28 "2020-12-18T00:06:20Z")

</div>

Sounds great, cheers 🙂

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [December 20, 2020, 9:14am UTC](https://forum.inductiveautomation.com/t/how-to-get-value-from-rpi-into-igntion/40374/29 "2020-12-20T09:14:06Z")

</div>

> [@tordvd](#):
>
> Im currently struggling a bit with the Python library regarding death messages. If you disconnect your client, are the data in Ignition marked as “Stale”?

Yes, my tags do turn Bad\_Stale when the client disconnects.

I'm having some issues with it connecting if Ignition isn't running before the MQTT client is running, or if Ignition drops out and loses connection to the MQTT client (such as stopping the Distributor module and restarting or disabling/re-enabling it). When I go to publish my new values, i'm looking at the return value and checking if the QOS is 4 (bad??) and then issuing a `client.reconnect()`. This reconnects the client, as evidenced by the QOS ret from the publish now = 0, but Ignition's tags are not getting updated anymore and quality is stale 😕

Edit: I had to issue a `client.disconnect()` first and then re-establish the whole connection with `startMQTTClient()`. client.reconnect() appears not to work..

---

<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:** [December 21, 2020, 2:13pm UTC](https://forum.inductiveautomation.com/t/how-to-get-value-from-rpi-into-igntion/40374/30 "2020-12-21T14:13:53Z")

</div>

Feel free ask me any questions about the Sparkplug specification and specifically how Ignition MQTT Engine behaves when you throw weird corner case messages at it. I’ve intentionally and unintentionally done a lot of non-standard things and then had to analyze the results while working on our product.

---

<div class="post-metadata">

**Author:** ![tordvd](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/tordvd/32/11525_2.png) [@tordvd](https://forum.inductiveautomation.com/u/tordvd)\
**Post date:** [December 21, 2020, 6:18pm UTC](https://forum.inductiveautomation.com/t/how-to-get-value-from-rpi-into-igntion/40374/31 "2020-12-21T18:18:27Z")

</div>

Ignition sends out rebirth messages to nodes that its missing info about. Are you sure you cannot just rebirth, instead of reconnecting.

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [December 21, 2020, 7:54pm UTC](https://forum.inductiveautomation.com/t/how-to-get-value-from-rpi-into-igntion/40374/32 "2020-12-21T19:54:32Z")

</div>

When you say it sends out rebirth messages, how does the spark plug b client code handle that? Is that in an event callback function somewhere?  
I’m having lots of issues atm. Ignition will be happy and receiving data from the mqtt client, and then some time later it’ll just stop getting data. Not sure why…

---

<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:** [December 21, 2020, 8:32pm UTC](https://forum.inductiveautomation.com/t/how-to-get-value-from-rpi-into-igntion/40374/33 "2020-12-21T20:32:43Z")

</div>

MQTT Engine will send an NCMD message to a tag named “Node Control/Rebirth” and it’s up to each client to how it implements the NCMD handler for that tag. You’ll need to add a `on_message` handler for Paho and have that call something like this:

```auto
def _mqtt_on_message(client, userdata, message):
	mqtt_logger.debug('RX topic=%s bytes=%d',message.topic,len(message.payload))
	if message.topic.startswith('spBv1.0/'):
		rx_payload = sparkplug_b_pb2.Payload()
		rx_payload.ParseFromString(message.payload)
		# TODO - Add your custom payload handler here
	else:
		logger.info('Unexpected message on topic %s',message.topic)

```

The sample client libraries in Tahu are a bit more minimal than most people would like right now. I know there’s some effort within the Eclipse team to improve that, but it may be a while. ☹  
This also presumes you’ve already subscribed to an appropriate MQTT topic to receive NCMD messages back to your device.

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [December 22, 2020, 12:16pm UTC](https://forum.inductiveautomation.com/t/how-to-get-value-from-rpi-into-igntion/40374/34 "2020-12-22T12:16:54Z")

</div>

> [@justin.brzozoski](#):
>
> The sample client libraries in Tahu are a bit more minimal than most people would like right now.

You got that right! I might have to give up on this for a bit as I just don't have the time to mess around with it. I've already got a webserver on my pi working and publishing the flows and a bunch of other stuff, so that'll have to do for now 😔

Thanks for the input though. If I get time i'll have a look and see what I need to do to fix it using the on\_message handler. I reckon I saw a function defined already, not sure what's in it though.

---

<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:** [January 7, 2021, 6:33am UTC](https://forum.inductiveautomation.com/t/how-to-get-value-from-rpi-into-igntion/40374/35 "2021-01-07T06:33:01Z")

</div>

Big code drop you might be interested in (specifically the python\_edge\_device branch):

> **[jbrzozoski/tahu](https://github.com/jbrzozoski/tahu/tree/python_edge_device)**
>
> python\_edge\_device

I haven’t done anything to make templates or datasets any easier, but the ability to implement an edge device in Python is vastly improved, all the integer casting works both ways… Take a look at the `standalone_examples/python/example.py` to see what using it looks like now.

For now the Sparkplug management is running in a separate thread, although I could make that be a callable function like the paho library does with MQTT.

If I have time to keep pushing this forward I will likely start a pull request with the official tahu maintainers, but … I changed a LOT.

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [March 20, 2021, 11:56pm UTC](https://forum.inductiveautomation.com/t/how-to-get-value-from-rpi-into-igntion/40374/36 "2021-03-20T23:56:07Z")

</div>

I ended up giving up and just writing the tag values into a local csv file, then reading that in ignition and setting the tag values. Super simple and it works 100%. I don’t have free time these days, so couldn’t look any more into other libraries 🙁

---

<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:** [March 23, 2021, 1:39pm UTC](https://forum.inductiveautomation.com/t/how-to-get-value-from-rpi-into-igntion/40374/37 "2021-03-23T13:39:19Z")

</div>

Is your code up on github or anywhere? I’m curious to see how quickly I could get it into Sparkplug, already understanding that side of the problem.

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [April 10, 2021, 11:14am UTC](https://forum.inductiveautomation.com/t/how-to-get-value-from-rpi-into-igntion/40374/38 "2021-04-10T11:14:41Z")

</div>

Sorry for the late reply, my code isn’t up on git and really it would be more trouble than it’s worth - I would just consider that I have a handful of variables that are mostly bools and floats that I need to get into Ignition.  
I’m actually instead looking to use `bottle` to serve my stuff up using restful api calls, with inspiration from Kevin’s [post](http://forum.inductiveautomation.com/t/python-jython-cpython-libraries-pip-and-python-2-7-vs-3-a-quick-primer/43201)

This post is interesting too:

> **[Building a Rest API with the Bottle Framework](https://www.toptal.com/bottle/building-a-rest-api-with-bottle-framework)**
>
> REST APIs are as popular as ever. The Bottle framework is a fast, lightweight Python web framework that makes building REST API services a breeze.
> 
> In this article, Toptal engineer Leandro Lima gives us an in-depth tutorial on how to build a REST API...

[Previous page](https://forum.inductiveautomation.com/t/how-to-get-value-from-rpi-into-igntion/40374.md?page=1)
