Пример #1
0
        static void Main(string[] args)
        {
            try
            {
                string data       = "name:foo,cpu:60,mem:50";
                string deviceType = "";
                string deviceId   = "";
                string evt        = "test";
                string format     = "json";

                Console.Write("Enter your org id :");
                orgId = Console.ReadLine();

                Console.Write("Enter your app id :");
                appId = Console.ReadLine();

                Console.Write("Enter your api Key :");
                apiKey = Console.ReadLine();

                Console.Write("Enter your auth token :");
                authToken = Console.ReadLine();



                Console.Write("Enter your device type :");
                deviceType = Console.ReadLine();

                Console.Write("Enter your device id :");
                deviceId = Console.ReadLine();



                ApplciationClient applicationClient = new ApplciationClient(orgId, appId, apiKey, authToken);
                applicationClient.connect();

                Console.WriteLine("Connected sucessfully to app id : " + appId);

                applicationClient.commandCallback      += processCommand;
                applicationClient.eventCallback        += processEvent;
                applicationClient.deviceStatusCallback += processDeviceStatus;
                applicationClient.appStatusCallback    += processAppStatus;

                applicationClient.subscribeToDeviceStatus();
                applicationClient.subscribeToApplicationStatus();

                Console.Write("Please enter device details to which you want to subscribe event and send command...");

                applicationClient.subscribeToDeviceEvents(deviceType, deviceId, evt, format, 0);



                applicationClient.publishCommand(deviceType, deviceId, "testcmd", "json", data, 0);

                applicationClient.disconnect();
            }
            catch (Exception)
            {
                // ignore
            }
        }
Пример #2
0
        static void Main(string[] args)
        {
            log4net.Config.XmlConfigurator.Configure();
            ILog log = log4net.LogManager.GetLogger(typeof(SampleAppClient));
            try
            {
                string data = "name:foo,cpu:60,mem:50";
                string deviceType = "TestType";
                string deviceId = "9663155111";
                string evt = "temp";
                string format = "json";

                ApplciationClient applicationClient = new ApplciationClient(orgId, appId, apiKey, authToken);
                applicationClient.connect();

                log.Info("Connected sucessfully to app id : " + appId);

                applicationClient.commandCallback += processCommand;
                applicationClient.eventCallback += processEvent;
                applicationClient.deviceStatusCallback += processDeviceStatus;
                applicationClient.appStatusCallback += processAppStatus;

                applicationClient.subscribeToDeviceStatus();
                applicationClient.subscribeToApplicationStatus();
                applicationClient.subscribeToDeviceEvents(deviceType, deviceId, evt, format, 0);
                applicationClient.publishCommand(deviceType, deviceId, "testcmd", "json", data, 0);

                applicationClient.disconnect();
            }
            catch (Exception)
            {
                // ignore
            }
        }
Пример #3
0
        //------------------------------------------------------------------------------------------------------------------------
        #endregion

        #region Constructor
        public AppClient(string organization, string appname, string apikey, string authtoken)
        {
            //create application endpoint
            applicationClient = new ApplciationClient(organization, appname, apikey, authtoken);
            //connect to mqtt broker
            applicationClient.connect();
            //register cb for devices' status
            applicationClient.deviceStatusCallback += StatusHandler;
            //register cb for the events that are published from devices to IOT Foundation
            applicationClient.eventCallback += EventHandler;
            //subscribe to both events
            //applicationClient.subscribeToDeviceStatus();
            applicationClient.subscribeToDeviceEvents();
        }