예제 #1
0
 private async Task CheckDeviceAsync(string deviceId)
 {
     if (_whiteList.ContainsKey(deviceId))
         return;
     if (_serviceSettings == null)
         return;
     var connectionString = string.Format("HostName={0}.azure-devices.net;SharedAccessKeyName={1};SharedAccessKey={2}",
                     _serviceSettings.Host, _serviceSettings.KeyName, _serviceSettings.Key);
     var registry = Microsoft.Azure.Devices.RegistryManager.CreateFromConnectionString(connectionString);
     var deviceReg = await registry.GetDeviceAsync(deviceId);
     if (deviceReg == null)
     {
         deviceReg = new Microsoft.Azure.Devices.Device(deviceId);
         deviceReg = await registry.AddDeviceAsync(deviceReg);
     }
     var device = new DeviceModel();
     device.DeviceId = deviceId;
     //device.DeviceRegId = deviceReg.Id;
     device.Key = deviceReg.Authentication.SymmetricKey.PrimaryKey;
     _whiteList.Add(deviceId, device);
     var data = new DeviceMetaData();
     data.Version = "1.0";
     data.IsSimulatedDevice = false;
     data.Properties.DeviceID = deviceId;
     data.Properties.FirmwareVersion = "42";
     data.Properties.HubEnabledState = true;
     data.Properties.Processor = "Foo";
     data.Properties.Platform = "Yep";
     data.Properties.SerialNumber = "Sigfox-" + deviceId;
     data.Properties.InstalledRAM = "1 MB";
     data.Properties.ModelNumber = "007-BOND";
     data.Properties.Manufacturer = "Sigfox";
     //data.Properties.UpdatedTime = DateTime.UtcNow;
     data.Properties.DeviceState = DeviceState.Normal;
     var content = JsonConvert.SerializeObject(data);
     connectionString = string.Format("HostName={0}.azure-devices.net;DeviceId={1};SharedAccessKey={2}",
         "sigfoxmonitoring", device.DeviceId, device.Key);
     _client = DeviceClient.CreateFromConnectionString(connectionString, TransportType.Http1);
     await _client.SendEventAsync(new Message(Encoding.UTF8.GetBytes(content)));
 }
예제 #2
0
 public async Task InitAsync()
 {
     _board = IoC.Instance.Resolve<IBoardService>();
     //if (_board == null)
     //    throw new Exception("A board must be registered");
     var connectionString = string.Format("HostName={0}.azure-devices.net;DeviceId={1};SharedAccessKey={2}",
         SettingsViewModel.Default.Host, SettingsViewModel.Default.DeviceId, SettingsViewModel.Default.Key);
     _client = DeviceClient.CreateFromConnectionString(connectionString, TransportType.Http1);
     var data = new DeviceMetaData();
     data.Version = "1.0";
     data.IsSimulatedDevice = false;
     data.Properties.DeviceID = SettingsViewModel.Default.DeviceId;
     data.Properties.FirmwareVersion = "1.42";
     data.Properties.HubEnabledState = true;
     data.Properties.Processor = "ARM";
     data.Properties.Platform = "UWP";
     data.Properties.SerialNumber = "1234567890";
     data.Properties.InstalledRAM = "1024 MB";
     data.Properties.ModelNumber = "007-BOND";
     data.Properties.Manufacturer = "Raspberry";
     //data.Properties.UpdatedTime = DateTime.UtcNow;
     data.Properties.DeviceState = DeviceState.Normal;
     data.Commands.Add(new DeviceCommandDefinition("SwitchLight"));
     data.Commands.Add(new DeviceCommandDefinition("LightColor",
         new DeviceCommandParameterDefinition[] {
             new DeviceCommandParameterDefinition("Color", DeviceCommandParameterType.String)
         }));
     data.Commands.Add(new DeviceCommandDefinition("PingDevice"));
     data.Commands.Add(new DeviceCommandDefinition("StartTelemetry"));
     data.Commands.Add(new DeviceCommandDefinition("StopTelemetry"));
     data.Commands.Add(new DeviceCommandDefinition("ChangeSetPointTemp"));
     data.Commands.Add(new DeviceCommandDefinition("DiagnosticTelemetry"));
     data.Commands.Add(new DeviceCommandDefinition("ChangeDeviceState"));
     var content = JsonConvert.SerializeObject(data);
     await _client.SendEventAsync(new Message(Encoding.UTF8.GetBytes(content)));
 }
예제 #3
0
파일: Program.cs 프로젝트: danvy/sigfox
 private static async Task CheckDeviceAsync(string deviceId)
 {
     if (_whiteList.ContainsKey(deviceId))
         return;
     //var connectionString = IotHubConnectionStringBuilder.Create("sigfoxmonitoring",
     //    AuthenticationMethodFactory.CreateAuthenticationWithSharedAccessPolicyKey(deviceId, "registryReadWrite", "weAJyh51pxOk5f/OVZRGXc4JR6AJDg+JYjiK3rlDTzs="));
     var connectionString = string.Format("HostName={0}.azure-devices.net;SharedAccessKeyName={1};SharedAccessKey={2}",
                     "sigfoxmonitoring", "iothubowner", "B2LsypvIEz7bdy0217QYfeUvO1xUjKVujlte4wETrvM=");
     var registry = Microsoft.Azure.Devices.RegistryManager.CreateFromConnectionString(connectionString);
     await registry.RemoveDeviceAsync("Sigfox-FAE88");
     return;
     var deviceReg = await registry.GetDeviceAsync(deviceId);
     if (deviceReg == null)
     {
         deviceReg = new Microsoft.Azure.Devices.Device(deviceId);
         deviceReg = await registry.AddDeviceAsync(deviceReg);
     }
     var device = new DeviceModel();
     device.DeviceId = deviceId;
     //device.DeviceRegId = deviceReg.Id;
     device.Key = deviceReg.Authentication.SymmetricKey.PrimaryKey;
     _whiteList.Add(deviceId, device);
     var data = new DeviceMetaData();
     data.Version = "1.0";
     data.IsSimulatedDevice = false;
     data.Properties.DeviceID = deviceId;
     data.Properties.FirmwareVersion = "42";
     data.Properties.HubEnabledState = true;
     data.Properties.Processor = "Foo";
     data.Properties.Platform = "Yep";
     data.Properties.SerialNumber = "Sigfox-" + deviceId;
     data.Properties.InstalledRAM = "1 MB";
     data.Properties.ModelNumber = "007-BOND";
     data.Properties.Manufacturer = "Sigfox";
     //data.Properties.UpdatedTime = DateTime.UtcNow;
     data.Properties.DeviceState = DeviceState.Normal;
     var content = JsonConvert.SerializeObject(data);
     connectionString = string.Format("HostName={0}.azure-devices.net;DeviceId={1};SharedAccessKey={2}",
         "sigfoxmonitoring", device.DeviceId, device.Key);
     _client = DeviceClient.CreateFromConnectionString(connectionString, TransportType.Http1);
     await _client.SendEventAsync(new Message(Encoding.UTF8.GetBytes(content)));
 }
예제 #4
0
 private static void Init()
 {
     _deviceId = ConfigurationManager.AppSettings["DeviceId"];
     var host = ConfigurationManager.AppSettings["Host"];
     var key = ConfigurationManager.AppSettings["Key"];
     var connectionString = string.Format("HostName={0}.azure-devices.net;DeviceId={1};SharedAccessKey={2}",
         host, _deviceId, key);
     _client = DeviceClient.CreateFromConnectionString(connectionString, TransportType.Http1);
     var data = new DeviceMetaData();
     data.Version = "1.0";
     data.IsSimulatedDevice = false;
     data.Properties.DeviceID = _deviceId;
     data.Properties.FirmwareVersion = "1.42";
     data.Properties.HubEnabledState = true;
     data.Properties.Processor = "ARM";
     data.Properties.Platform = "UWP";
     data.Properties.SerialNumber = "1234567890";
     data.Properties.InstalledRAM = "1024 MB";
     data.Properties.ModelNumber = "007-BOND";
     data.Properties.Manufacturer = "Raspberry";
     //data.Properties.UpdatedTime = DateTime.UtcNow;
     data.Properties.DeviceState = DeviceState.Normal;
     data.Commands.Add(new DeviceCommandDefinition("SwitchLight"));
     data.Commands.Add(new DeviceCommandDefinition("LightColor",
         new DeviceCommandParameterDefinition[] {
             new DeviceCommandParameterDefinition("Color", DeviceCommandParameterType.String),
             new DeviceCommandParameterDefinition("Color2", DeviceCommandParameterType.String)
         }));
     data.Commands.Add(new DeviceCommandDefinition("PingDevice"));
     data.Commands.Add(new DeviceCommandDefinition("StartTelemetry"));
     data.Commands.Add(new DeviceCommandDefinition("StopTelemetry"));
     var content = JsonConvert.SerializeObject(data);
     _client.SendEventAsync(new Message(Encoding.UTF8.GetBytes(content)));
 }