## Edge application This is a Python application that runs on the Edge device. It connects all the components together and is reponsible for the loop that reads the sensors data, prepare the data, invoke the ML model and report back to the cloud metrics and logs. This is the reference architecture of this application: ![Application Architecture](/imgs/app_architecture.png) As you can see, the application has some Python modules responsible for: - **run.py**: main application that launches all the other components - **EdgeAgentClient**: client that communicates with SageMaker Edge Agent, using protobuf/grpc - **AgentStubs**: Python stubs generated by the protobuf compiler - **Logger**: module responsible for buffering application logs and then sending this data to the cloud via MQTT - **OTAModelUpdate**: module that subscribes to special MQTT topics, gets notifications of new models and deploys the models to the edge device ### Running the application You can run this application manually or using the bash scripts that start/stop the agent and the application. **Manual execution** ```bash $ ./run.py -h usage: run.py [-h] [--test-mode] [--inject-noise] [--debug] [--agent-socket AGENT_SOCKET] [--model-path MODEL_PATH] [--serial-port SERIAL_PORT] [--serial-baud SERIAL_BAUD] [--sagemaker-edge-configfile-path SAGEMAKER_EDGE_CONFIGFILE_PATH] optional arguments: -h, --help show this help message and exit --test-mode Use a dummy file as sensors readings --inject-noise Add random noise to the raw data --debug Enable debugging messages --agent-socket AGENT_SOCKET The unix socket path created by the agent --model-path MODEL_PATH Absolute path to the model dir --serial-port SERIAL_PORT Path to the USB port used by the wind turbine --serial-baud SERIAL_BAUD Serial comm. speed in bits per second --sagemaker-edge-configfile-path SAGEMAKER_EDGE_CONFIGFILE_PATH Path to the agent config file ``` All the parameters are optional. By default, it will use an env var **SM_EDGE_AGENT_HOME** that points to the dir where you installed SageMaker Edge Agent. Test mode: if you pass **--test-mode** the application will download a dummy file and use it as the sensors readings. You don't need the real wind turbines connected to the edge device in this mode. **Bash scripts** - [app_start.sh](/04_EdgeApplication/scripts/app_start.sh): initialize two background processes; one for the agent and another for the application. You can also invoke this script to make sure your application is still running. It checks a **PID** file to see if the processes are running; - [app_stop.sh](/04_EdgeApplication/scripts/app_stop.sh): kills both processes; the agent and the app. ## Reports/dashboards [Find here](/04_EdgeApplication/report) instructions to plug your wind turbine farm application to a report tool. You'll see how to use Elastisearch/Kibana or AWS CloudWatch to visualize anomalies and other info related to your turbines.