app/main.py file inside the dep-ppl-app repository. This
script handles the NATS connection to the PPL controller, sets up logging, and runs a continuous control loop where you
implement your custom logic.
You should edit this file directly to build your application. As your application grows, you can create additional modules
and a full folder structure inside the app folder to organize your code.
The Main Script
Below is the defaultmain.py script included in the repository:
app/main.py
How It Works
The script does the following:- Loads environment variables from the
.envfile (IP_ADDRESS,NATS_USERNAME,NATS_PASSWORD). - Sets up logging to both the console and a file (
app.login the project root). - Connects to the controller using the
pplappmodule. - Runs a continuous control loop that calls the
ems()function at a configurable interval. - Handles errors gracefully — exceptions in the loop are logged without crashing the application, and a keyboard interrupt triggers a clean shutdown.
ems() function is where you implement your custom logic. The app parameter gives you access to all pplapp
module functions for reading data from and sending commands to the controller.
Extending Your Application
Theapp folder is your workspace. As your application grows beyond a single file, you can create a full folder structure
inside it. For example:
App Folder Structure
main.py and call them from the ems() function. This keeps your code modular and maintainable.