public static void Main(string[] args) { DiscoverySniffer sniffer = new DiscoverySniffer(); sniffer.discoverIP(); String localIP = sniffer.GetLocalIPAddress(); string jsonString = System.IO.File.ReadAllText(REGIST_PATH); JObject registJSON = JObject.Parse(jsonString); JToken deviceID = registJSON.GetValue("device_id"); //publish the topic for the regist MQTTclient mqtt = new MQTTclient(); mqtt.connect(localIP, deviceID.ToString()); mqtt.publish(TOPIC_REGIST, registJSON.ToString()); //mqtt.disconnect(); //subscribe the list topic string[] topicStrings = { TOPIC_GETTOPICS }; SubscribeTopicsList topSub = new SubscribeTopicsList(TOPICS_PATH, localIP, topicStrings); topSub.getList(); System.Threading.Thread.Sleep(10000); topSub.disconnect(); PublishData pubData = new PublishData(TOPICS_PATH, localIP, deviceID.ToString()); pubData.createPublishDataThreads(); }
public void attributePublish(string topic, MQTTclient pubData, int sleep) { Random rd = new Random(); while (true) { int value = rd.Next(100); Console.WriteLine("Topic: " + topic); pubData.publish(topic, value.ToString()); System.Threading.Thread.Sleep(sleep); } }