public GardenService(IMQTTQueueService mqttService, IGardenWaterControllerService waterController, ILogger <GardenService> logger) { _logger = logger; _mqttService = mqttService; _waterController = waterController; _mqttService.AddSubscriber(Constants.Garden.Queues.Water, _gardenWaterMessageManager); }
public static ILoggerFactory AddMQTTLogger(this ILoggerFactory loggerFactory, Action <MQTTLoggerConfiguration> configure, IMQTTQueueService mqttService) { var config = new MQTTLoggerConfiguration(); configure(config); return(loggerFactory.AddMQTTLogger(config, mqttService)); }
public static ILoggerFactory AddMQTTLogger(this ILoggerFactory loggerFactory, MQTTLoggerConfiguration config, IMQTTQueueService mqttService) { loggerFactory.AddProvider(new MQTTLoggerProvider(config, mqttService)); return(loggerFactory); }
public MQTTLogger(string name, IMQTTQueueService mqttService, MQTTLoggerConfiguration config) { _name = name; _config = config; _mqttService = mqttService; }
public PowerService(IMQTTQueueService mqttService, ILogger <PowerService> logger) { _logger = logger; _mqttService = mqttService; _mqttService.AddSubscriber(Constants.Power.Queues.Production, _powerProductionAcquired); }
public void Run() { ILogger <InverterTask> logger = ServiceFactory.CurrentServiceProvider.GetService <ILogger <InverterTask> >(); ILogger <FimerR25Inverter> loggerFimer = ServiceFactory.CurrentServiceProvider.GetService <ILogger <FimerR25Inverter> >(); IMQTTQueueService mqttService = ServiceFactory.CurrentServiceProvider.GetService <IMQTTQueueService>(); using (IInverter currentInverter = new FimerR25Inverter(loggerFimer)) { Hashtable ht = new Hashtable { { InverterCommonProperties.NET_IP_ADDRESS, "192.168.0.99" }, { InverterCommonProperties.NET_IP_PORT, "33330" }, { InverterCommonProperties.SERIAL_NUMBER, "18344" } }; logger.LogDebug($"Connect to: {ht[InverterCommonProperties.NET_IP_ADDRESS]} - Port: {ht[InverterCommonProperties.NET_IP_PORT]} - Serial : {ht[InverterCommonProperties.SERIAL_NUMBER]}"); Ping p = new Ping(); PingReply pr = p.Send(IPAddress.Parse((string)ht[InverterCommonProperties.NET_IP_ADDRESS]), 5000); if (pr.Status == IPStatus.Success) { logger.LogDebug("initing..."); currentInverter.Init(ht); logger.LogDebug("connecting..."); TransmissionState ts = currentInverter.Connect(); logger.LogDebug("connected"); if (ts == TransmissionState.Ok) { logger.LogDebug("start reading..."); ConverterStatus?cs = currentInverter.ReadData(31); logger.LogDebug("Reading status:" + (cs != null).ToString()); if (cs == null) { logger.LogDebug("Nessun dato letto"); currentInverter.Dispose(); } ServiceFactory.CurrentServiceProvider.GetService <IPersisterFactory>().Save(currentInverter, cs); MessageBase mb = new MessageBase { Command = Constants.Power.Messages.ProductionDataAcquired, Data = new ProductionDataInfo { DailyValue = cs.Value.CommonStatus.EnergieTag * 1000, CurrentValue = (ushort)cs.Value.TypeStatus.GetProperty(CommonPropertyType.ProduzioneCorrente) } }; var jsonSerializerSettings = new JsonSerializerSettings() { TypeNameHandling = TypeNameHandling.All }; mqttService.Publish(Constants.Power.Queues.Production, JsonConvert.SerializeObject(mb, jsonSerializerSettings)); } else { logger.LogDebug($"reading error:{ts}"); } } } }
public MQTTLoggerProvider(MQTTLoggerConfiguration config, IMQTTQueueService mqttService) { _config = config; _mqttService = mqttService; }