public void ConnectToBroker_Null_TransmitterId_ThrowInvalidArgsException()
 {
     try 
     { 
         Transmitter transmitter = new Transmitter(null);
         Assert.Fail();
     }
     catch(ArgumentException e)
     {
     
     }
 }
Exemple #2
0
        public async void getMeasurements()
        {
            // Set the OAuth token = "YOUR OAUTH TOKEN HERE"
            Relayr.OauthToken = "8IBG3kct-JmrRy_cU5-IoLN708Z9_fAn";

            // Get a list of transmitters and connect to the MQTT broker with the first one in the list
            transmitters = await Relayr.GetTransmittersAsync();   // "CLIENT ID OF YOUR CHOICE"
            transmitter = Relayr.ConnectToBroker(transmitters[0], "4f585a21-f19b-44cc-8874-7afef539dcbb");
            userId = Relayr.UserId;
            userName = Relayr.Name;
            userEmail = Relayr.Email;
            displayUserInfo(userId, userName, userEmail);

            // Get a list of devices associated with the transmitter, 
            // Subscribe to data from the first device on the list
            devices = await transmitter.GetDevicesAsync();    // "{ADD SENSOR ID}"

            //Device[] listOfDevices;
            for (int i = 0; i < devices.Count; i++)
            {
                string tmpId = (devices[i]["id"]).ToString();
                string tmpName = (devices[i]["name"]).ToString();

                Device tmpDevice = new Device((devices[i]["id"]).ToString(), (devices[i]["name"]).ToString(), (devices[i]["firmwareVersion"]).ToString());
                devicesOfUser.Add(tmpDevice);
                //listOfDevices[i] = await transmitter.SubscribeToDeviceDataAsync((devices[i]["id"]).ToString());
                //listOfDevices[i].PublishedDataReceived += device_PublishedDataReceived;

                switch (tmpName)
                {
                    case "gyroscope":
                        Gyroscope(tmpId);
                        break;
                    case "light":
                        Light(tmpId);
                        break;
                    case "microphone":
                        Microphone(tmpId);
                        break;
                    case "thermometer":
                        Thermometer(tmpId);
                        break;


                    default:
                        //Console.WriteLine("Default case");
                        break;
                }
            }
            displayDevices(devicesOfUser);
        }
Exemple #3
0
        // Try to connect to the broker using the given dynamic representation of a transmitter and
        // the specified clientID. If connection is successful, it will return a Transmitter isntance
        // representing the transmitter. Returns null otherwise.
        public static Transmitter ConnectToBroker(dynamic transmitterInfo, string clientId)
        {

            // Check arguments
            if (transmitterInfo == null)
            {
                throw new ArgumentException("Transmitter Info argument cannot be null");
            }

            if (clientId == null || clientId.Equals(""))
            {
                throw new ArgumentException("ClientId cannot be null or empty");
            }

            // Get required fields, try to open a connection
            string transmitterId = (string)transmitterInfo["id"];
            string transmitterSecret = (string)transmitterInfo["secret"];

            Transmitter transmitter = new Transmitter(transmitterId);
            bool success = transmitter.ConnectToBroker(clientId, transmitterSecret);

            if (!success)
            {
                return null;
            }

            return transmitter;
        }
        public void ConnectToBroker_Null_ClientId_ThrowInvalidArgsException()
        {
            try
            {
                Transmitter transmitter = new Transmitter(transmitterId);
                transmitter.ConnectToBroker(null, transmitterSecret);
                Assert.Fail();
            }
            catch(ArgumentException e)
            {

            }
        }
 public void ConnectToBroker_Incorrect_TransmitterId_Return_False()
 {
     Transmitter transmitter = new Transmitter("asdasdf");
     Assert.IsFalse(transmitter.ConnectToBroker("hello", transmitterSecret));
 }
        public async void SubscribeToSensor_Connection_Successful_ReturnDevice()
        {
            Transmitter transmitter = new Transmitter(transmitterId);
            transmitter.ConnectToBroker("hello", transmitterSecret);
            Device device = await transmitter.SubscribeToDeviceDataAsync("d1fa0703-36bb-4694-8db1-a71becc9d489");

            Assert.IsNotNull(device);
        }
 public void ConnectToBroker_ValidCredentials_Success()
 {
     Transmitter transmitter = new Transmitter(transmitterId);
     Assert.IsTrue(transmitter.ConnectToBroker("hello", transmitterSecret));
 }
        public async void SubscribeToSensor_Connection_Fails_ReturnNull()
        {
            Transmitter transmitter = new Transmitter(transmitterId);
            transmitter.ConnectToBroker("hello", transmitterSecret);
            Device device = await transmitter.SubscribeToDeviceDataAsync("asdasd33");

            //Assert.IsNull(device);
        }
        public void SubscribeToSensor_Empty_DeviceId_ThrowException()
        {
            try
            {
                Transmitter transmitter = new Transmitter(transmitterId);
                transmitter.ConnectToBroker("hello", transmitterSecret);
                transmitter.SubscribeToDeviceDataAsync("");
                Assert.Fail();
            }
            catch (ArgumentException e)
            {

            }
        }
 public void ConnectToBroker_Empty_Secret_False()
 {
     Transmitter transmitter = new Transmitter(transmitterId);
     Assert.IsFalse(transmitter.ConnectToBroker("hello", ""));
 }
 public void ConnectToBroker_Empty_ClientId_False()
 {
     Transmitter transmitter = new Transmitter(transmitterId);
     Assert.IsFalse(transmitter.ConnectToBroker("", transmitterSecret));
 }
        public void ConnectToBroker_Null_Secret_ThrowInvalidArgsException()
        {
            try
            {
                Transmitter transmitter = new Transmitter(transmitterId);
                transmitter.ConnectToBroker("hello", null);
                Assert.Fail();
            }
            catch (ArgumentException e)
            {

            }
        }