Hey, can anybody help here:
Please don't make duplicate topics.
Hi I just created this forum post today. Can you use Python at all? Run a Flask App along side Node Red? BACnet data read, write, release from Node Red via Rest
I am curious if this would help the Node Red community at all... Let me know if I can help out at all. Feel free to submit a git issue on the repo link to the Flask restful bacnet, I can at least help getting someone started out with Python web app. You would just need to make http GET requests from Node Red to the Flask App to get the BACnet data via rest API calls.
Hi ok I can't answer you question directly.
I use the node-red-bacnet node but as you say it's not supported. But Klauss has done a good job of the underlying BACnet node.js node but the node-red (NR) node is limited no COV support ect.
In terms of your approach people have called BACpypes from node-red (NR) using I believe node-red-contrib-pythonshell (node) - Node-RED
In terms of your approach abstracting via a rest API makes sense but I wonder if you would be better off using the pythonshell and start by exposing BACpypes functions. This would be A less work & B much easier for others to pickup if you decided that you couldn't continue to support the project.
I would start with a IP Client with simple read & write then add COV. There are use cases for a Server but building an MSTP client would again make more sense in terms of focus.
I'm happy to help out I've got a dedicated BACnet IP controller on my lab rig and use Yabe room and demo server for testing. I integrate a lot of protocols used in Building Automation modbus/KNX/EnOcean and often use LoRaWAN to send data back to cloud.
Having a industrial strength BACnet solution based on BACpypes would be a significant contribution to the NR eco system.
Hi. Hope you don't mind me saying...
If the underlying bacnet node js implementation is good, I would personally recommend forking & fixing the node-red node before implementing an alternative solution using python.
It's not uncommon for users to have issues with nodes that spawn other processes.
my 2¢
Hi I am interested in learning this.
So can you reiterate this more? I can run Python scripts from Node red and get the BACnet data into Node Red? I am actually still learning Node Red very beginner level with javascript.
I am very familiar with the BAC0 Python package that uses BACpypes under the hood. I also have a test bench in my lab but only an MSTP device.
This is a BAC0 script where I can test out writing and reading BACnet values, could this be used on Node Red directly? I totally agree about the restful interface of just being an extra hassle, but didnt know there is another way!
Can you help me get started using this, the Python shell from Node Red? I think in the past I tinkered around with running Python scripts from Node Red but couldn't figure out how to get the "data" into Node Red.
One additional question now, could you ever run Python scripts from Node Red that handles all of the BACnet "stuff" and then dump that BACnet data into a shared database as node red? Like a post gres SQL or something? Curious about your incite...
Thanks,
Ben
Hi I've never called python from node-red (NR) so sorry can't answer your question. I will have some time later in the wk so will get back to you then.
Yes, with the exec
node
Probably a few ways, but you will have to do some searching/reading
Hi Thanks for your incite if a shared database would be better/easy/more efficient than a restFul API to bridge the gaps from Node Red to Python BACnet stacks.
I have tinkered around with this in the past running Python scripts on a scheduled interval from Node Red where I know I could modify my Python scripts to dump the data into a PostGres DB or something.
Would anyone else in the community have any incite on this? If you needed BACnet data or make commands to BACnet devices. What would you rather do?
Option 1) Make a restful API calls to a Python BACnet app running along side node red?
OR
Option 2) Make Python scripts that can be ran from Node Red where the Python scripts just ingest the BACnet data directly into a shared database.
Where my "thinking" goes on this if someone is looking to collect data, like lots of data on 5 minute intervals option 2 would be the way to go. Whereas if some was only interested in a "control" script / algorithm maybe option 1 would be better if you only need a little bit of data every so often and then make BACnet write commands for your control needs.
All of this stems from needing better BACnet features than what the javascript BACnet libraries could support.
I maybe just have to stick with my Python BAC0 scripts. Its super easy! I couldnt get the javascript BACnet libraries to work for what I needed. I needed to do alot of work on MSTP type networks and when I was researching this the javascript BACnet stacks didnt support MSTP networks, but maybe they do now.
Steve while the underlying nodejs is good for BACnet IP I would have to investigate it's use with MSTP which is just an RS485 protocol. Klaus who wrote the nodejs & nr node has his freetime cut out looking after the Modbus node and I know he doesn't have time for the BACnet node/js.
The thing about the bacpypes python library is it's well used, reliable and maintained. But always welcome your 2¢ and apricate your significant contribution to the eco system
I wouldn't put a shared database in-between you should be able to return the result of the script. I would start with a simple read/write. When using the exec node if your script outputs to the cmd line then the exec node will show that it's fist output.
you would need to create some separate scripts for read, & write. They will need to read from the cmd line so from exec node something like python BACnet_read 192.118.2.1 0 1
so arguments are address, type, instance and assume property is 85 pv.
I would response with JSON {"pv": 20.1, "type"; "analog_input", "error": false }
looking at your script all you need is a single print when operation is complete.
@bbartling Ben I've had a very quick play
using the exec node in the Command field in enter
python3 /home/pi/.node-red/BACnet_read.py 192.168.3.33 analogValue 302
my python code is
import sys
def bacnet_read(rv):
print('{"pv": 20.1, "type": "analog_input", "error": false }')
read_vals = f"{sys.argv[1]} {sys.argv[2]} {sys.argv[3]} presentValue"
check = bacnet_read(read_vals)
#print('add:',sys.argv[1])
#print('type:',sys.argv[2])
#print('instance:',sys.argv[3])
I get "{"pv": 20.1, "type": "analog_input", "error": false }' back on stdout on the first exec node.
sys.argv is an array of command-line arguments. As you can see I just pass them into your read_vals var. I created a simple function to return the a JSON sting this can be passed to create an object that can be used within NR nodes & functions.
This is really interesting.
Is there a way to document this process so others in the community could use this too? I'm actually new to Node Red and it's a little over my head but I can understand the basic concepts.
This may be asking a lot but any chance for a YouTube video on you did this on Node Red? I think a lot of people in the community would get use of this : )
@bbartling Ben most NR users would understand this.
Sorry we don't teach on forum but we help. So what you have a is a straw man from me, I suggest you spend some time getting to know NR this is a brilliant resource https://stevesnoderedguide.com/
I have a wee BACnet project on the back burner for auto discovery via yabe export EDE files and then create a polling system to read PV from ip devices. When I get back to it I will try out BACpypes and then post a flow to do simple read & write.
Happy learning
Sounds good, thank you. Looking forward to seeing the Bacpypes approach.
This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.