Example #1
0
        async static Task Main(string[] args)
        {
            Console.WriteLine("started");
            var deviceMqttClientOptions = new DeviceClientOptionsBuilder()
                                          .WithClientId("CAEb473a19a-cb16-4065-88c9-eb1d02abe80d")
                                          .WithCSEId("/bay-uwt_015d7f1c-5c56-4a1d-ae8a-18b11cfd5b9f")
                                          .WithMqttOptions("mqtt.kocdigital.com", 1883, 120, "bay1RI", "WL6#q7Q7")
                                          .Build();

            IDeviceServiceFactory _deviceServiceFactory = new DeviceServiceFactory();
            var _deviceService = _deviceServiceFactory.CreateDeviceService(deviceMqttClientOptions);

            Console.WriteLine("connecting");
            await _deviceService.ConnectToPlatformAsync();

            Console.WriteLine("connected");
            var sensors = _deviceService.GetSensors();

            _deviceService.UseSensorValueChangeRequestHandler(async e =>
            {
                Console.WriteLine($"sensor value has changed {e.SensorId} - {e.Value}");
            });

            Console.WriteLine($"sensor list: {string.Join(',', sensors.Select(t => t.SensorName).ToList())}");

            var random = new Random();

            if (sensors.Count > 0)
            {
                while (true)
                {
                    foreach (var sensor in sensors)
                    {
                        try
                        {
                            var number = random.Next(0, 15);
                            await _deviceService.PushSensorDataToPlatformAsync(sensor.Id, $"{number}", $"Celcius", $"{number}");

                            Console.WriteLine($"{DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss")}: {sensor.SensorName} sensörüne data gönderildi, {number}");
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine($"error: {ex.Message}");
                        }
                    }
                    Thread.Sleep(1000);
                }
            }
        }
Example #2
0
        async static Task Main(string[] args)
        {
            var mqttOptions = new DeviceClientOptionsBuilder()
                              .WithClientId("CAE5e2997cb-7d97-4e02-857d-48812fddef60")
                              .WithCSEId("/bay-uwt_015d7f1c-5c56-4a1d-ae8a-18b11cfd5b9f")
                              .WithMqttOptions("mqtt.kocdigital.com", 1883, 120, "bay1RI", "WL6#q7Q7")
                              .Build();

            IDeviceManagementServiceFactory deviceManagementServiceFactory = new DeviceManagementServiceFactory();
            IDeviceServiceFactory           deviceServiceFactory           = new DeviceServiceFactory();

            var deviceManagementService = deviceManagementServiceFactory.CreateDeviceManagementService(mqttOptions);
            var deviceService           = deviceServiceFactory.CreateDeviceService(mqttOptions);

            await deviceManagementService.ConnectToPlatformAsync();

            await deviceService.ConnectToPlatformAsync();

            var newSensor = await deviceService.CreateSensorAsync("BidirectionalSensor", true);

            Console.WriteLine("Hello World!");
        }
Example #3
0
        async static Task Main(string[] args)
        {
            Console.WriteLine("started");

            var mqttOptions = new DeviceClientOptionsBuilder()
                              .WithClientId("CAE013c7a01-e2e5-415f-83e5-8b43d1604627")
                              .WithCSEId("/bay-uwt_015d7f1c-5c56-4a1d-ae8a-18b11cfd5b9f")
                              .WithMqttOptions("mqtt.kocdigital.com", 1883, 120, "bay1RI", "WL6#q7Q7")
                              .Build();

            var deviceServiceFactory = new DeviceServiceFactory();
            var deviceService        = deviceServiceFactory.CreateDeviceService(mqttOptions);

            await deviceService.ConnectToPlatformAsync();

            deviceService.UseSensorValueChangeRequestHandler(async e =>
            {
                Console.WriteLine(e.SensorId);
                Console.WriteLine(e.Value);
            });

            Console.ReadLine();
        }
Example #4
0
File: Program.cs Project: VB10/pati
        public async static Task platform360InitAsync(String data)
        {
            // Mqtt Client Options
            var deviceMqttClientOptions = new DeviceClientOptionsBuilder()
                                          .WithClientId(user.clientid)
                                          .WithCSEId(user.CSEid)
                                          .WithMqttOptions(user.MQTTpointOfAcsesss, user.MQTTport, user.timeout, user.MQTTuserName, user.MQTTpassword).Build();
            IDeviceServiceFactory _deviceServiceFactory = new DeviceServiceFactory();
            var _deviceService = _deviceServiceFactory.CreateDeviceService(deviceMqttClientOptions);
            await _deviceService.ConnectToPlatformAsync();

            var sensor = _deviceService.GetSensors();

            var existedSensors = deviceService.GetSensors();

            // Notification event when any sensor value change request is sent.

            if (existedSensors.Count > 0)
            {
                // It sends the request to platform to save sensor data.
                await deviceService.PushSensorDataToPlatformAsync(existedSensors[0].Id, data, "on", "off", DateTime.Now);
            }
        }
Example #5
0
        async static Task Main(string[] args)
        {
            // Mqtt Client Options
            var deviceMqttClientOptions = new DeviceClientOptionsBuilder()
                                          .WithClientId("CAEb473a19a-cb16-4065-88c9-eb1d02abe80d")
                                          .WithCSEId("/bay-uwt_015d7f1c-5c56-4a1d-ae8a-18b11cfd5b9f")
                                          .WithMqttOptions("mqtt.kocdigital.com", 1883, 120, "bay1RI", "WL6#q7Q7")
                                          .Build();

            IEnrollmentServiceFactory       _enrollmentServiceFactory       = new EnrollmentServiceFactory();
            IDeviceManagementServiceFactory _deviceManagementServiceFactory = new DeviceManagementServiceFactory();
            IDeviceServiceFactory           _deviceServiceFactory           = new DeviceServiceFactory();

            // Create Enrollment Service to Enroll Device
            var enrollmentService = _enrollmentServiceFactory.CreateEnrollmentService(deviceMqttClientOptions);

            // Create Device Management Service to Use Device Management Objects
            var deviceManagementService = _deviceManagementServiceFactory.CreateDeviceManagementService(deviceMqttClientOptions);

            // Create Device Service to Use Device Functionalities
            var deviceService = _deviceServiceFactory.CreateDeviceService(deviceMqttClientOptions);

            //// It creates a device on the platform.
            await enrollmentService.EnrollDeviceAsync("RaspberryDevice");

            // Here related resources and properties are loaded to device management objects
            await deviceManagementService.ConnectToPlatformAsync();

            // Here related resources and properties are loaded to device service objects
            await deviceService.ConnectToPlatformAsync();

            // Sensor Creation
            // Parameters: Sensor Name and isBidirectional
            var sensor1 = await deviceService.CreateSensorAsync("TemperatureSensor", true);

            var sensor2 = await deviceService.CreateSensorAsync("HumidtySensor", true);

            var existedSensors = deviceService.GetSensors();

            // Notification event when any sensor value change request is sent.
            deviceService.UseSensorValueChangeRequestHandler(async e =>
            {
                Console.WriteLine(e.SensorId);
                Console.WriteLine(e.Value);
            });

            if (existedSensors.Count > 0)
            { // It sends the request to platform to save sensor data.
                foreach (var existedSensor in existedSensors)
                {
                    await deviceService.PushSensorDataToPlatformAsync(existedSensor.Id, "OFF", "unit off", "data off");

                    await deviceService.PushSensorDataToPlatformAsync(existedSensor.Id, "ON", "unit on", "data off");
                }
            }

            var battery = new DeviceBatteryCreateData {
                BatteryLevel  = 10,
                BatteryStatus = BatteryStatus.LowBattery,
                Name          = "DeviceBattery"
            };
            var batteryBackup = new DeviceBatteryCreateData {
                BatteryLevel  = 100,
                BatteryStatus = BatteryStatus.Normal,
                Name          = "DeviceSecondBattery"
            };

            var reboot = new DeviceRebootCreateData {
                Name = "DeviceReboot/FactoryResetFunction"
            };

            // It sends a request to save battery data on platform.
            var batteryResult = await deviceManagementService.CreateBatteryAsync(battery);

            var batteryBackupResult = await deviceManagementService.CreateBatteryAsync(batteryBackup);

            //var rebootResult = await deviceManagementService.CreateRebootAsync(reboot);
            var batteries = await deviceManagementService.GetBatteriesAsync();

            //var reboots = await deviceManagementService.GetRebootAsync();

            // Notification event when reboot update request is handled to process.
            deviceManagementService.UseDeviceManagementRebootFunctionHandler(async e => {
                Console.WriteLine(e.IsFactoryReset);
                Console.WriteLine(e.Reboot);
            });


            Console.ReadLine();
        }