How to get value from rpi into Igntion

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 :roll_eyes:
    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?

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

#! /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

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

1 Like

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.

1 Like

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?

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

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.

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…

2 Likes

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

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 :nerd_face:

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?

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.

1 Like

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 :thinking: This is all I see:
image

First time using MQTT

I followed Steve (or is it Alan? :grin:) in order to code the python, if it’s of anyone’s interest:
http://www.steves-internet-guide.com/into-mqtt-python-client/

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.

1 Like

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

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;)

1 Like

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

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

1 Like