Example #1
0
 void d_PublishedDataReceived(object sender, PublishedDataReceivedEventArgs args)
 {
     // Do something with the data. The data is part of 'args'
 }
Example #2
0
        // Provide new data to the device, process the data into a dynamic object, and raise the data received
        // event. The user could call this, but why would they?
        public virtual void NewData(byte[] rawData, bool retain, bool dupFlag, QualityOfService qosLevel)
        {
            if (PublishedDataReceived != null)
            {
                string json = System.Text.Encoding.UTF8.GetString(rawData, 0, rawData.Length);

                dynamic dataObject;

                try {
                    // If the Json data is an array, parse it as one
                    if (json[0] == '[')
                    {
                        JArray responseElements = JArray.Parse(json);
                        dataObject = responseElements.ToArray<dynamic>();
                    }
                    // Otherise, parse it as a single object
                    else
                    {
                        dataObject = JObject.Parse(json);
                    }
                }
                catch (Exception e)
                {
                    throw new ArgumentException("There was an error processing the JSON, it is probably improperly formatted", e);
                }

                PublishedDataReceivedEventArgs args = new PublishedDataReceivedEventArgs(dataObject, dupFlag, retain, qosLevel);
                PublishedDataReceived(this, args);
            }
        }
Example #3
0
 void device_PublishedDataReceivedGyroscope(object sender, PublishedDataReceivedEventArgs args)
 {
     this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
     {
         outputGyroscope.Text = "The angularSpeed is " + args.Data["gyro"] + " and acceleration is: " + args.Data["accel"];
     });
 }
Example #4
0
 void device_PublishedDataReceivedLight(object sender, PublishedDataReceivedEventArgs args)
 {
     this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
     {
         outputLight.Text = "The amount of light is " + args.Data["light"] + " lux and amount of red, green and blue: " + args.Data["clr"];
     });
 }
Example #5
0
 void device_PublishedDataReceivedMicrophone(object sender, PublishedDataReceivedEventArgs args)
 {
     this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
     {
         outputMicrophone.Text = "The Noise is " + args.Data["snd_level"] + " dB - TimeStamp:" + args.Data["ts"];
     });
 }
Example #6
0
        // Create Handlers for the the sensor's data published event
        void device_PublishedDataReceivedThermometer(object sender, PublishedDataReceivedEventArgs args)
        {
            this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                string tmpTemperature = args.Data["temp"];
                double tmpTimeStamp = args.Data["ts"];
                DateTime tmpDateTime = ConvertUnixTimeStamp(tmpTimeStamp);
                string formattedDate = tmpDateTime.ToString("yyyy-MM-dd hh:mm:ss.fff tt");

                outputThermometer.Text = "The Temperature is " + tmpTemperature + " °C - TimeStamp: " + formattedDate;
                outputThermometer2.Text = "The Humidity is " + args.Data["hum"] + " % - TimeStamp: " + formattedDate;
            });
        }