Skip to content

Latest commit

 

History

History
73 lines (51 loc) · 3.22 KB

File metadata and controls

73 lines (51 loc) · 3.22 KB

Display text data sent to the broker

Sensor readings and other data sent from the Raspberry Pi are temporarily stored in the Kafka broker on the server. Here is the procedure for running consumer.py, which displays the text data sent to the Kafka broker on the client.

flowchart LR
  subgraph R[Raspberry Pi]
    C(SINETStream)
  end
  subgraph S[Server]
    B[Kafka Broker]
  end
  subgraph V["consumer.py"]
    SUB(SINETStream)
  end
  C-.->B==>SUB
Loading

1. Preparation

1.1. Prerequisites

The following are the prerequisites for running consumer.py.

  • Python
    • Python 3.8 or later

The Kafka broker from which the text data will be retrieved must be available. Please pre-build the Kafka broker with one of the following configurations.

1.2. Library Installation

Install the Python libraries used by consumer.py.

pip install -U --user sinetstream-kafka sinetstream-mqtt

If you get an error because of conflicts with libraries you have already installed, you can use venv or pipenv. Also, the pip command may be pip3 in some environments. Replace it as necessary.

1.3. Configuration Files

In consumer.py, we use the SINETStream library to retrieve sensor data from the Kafka broker. SINETStream requires parameters such as the address of the message brokers to be accessed (brokers), topic name (topic) and type (type) to be described in the configuration file .sinetstream_config.yml. An example of the configuration file is shown below.

sensors:
  topic: sinetstream.sensor
  brokers: kafka.example.org:9092
  type: kafka
  consistency: AT_LEAST_ONCE
  group_id: text-consumer-001

Modify the values of brokers and topic to match your environment. See SINETStream - Configuration File for details on how to write .sinetstream_config.yml, including how to specify other parameters.

An example file of .sinetstream_config.yml can be found in example_sinetstream_config.yml. Use it as a template.

2. Execution

Here is how to specify the command line arguments for consumer.py.

usage: consumer.py [-s <service name>] [-c <config name>]
  -s/--service  Service name
  -c/--config   Config name

-s specifies the service name. The SINETStream configuration file .sinetstream_config.yml can contain multiple parameter sets. The identifier of each parameter set is called the service name in SINETStream. The service name is described as a key in the top-level map of the configuration file. For example, the service name in the example configuration file description example_sinetstream_config.yml in this directory is sensors.

If you want to use a config server without using a local file configuration file, specify the config name with -c.