tagscope 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- tagscope-0.1.0/.gitignore +16 -0
- tagscope-0.1.0/CHANGELOG.md +18 -0
- tagscope-0.1.0/LICENSE +21 -0
- tagscope-0.1.0/PKG-INFO +207 -0
- tagscope-0.1.0/README.md +165 -0
- tagscope-0.1.0/examples/postgres.yaml +15 -0
- tagscope-0.1.0/examples/siemens-s7-1500.yaml +33 -0
- tagscope-0.1.0/pyproject.toml +69 -0
- tagscope-0.1.0/src/tagscope/__init__.py +5 -0
- tagscope-0.1.0/src/tagscope/__main__.py +3 -0
- tagscope-0.1.0/src/tagscope/cli.py +215 -0
- tagscope-0.1.0/src/tagscope/collector.py +154 -0
- tagscope-0.1.0/src/tagscope/config.py +159 -0
- tagscope-0.1.0/src/tagscope/hub.py +148 -0
- tagscope-0.1.0/src/tagscope/simulator.py +175 -0
- tagscope-0.1.0/src/tagscope/static/app.css +219 -0
- tagscope-0.1.0/src/tagscope/static/app.js +469 -0
- tagscope-0.1.0/src/tagscope/static/index.html +87 -0
- tagscope-0.1.0/src/tagscope/static/vendor/uPlot.LICENSE +21 -0
- tagscope-0.1.0/src/tagscope/static/vendor/uPlot.iife.min.js +2 -0
- tagscope-0.1.0/src/tagscope/static/vendor/uPlot.min.css +1 -0
- tagscope-0.1.0/src/tagscope/storage.py +262 -0
- tagscope-0.1.0/src/tagscope/web.py +111 -0
- tagscope-0.1.0/tests/__init__.py +0 -0
- tagscope-0.1.0/tests/conftest.py +40 -0
- tagscope-0.1.0/tests/test_cli.py +40 -0
- tagscope-0.1.0/tests/test_config.py +67 -0
- tagscope-0.1.0/tests/test_hub.py +69 -0
- tagscope-0.1.0/tests/test_live.py +86 -0
- tagscope-0.1.0/tests/test_simulator.py +27 -0
- tagscope-0.1.0/tests/test_storage.py +62 -0
- tagscope-0.1.0/tests/test_web.py +64 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project are documented here. The format follows
|
|
4
|
+
[Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and the project uses
|
|
5
|
+
[Semantic Versioning](https://semver.org/).
|
|
6
|
+
|
|
7
|
+
## [0.1.0] - 2026-11-22
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
- OPC UA subscriptions for any number of servers, with automatic reconnect and back-off.
|
|
11
|
+
- Storage in SQLite (zero config) or PostgreSQL / TimescaleDB through SQLAlchemy.
|
|
12
|
+
- Per-tag deadband, high/low limits with alarm and clear events, retention clean-up.
|
|
13
|
+
- Live dashboard: tag list with search, value cards with sparklines and limit bars,
|
|
14
|
+
multi-tag zoomable trends (5 min to 24 h, server-side downsampling), event log,
|
|
15
|
+
address space browser, CSV export, dark and light themes.
|
|
16
|
+
- REST API (`/api/docs`) and a WebSocket feed (`/ws`).
|
|
17
|
+
- CLI: `tagscope demo`, `run`, `init`, `browse`, `export`.
|
|
18
|
+
- Built-in simulated plant so anyone can try it without hardware.
|
tagscope-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Dan Shinde
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
tagscope-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: tagscope
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Log OPC UA tags to SQLite or PostgreSQL and watch them live in a fast, modern web dashboard.
|
|
5
|
+
Project-URL: Homepage, https://github.com/DanShinde/tagscope
|
|
6
|
+
Project-URL: Issues, https://github.com/DanShinde/tagscope/issues
|
|
7
|
+
Project-URL: Changelog, https://github.com/DanShinde/tagscope/blob/main/CHANGELOG.md
|
|
8
|
+
Author: Dan Shinde
|
|
9
|
+
License-Expression: MIT
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: dashboard,data-logger,historian,iiot,industrial,opc-ua,opcua,plc,scada,siemens
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Environment :: Web Environment
|
|
14
|
+
Classifier: Framework :: AsyncIO
|
|
15
|
+
Classifier: Framework :: FastAPI
|
|
16
|
+
Classifier: Intended Audience :: Developers
|
|
17
|
+
Classifier: Intended Audience :: Manufacturing
|
|
18
|
+
Classifier: Operating System :: OS Independent
|
|
19
|
+
Classifier: Programming Language :: Python :: 3
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
24
|
+
Classifier: Topic :: Scientific/Engineering :: Interface Engine/Protocol Translator
|
|
25
|
+
Classifier: Topic :: System :: Monitoring
|
|
26
|
+
Requires-Python: >=3.10
|
|
27
|
+
Requires-Dist: asyncua>=1.1
|
|
28
|
+
Requires-Dist: fastapi>=0.110
|
|
29
|
+
Requires-Dist: pyyaml>=6.0
|
|
30
|
+
Requires-Dist: sqlalchemy>=2.0
|
|
31
|
+
Requires-Dist: uvicorn>=0.29
|
|
32
|
+
Requires-Dist: websockets>=12
|
|
33
|
+
Provides-Extra: dev
|
|
34
|
+
Requires-Dist: build; extra == 'dev'
|
|
35
|
+
Requires-Dist: httpx>=0.27; extra == 'dev'
|
|
36
|
+
Requires-Dist: pytest-asyncio>=0.23; extra == 'dev'
|
|
37
|
+
Requires-Dist: pytest>=8; extra == 'dev'
|
|
38
|
+
Requires-Dist: ruff>=0.5; extra == 'dev'
|
|
39
|
+
Provides-Extra: postgres
|
|
40
|
+
Requires-Dist: psycopg[binary]>=3.1; extra == 'postgres'
|
|
41
|
+
Description-Content-Type: text/markdown
|
|
42
|
+
|
|
43
|
+
<div align="center">
|
|
44
|
+
|
|
45
|
+
# TagScope
|
|
46
|
+
|
|
47
|
+
**Log OPC UA tags to a database and watch them live in your browser.**
|
|
48
|
+
|
|
49
|
+
A lightweight historian for PLCs and industrial equipment: subscribe to any OPC UA server
|
|
50
|
+
(Siemens S7-1500, Beckhoff, B&R, Kepware, Ignition, Prosys…), store every change in SQLite or
|
|
51
|
+
PostgreSQL, and get a fast, modern dashboard with live values, trends, alarms and CSV export.
|
|
52
|
+
One `pip install`, one YAML file, no cloud.
|
|
53
|
+
|
|
54
|
+
[](https://github.com/DanShinde/tagscope/actions/workflows/ci.yml)
|
|
55
|
+
[](https://pypi.org/project/tagscope/)
|
|
56
|
+
[](https://pypi.org/project/tagscope/)
|
|
57
|
+
[](LICENSE)
|
|
58
|
+
|
|
59
|
+
<img src="docs/demo.gif" alt="TagScope dashboard showing live tag cards, a multi-tag trend and the OPC UA address space browser" width="900">
|
|
60
|
+
|
|
61
|
+
</div>
|
|
62
|
+
|
|
63
|
+
## Try it in 10 seconds
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
pip install tagscope
|
|
67
|
+
tagscope demo
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
`demo` starts a small simulated plant (a buffer tank, a transfer pump that trips now and then,
|
|
71
|
+
a reactor and a filler) as an OPC UA server, logs it to `tagscope-demo.db` and opens the dashboard
|
|
72
|
+
at <http://localhost:8000>. It even pre-fills 30 minutes of history, so the trends look alive
|
|
73
|
+
from the first second.
|
|
74
|
+
|
|
75
|
+
## Why
|
|
76
|
+
|
|
77
|
+
Getting PLC data into a database usually means a commercial historian, a Node-RED flow you have
|
|
78
|
+
to babysit, or a one-off script without a UI. TagScope sits in between:
|
|
79
|
+
|
|
80
|
+
- **Small**: a single Python process, no broker, no separate front-end build.
|
|
81
|
+
- **Honest storage**: plain SQL tables you can query from Grafana, Power BI, Excel or pandas.
|
|
82
|
+
- **Made for the plant floor**: limits and alarms, deadbands, reconnects that just work,
|
|
83
|
+
and a dashboard that follows ISA-101 ideas (calm grey, colour only when something is wrong).
|
|
84
|
+
|
|
85
|
+
## Features
|
|
86
|
+
|
|
87
|
+
| | |
|
|
88
|
+
|---|---|
|
|
89
|
+
| **Collect** | OPC UA subscriptions (not polling) for many servers at once, username/password login, automatic reconnect with back-off, per-tag deadband |
|
|
90
|
+
| **Store** | SQLite out of the box, PostgreSQL / TimescaleDB via `tagscope[postgres]`, retention clean-up, quality flag per sample |
|
|
91
|
+
| **See** | Live value cards with sparklines and limit bars, multi-tag trends with zoom (5 min to 24 h, downsampled server side), event log, dark and light themes, works on a phone |
|
|
92
|
+
| **Alarm** | High / low limits per tag, alarm and clear events with timestamps, active alarm counter |
|
|
93
|
+
| **Explore** | Built-in address space browser: click through the server and copy node ids into your config |
|
|
94
|
+
| **Export** | One click CSV from the dashboard, `tagscope export` from the shell, REST API with OpenAPI docs at `/api/docs`, WebSocket feed at `/ws` |
|
|
95
|
+
|
|
96
|
+
## Use it with your PLC
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
tagscope init # writes an example tagscope.yaml
|
|
100
|
+
tagscope browse opc.tcp://192.168.0.1:4840 # find the node ids you need
|
|
101
|
+
tagscope run tagscope.yaml --open
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
```yaml
|
|
105
|
+
storage: sqlite:///line1.db # or postgresql+psycopg://user:${DB_PASSWORD}@host/db
|
|
106
|
+
retention_days: 90
|
|
107
|
+
|
|
108
|
+
servers:
|
|
109
|
+
- name: line1-plc
|
|
110
|
+
endpoint: opc.tcp://192.168.0.1:4840
|
|
111
|
+
username: ${PLC_USER:-} # values can come from the environment
|
|
112
|
+
password: ${PLC_PASSWORD:-}
|
|
113
|
+
publishing_interval_ms: 500
|
|
114
|
+
tags:
|
|
115
|
+
- name: Mixer/Temperature
|
|
116
|
+
node: ns=3;s="DB_Mixer"."Temperature"
|
|
117
|
+
unit: °C
|
|
118
|
+
low: 20
|
|
119
|
+
high: 85
|
|
120
|
+
deadband: 0.1 # store only changes bigger than this
|
|
121
|
+
- name: Mixer/Running
|
|
122
|
+
node: ns=3;s="DB_Mixer"."Running"
|
|
123
|
+
- ns=3;s="DB_Counters"."Good" # short form: the node id is the name
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
More in [`examples/`](examples), including a Siemens S7-1500 setup and PostgreSQL.
|
|
127
|
+
|
|
128
|
+
> **Siemens tip:** enable the OPC UA server in the PLC properties in TIA Portal and tick
|
|
129
|
+
> *Accessible from HMI/OPC UA* on the data blocks you want to log. Node ids then look like
|
|
130
|
+
> `ns=3;s="DB_Name"."Member"`.
|
|
131
|
+
|
|
132
|
+
## Command line
|
|
133
|
+
|
|
134
|
+
| Command | What it does |
|
|
135
|
+
|---|---|
|
|
136
|
+
| `tagscope demo` | Simulated plant + logger + dashboard, nothing to configure |
|
|
137
|
+
| `tagscope run CONFIG` | Log the servers and tags in a YAML file and serve the dashboard |
|
|
138
|
+
| `tagscope init [PATH]` | Write an example config |
|
|
139
|
+
| `tagscope browse ENDPOINT [NODE]` | List the nodes of a server, with current values |
|
|
140
|
+
| `tagscope export CONFIG --minutes 60 -o out.csv` | Export logged samples |
|
|
141
|
+
|
|
142
|
+
## Data model
|
|
143
|
+
|
|
144
|
+
Three tables, easy to query from anything that speaks SQL:
|
|
145
|
+
|
|
146
|
+
```sql
|
|
147
|
+
SELECT t.name, s.ts, s.value
|
|
148
|
+
FROM tagscope_samples s JOIN tagscope_tags t ON t.id = s.tag_id
|
|
149
|
+
WHERE t.name = 'Mixer/Temperature' AND s.ts > CAST(strftime('%s', 'now', '-1 hour') AS REAL);
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
| Table | Columns |
|
|
153
|
+
|---|---|
|
|
154
|
+
| `tagscope_tags` | `id, name, server, node, unit, description, low, high` |
|
|
155
|
+
| `tagscope_samples` | `tag_id, ts (epoch seconds), value, quality (0 good, 1 uncertain, 2 bad)` |
|
|
156
|
+
| `tagscope_events` | `id, ts, tag, kind (alarm, cleared, info, warning, error), message` |
|
|
157
|
+
|
|
158
|
+
## How it works
|
|
159
|
+
|
|
160
|
+
```mermaid
|
|
161
|
+
flowchart LR
|
|
162
|
+
PLC1[PLC / OPC UA server] -- subscriptions --> C[Collector]
|
|
163
|
+
PLC2[More servers] -- subscriptions --> C
|
|
164
|
+
C --> H[(Live state + alarms)]
|
|
165
|
+
H -- batched writes --> DB[(SQLite / PostgreSQL)]
|
|
166
|
+
H -- WebSocket --> UI[Dashboard]
|
|
167
|
+
DB -- history, CSV --> API[REST API] --> UI
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
Everything runs on one asyncio event loop: asyncua subscriptions feed an in-memory hub,
|
|
171
|
+
which applies deadbands and limits, pushes updates to browsers over a WebSocket and hands
|
|
172
|
+
batches to a writer that flushes to the database once a second.
|
|
173
|
+
|
|
174
|
+
## Docker
|
|
175
|
+
|
|
176
|
+
```bash
|
|
177
|
+
docker build -t tagscope .
|
|
178
|
+
docker run -p 8000:8000 tagscope demo --host 0.0.0.0 --no-browser
|
|
179
|
+
docker run -p 8000:8000 -v $PWD:/data tagscope # uses ./tagscope.yaml
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
## Development
|
|
183
|
+
|
|
184
|
+
```bash
|
|
185
|
+
git clone https://github.com/DanShinde/tagscope && cd tagscope
|
|
186
|
+
python -m venv .venv && source .venv/bin/activate
|
|
187
|
+
pip install -e ".[dev]"
|
|
188
|
+
pytest # includes end-to-end tests against the simulated OPC UA server
|
|
189
|
+
ruff check . && ruff format --check .
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
The dashboard is plain HTML, CSS and JavaScript in `src/tagscope/static`, no build step.
|
|
193
|
+
Charts use [uPlot](https://github.com/leeoniya/uPlot) (MIT), bundled for offline use.
|
|
194
|
+
|
|
195
|
+
## Roadmap
|
|
196
|
+
|
|
197
|
+
- Write values back to the PLC from the dashboard (opt-in, with confirmation)
|
|
198
|
+
- Add tags from the address space browser without editing YAML
|
|
199
|
+
- Modbus TCP and Siemens S7 (snap7) sources
|
|
200
|
+
- MQTT / Sparkplug B output
|
|
201
|
+
- Desktop build (single executable for Windows engineering laptops)
|
|
202
|
+
|
|
203
|
+
Ideas and pull requests are welcome, see the [issues](https://github.com/DanShinde/tagscope/issues).
|
|
204
|
+
|
|
205
|
+
## License
|
|
206
|
+
|
|
207
|
+
[MIT](LICENSE) © Dan Shinde
|
tagscope-0.1.0/README.md
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+
# TagScope
|
|
4
|
+
|
|
5
|
+
**Log OPC UA tags to a database and watch them live in your browser.**
|
|
6
|
+
|
|
7
|
+
A lightweight historian for PLCs and industrial equipment: subscribe to any OPC UA server
|
|
8
|
+
(Siemens S7-1500, Beckhoff, B&R, Kepware, Ignition, Prosys…), store every change in SQLite or
|
|
9
|
+
PostgreSQL, and get a fast, modern dashboard with live values, trends, alarms and CSV export.
|
|
10
|
+
One `pip install`, one YAML file, no cloud.
|
|
11
|
+
|
|
12
|
+
[](https://github.com/DanShinde/tagscope/actions/workflows/ci.yml)
|
|
13
|
+
[](https://pypi.org/project/tagscope/)
|
|
14
|
+
[](https://pypi.org/project/tagscope/)
|
|
15
|
+
[](LICENSE)
|
|
16
|
+
|
|
17
|
+
<img src="docs/demo.gif" alt="TagScope dashboard showing live tag cards, a multi-tag trend and the OPC UA address space browser" width="900">
|
|
18
|
+
|
|
19
|
+
</div>
|
|
20
|
+
|
|
21
|
+
## Try it in 10 seconds
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
pip install tagscope
|
|
25
|
+
tagscope demo
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
`demo` starts a small simulated plant (a buffer tank, a transfer pump that trips now and then,
|
|
29
|
+
a reactor and a filler) as an OPC UA server, logs it to `tagscope-demo.db` and opens the dashboard
|
|
30
|
+
at <http://localhost:8000>. It even pre-fills 30 minutes of history, so the trends look alive
|
|
31
|
+
from the first second.
|
|
32
|
+
|
|
33
|
+
## Why
|
|
34
|
+
|
|
35
|
+
Getting PLC data into a database usually means a commercial historian, a Node-RED flow you have
|
|
36
|
+
to babysit, or a one-off script without a UI. TagScope sits in between:
|
|
37
|
+
|
|
38
|
+
- **Small**: a single Python process, no broker, no separate front-end build.
|
|
39
|
+
- **Honest storage**: plain SQL tables you can query from Grafana, Power BI, Excel or pandas.
|
|
40
|
+
- **Made for the plant floor**: limits and alarms, deadbands, reconnects that just work,
|
|
41
|
+
and a dashboard that follows ISA-101 ideas (calm grey, colour only when something is wrong).
|
|
42
|
+
|
|
43
|
+
## Features
|
|
44
|
+
|
|
45
|
+
| | |
|
|
46
|
+
|---|---|
|
|
47
|
+
| **Collect** | OPC UA subscriptions (not polling) for many servers at once, username/password login, automatic reconnect with back-off, per-tag deadband |
|
|
48
|
+
| **Store** | SQLite out of the box, PostgreSQL / TimescaleDB via `tagscope[postgres]`, retention clean-up, quality flag per sample |
|
|
49
|
+
| **See** | Live value cards with sparklines and limit bars, multi-tag trends with zoom (5 min to 24 h, downsampled server side), event log, dark and light themes, works on a phone |
|
|
50
|
+
| **Alarm** | High / low limits per tag, alarm and clear events with timestamps, active alarm counter |
|
|
51
|
+
| **Explore** | Built-in address space browser: click through the server and copy node ids into your config |
|
|
52
|
+
| **Export** | One click CSV from the dashboard, `tagscope export` from the shell, REST API with OpenAPI docs at `/api/docs`, WebSocket feed at `/ws` |
|
|
53
|
+
|
|
54
|
+
## Use it with your PLC
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
tagscope init # writes an example tagscope.yaml
|
|
58
|
+
tagscope browse opc.tcp://192.168.0.1:4840 # find the node ids you need
|
|
59
|
+
tagscope run tagscope.yaml --open
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
```yaml
|
|
63
|
+
storage: sqlite:///line1.db # or postgresql+psycopg://user:${DB_PASSWORD}@host/db
|
|
64
|
+
retention_days: 90
|
|
65
|
+
|
|
66
|
+
servers:
|
|
67
|
+
- name: line1-plc
|
|
68
|
+
endpoint: opc.tcp://192.168.0.1:4840
|
|
69
|
+
username: ${PLC_USER:-} # values can come from the environment
|
|
70
|
+
password: ${PLC_PASSWORD:-}
|
|
71
|
+
publishing_interval_ms: 500
|
|
72
|
+
tags:
|
|
73
|
+
- name: Mixer/Temperature
|
|
74
|
+
node: ns=3;s="DB_Mixer"."Temperature"
|
|
75
|
+
unit: °C
|
|
76
|
+
low: 20
|
|
77
|
+
high: 85
|
|
78
|
+
deadband: 0.1 # store only changes bigger than this
|
|
79
|
+
- name: Mixer/Running
|
|
80
|
+
node: ns=3;s="DB_Mixer"."Running"
|
|
81
|
+
- ns=3;s="DB_Counters"."Good" # short form: the node id is the name
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
More in [`examples/`](examples), including a Siemens S7-1500 setup and PostgreSQL.
|
|
85
|
+
|
|
86
|
+
> **Siemens tip:** enable the OPC UA server in the PLC properties in TIA Portal and tick
|
|
87
|
+
> *Accessible from HMI/OPC UA* on the data blocks you want to log. Node ids then look like
|
|
88
|
+
> `ns=3;s="DB_Name"."Member"`.
|
|
89
|
+
|
|
90
|
+
## Command line
|
|
91
|
+
|
|
92
|
+
| Command | What it does |
|
|
93
|
+
|---|---|
|
|
94
|
+
| `tagscope demo` | Simulated plant + logger + dashboard, nothing to configure |
|
|
95
|
+
| `tagscope run CONFIG` | Log the servers and tags in a YAML file and serve the dashboard |
|
|
96
|
+
| `tagscope init [PATH]` | Write an example config |
|
|
97
|
+
| `tagscope browse ENDPOINT [NODE]` | List the nodes of a server, with current values |
|
|
98
|
+
| `tagscope export CONFIG --minutes 60 -o out.csv` | Export logged samples |
|
|
99
|
+
|
|
100
|
+
## Data model
|
|
101
|
+
|
|
102
|
+
Three tables, easy to query from anything that speaks SQL:
|
|
103
|
+
|
|
104
|
+
```sql
|
|
105
|
+
SELECT t.name, s.ts, s.value
|
|
106
|
+
FROM tagscope_samples s JOIN tagscope_tags t ON t.id = s.tag_id
|
|
107
|
+
WHERE t.name = 'Mixer/Temperature' AND s.ts > CAST(strftime('%s', 'now', '-1 hour') AS REAL);
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
| Table | Columns |
|
|
111
|
+
|---|---|
|
|
112
|
+
| `tagscope_tags` | `id, name, server, node, unit, description, low, high` |
|
|
113
|
+
| `tagscope_samples` | `tag_id, ts (epoch seconds), value, quality (0 good, 1 uncertain, 2 bad)` |
|
|
114
|
+
| `tagscope_events` | `id, ts, tag, kind (alarm, cleared, info, warning, error), message` |
|
|
115
|
+
|
|
116
|
+
## How it works
|
|
117
|
+
|
|
118
|
+
```mermaid
|
|
119
|
+
flowchart LR
|
|
120
|
+
PLC1[PLC / OPC UA server] -- subscriptions --> C[Collector]
|
|
121
|
+
PLC2[More servers] -- subscriptions --> C
|
|
122
|
+
C --> H[(Live state + alarms)]
|
|
123
|
+
H -- batched writes --> DB[(SQLite / PostgreSQL)]
|
|
124
|
+
H -- WebSocket --> UI[Dashboard]
|
|
125
|
+
DB -- history, CSV --> API[REST API] --> UI
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
Everything runs on one asyncio event loop: asyncua subscriptions feed an in-memory hub,
|
|
129
|
+
which applies deadbands and limits, pushes updates to browsers over a WebSocket and hands
|
|
130
|
+
batches to a writer that flushes to the database once a second.
|
|
131
|
+
|
|
132
|
+
## Docker
|
|
133
|
+
|
|
134
|
+
```bash
|
|
135
|
+
docker build -t tagscope .
|
|
136
|
+
docker run -p 8000:8000 tagscope demo --host 0.0.0.0 --no-browser
|
|
137
|
+
docker run -p 8000:8000 -v $PWD:/data tagscope # uses ./tagscope.yaml
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
## Development
|
|
141
|
+
|
|
142
|
+
```bash
|
|
143
|
+
git clone https://github.com/DanShinde/tagscope && cd tagscope
|
|
144
|
+
python -m venv .venv && source .venv/bin/activate
|
|
145
|
+
pip install -e ".[dev]"
|
|
146
|
+
pytest # includes end-to-end tests against the simulated OPC UA server
|
|
147
|
+
ruff check . && ruff format --check .
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
The dashboard is plain HTML, CSS and JavaScript in `src/tagscope/static`, no build step.
|
|
151
|
+
Charts use [uPlot](https://github.com/leeoniya/uPlot) (MIT), bundled for offline use.
|
|
152
|
+
|
|
153
|
+
## Roadmap
|
|
154
|
+
|
|
155
|
+
- Write values back to the PLC from the dashboard (opt-in, with confirmation)
|
|
156
|
+
- Add tags from the address space browser without editing YAML
|
|
157
|
+
- Modbus TCP and Siemens S7 (snap7) sources
|
|
158
|
+
- MQTT / Sparkplug B output
|
|
159
|
+
- Desktop build (single executable for Windows engineering laptops)
|
|
160
|
+
|
|
161
|
+
Ideas and pull requests are welcome, see the [issues](https://github.com/DanShinde/tagscope/issues).
|
|
162
|
+
|
|
163
|
+
## License
|
|
164
|
+
|
|
165
|
+
[MIT](LICENSE) © Dan Shinde
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Store samples in PostgreSQL (or TimescaleDB). Install the extra first:
|
|
2
|
+
# pip install "tagscope[postgres]"
|
|
3
|
+
storage: postgresql+psycopg://tagscope:${DB_PASSWORD}@localhost:5432/tagscope
|
|
4
|
+
retention_days: 365
|
|
5
|
+
|
|
6
|
+
servers:
|
|
7
|
+
- name: prosys-sim
|
|
8
|
+
endpoint: opc.tcp://localhost:53530/OPCUA/SimulationServer
|
|
9
|
+
tags:
|
|
10
|
+
- name: Counter
|
|
11
|
+
node: ns=3;i=1001
|
|
12
|
+
- name: Sinusoid
|
|
13
|
+
node: ns=3;i=1004
|
|
14
|
+
low: -1.5
|
|
15
|
+
high: 1.5
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# Logging a Siemens S7-1500 with the built-in OPC UA server enabled
|
|
2
|
+
# (TIA Portal: PLC properties > OPC UA > Server > Activate OPC UA server).
|
|
3
|
+
# Data blocks must have "Accessible from HMI/OPC UA" ticked.
|
|
4
|
+
storage: sqlite:///line1.db
|
|
5
|
+
retention_days: 90
|
|
6
|
+
|
|
7
|
+
web:
|
|
8
|
+
host: 0.0.0.0 # reachable from other PCs on the network
|
|
9
|
+
port: 8000
|
|
10
|
+
|
|
11
|
+
servers:
|
|
12
|
+
- name: line1-plc
|
|
13
|
+
endpoint: opc.tcp://192.168.0.1:4840
|
|
14
|
+
username: ${PLC_USER:-}
|
|
15
|
+
password: ${PLC_PASSWORD:-}
|
|
16
|
+
publishing_interval_ms: 500
|
|
17
|
+
tags:
|
|
18
|
+
- name: Mixer/Speed
|
|
19
|
+
node: ns=3;s="DB_Mixer"."Speed"
|
|
20
|
+
unit: rpm
|
|
21
|
+
high: 1450
|
|
22
|
+
deadband: 2
|
|
23
|
+
- name: Mixer/Temperature
|
|
24
|
+
node: ns=3;s="DB_Mixer"."Temperature"
|
|
25
|
+
unit: °C
|
|
26
|
+
low: 20
|
|
27
|
+
high: 85
|
|
28
|
+
deadband: 0.1
|
|
29
|
+
- name: Mixer/Running
|
|
30
|
+
node: ns=3;s="DB_Mixer"."Running"
|
|
31
|
+
- name: Line/GoodCount
|
|
32
|
+
node: ns=3;s="DB_Counters"."Good"
|
|
33
|
+
unit: pcs
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling>=1.24"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "tagscope"
|
|
7
|
+
dynamic = ["version"]
|
|
8
|
+
description = "Log OPC UA tags to SQLite or PostgreSQL and watch them live in a fast, modern web dashboard."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "MIT"
|
|
11
|
+
license-files = ["LICENSE"]
|
|
12
|
+
requires-python = ">=3.10"
|
|
13
|
+
authors = [{ name = "Dan Shinde" }]
|
|
14
|
+
keywords = ["opc-ua", "opcua", "historian", "scada", "plc", "industrial", "iiot", "data-logger", "siemens", "dashboard"]
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Development Status :: 4 - Beta",
|
|
17
|
+
"Environment :: Web Environment",
|
|
18
|
+
"Framework :: AsyncIO",
|
|
19
|
+
"Framework :: FastAPI",
|
|
20
|
+
"Intended Audience :: Manufacturing",
|
|
21
|
+
"Intended Audience :: Developers",
|
|
22
|
+
"Operating System :: OS Independent",
|
|
23
|
+
"Programming Language :: Python :: 3",
|
|
24
|
+
"Programming Language :: Python :: 3.10",
|
|
25
|
+
"Programming Language :: Python :: 3.11",
|
|
26
|
+
"Programming Language :: Python :: 3.12",
|
|
27
|
+
"Programming Language :: Python :: 3.13",
|
|
28
|
+
"Topic :: Scientific/Engineering :: Interface Engine/Protocol Translator",
|
|
29
|
+
"Topic :: System :: Monitoring",
|
|
30
|
+
]
|
|
31
|
+
dependencies = [
|
|
32
|
+
"asyncua>=1.1",
|
|
33
|
+
"fastapi>=0.110",
|
|
34
|
+
"uvicorn>=0.29",
|
|
35
|
+
"websockets>=12",
|
|
36
|
+
"sqlalchemy>=2.0",
|
|
37
|
+
"pyyaml>=6.0",
|
|
38
|
+
]
|
|
39
|
+
|
|
40
|
+
[project.optional-dependencies]
|
|
41
|
+
postgres = ["psycopg[binary]>=3.1"]
|
|
42
|
+
dev = ["pytest>=8", "pytest-asyncio>=0.23", "httpx>=0.27", "ruff>=0.5", "build"]
|
|
43
|
+
|
|
44
|
+
[project.scripts]
|
|
45
|
+
tagscope = "tagscope.cli:main"
|
|
46
|
+
|
|
47
|
+
[project.urls]
|
|
48
|
+
Homepage = "https://github.com/DanShinde/tagscope"
|
|
49
|
+
Issues = "https://github.com/DanShinde/tagscope/issues"
|
|
50
|
+
Changelog = "https://github.com/DanShinde/tagscope/blob/main/CHANGELOG.md"
|
|
51
|
+
|
|
52
|
+
[tool.hatch.version]
|
|
53
|
+
path = "src/tagscope/__init__.py"
|
|
54
|
+
|
|
55
|
+
[tool.hatch.build.targets.sdist]
|
|
56
|
+
include = ["src", "tests", "examples", "README.md", "LICENSE", "CHANGELOG.md"]
|
|
57
|
+
|
|
58
|
+
[tool.pytest.ini_options]
|
|
59
|
+
asyncio_mode = "auto"
|
|
60
|
+
asyncio_default_fixture_loop_scope = "function"
|
|
61
|
+
testpaths = ["tests"]
|
|
62
|
+
|
|
63
|
+
[tool.ruff]
|
|
64
|
+
line-length = 120
|
|
65
|
+
target-version = "py310"
|
|
66
|
+
|
|
67
|
+
[tool.ruff.lint]
|
|
68
|
+
select = ["E", "F", "W", "I", "B", "UP", "SIM", "BLE"]
|
|
69
|
+
ignore = ["SIM105"]
|