RPI Monitor 1

Description

As has been outlined in the mini project some monitoring functionality shall be implemented on the Raspberry PI (RPI).

Requirements

  • Images shall be captured and stored at regulary time instants using the HQ camera attached to the RPI.
  • The RPI shall observe if new images have been captured/stored. If a remote client program (PC) connects to the RPI the client program shall receive notifications of newly available images. The client can then request the transfer of an image. Additionally the RPI shall emulate a set of sensors. These sensors produce random data either at regular time instants or at randomly selected time instants. (later these fake sensors will be replaced by real sensor). Whenever sensor data become available the client shall be notified by sending a message. The communication between RPI and the client program on a PC shall use websockets.
  • The process of capturing images and observing new images / communication with the client shall be decoupled. These function are each run in separate processes on the RPI.

Implementation

Capturing/Storing Images

Program getImgJpgMulti.py captures images using the HQ camera. The application needs configuration parameters which are provided by a configuration file (json format). The workflow implemented by this program is as follows:

The program initialises the HQ camera and waits for the settings to become stable. Then the cycle of capturing/storing images run repeatedly until the maximum number of images has been reached.

A screenshot shows

Monitoring Events / Interacting with Client

Program monitor_rpi_ws_server.py scans a specific directory on the RPI for new images resulting from another process which runs program getImgJpgMulti.py. Additonally the programs implements some sensors/fake sensors.

The application needs configuration parameters which are provided by a configuration file (json format). The workflow implemented by this program is as follows:

After starting the program a websocket server is started and listens for connection request from clients.

Having successfully connected, the server invokes an asynchronous handler function. The handler function starts the monitoring process:

The content of the directory into which captured images are stored is repeatedly checked. On detection of a new image the client is notified. The client might then decide to send a request to the program to retrieve the image. Independently of this procedure sensor data are produced and the client is notified by messages.

Currently sensors are only emulated (it is planned to add real sensors in future version of this program).

Available (emulated) sensors:

sensordescription
random_datagenerates numerical values at regular intervals values are chosen randomly from a range
pir_sensorgenerates boolean data values `true` or  `false` at randomly distributed time intervals; emulates a PIR sensor where `true` indicates an event occurred
temp_sensorgenerates random temperature value in a given range at regular intervals
light_sensoremulates a light sensor producing numeric values corresponding to the light intenity
(emulated) sensor in program monitor_rpi_ws_server.py

Summary

The monitoring facility which is part of the mini projects requires two programs running on the RPI. For testing purposes these programs can be started from a PC by executing these programs via SSH session. While the programs are running the SSH session persist and binds resources on the RPI. A more elegant solution would be to login via SSH, start programs and exit the SSH session without terminating the programs.

A possible approach is described here.


Resources

Programs getImgJpgMulti.py, monitor_rpi_ws_server.py will be made available on GitHub.

https://github.com/michaelbiester/RPI_MiniProject