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:
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
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?
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.
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?
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 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.
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.
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:
First time using MQTT
I followed Steve (or is it Alan? ) in order to code the python, if it’s of anyone’s interest:
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.
I'm trying to use sparkplug, looking at the example on git here and here, 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:
Clearly they're not the only dependencies though if these are the imports:
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