static int Main(string[] args) { if (args.Count() != 4) { Console.WriteLine("Syntax: IHCExample ihc-controller-url username password resourceid"); return(0); } IHCController ihc = new IHCController(args[0]); if (!ihc.Authenticate(args[1], args[2])) { Console.WriteLine("Authentication failed"); return(0); } int resourceid = int.Parse(args[3]); // Get the value and toggle it bool value = ihc.GetRuntimeValueBool(resourceid); ihc.SetRuntimeValueBool(resourceid, !value); // Register a callback for changes to the resourceid ihc.RegisterNotify(resourceid, ResourceChange); // Start the notify thread ihc.StartNotify(); // Wait until a key is pressed Console.ReadKey(); Console.WriteLine("Disconnecting"); ihc.Disconnect(); return(1); }
static void Main(string[] args) { Console.WriteLine(String.Format("IhcMqttGateway {0} (c) 2017 J.Ø.N. Dingus.dk", GetVersion())); if (!ProcessCmdLine(args)) { return; } if (!conf.Load(confpath)) { Console.Error.WriteLine("Error loading the configuration: ihcmqttgateway.conf"); return; } ihcstates = new Dictionary <int, string>(); mqttstates = new Dictionary <int, string>(); ihctypes = new Dictionary <int, Type>(); Console.WriteLine("Connectiong to ihc controller: " + conf.IhcUrl); ihc = new IHCController(conf.IhcUrl); if (!ihc.Authenticate(conf.IhcUser, conf.IhcPassword)) { Console.WriteLine("Authentication failed"); return; } Console.WriteLine("Authentication succecfull"); foreach (var i in conf.IhcOut) { ihc.RegisterNotify(i.Key, ResourceChanges); } mqttclient = new MqttClient(conf.MqttHost); mqttclient.MqttMsgPublishReceived += MqttMsgPublishReceived; string clientId = Guid.NewGuid().ToString(); Console.WriteLine("Conneting to MQTT"); byte conack = conf.MqttUsername != null? mqttclient.Connect(clientId, conf.MqttUsername, conf.MqttPassword) : mqttclient.Connect(clientId); if (conack != 0) { Console.WriteLine("Connecting to the MQTT broker failed"); return; } Console.WriteLine("Subscribe to MQTT"); // Subscribe to all topics! mqttclient.Subscribe(new string[] { "#" }, new byte[] { MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE }); ihc.StartNotify(); Console.WriteLine("READY (press 'q' to exit)"); while (Console.ReadKey().KeyChar != 'q') { } Console.WriteLine("\r\nDisconnecting"); mqttclient.Disconnect(); ihc.Disconnect(); }