# 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:** 20\
**Page:** 1

<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:** [November 5, 2020, 8:51pm UTC](https://forum.inductiveautomation.com/t/how-to-get-value-from-rpi-into-igntion/40374/1 "2020-11-05T20:51:54Z")

</div>

I have an rpi and I’ve written a class and python code that will calculate instantaneous flow rate and log flow volumes to a sqlite database, upon getting a rising edge trigger from two flowmeters, where a pulse = 1L or 10L (i have two different flowmeters). The class subscribes to a pin change interrupt and waits for the rising edge to do its thing.

I’m trying to get the instantaneous flow rate value into igntion maker edition running on the Pi, but I’m not sure the best approach. I’m more or less a noob with pi’s/Linux, node red, web tech in general.

Few questions:

1. how should I run my flowmeter script? At the moment, i manually execute the script in the debian terminal… All my attempts to run it automatically on boot have failed… Linux is friggin hard 🙄  
I assume it’s not possible to run in igntion as the rpi libraries are most likely C-based? Also, I want the code running even when igntion isn’t

2. how do I get the value into igntion? Via node-red? If so, how do I write the value from my terminal running script into node-red?

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [November 5, 2020, 10:06pm UTC](https://forum.inductiveautomation.com/t/how-to-get-value-from-rpi-into-igntion/40374/2 "2020-11-05T22:06:29Z")

</div>

To run your script on boot up you can put your command in a shell script

```auto
#! /bin/bash
sleep 10 (optional if you want start delay)
python /path/to/my/script.py

```

you can save this file something like `flowrate.sh`

Then you need to give this file executable permissions

```auto
chmod +x flowrate.sh

```

To run this on boot up add `flowrate.sh` to `/etc/xdg/lxsession/LXDE-pi/autostart`  
add this line `@/path/to/flowrate.sh`

---

<div class="post-metadata">

**Author:** ![mgross](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mgross/32/3311_2.png) [@mgross](https://forum.inductiveautomation.com/u/mgross)\
**Post date:** [November 5, 2020, 10:10pm UTC](https://forum.inductiveautomation.com/t/how-to-get-value-from-rpi-into-igntion/40374/3 "2020-11-05T22:10:20Z")

</div>

You said that all these values are being written to a SQLite database, correct? You should be able to make a SQLite database connection in the Ignition gateway. Then you can query through that connection.

---

<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:** [November 5, 2020, 10:39pm UTC](https://forum.inductiveautomation.com/t/how-to-get-value-from-rpi-into-igntion/40374/4 "2020-11-05T22:39:55Z")

</div>

I store each pulse and the volume of the pulse in the database, yes, but to extract the instantaneous flowrate from that is a bit more involved which is what my class is doing. I also want to pull in the temperature and load of the CPU, RAM, etc. so I’d rather not have to store into the database to get into Ignition. Is it possible using node-red?

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [November 5, 2020, 10:58pm UTC](https://forum.inductiveautomation.com/t/how-to-get-value-from-rpi-into-igntion/40374/5 "2020-11-05T22:58:41Z")

</div>

I haven’t used node red, but Im pretty sure that is how @nader.chinichian did his home automation project

---

<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:** [November 6, 2020, 4:06am UTC](https://forum.inductiveautomation.com/t/how-to-get-value-from-rpi-into-igntion/40374/6 "2020-11-06T04:06:26Z")

</div>

Python support opc ua lib so you can push value to ignition but if I want to do that I write my code in javascript in nodered and then send the value either by opc ua or ignition-nodered module.

---

<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:** [November 6, 2020, 6:52am UTC](https://forum.inductiveautomation.com/t/how-to-get-value-from-rpi-into-igntion/40374/7 "2020-11-06T06:52:52Z")

</div>

I have a python mqtt project I have been working on. It is pretty easy to extend, might fit your use case perfectly. Just have to finish it…

---

<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:** [November 6, 2020, 6:54am UTC](https://forum.inductiveautomation.com/t/how-to-get-value-from-rpi-into-igntion/40374/8 "2020-11-06T06:54:56Z")

</div>

Sounds good! I’m not in any rush, just another home project to do on my endless list 😆

---

<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:** [November 21, 2020, 6:10pm UTC](https://forum.inductiveautomation.com/t/how-to-get-value-from-rpi-into-igntion/40374/9 "2020-11-21T18:10:38Z")

</div>

I use node red and the sparkplug library. I love that the values get quality code and source timestamp. If ur code hangs or ur power goes off, you see it directly. Also you can buffer data with store and forward via an additional edge node if needed.

How did you solve it? Curious 🤓

---

<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:** [November 21, 2020, 8:49pm UTC](https://forum.inductiveautomation.com/t/how-to-get-value-from-rpi-into-igntion/40374/10 "2020-11-21T20:49:48Z")

</div>

I haven’t solved it yet, too busy at work at the moment and haven’t had a chance. I haven’t used node red much at all, but how would I send the instantaneous flow calculated by my python code running in the background (not in ignition) to node red?

---

<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:** [November 22, 2020, 9:56am UTC](https://forum.inductiveautomation.com/t/how-to-get-value-from-rpi-into-igntion/40374/11 "2020-11-22T09:56:42Z")

</div>

Maybe better to use the python code instead of node red then. There are python code and examples in the sparkplug git repo.

I have a fan with a web interface. Someone made a python script to control the fan. Then I just merged that code with the sparkplug code. One has to spent a little time to understand the sparkplug examples of course.

---

<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:** [November 26, 2020, 9:26pm UTC](https://forum.inductiveautomation.com/t/how-to-get-value-from-rpi-into-igntion/40374/12 "2020-11-26T21:26:02Z")

</div>

I had a look again at this last night and found the paho-mqtt library. I got my python script publishing topics / data to my Maker Ignition MQTT Distributor, however the MQTT Engine isn’t picking it up yet… I connected to the Dist. with another MQTT client and could see the topics. Not sure what’s up with the Ignition Engine 🤔 This is all I see:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/4/4/44c3ff1cd5e720ee2a63fbcea0efb9b39076fb6b.png)

First time using MQTT

I followed Steve (or is it Alan? 😁) in order to code the python, if it’s of anyone’s interest:

> **[The Paho MQTT Python Client-Beginners Guide](http://www.steves-internet-guide.com/into-mqtt-python-client/)**
>
> In this tutorial we look at subscribing and publishing using the Paho MQTT Python Client, using an example python script and the online Mosquitto broker.

---

<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:** [November 26, 2020, 9:47pm UTC](https://forum.inductiveautomation.com/t/how-to-get-value-from-rpi-into-igntion/40374/13 "2020-11-26T21:47:48Z")

</div>

If you want to use normal mqtt like that, you have to subscribe to the same topics with the mqtt engine. You do this on the config section under mqtt engine.

Basically you give ur subscription group a name (will give you a tag folder in mqtt engine tag provider) then just add wildcard # or #/ to that group then ALL topics will populate once they are published.

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.

---

<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:** [November 26, 2020, 9:52pm UTC](https://forum.inductiveautomation.com/t/how-to-get-value-from-rpi-into-igntion/40374/14 "2020-11-26T21:52:12Z")

</div>

Cool, i’ll give that a go over the weekend!

Pretty sure i’m using python 3.7. What does sparkplug add to the mix?

Cheers

---

<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:** [November 26, 2020, 10:19pm UTC](https://forum.inductiveautomation.com/t/how-to-get-value-from-rpi-into-igntion/40374/15 "2020-11-26T22:19:35Z")

</div>

You don’t have to worry about a lot of stuff. Like

- birth/death messages.
- If you reboot ignition, ignition will ask your sparkplug node to rebirth.
- automatic population of sparkplug nodes, no need to subscribe.
- quality codes
- timestamps
- online status for both sparkplug nodes and devices.
- keep alive setting (I’m actually a bit struggling with the python code for this)
- data compression
- ++

For all my home devices I put timeouts on them, killing the respective node or device. Giving me disconnection alarms in ignition.

It might be overkill for home automation. But you can take it to work later;)

---

<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:** [November 27, 2020, 12:41am UTC](https://forum.inductiveautomation.com/t/how-to-get-value-from-rpi-into-igntion/40374/16 "2020-11-27T00:41:29Z")

</div>

Sounds much better! I’ll look into it, thanks for the tip

---

<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:** [November 27, 2020, 9:00am UTC](https://forum.inductiveautomation.com/t/how-to-get-value-from-rpi-into-igntion/40374/17 "2020-11-27T09:00:42Z")

</div>

Try sparkplug in nodered first, Its easier to get a quick overview this way. Here is an example can get you going:

> [@Nodered MQTT (sparkplug) flow](http://forum.inductiveautomation.com/t/nodered-mqtt-sparkplug-flow/37066):
>
> Hi, I just wanted to share a fully working sparkplug flow for those of you considering using nodered as an Ignition interface. Here you can test inputs, outputs, DBirth, DDeath, rebirth and probably more… Screenshot: I suggest using NPM and installing sparkplug client first like this: npm install --unsafe-perm sparkplug-client npm install --unsafe-perm node-red-contrib-sparkplug I am not completely sure, but my assumption is that you get the latest sparkplug-client this way. cont…

---

<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 9, 2020, 12:04pm UTC](https://forum.inductiveautomation.com/t/how-to-get-value-from-rpi-into-igntion/40374/18 "2020-12-09T12:04:09Z")

</div>

I’m just getting back to this. When running a script like this on startup:

1. can I run it in a terminal? I print stuff to the terminal so that I know what’s going on. Maybe not the best practice, but it’s all I know
2. how do I know if it’s running? My python script runs indefinitely

---

<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 9, 2020, 12:42pm UTC](https://forum.inductiveautomation.com/t/how-to-get-value-from-rpi-into-igntion/40374/19 "2020-12-09T12:42:21Z")

</div>

Make it a service (Google “systemd.service” and “systemd.unit”).

Script output can be sent to your logs, or you can explicitly call logging functions.

---

<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 11, 2020, 11:19am UTC](https://forum.inductiveautomation.com/t/how-to-get-value-from-rpi-into-igntion/40374/20 "2020-12-11T11:19:39Z")

</div>

> [@dkhayes117](#):
>
> `etc/xdg/lxsession/LXDE-pi/autostart`

I'm trying to use sparkplug, looking at the example on git [here](https://github.com/eclipse/tahu/tree/master/sparkplug_b/raspberry_pi_examples/python) and [here](https://docs.chariot.io/display/CLD79/B:+Example+Python+Client), but they seem to have errors in them (all the print statements use `print "hello"` instead of `print("hello")` - still not sure why Ignition's Jython uses the former and any Python I write outside of Ignition needs brackets) and they always complain that the library `sparkplug_b` is missing. I don't know how to install it though. There's a 'sparkplug' library included in pip, but it doesn't seem to have the B spec. I have no idea how to install B...

This is what the official Cirrus Link guide says:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/0/c/0ceabbf06d21941a77eb2c50e7f0e6e0249ef134.png)

Clearly they're not the only dependencies though if these are the imports:

```python
import sys
import paho.mqtt.client as mqtt
import pibrella
import sparkplug_b as sparkplug
import time
import random
import subprocess

```

The second link guide also has no mention of which version of Python they wrote the example in 😕

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