Django and pylogix

This is my first django project. I have script that is using pylogix to grab plc data. I would prefer to run this as a seperate script from django and pass the values to my django app to update the pages i have created. The script will grab the plc data every 15 seconds. If someone can point me in the right direction that would be greatly appreciated. How can i send the data from my python script to my django app to store this. I can read the docs but I’m unsure of what route to take.

There are at least three ways you can do this, depending upon what you’re comfortable doing and how you choose to do it.

  • Your script could write directly to the same database and tables that Django uses.

  • Your script could send the data to Django through an API you create.

The third option really is only worth considering if you’re already using Channels, and that would be to have your script write to the channel layer.

Are one of the ways more reliable or less hardware intensive than the others.

What other benefits does using channels have?

For something that only happens once every 15 seconds? Any difference is going to be immaterial.

Channels supports websocket connections with browsers. That would allow the server to push updates to the browser rather than having the browsers poll for updated data. Whether that has any real value depends on other, external factors such as the number of browsers looking to grab the updated data.

Side note: I’ve mentioned a few times here that I’ve got a couple of projects running on a Raspberry Pi (or other SBCs of a similar class), with one project that reads from, and writes data to, an Arduino-based system. The Pi handles these projects with no problem at all.