public void GetAndSetResourceValues() { var sdk = new SDK(); // an example: get and set a resource value // cloak /* * // uncloak * using Mbed.Cloud; * using Mbed.Cloud.Common; * using Mbed.Cloud.Foundation; * using Mbed.Cloud.Foundation.Enums; * using MbedCloudSDK.Connect.Api; * // cloak */ // uncloak // Use the Foundation interface to find a connected device. var device = sdk .Foundation() .DeviceRepository() .List(new DeviceListOptions().StateEqualTo(DeviceState.REGISTERED)) .FirstOrDefault(); // Use the Legacy interface for find resources var config = new Config { AutostartNotifications = true, }; using (var connect = new ConnectApi(config)) { // Find an observable resource var resource = connect .ListResources(device.Id) .FirstOrDefault(r => r.Observable == true); // Set a resource value connect.SetResourceValue(resource.DeviceId, resource.Path, "12"); // Get a resource value var value = connect.GetResourceValue(resource.DeviceId, resource.Path); Console.WriteLine($"Device {device.Id}, path {resource.Path}, current value: {value}"); } // end of example }
/// <summary> /// Gets the value of the resource. /// </summary> /// <returns>Resource value</returns> public string GetResourceValue() { return(api.GetResourceValue(DeviceId, Path)); }