Beispiel #1
0
        public void createPublishDataThreads()
        {
            string  jsonString = System.IO.File.ReadAllText(topicsPath);
            JObject topicsJSON = JObject.Parse(jsonString);
            JArray  vector     = (JArray)topicsJSON.GetValue("topics");

            //JObject iterator = (JObject) vector.First;
            //JToken token;
            Console.WriteLine(vector.Count);

            MQTTclient pubData = new MQTTclient();

            pubData.connect(deviceIP, deviceID + "DataPublisher");
            int i = 1;

            foreach (var item in vector.Children())
            {
                JToken t   = item.SelectToken("url");
                string url = t.ToString();

                if (url == deviceURL)
                {
                    JToken token = item.SelectToken("topic");
                    Console.WriteLine(token.ToString());
                    Thread thread = new Thread(() => attributePublish(token.ToString(), pubData, i * 2000));
                    thread.Start();
                }
                i++;
            }
        }
Beispiel #2
0
        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();
        }
Beispiel #3
0
        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);
            }
        }