public void IotDataTests() { var topicName = "$aws/things/" + THING_NAME + "/shadow/update"; Client.Publish(new PublishRequest { Topic = topicName, Qos = 1, Payload = new MemoryStream(new byte[] { 1, 2, 3, 4 }) }); Client.Publish(new PublishRequest { Topic = topicName, Qos = 1 }); topicName = "$aws/things/" + THING_NAME + "/shadow/get"; Client.Publish(new PublishRequest { Topic = topicName, Qos = 1, Payload = new MemoryStream(new byte[] { 1, 2, 3, 4 }) }); Client.Publish(new PublishRequest { Topic = topicName, Qos = 1 }); var payload = new MemoryStream(System.Text.Encoding.UTF8.GetBytes( @"{ ""state"": {}}" )); var updateThingShadowResponse = Client.UpdateThingShadow(new UpdateThingShadowRequest { ThingName = THING_NAME, Payload = payload }); Assert.IsTrue(payload.Length < updateThingShadowResponse.Payload.Length); var getThingShadowResponse = Client.GetThingShadow(new GetThingShadowRequest { ThingName = THING_NAME }); Assert.IsTrue(getThingShadowResponse.Payload.Length > 0); var deleteThingShadowResponse = Client.DeleteThingShadow(new DeleteThingShadowRequest { ThingName = THING_NAME }); Assert.IsTrue(getThingShadowResponse.Payload.Length > 0); }
public ActionResult State(string devName) { GetThingShadowRequest req = new GetThingShadowRequest(); req.ThingName = devName; GetThingShadowResponse res = _client.GetThingShadow(req); string state = Encoding.UTF8.GetString(res.Payload.ToArray()); return(Content(Request["callback"] + "(" + state + ")")); }