Skip to content

Commit bc3cca0

Browse files
mod: Modified common-service.md
Modified common-service.md as PR: intel-retail/automated-self-checkout#684 has modifications
1 parent 961f972 commit bc3cca0

1 file changed

Lines changed: 66 additions & 48 deletions

File tree

Lines changed: 66 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,31 @@
1-
# Common Service: LiDAR & Weight Sensor Microservice
2-
This microservice manages **both LiDAR and Weight sensors** in a single container. It publishes sensor data over **MQTT** , **Kafka** , or **HTTP** (or any combination), controlled entirely by environment variables.
3-
4-
## Overview
1+
# Common-Service: LiDAR & Weight Sensor Microservice
2+
This microservice manages **Barcode, LiDAR, and Weight sensors** in a single container. It publishes sensor data over **MQTT** , **Kafka** , or **HTTP** (or any combination), controlled entirely by environment variables.
3+
## 1. Overview
54

65
- **Sensors**
7-
- LiDAR & Weight support in the same codebase.
6+
- Barcode, LiDAR, & Weight support in the same codebase.
87

9-
- Configuration for each sensor (e.g., ID, port, mock mode, intervals).
8+
- Configuration for each sensor (e.g., ID, port, mock mode, intervals).
109

1110
- **Publishing**
12-
- `publisher.py` handles publishing to one or more protocols:
13-
- **MQTT**
14-
15-
- **Kafka**
16-
17-
- **HTTP**
11+
- `publisher.py` handles publishing to one or more protocols:
12+
- **MQTT**
13+
14+
- **Kafka**
15+
16+
- **HTTP**
1817

1918
- **Apps**
20-
- Two main modules:
21-
- `lidar_app.py`
22-
23-
- `weight_app.py`
19+
- Three main modules:
20+
- `barcode_app.py`
21+
22+
- `lidar_app.py`
2423

25-
- Each uses shared methods from `publisher.py` & `config.py`.
24+
- `weight_app.py`
25+
26+
- Each uses shared methods from `publisher.py` & `config.py`.
2627

27-
## Environment Variables
28+
## 2. Environment Variables
2829
All settings are defined in `docker-compose.yml` under the `asc_common_service` section. Key variables include:
2930
### LiDAR
3031
| Variable | Description | Example |
@@ -60,29 +61,46 @@ All settings are defined in `docker-compose.yml` under the `asc_common_service`
6061
| WEIGHT_PUBLISH_INTERVAL | Interval (in seconds) for Weight data publishing | 1.0 |
6162
| WEIGHT_LOG_LEVEL | Logging level (DEBUG, INFO, etc.) | INFO |
6263

64+
### Barcode
65+
| Variable | Description | Example |
66+
| --- | --- | --- |
67+
| BARCODE_COUNT | Number of Barcode sensors | 2 |
68+
| BARCODE_SENSOR_ID_1 | Unique ID for first Barcode sensor | barcode-001 |
69+
| BARCODE_SENSOR_ID_2 | Unique ID for second Barcode sensor (if any) | barcode-002 |
70+
| BARCODE_MOCK_1 | Enable mock data for first Barcode sensor (true/false) | true |
71+
| BARCODE_MQTT_ENABLE | Toggle MQTT publishing | true |
72+
| BARCODE_MQTT_BROKER_HOST | MQTT broker host | mqtt-broker_1 |
73+
| BARCODE_MQTT_BROKER_PORT | MQTT broker port | 1883 |
74+
| BARCODE_KAFKA_ENABLE | Toggle Kafka publishing | false |
75+
| BARCODE_MQTT_TOPIC | MQTT topic name for Barcode data | barcode/data |
76+
| BARCODE_HTTP_ENABLE | Toggle HTTP publishing | false |
77+
| BARCODE_PUBLISH_INTERVAL | Interval (in seconds) for Barcode data publishing | 1.0 |
78+
| BARCODE_LOG_LEVEL | Logging level (DEBUG, INFO, etc.) | INFO |
79+
6380
> **Note:** Change `"true"` or `"false"` to enable or disable each protocol. Adjust intervals, logging levels, or sensor counts as needed.
64-
## Usage
81+
## 3. Usage
6582

6683
1. **Build and Run**
6784

68-
```bash
69-
make run-demo
70-
```
71-
This spins up the `asc_common_service` container (and related services like Mosquitto or Kafka, depending on your configuration).
85+
```bash
86+
make build-sensors
87+
make run-sensors
88+
```
89+
This spins up the `asc_common_service` container (and related services like Mosquitto or Kafka, depending on your configuration).
7290

7391
2. **Data Flow**
74-
- By default, LiDAR publishes to `lidar/data` (MQTT, if enabled) or `lidar-data` (Kafka), or an HTTP endpoint if configured.
92+
- By default, LiDAR publishes to `lidar/data` (MQTT, if enabled) or `lidar-data` (Kafka), or an HTTP endpoint if configured.
7593

76-
- Weight sensor similarly publishes to `weight/data` or `weight-data`.
94+
- Weight sensor similarly publishes to `weight/data` or `weight-data`.
7795

7896
3. **Mock Mode**
79-
- Setting `LIDAR_MOCK_1="true"` (or `WEIGHT_MOCK_1="true"`) forces the sensor to generate **random** data rather than reading from actual hardware.
97+
- Setting `LIDAR_MOCK_1="true"` (or `WEIGHT_MOCK_1="true"`) forces the sensor to generate **random** data rather than reading from actual hardware.
8098

81-
## Testing
99+
## 4. Testing
82100

83101
### A. MQTT
84102

85-
- **Grafana** : A pre-loaded dashboard named *Sensor-Analytics* is available at [http://localhost:3000](http://localhost:3000/) (default credentials `admin`/`admin`).
103+
- **Grafana** : A pre-loaded dashboard named *Retail Analytics Dashboard* is available at [http://localhost:3000](http://localhost:3000/) (default credentials `admin`/`admin`).
86104

87105
- Check that the MQTT data source in Grafana points to `tcp://mqtt-broker_1:1883` (or `tcp://mqtt-broker:1883`, depending on the network).
88106

@@ -92,38 +110,38 @@ All settings are defined in `docker-compose.yml` under the `asc_common_service`
92110

93111
- Test from inside the container:
94112

95-
```bash
96-
docker exec asc_common_service python kafka_publisher_test.py --topic lidar-data
97-
```
98-
You should see incoming messages in the console.
113+
```bash
114+
docker exec asc_common_service python kafka_publisher_test.py --topic lidar-data
115+
```
116+
You should see incoming messages in the console.
99117

100118
### C. HTTP
101119

102-
1️. **Local Test (Inside Docker)**
120+
1️ **Local Test (Inside Docker)**
103121

104-
- Set `LIDAR_HTTP_URL="http://localhost:5000/api/lidar_data"` in the environment.
105-
- Run `make run-demo` and wait for all containers to start.
106-
- Once up, execute:
122+
- Set `LIDAR_HTTP_URL="http://localhost:5000/api/lidar_data"` in the environment.
123+
- Run `make run-sensors` and wait for all containers to start.
124+
- Once up, execute:
107125

108-
```bash
109-
docker exec asc_common_service python http_publisher_test.py
110-
```
126+
```bash
127+
docker exec asc_common_service python http_publisher_test.py
128+
```
111129

112-
- This will trigger the HTTP publisher and display the received data inside the container.
130+
- This will trigger the HTTP publisher and display the received data inside the container.
113131

114-
2️. **Using an External Webhook Service**
132+
2️ **Using an External Webhook Service**
115133

116-
- Visit [Webhook.site](https://webhook.site/) and get a unique URL.
117-
- Set `LIDAR_HTTP_URL` to this URL.
118-
- Run `make run-demo`, and you should see the HTTP requests arriving on the Webhook.site dashboard.
134+
- Visit [Webhook.site](https://webhook.site/) and get a unique URL.
135+
- Set `LIDAR_HTTP_URL` to this URL.
136+
- Run `make run-sensors`, and you should see the HTTP requests arriving on the Webhook.site dashboard.
119137

120138

121139

122-
## Contributing & Development
140+
## 5. Contributing & Development
123141

124142
- **Code Structure**
125-
- `publisher.py`: Core publishing logic (MQTT, Kafka, HTTP).
143+
- `publisher.py`: Core publishing logic (MQTT, Kafka, HTTP).
126144

127-
- `config.py`: Loads environment variables and configures each sensor.
145+
- `config.py`: Loads environment variables and configures each sensor.
128146

129-
- `lidar_app.py` and `weight_app.py`: Sensor-specific logic.
147+
- `barcode_app.py`, `lidar_app.py`, and `weight_app.py`: Sensor-specific logic.

0 commit comments

Comments
 (0)