{"id":46638229,"url":"https://github.com/tetherto/miningos-wrk-powermeter-abb","last_synced_at":"2026-03-08T02:13:16.963Z","repository":{"id":335315293,"uuid":"1129676735","full_name":"tetherto/miningos-wrk-powermeter-abb","owner":"tetherto","description":null,"archived":false,"fork":false,"pushed_at":"2026-02-26T23:00:55.000Z","size":107,"stargazers_count":0,"open_issues_count":0,"forks_count":3,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-02-27T05:33:39.680Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tetherto.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-01-07T12:29:31.000Z","updated_at":"2026-02-26T23:01:01.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/tetherto/miningos-wrk-powermeter-abb","commit_stats":null,"previous_names":["tetherto/miningos-wrk-powermeter-abb"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/tetherto/miningos-wrk-powermeter-abb","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tetherto%2Fminingos-wrk-powermeter-abb","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tetherto%2Fminingos-wrk-powermeter-abb/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tetherto%2Fminingos-wrk-powermeter-abb/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tetherto%2Fminingos-wrk-powermeter-abb/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tetherto","download_url":"https://codeload.github.com/tetherto/miningos-wrk-powermeter-abb/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tetherto%2Fminingos-wrk-powermeter-abb/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30242406,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-08T00:58:18.660Z","status":"online","status_checked_at":"2026-03-08T02:00:06.215Z","response_time":56,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-03-08T02:13:12.534Z","updated_at":"2026-03-08T02:13:16.948Z","avatar_url":"https://github.com/tetherto.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# miningos-wrk-powermeter-abb\n\nMiningOS worker for managing ABB powermeters in mining operations - provides real-time power monitoring, energy consumption tracking, and alarm management for Bitcoin mining facilities through Modbus TCP communication.\n\n## Table of Contents\n\n1. [Overview](#overview)\n2. [Prerequisites](#prerequisites)\n3. [Installation](#installation)\n4. [Configuration](#configuration)\n5. [Starting the Worker](#starting-the-worker)\n6. [Mock Servers](#mock-servers)\n7. [Architecture](#architecture)\n8. [Registering Powermeters](#registering-powermeters)\n9. [Development](#development)\n10. [Troubleshooting](#troubleshooting)\n11. [Contributing](#contributing)\n\n## Overview\n\nThis worker extends the base `miningos-tpl-wrk-powermeter` template to provide ABB-specific powermeter integration:\n- Communicates with ABB powermeters via Modbus TCP\n- Collects real-time power, voltage, current, and energy data\n- Supports multiple ABB powermeter models (B23, B24, M1M20, M4M20, REU615)\n- Manages alarm configurations and monitoring\n- Aggregates power statistics across sites and containers\n- Integrates with MiningOS's P2P RPC network (Hyperswarm)\n\n## Prerequisites\n\n- Node.js \u003e= 20.0\n- Network access to ABB powermeters (Modbus TCP on port 502 or custom)\n- Access to MiningOS Ork cluster (RPC public key required)\n- Basic understanding of Modbus TCP protocol\n\n## Installation\n\n1. Clone the repository:\n```bash\ngit clone https://github.com/tetherto/miningos-wrk-powermeter-abb.git\ncd miningos-wrk-powermeter-abb\n```\n\n2. Install dependencies:\n```bash\nnpm install\n```\n\n3. Setup configuration files:\n```bash\nbash setup-config.sh\n# For test configurations as well:\nbash setup-config.sh --test\n```\n\n## Configuration\n\n### Common Configuration (config/common.json)\n\nConfigure worker-level settings and powermeter-specific options:\n\n```json\n{\n  \"rack\": \"rack-0\",\n  \"wtype\": \"wrk-powermeter-rack-b24\",\n  \"env\": \"development\",\n  \"thing\": {\n    \"powermeter\": {\n      \"timeout\": 5000,\n      \"retries\": 3\n    }\n  }\n}\n```\n\n### Base Thing Configuration (config/base.thing.json)\n\nTemplate for registering new powermeters:\n\n```json\n{\n  \"info\": {\n    \"pos\": \"site\",\n    \"container\": \"container-1\",\n    \"description\": \"Main site power meter\"\n  },\n  \"opts\": {\n    \"address\": \"192.168.1.100\",\n    \"port\": 502,\n    \"unitId\": \"0\"\n  }\n}\n```\n\n**Thing Parameters:**\n- `info.pos`: Position identifier (e.g., \"site\", \"rack\", \"container\")\n- `info.container`: Container grouping for statistics\n- `opts.address`: IP address of the ABB powermeter\n- `opts.port`: Modbus TCP port (typically 502)\n- `opts.unitId`: Modbus unit ID (typically \"0\")\n\n### Network Configuration (config/facs/net.config.json)\nConfigure Hyperswarm network settings for RPC communication with Ork clusters.\n\n### Modbus Configuration (config/facs/modbus_0.config.json)\nConfigure Modbus facility settings (timeouts, connection pooling, etc.).\n\n## Starting the Worker\n\n### Supported Worker Types\n\nEach ABB powermeter model has its own worker type:\n- `wrk-powermeter-rack-b23` - ABB B23 powermeters\n- `wrk-powermeter-rack-b24` - ABB B24 powermeters\n- `wrk-powermeter-rack-m1m20` - ABB M1M20 powermeters\n- `wrk-powermeter-rack-m4m20` - ABB M4M20 powermeters\n- `wrk-powermeter-rack-reu615` - ABB REU615 protection relays\n\n### Development Mode\n\nUsing npm scripts (M1M20 model):\n```bash\nnpm run worker\n# Runs: node worker.js --wtype wrk-powermeter-rack-M1M20 --env development --rack rack-0\n```\n\n### Custom Configuration\n\n```bash\nnode worker.js --wtype wrk-powermeter-rack-b24 --env production --rack rack-1\nnode worker.js --wtype wrk-powermeter-rack-m1m20 --env development --rack rack-0\nnode worker.js --wtype wrk-powermeter-rack-reu615 --env production --rack rack-2\n```\n\n**Command Parameters:**\n- `--wtype`: Worker type (must match supported models)\n- `--env`: Environment (development, production)\n- `--rack`: Rack identifier for this worker instance\n\n## Mock Servers\n\nMock servers simulate ABB powermeters for development and testing without physical hardware.\n\n### Starting a Mock Server\n\n```bash\n# Using npm (M1M20 model, port 4008):\nnpm run mock\n\n# Custom configurations:\nnode mock/server.js --type B24 -p 5020 -h 0.0.0.0\nnode mock/server.js --type M1M20 -p 4008 -h 127.0.0.1\nnode mock/server.js --type M4M20 -p 4009 -h 0.0.0.0 --mockControlPort 5009\nnode mock/server.js --type REU615 -p 5030 -h 0.0.0.0\n```\n\n**Mock Server Parameters:**\n- `--type`: Powermeter model (B23, B24, M1M20, M4M20, REU615)\n- `-p, --port`: Modbus TCP port (default: 5020)\n- `-h, --host`: Host address (default: 127.0.0.1)\n- `--mockControlPort`: Control port for mock agent (default: 9999)\n\n### Mock Server Features\n\n- Simulates Modbus register responses based on ABB specifications\n- Provides realistic power, voltage, current readings\n- Supports write operations for alarm configurations\n- M4M20 mock intentionally fails 12.5% of requests to simulate real-world errors\n\n### Testing with Mock Servers\n\n1. Start a mock server:\n```bash\nnode mock/server.js --type B24 -p 5020 -h 0.0.0.0\n```\n\n2. Start the worker in another terminal:\n```bash\nnode worker.js --wtype wrk-powermeter-rack-b24 --env development --rack rack-0\n```\n\n3. Register the mock powermeter (see [Registering Powermeters](#registering-powermeters))\n\n## Architecture\n\n### Core Components\n\n#### Worker Hierarchy\n```\nbfx-svc-boot-js (CLI framework)\n  └─\u003e miningos-tpl-wrk-powermeter (base template)\n      └─\u003e workers/lib/worker-base.js (ABB-specific base)\n          └─\u003e workers/[model].rack.powermeter.wrk.js (model workers)\n              └─\u003e workers/lib/models/[model].js (device control)\n```\n\n#### Worker Classes\n\n**`workers/lib/worker-base.js`** - Base class for all ABB workers:\n- Initializes Modbus facility (`svc-facs-modbus`)\n- Manages thing connection lifecycle\n- Implements snapshot collection\n- Handles error recovery and reconnection\n- Sets thing tags: `['abb']` and spec tags: `['powermeter']`\n\n**Model-Specific Workers:**\n- `workers/b23.rack.powermeter.wrk.js` - B23 implementation (uses B2X model)\n- `workers/b24.rack.powermeter.wrk.js` - B24 implementation (uses B2X model)\n- `workers/m1m20.rack.powermeter.wrk.js` - M1M20 implementation\n- `workers/m4m20.rack.powermeter.wrk.js` - M4M20 implementation\n- `workers/reu615.rack.powermeter.wrk.js` - REU615 implementation\n\n#### Device Models (`workers/lib/models/`)\n\nDevice-specific control classes that implement:\n- Modbus register mapping for each model\n- `getSnap()` - Collects current readings\n- Alarm configuration methods\n- Reset operations (energy counters, logs, etc.)\n\n#### Statistics Aggregation (`workers/lib/stats.js`)\n\nDefines aggregation operations:\n- **`site_power_w`**: Sums power for devices with `pos: 'site'`\n- **`power_w_container_group_sum`**: Groups and sums power by container\n\n### Thing Lifecycle\n\n1. **Register**: Thing registered via RPC `registerThing` method\n2. **Connect**: Worker creates model-specific instance with Modbus client\n3. **Collect**: Periodically calls `getSnap()` to gather readings\n4. **Error Handling**: Connection errors trigger automatic reconnection\n5. **Disconnect**: Clean shutdown on worker stop or persistent errors\n\n### Data Flow\n\n1. Worker receives snapshot request from Ork\n2. Calls `collectThingSnap(thg)` on registered thing\n3. Device model reads Modbus registers\n4. Data normalized to standard format\n5. Statistics aggregated across things\n6. Snapshot returned via RPC to Ork\n\n## Registering Powermeters\n\nPowermeters (\"things\") are registered to workers via RPC using the `hp-rpc-cli` tool.\n\n### Prerequisites\n\n- Worker must be running\n- Worker's RPC public key (from worker logs or config)\n- Powermeter must be network accessible\n\n### Registration Command\n\n```bash\nhp-rpc-cli -s [WORKER_PUBLIC_KEY] -m registerThing -d '{\n  \"info\": {\n    \"pos\": \"site\",\n    \"container\": \"container-1\",\n    \"description\": \"Main site power meter\"\n  },\n  \"opts\": {\n    \"address\": \"192.168.1.100\",\n    \"port\": 502,\n    \"unitId\": \"0\"\n  }\n}'\n```\n\n### Example: Register Mock Powermeter\n\n```bash\nhp-rpc-cli -s wrk -m registerThing -d '{\n  \"info\": {},\n  \"opts\": {\n    \"address\": \"127.0.0.1\",\n    \"port\": 5020,\n    \"unitId\": \"0\"\n  }\n}'\n```\n\n### Verify Registration\n\nCheck worker logs for successful connection messages. The worker will attempt to connect to the powermeter and start collecting snapshots.\n\n## Development\n\n### Running Tests\n\n```bash\nnpm test              # Run main integration test\nnpm run test:unit     # Run all unit tests\nnpm run lint          # Check code style (Standard.js)\nnpm run lint:fix      # Auto-fix linting issues\n```\n\n### Running Individual Tests\n\n```bash\nbrittle tests/unit/stats.test.js\nbrittle tests/unit/m1m20.test.js\nbrittle tests/unit/b2x.test.js\nbrittle tests/unit/base.test.js\nbrittle tests/unit/utils.test.js\n```\n\n### Code Style\n\n- **Standard.js**: JavaScript Standard Style (no semicolons, 2 spaces)\n- **Strict Mode**: All files use `'use strict'`\n- Run `npm run lint:fix` before committing\n\n### Project Structure\n\n```\n.\n├── config/                    # Configuration files\n│   ├── common.json            # Worker configuration\n│   ├── base.thing.json        # Thing template\n│   └── facs/                  # Facility configs (net, modbus, storage)\n├── workers/\n│   ├── b23.rack.powermeter.wrk.js     # B23 worker\n│   ├── b24.rack.powermeter.wrk.js     # B24 worker\n│   ├── m1m20.rack.powermeter.wrk.js   # M1M20 worker\n│   ├── m4m20.rack.powermeter.wrk.js   # M4M20 worker\n│   ├── reu615.rack.powermeter.wrk.js  # REU615 worker\n│   └── lib/\n│       ├── worker-base.js     # ABB worker base class\n│       ├── stats.js           # Statistics definitions\n│       ├── alerts.js          # Alert handling\n│       ├── models/            # Device-specific implementations\n│       │   ├── base.js        # Base model class\n│       │   ├── b2x.js         # B23/B24 model\n│       │   ├── m1m20.js       # M1M20 model\n│       │   ├── m4m20.js       # M4M20 model\n│       │   └── reu615.js      # REU615 model\n│       └── utils/             # Utility functions\n├── mock/\n│   ├── server.js              # Mock server entry point\n│   └── mock-control-agent.js  # Mock control interface\n├── tests/\n│   ├── unit/                  # Unit tests\n│   ├── schema/                # Schema validation tests\n│   └── powermeter.test.js     # Integration tests\n├── docs/\n│   ├── abb.md                 # Common ABB API docs\n│   ├── abb-b23.md             # B23 specific docs\n│   ├── abb-b24.md             # B24 specific docs\n│   └── mock.md                # Mock server docs\n└── worker.js                  # Entry point\n```\n\n### ABB Powermeter API\n\nEach model supports standard operations documented in `docs/`:\n\n- **`getSnap()`** - Get current power readings\n- **`resetPowerFailCounter()`** - Reset power fail counter\n- **`resetPowerOutageTime()`** - Reset outage time\n- **`resetSystemLog()`** - Reset system log\n- **`resetEventLog()`** - Reset event log\n- **`resetNetQualityLog()`** - Reset net quality log\n- **`setAlarmConfig(alarmConfig)`** - Configure alarms (1-25)\n- **`getAlarmConfig(index)`** - Get alarm configuration\n\nSee `docs/abb.md` for complete API reference.\n\n## Troubleshooting\n\n### Common Issues\n\n1. **Cannot connect to powermeter**\n   - Verify IP address and port in thing registration\n   - Check network connectivity: `ping [POWERMETER_IP]`\n   - Ensure Modbus TCP port (typically 502) is not blocked by firewall\n   - Verify unit ID matches powermeter configuration\n   - Check worker logs for connection errors\n\n2. **Worker fails to start**\n   - Run `bash setup-config.sh` to ensure config files exist\n   - Check Node.js version: `node --version` (must be \u003e= 20.0)\n   - Verify all dependencies installed: `npm install`\n   - Review worker logs for specific error messages\n\n3. **Mock server not responding**\n   - Ensure mock server is running: `ps aux | grep mock`\n   - Verify port is not in use: `lsof -i :[PORT]`\n   - Check host/port match in registration\n   - Review mock server logs (use `DEBUG=* node mock/server.js ...`)\n\n4. **Modbus timeout errors**\n   - Increase timeout in `config/common.json` under `thing.powermeter.timeout`\n   - Check network latency to powermeter\n   - Verify powermeter is not overloaded with requests\n   - Try reducing request frequency\n\n5. **Test failures**\n   - Ensure `NODE_ENV=test` is set\n   - Run `bash setup-config.sh --test` to create test configs\n   - Check for missing dependencies: `npm install`\n   - Review specific test output for error details\n\n6. **Statistics not aggregating**\n   - Verify `info.pos` field is set correctly on things\n   - Check `info.container` for container grouping\n   - Ensure things are successfully collecting snapshots\n   - Review `workers/lib/stats.js` filter functions\n\n### Debug Mode\n\nEnable debug logging:\n```bash\nDEBUG=* node worker.js --wtype wrk-powermeter-rack-b24 --env development --rack rack-0\nDEBUG=mock node mock/server.js --type B24 -p 5020\n```\n\n## Contributing\n\nContributions are welcome and appreciated!\n\n### How to Contribute\n\n1. **Fork** the repository\n2. **Create a new branch** for your feature or fix:\n   ```bash\n   git checkout -b feature/your-feature-name\n   ```\n3. **Make your changes** and ensure tests pass:\n   ```bash\n   npm test\n   ```\n4. **Push** to your fork:\n   ```bash\n   git push origin feature/your-feature-name\n   ```\n5. **Open a Pull Request** describing what you changed and why\n\n### Guidelines\n\n- Follow Standard.js code style (`npm run lint`)\n- Add tests for new functionality\n- Keep PRs focused—one feature or fix per pull request\n- Update documentation as needed (`docs/` and this README)\n- Ensure all tests pass before submitting\n- Test with mock servers before deploying to real hardware\n\n### Areas for Contribution\n\n- Support for additional ABB powermeter models\n- Enhanced alarm management features\n- Improved error recovery and reconnection logic\n- Performance optimizations for Modbus communication\n- Additional statistics aggregation operations\n- Enhanced mock server features\n- Documentation improvements\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftetherto%2Fminingos-wrk-powermeter-abb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftetherto%2Fminingos-wrk-powermeter-abb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftetherto%2Fminingos-wrk-powermeter-abb/lists"}