Package: gridworks-proactor
Gridworks ProactorThis packages provides "live actor" and "application monitored communication" infrastructure for theGridWorks SpaceHeat SCADAproject. This separation
allows the scada code to be more focussed on on application specific details and provides the potential to re-use the
"live actor" and "application monitored" infrastructure.Features, a single threaded event loop running on asyncio, for exchanging messages between the main application
object, "live actor" subobjects and MQTT clients.Acommunication state("active" or not) for each external communications link is available to the proactor and
sub-objects. "Active" communications is defined as ALL of the following:The underlying communications mechanism (MQTT) is connected.All input channels of underlying mechanism (MQTT topics) are established.A application messages requiring acknowledgement have been ACKed in timely fashion (by default 5 seconds).A message has been received "recently" (by default within 1 minute).Reliable delievery of "Events" generated locally. Generated Events are stored locally until they are acknowledged
and unacknowledged Events are retransmitted when the "Active" communication state is restored., a test package for development and test environments of projects that implement a class derived
from, allowing the derived class to be tested with the base-class tests.RequirementsMosquittoTesting requires an MQTT broker. The Mosquitto broker can be installed with:brewinstallmosquitto
brewservicesrestartmosquittoTLSTesting uses TLS by default. The tests require the path to the CA certificate and private key used to sign the certificate
of the MQTT broker. To set up TLS:Install gridworks-cert (gwcert):pipxinstallgridworks-certCreate a local Certificate Authority:gwcertcacreateCreate certificate and key for the Mosquitto MQTT broker:gwcertkeyadd--dnslocalhostmosquittoNOTE: This command will generate a broker certificate thatonlyallow connections tolocalhost. SeeExternal connectionsbelow to create a broker certificate which can accept connections from
external devices.Find the path tomosquitto.confin the output of:brewservicesinfomosquitto-vModifymosquitto.confwith the TLS configuration inexample-test-mosquitto.conf, fixing up the paths with real
absolute paths to certificate, key and CA certificate files. These paths can be found with:gwcertcainfoRestart the Mosquitto server:brewservicesrestartmosquittoTest Mosquitto 'clear' port:# in one windowmosquitto_sub-hlocalhost-p1883-tfoo# in another windowmosquitto_pub-hlocalhost-p1883-tfoo-m'{"bla":1}'Test Mosquitto TLS port:gwcertkeyaddpubsub# in one windowmosquitto_sub-hlocalhost-p8883-tfoo\--cafile$HOME/.local/share/gridworks/ca/ca.crt\--cert$HOME/.local/share/gridworks/ca/certs/pubsub/pubsub.crt\--key$HOME/.local/share/gridworks/ca/certs/pubsub/private/pubsub.pem# in another windowmosquitto_pub-hlocalhost-p8883-tfoo\--cafile$HOME/.local/share/gridworks/ca/ca.crt\--cert$HOME/.local/share/gridworks/ca/certs/pubsub/pubsub.crt\--key$HOME/.local/share/gridworks/ca/certs/pubsub/private/pubsub.pem\-m'{"bar":1}'Troubleshooting MosquittoMosquitto logging can be enabled in themosquitto.conffile with the lines:log_dest stderr
log_type allTo see the console output, stop the Mosquitto service and start it explicitly on the command line:brewservicesstopmosquitto
mosquitto-c/opt/homebrew/etc/mosquitto/mosquitto.confExternal connectionsThe broker certificate must be created with thehostnamethe client will use to connect to it. For example, to create
a broker certificate reachable atlocalhost,MyMac.local,192.168.1.10andfoo.bar.bazuse the command:gwcertkeyadd\--dnslocalhost\--dnsMyMac.local\--dns192.168.1.10\--dnsfoo.bar.baz\mosquittoPre-existing key filesIf CA or Mosquito certificate can key filesalreadyexist, their paths can be specified inmosquitto.confas above and
for the tests with there GWPROACTOR_TEST_CA_CERT_PATH and GWPROACTOR_TEST_CA_KEY_PATH environment variables.Disabling TLSTo disable testing of TLS, modify the the filetests/.env-gwproactor-testwith:GWCHILD_PARENT_MQTT__TLS__USE_TLS=false
GWPARENT_CHILD_MQTT__TLS__USE_TLS=falseInstallationYou can installGridworks ProactorviapipfromPyPI:$pipinstallgridworks-proactorContributingContributions are very welcome. In order to develop, do this:$poetryinstall--all-extrasTo learn more, see theContributor Guide.LicenseDistributed under the terms of theMIT license,Gridworks Proactoris free and open source software.IssuesIf you encounter any problems,
pleasefile an issuealong with a detailed description.CreditsThis project was generated from@cjolowicz'sHypermodern Python Cookiecuttertemplate.