示例#1
0
 private void button_Click(object sender, EventArgs e)
 {
     if ((mqttClient != null) && (mqttClientConnected))
     {
         Button btn = (Button)sender;
         if (btn.Name.StartsWith("button"))
         {
             ICControlObject obj = new ICControlObject();
             int             rm  = int.Parse(btn.Name.Substring("button".Length));
             settingRefObjChannel(ref obj, rm);
             string topic = String.Format(txTopicFmt, txDevs[rm - 1]);
             var    msg   = new MQTTnet.MqttApplicationMessageBuilder()
                            .WithPayload(JsonConvert.SerializeObject(obj))
                            .WithTopic(topic)
                            .WithAtMostOnceQoS()
                            .Build();
             mqttClient.PublishAsync(msg);
             string json = JsonConvert.SerializeObject(obj);
             debugOutput("topic", topic);
             debugOutput("json", json);
         }
     }
 }
示例#2
0
 private void settingRefObjChannel(ref ICControlObject refObj, int rm)
 {
     if (rm == 1)
     {
         [email protected] = toggleSwitch1.Checked;
         [email protected] = toggleSwitch2.Checked;
         [email protected] = toggleSwitch3.Checked;
         [email protected] = toggleSwitch4.Checked;
     }
     else if (rm == 2)
     {
         [email protected] = toggleSwitch5.Checked;
         [email protected] = toggleSwitch6.Checked;
         [email protected] = toggleSwitch7.Checked;
         [email protected] = toggleSwitch8.Checked;
     }
     else if (rm == 3)
     {
         [email protected] = toggleSwitch9.Checked;
         [email protected] = toggleSwitch10.Checked;
         [email protected] = toggleSwitch11.Checked;
         [email protected] = toggleSwitch12.Checked;
     }
 }