public ModbusBackgroundService(ILoggerFactory loggerFactory, IModbusFactory modbus_factory, MqttClientProxyCollection mqttClientProxies, IRedisConnectionFactory redisFactory, IConfiguration configuration, ModbusSystem modbusSystem) { logger = loggerFactory.CreateLogger <ModbusBackgroundService>(); config = configuration; modbusFactory = modbus_factory; mqtt_clients = mqttClientProxies; mqtt_config = configuration.GetSection("MQTTBrokers").Get <MqttConfig>(); SiteId = configuration.GetSection("SiteId").Get <int>(); DeviceIndex = configuration.GetSection("DeviceIndex").Get <int>(); modbus = modbusSystem; redis = redisFactory.Connection().GetDatabase(1); }
private async Task <MqttClientProxyCollection> TryInitializeMqtt(MqttConfig config) { MqttClientProxyCollection result = new MqttClientProxyCollection(); IMqttClient peiu_client = await CreateMqttClient(config.PEIUEventBrokerAddress); result.PeiuEventBrokerProxy = new MqttClientProxy(peiu_client, config.PEIUEventBrokerAddress); foreach (MqttAddress addr in config.DataBrokerAddress) { IMqttClient client = await CreateMqttClient(addr); if (client != null) { result.Add(new MqttClientProxy(client, addr)); } } return(result); }