コード例 #1
0
		/// <summary>
		/// Add a new sensor to the Device.
		/// </summary>
		/// <param name="sensorName">Name that will be given to the sensor.  Once a sensor is created it's name cannot be changed.
		/// <remarks>sensorName must be between 1 and 50 characters in length, and only contain characters in the set[A-Z,a-z,0-9,_]</remarks>
		/// </param>
		/// <param name="label">User Friendly label for the sensor.  May be changed later.
		/// <remarks>label supports unicode, and must not be more than 50 bytes when encoded as UTF-8.</remarks>
		/// </param>
		/// <param name="type">Type of the sensor. May be changed later.
		/// <remarks>type supports unicode, and must not be more than 50 bytes when encoded as UTF-8.</remarks>
		/// </param>
		/// <param name="description">Description of the sensor.  May be changed later.
		/// <remarks>description supports unicode, and must not be more than 1000 bytes when encoded as UTF-8.</remarks>
		/// </param>
		public Sensor AddSensor(String sensorName, String label, String type, String description)
		{
			var payload = new MemoryStream();
			var xdr = new XdrWriter(payload);
			
			int VERSION = 1;
			xdr.WriteInt(VERSION);
			xdr.WriteString(type);
			xdr.WriteString(label);
			xdr.WriteString(description);
			
			var request = _requests.url("/sensors/" + sensorName + "/")
								   .Param("version", "1")
								   .ContentType("application/xdr")
								   .Data(payload.ToArray())
								   .Put();
			
			// check the response code for success
			if (request.ResponseCode != HttpStatusCode.Created)
			{
				throw SensorCloudException.GenerateSensorCloudException(request, "AddSensor Failed");
			}

			return new Sensor(sensorName, _requests);
		}
コード例 #2
0
ファイル: Sensor.cs プロジェクト: vijaycvk/SensorCloud
        // Save  type, label, and descritpion to SensorCloud
        private void  SaveState(string label, string description, string type)
        {
            var payload = new MemoryStream();
            var xdr     = new XdrWriter(payload);

            const int VERSION = 1;

            xdr.WriteInt(VERSION);
            xdr.WriteString(type);
            xdr.WriteString(label);
            xdr.WriteString(description);


            var request = _requests.url("/sensors/" + this.Name + "/")
                          .Param("version", "1")
                          .Accept("application/xdr")
                          .ContentType("application/xdr")
                          .Data(payload.ToArray())
                          .Post();

            if (request.ResponseCode != HttpStatusCode.Created)
            {
                throw SensorCloudException.GenerateSensorCloudException(request, "Save Sensor state failed.");
            }
        }
コード例 #3
0
ファイル: Channel.cs プロジェクト: vijaycvk/SensorCloud
        /// <summary>
        /// Add time-series data to the channel.
        /// </summary>
        /// <param name="sensorName">sensor containing the channel to add data to.</param>
        /// <param name="channelName">channel to add data to.</param>
        /// <param name="sampleRate">sample-rate for points in data</param>
        /// <param name="data">a list of points to add to the channel.
        /// <remarks>The points should be ordered and match the sample-rate provided.</remarks>
        /// </param>
        public void AddTimeSeriesData(SampleRate sampleRate, IEnumerable <Point> data)
        {
            var payload = new MemoryStream();
            var xdr     = new XdrWriter(payload);

            const int VERSION = 1;

            xdr.WriteInt(VERSION);
            xdr.WriteInt(sampleRate.Type.ToXdr());
            xdr.WriteInt(sampleRate.Rate);

            //Writing an array in XDR.  an array is always prefixed by the array length
            xdr.WriteInt(data.Count());
            foreach (Point p in data)
            {
                xdr.WriteUnsingedHyper(p.UnixTimestamp);
                xdr.WriteFloat(p.Value);
            }

            string url     = "/sensors/" + _sensorName + "/channels/" + this.Name + "/streams/timeseries/data/";
            var    request = _requests.url(url)
                             .Param("version", "1")
                             .ContentType("application/xdr")
                             .Data(payload.ToArray())
                             .Put();

            // check the response code for success
            if (request.ResponseCode != HttpStatusCode.Created)
            {
                throw SensorCloudException.GenerateSensorCloudException(request, "AddTimeSeriesData failed.");
            }
        }
コード例 #4
0
ファイル: Sensor.cs プロジェクト: vijaycvk/SensorCloud
        /// <summary>
        /// Add a new channel to the Device.
        /// </summary>
        /// <param name="channelName">Name of the channel to create. Once a channel is created it's name cannot be changed.
        /// <remarks>sensorName must be between 1 and 50 charcters in length, and only contain characters in the set[A-Z,a-z,0-9,_]</remarks>
        /// </param>
        /// <param name="label">User Friendly label for the channel.  May be changed later.
        /// <remarks>label supports unicode, and must not be more than 50 bytes when encoded as UTF-8.</remarks>
        /// </param>
        /// <param name="description">Description of the channel.  May be changed later.
        /// <remarks>description supports unicode, and must not be more than 1000 bytes when encoded as UTF-8.</remarks>
        /// </param>
        public Channel AddChannel(string channelName, string label, string description)
        {
            var payload = new MemoryStream();
            var xdr     = new XdrWriter(payload);

            const int VERSION = 1;

            xdr.WriteInt(VERSION);
            xdr.WriteString(label);
            xdr.WriteString(description);

            string url     = "/sensors/" + this.Name + "/channels/" + channelName + "/";
            var    request = _requests.url(url)
                             .Param("version", "1")
                             .ContentType("application/xdr")
                             .Data(payload.ToArray())
                             .Put();

            // check the response code for success
            if (request.ResponseCode != HttpStatusCode.Created)
            {
                throw new SensorCloudException("AddChannel failed. http status:" + request.ResponseCode + " " + request.ResponseMessage + "  info:" + request.Text);
            }

            return(new Channel(this.Name, channelName, _requests));
        }
コード例 #5
0
		/// <summary>
		/// Add time-series data to the channel.
		/// </summary>
		/// <param name="sensorName">sensor containing the channel to add data to.</param>
		/// <param name="channelName">channel to add data to.</param>
		/// <param name="sampleRate">sample-rate for points in data</param>
		/// <param name="data">a list of points to add to the channel.
		/// <remarks>The points should be ordered and match the sample-rate provided.</remarks>
		/// </param>
		public void AddTimeSeriesData(SampleRate sampleRate, IEnumerable<Point> data)
		{
			var payload = new MemoryStream();
			var xdr = new XdrWriter(payload);

			const int VERSION = 1;
			xdr.WriteInt(VERSION);
			xdr.WriteInt(sampleRate.Type.ToXdr());
			xdr.WriteInt(sampleRate.Rate);

			//Writing an array in XDR.  an array is always prefixed by the array length
			xdr.WriteInt(data.Count());
			foreach (Point p in data)
			{
				xdr.WriteUnsingedHyper(p.UnixTimestamp);
				xdr.WriteFloat(p.Value);
			}

			string url = "/sensors/" + _sensorName + "/channels/" + this.Name + "/streams/timeseries/data/";
			var request = _requests.url(url)
								   .Param("version", "1")
								   .ContentType("application/xdr")
								   .Data(payload.ToArray())
								   .Put();

			// check the response code for success
			if (request.ResponseCode != HttpStatusCode.Created)
			{
				throw SensorCloudException.GenerateSensorCloudException(request, "AddTimeSeriesData failed.");
			}
		}
コード例 #6
0
ファイル: Device.cs プロジェクト: vijaycvk/SensorCloud
        /// <summary>
        /// Add a new sensor to the Device.
        /// </summary>
        /// <param name="sensorName">Name that will be given to the sensor.  Once a sensor is created it's name cannot be changed.
        /// <remarks>sensorName must be between 1 and 50 characters in length, and only contain characters in the set[A-Z,a-z,0-9,_]</remarks>
        /// </param>
        /// <param name="label">User Friendly label for the sensor.  May be changed later.
        /// <remarks>label supports unicode, and must not be more than 50 bytes when encoded as UTF-8.</remarks>
        /// </param>
        /// <param name="type">Type of the sensor. May be changed later.
        /// <remarks>type supports unicode, and must not be more than 50 bytes when encoded as UTF-8.</remarks>
        /// </param>
        /// <param name="description">Description of the sensor.  May be changed later.
        /// <remarks>description supports unicode, and must not be more than 1000 bytes when encoded as UTF-8.</remarks>
        /// </param>
        public Sensor AddSensor(String sensorName, String label, String type, String description)
        {
            var payload = new MemoryStream();
            var xdr     = new XdrWriter(payload);

            int VERSION = 1;

            xdr.WriteInt(VERSION);
            xdr.WriteString(type);
            xdr.WriteString(label);
            xdr.WriteString(description);

            var request = _requests.url("/sensors/" + sensorName + "/")
                          .Param("version", "1")
                          .ContentType("application/xdr")
                          .Data(payload.ToArray())
                          .Put();

            // check the response code for success
            if (request.ResponseCode != HttpStatusCode.Created)
            {
                throw SensorCloudException.GenerateSensorCloudException(request, "AddSensor Failed");
            }

            return(new Sensor(sensorName, _requests));
        }
コード例 #7
0
		// Save  type, label, and descritpion to SensorCloud
		private void  SaveState(string label, string description, string type)
		{
			var payload = new MemoryStream();
			var xdr = new XdrWriter(payload);

			const int VERSION = 1;
			xdr.WriteInt(VERSION);
			xdr.WriteString(type);
			xdr.WriteString(label);
			xdr.WriteString(description);
			

			var request = _requests.url("/sensors/" + this.Name + "/")
								  .Param("version", "1")
								  .Accept("application/xdr")
								  .ContentType("application/xdr")
								  .Data(payload.ToArray())
								  .Post();

			if (request.ResponseCode != HttpStatusCode.Created)
			{
				throw SensorCloudException.GenerateSensorCloudException(request, "Save Sensor state failed.");
			}
		}
コード例 #8
0
		/// <summary>
		/// Add a new channel to the Device.
		/// </summary>
		/// <param name="channelName">Name of the channel to create. Once a channel is created it's name cannot be changed.
		/// <remarks>sensorName must be between 1 and 50 charcters in length, and only contain characters in the set[A-Z,a-z,0-9,_]</remarks>
		/// </param>
		/// <param name="label">User Friendly label for the channel.  May be changed later.
		/// <remarks>label supports unicode, and must not be more than 50 bytes when encoded as UTF-8.</remarks>
		/// </param>
		/// <param name="description">Description of the channel.  May be changed later.
		/// <remarks>description supports unicode, and must not be more than 1000 bytes when encoded as UTF-8.</remarks>
		/// </param>
		public Channel AddChannel(string channelName, string label, string description)
		{
			var payload = new MemoryStream();
			var xdr = new XdrWriter(payload);

			const int VERSION = 1;
			xdr.WriteInt(VERSION);
			xdr.WriteString(label);
			xdr.WriteString(description);

			string url = "/sensors/" + this.Name + "/channels/" + channelName + "/";
			var request = _requests.url(url)
								  .Param("version", "1")
								  .ContentType("application/xdr")
								  .Data(payload.ToArray())
								  .Put();

			// check the response code for success
			if (request.ResponseCode != HttpStatusCode.Created)
			{
				throw new SensorCloudException("AddChannel failed. http status:" + request.ResponseCode + " " + request.ResponseMessage + "  info:" + request.Text);
			}

			return new Channel(this.Name, channelName, _requests);
		}