// 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."); } }
/// <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)); }
/// <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)); }
/// <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); }
/// <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); }