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 MqttMsgPublishReceived(object sender, MqttMsgPublishEventArgs e) { try { if (!conf.IhcIn.ContainsKey(e.Topic)) { return; } int ihcid = conf.IhcIn[e.Topic]; string value = Encoding.ASCII.GetString(e.Message); if (verbose) { Console.Out.WriteLine("MQTT: " + e.Topic + " -> " + value); } mqttstates[ihcid] = value; if (!ihctypes.ContainsKey(ihcid)) { var values = ihc.GetRuntimeValues(new int[] { ihcid }); var v = values[0]; ihctypes[ihcid] = v.GetType(); ihcstates[ihcid] = ValueToString(v); } if (ihcstates.ContainsKey(ihcid) && ihcstates[ihcid] == value) { return; } ihcstates[ihcid] = value; switch (ihctypes[ihcid].Name) { case "Boolean": ihc.SetRuntimeValueBool(ihcid, value == conf.BooleanTrue); break; case "Int32": ihc.SetRuntimeValueInt(ihcid, int.Parse(value)); break; case "Double": case "Single": ihc.SetRuntimeValueFloat(ihcid, float.Parse(value)); break; } } #pragma warning disable CS0168 catch (Exception ex) { } }