コード例 #1
0
        public void GetDatastreamTest()
        {
            // act
            var datastream       = client.GetDatastream("760827").Result.Result;
            var observations     = datastream.GetObservations(client).Result.Result;
            var observedProperty = datastream.GetObservedProperty(client).Result.Result;
            var sensor           = datastream.GetSensor(client).Result.Result;
            var thing            = datastream.GetThing(client).Result.Result;


            // assert
            Assert.IsTrue(datastream.Id == "760827");
            Assert.IsTrue(datastream.SelfLink == "http://scratchpad.sensorup.com/OGCSensorThings/v1.0/Datastreams(760827)");
            Assert.IsTrue(datastream.Description == "Data stream description");
            Assert.IsTrue(datastream.Name == "NYP_DATASTREM_4321");
            Assert.IsTrue(datastream.ObservationType == "http://www.opengis.net/def/observationType/OGC-OM/2.0/OM_Measurement");
            Assert.IsTrue(datastream.UnitOfMeasurement.Symbol == "BPM");
            Assert.IsTrue(datastream.UnitOfMeasurement.Name == "Beats Per Minute");
            Assert.IsTrue(datastream.UnitOfMeasurement.Definition == "http://www.qudt.org/qudt/owl/1.0.0/unit/Instances.html#BPM");
            Assert.IsTrue(datastream.ObservationsNavigationLink == "http://scratchpad.sensorup.com/OGCSensorThings/v1.0/Datastreams(760827)/Observations");
            Assert.IsTrue(datastream.ObservedPropertyNavigationLink == "http://scratchpad.sensorup.com/OGCSensorThings/v1.0/Datastreams(760827)/ObservedProperty");
            Assert.IsTrue(datastream.SensorNavigationLink == "http://scratchpad.sensorup.com/OGCSensorThings/v1.0/Datastreams(760827)/Sensor");
            Assert.IsTrue(datastream.ThingNavigationLink == "http://scratchpad.sensorup.com/OGCSensorThings/v1.0/Datastreams(760827)/Thing");
            Assert.IsTrue(observations.Count > 0);
            Assert.IsTrue(observedProperty.Description == "acceleration of sensor");
            Assert.IsTrue(sensor.Id == "760611");
            Assert.IsTrue(thing.Id == "760737");
        }
コード例 #2
0
        private async void LoadData()
        {
            var client = new SensorThingsClient(serverurl);
            var odata  = new OdataQuery {
                QueryExpand = new QueryExpand(new[]
                {
                    new Expand(new[] { "Observations" })
                }
                                              )
            };


            var response = await client.GetDatastream(datastreamid, odata);

            var datastream = response.Result;

            var lineSerie = new OxyPlot.Series.LineSeries
            {
                StrokeThickness             = 2,
                MarkerSize                  = 3,
                MarkerStroke                = Colors.GetColors[0],
                MarkerType                  = MarkerTypes.markerTypes[0],
                CanTrackerInterpolatePoints = false,
                Title  = datastream.Description,
                Smooth = false,
            };

            var obs = datastream.Observations.OrderBy(m => m.PhenomenonTime.Start);

            foreach (var observation in obs)
            {
                if (observation.PhenomenonTime != null)
                {
                    var time = observation.GetPhenomenonTime(true);
                    var res  = Convert.ToDouble(observation.Result);
                    lineSerie.Points.Add(new DataPoint(OxyPlot.Axes.DateTimeAxis.ToDouble(time), res));
                }
            }

            plotModel.Series.Add(lineSerie);
            plotview.InvalidatePlot();
        }
コード例 #3
0
        private async void LoadData()
        {
            var client   = new SensorThingsClient(serverurl);
            var response = await client.GetDatastream(datastreamid);

            var datastream           = response.Result;
            var observationsResponse = await datastream.GetObservations(client);

            var observations = observationsResponse.Result;
            var obs          = observations.Items.OrderBy(m => m.PhenomenonTime.Start);

            foreach (var observation in obs)
            {
                var lPhenomenonTime = observation.GetPhenomenonTime(true).Value;
                var res             = Convert.ToDouble(observation.Result);
                var newpoint        = new DateTimePoint(lPhenomenonTime, res);

                Dispatcher.Invoke(() =>
                {
                    SeriesCollection[0].Values.Add(newpoint);
                });
            }
        }
    void Start()
    {
        if (server.Contains("https"))
        {
            //trust the certificate...
            ServicePointManager.ServerCertificateValidationCallback = (a, b, c, d) => { return(true); };
        }

        var client = new SensorThingsClient(server);
        var ds     = client.GetDatastream(datastream);

        lastObservation = ds.GetObservations().Items.First().Result.ToString();
        // todo: do something with the location...
        // var dsLocation = ds.GetThing().GetLocations().Items.First();
        Debug.Log("Last observation: " + lastObservation);

        var mqttclient = new MqttClient(new Uri(server).Host);

        mqttclient.Connect(Guid.NewGuid().ToString());

        mqttclient.Subscribe(new string[] { $"Datastreams({datastream})/Observations" },
                             new byte[] { MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE });
        mqttclient.MqttMsgPublishReceived += client_MqttMsgPublishReceived;

        go = new GameObject();
        var tr = go.GetComponent <Transform>();
        var p  = new Vector3(0, 0, 0);
        var q  = new Quaternion(0, 0, 0, 0);

        tr.SetPositionAndRotation(p, q);
        var myText = go.AddComponent <TextMesh>();

        myText.name     = "temperature";
        myText.fontSize = 50;
        myText.anchor   = TextAnchor.LowerCenter;
        myText.text     = lastObservation;
    }
コード例 #5
0
        static void Main()
        {
            Console.WriteLine("Sample console app for SensorThings API client");
            var server = "http://scratchpad.sensorup.com/OGCSensorThings/v1.0/";

            var client = new SensorThingsClient(server);

            Console.WriteLine("Create observation for datastream 18");
            var datastream = new Datastream {
                Id = "263"
            };
            var observation = new Observation
            {
                Datastream     = datastream,
                PhenomenonTime = new DateTimeRange(DateTime.UtcNow),
                Result         = 100
            };

            // do not create observations for now
            _ = client.CreateObservation(observation).Result;

            Console.WriteLine("Retrieve all paged datastreams...");
            var response = client.GetDatastreamCollection().Result;
            var page     = response.Result;

            var pagenumber = 1;

            while (page != null)
            {
                Console.WriteLine("---------------------------------------");
                WritePage(response.Result);
                var pageResponse = page.GetNextPage().Result;
                page = pageResponse?.Result;

                pagenumber++;
            }
            Console.WriteLine("End retrieving datastreams...");
            Console.WriteLine("Number of pages: " + pagenumber);

            var datastreamResponse = client.GetDatastream("263").Result;

            datastream = datastreamResponse.Result;
            var observationsResponse = datastream.GetObservations(client).Result;
            var observations         = observationsResponse.Result;

            Console.WriteLine("Number if observations: " + observations.Count);

            Console.WriteLine("Sample with locations");
            var locationsResponse = client.GetLocationCollection().Result;
            var locations         = locationsResponse.Result;

            // Get location without using GeoJSON.NET (works only for points)
            var firstlocation = locations.Items[0];
            var feature       = (JObject)firstlocation.Feature;
            var lon           = feature.First.First.First.Value <double>();
            var lat           = feature.First.First.Last.Value <double>();

            Console.WriteLine($"Location: {lon},{lat}");

            // if using GeoJSON.NET use something like:
            // var p = JsonConvert.DeserializeObject<Point>(feature.ToString());
            //  var ipoint = (GeographicPosition)p.Coordinates;
            // Console.WriteLine("Location: " + ipoint.Longitude + ", " + ipoint.Latitude);

            Console.WriteLine("Program ends... Press a key to continue.");
            Console.ReadKey();
        }