Install & Compatibility
Where this runs
No compatibility data collected yet for this library.
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
utils
✓ const utils = require('@iobroker/adapter-core');
✗ import utils from '@iobroker/adapter-core';
ioBroker adapters are CommonJS-only; ESM is not supported.
Adapter
✓ const { Adapter } = require('@iobroker/adapter-core');
✗ const Adapter = require('@iobroker/adapter-core');
Adapter is a named export, not the default.
createAdapter
✓ const createAdapter = require('@iobroker/adapter-core').Adapter;
✗ const adapter = createAdapter();
createAdapter is a factory; call it directly in adapter.js.
Shows minimal ioBroker adapter setup with gRPC connection and state handling.
const utils = require('@iobroker/adapter-core');
const grpc = require('@grpc/grpc-js');
const protoLoader = require('@grpc/proto-loader');
const PROTO_PATH = __dirname + '/lib/hannah.proto';
const packageDefinition = protoLoader.loadSync(PROTO_PATH, {
keepCase: true,
longs: String,
enums: String,
defaults: true,
oneofs: true,
});
const hannahProto = grpc.loadPackageDefinition(packageDefinition).hannah;
class HannahAdapter extends utils.Adapter {
constructor(options) {
super({
...options,
name: 'hannah',
});
this.on('ready', this.onReady.bind(this));
this.on('stateChange', this.onStateChange.bind(this));
this.on('unload', this.onUnload.bind(this));
}
async onReady() {
const host = this.config.host || '127.0.0.1';
const port = this.config.port || 50051;
const client = new hannahProto.AgentConnect(`${host}:${port}`, grpc.credentials.createInsecure());
const stream = client.connect();
stream.on('data', (msg) => {
if (msg.command === 'setState') {
this.setState(msg.id, msg.val, true);
}
});
stream.on('error', (err) => console.error('gRPC error:', err));
this.subscribeStates('*');
this.setState('info.connection', true, true);
}
onStateChange(id, state) {
if (state && !state.ack) {
// forward to Hannah
}
}
onUnload(callback) {
callback();
}
}
if (require.main !== module) {
module.exports = (options) => new HannahAdapter(options);
} else {
new HannahAdapter();
}
Errors
Common errors & fixes
Error: Cannot find module '@grpc/grpc-js'
Missing native gRPC dependency; npm install did not install all packages.
fixRun 'npm install @grpc/grpc-js' in the adapter directory or reinstall the adapter from ioBroker admin.
Error: 14 UNAVAILABLE: failed to connect to all addresses
Hannah Core is not running or gRPC port is blocked/firewalled.
fixEnsure Hannah Core is running and accessible on the configured host:port. Check firewall rules and verify the port (default 50051).
Audit
Dependencies
@grpc/grpc-jsrequiredgRPC client for bidirectional stream to Hannah Core
@iobroker/adapter-corerequiredioBroker adapter framework