Smart Site
Home Docs Smart Data Collector Management

Collector Management

The Collector module is responsible for reading data from physical devices and pushing it through the processing pipeline. Each protocol is implemented as a collector plugin that extends the abstract BaseCollectorService class.

Interface Screenshot

Collector - Plugin List (English UI)

Captured from the live Smart Site system with the English UI. See the zh-CN counterpart for the Chinese-UI screenshot.

1. Collector Architecture

Every collector implements IProtocolAdapter and extends BaseCollectorService (in @ss-node/ss-collector-sdk). The base class handles connection pooling, scheduling, retries, and lifecycle; subclasses only implement the protocol-specific parts:

export abstract class BaseCollectorService implements IProtocolAdapter, OnModuleDestroy {
  abstract connect(device: IDeviceContext): Promise<any>;
  protected abstract doReadTag(client: any, tag: ITagContext): Promise<{ tagId; value; timestamp }>;
  protected abstract doWriteTag(client: any, tag: ITagContext, value: any): Promise<void>;
  protected abstract doDisconnect(client: any): Promise<void>;
}

The IDeviceContext and ITagContext interfaces carry the connection parameters and tag addressing that a collector needs at runtime.

Collectors are loaded by the PluginRegistryService and run inside the pipeline orchestrator. The orchestrator invokes the protocol-read step, then forwards results to cache-update, deadband, persist, alarm-check, and publish steps.

2. Supported Protocols

Protocol Package Library Typical Use
Modbus @ss-node/ss-collector-modbus modbus-serial PLCs, RTUs, meters
OPC UA @ss-node/ss-collector-opcua node-opcua DCS, modern PLCs
MQTT @ss-node/ss-collector-mqtt mqtt IoT gateways, edge devices
S7 @ss-node/ss-collector-s7 snap7 Siemens S7-300/400/1200
Virtual @ss-node/ss-collector-virtual (built-in sims) Testing, demos

The Virtual collector ships with simulators (fixed-value, range-value, bool, enum-value, string) so you can exercise the full pipeline without real hardware.

3. Collection Scheduling

The EnhancedScheduler (in @ss-node/ss-core) drives collection:

  • Each device has a scan rate (in milliseconds) stored on the device record
  • The scheduler groups devices by rate to batch reads efficiently
  • A bounded backpressure queue prevents slow devices from blocking fast ones
  • The circuit breaker opens after N consecutive failures and retries with exponential backoff
[Scheduler] -> [protocol-read] -> [cache-update] -> [deadband]
            -> [persist] -> [alarm-check] -> [publish(WS)]

4. Scan Rate Configuration

The scan rate is set per device in the device editor and defaults to 1000 ms. Guidelines:

Scan Rate Suitable For
100–500 ms Fast control signals, alarms
1000 ms General telemetry (default)
5000+ ms Slow environmental sensors, counters

Lowering the scan rate increases load on both the device and the network. Verify the device can sustain the requested rate using the diagnostic endpoint.

5. Collection Status Monitoring

The StatusMonitorService and CollectorDiagnosticsService expose runtime status:

  • Per-device connection state (connected / disconnected / error)
  • Last successful read timestamp
  • Consecutive failure count
  • Throughput (points/sec) and latency percentiles

Frontend pages under System → Plugins render this status; the same data is available via the diagnostics REST endpoints and the metrics controller.

6. Operational Guidance

6.1 Starting / Stopping a Collector

Collectors start automatically when their module is loaded by the NestJS application. To temporarily stop collection for one device without deleting it, disable the device (the scheduler skips disabled devices).

6.2 Viewing Logs

Collector logs flow through StructuredLogger (@ss-node/ss-core). Each log entry includes deviceId, protocol, and tagId context so you can filter by device. Use the System → Base Services page to tail logs, or read the log files directly.

6.3 Handling Connection Failures

  1. Run POST /devices/:id/ping to confirm the address is reachable
  2. Check the circuit breaker state in the diagnostics page
  3. If open, wait for the cooldown or restart the backend to reset it
  4. Verify credentials / network firewall for the protocol port (502, 4840, 1883, 102)

7. FAQ

Q: A collector reports "connection refused". A: Confirm the device IP and port are correct and that no firewall blocks the protocol port. For Modbus, ensure the slave ID matches; for OPC UA, verify the security policy and endpoint URL.

Q: Values update slowly even though the scan rate is 200 ms. A: The pipeline may be applying deadband or frequency-reduction strategies. Check the deadband config on the tags and the frequency-reduction.strategy.ts settings. Also confirm the device itself can respond at 200 ms.

Q: How do I add a new protocol? A: Create a new package under ss-collector/ that extends BaseCollectorService, implement the four abstract methods, register it in the plugin registry, and add it to app.module.ts. See the SDK article for details.

Q: Does the Virtual collector write to InfluxDB? A: Yes — it flows through the same pipeline as real collectors, so persist and publish steps run normally. It is ideal for end-to-end testing.

  • ../../05-collector/plugin-dev-rules.md (Collector plugin development rules: template 8 red lines + external plugin 10 red lines + handle/i18n/isolation-log/build whitelist)
  • ../../05-collector/plugin-detail.md
  • ../../08-protocol/README.md
  • ../../17-sdk/README.md
  • Collector Architecture Design
  • BaseCollectorService Source