Exemplo n.º 1
0
        private void EntryDevice()
        {
#if (ACCESS_MOBILE_SERVICE)
            if (mobileService == null)
            {
                mobileService = new EGIoTKit.Utility.SimpleMobileAppsClient(IoTHoLConfig.DeviceEntryEndPoint);
                if (proxyHost != null && proxyHost != "")
                {
                    mobileService.ProxyHost = proxyHost;
                    mobileService.ProxyPort = proxyPort;
                }
            }
            var registered = mobileService.Query(DeviceEntryTableName);
            bool registed = false;
            if (registered != null && registered.Count > 0)
            {
                foreach (var re in registered)
                {
                    var registedEntry = re as Hashtable;
                    if ((string)(registedEntry["deviceId"]) == deviceId)
                    {
                        if (registedEntry["serviceAvailable"] != null)
                        {
                            IoTServiceAvailabled = (bool)registedEntry["serviceAvailable"];
                            if (IoTServiceAvailabled)
                            {
                                IoTHoLConfig.IoTHubEndpoint = (string)registedEntry["iotHubEndpoint"];
                                IoTHoLConfig.DeviceKey = (string)registedEntry["deviceKey"];
                                Debug.Print("IoT Hub Service Availabled - IoTHubEndpoint=" + IoTHoLConfig.IoTHubEndpoint + ",deviceKey=" + IoTHoLConfig.DeviceKey);
                            }
                        }
                        registed = true;
                        break;
                    }
                }
            }
            if (!registed)
            {
                var entry = new Models.DeviceEntry()
                {
                    DeviceId = deviceId.ToString(),
                    ServiceAvailable = false,
                    DeviceKey = "",
                    IoTHubEndpoint = ""
                };
                var insertedItem = mobileService.Insert(DeviceEntryTableName, entry);
            }
#else
#if (ACCESS_IOT_HUB)
            IoTServiceAvailabled = true;
#endif
#endif
            if (IoTServiceAvailabled)
            {
                srMax = (int)(uploadIntervalMSec / measureIntervalMSec);
                sensorReadings = new PinKitIoTApp.Models.SensorReading[srMax];
                for (int i = 0; i < srMax; i++)
                {
                    sensorReadings[i] = new PinKitIoTApp.Models.SensorReading();
                }
                srCount = 0;
            }
        }
Exemplo n.º 2
0
        /**
         *
         */
        private void EntryDevice()
        {
#if (ACCESS_MOBILE_SERVICE)
            if (mobileService == null)
            {
                mobileService = new EGIoTKit.Utility.SimpleMobileAppsClient(IoTHoLConfig.DeviceEntryEndPoint);
                if (proxyHost != null && proxyHost != "")
                {
                    mobileService.ProxyHost = proxyHost;
                    mobileService.ProxyPort = proxyPort;
                }
            }
            var  registered = mobileService.Query(DeviceEntryTableName);
            bool registed   = false;
            if (registered != null && registered.Count > 0)
            {
                foreach (var re in registered)
                {
                    var registedEntry = re as Hashtable;
                    if ((string)(registedEntry["deviceId"]) == deviceId)
                    {
                        if (registedEntry["serviceAvailable"] != null)
                        {
                            IoTServiceAvailabled = (bool)registedEntry["serviceAvailable"];
                            if (IoTServiceAvailabled)
                            {
                                IoTHoLConfig.IoTHubEndpoint = (string)registedEntry["iotHubEndpoint"];
                                IoTHoLConfig.DeviceKey      = (string)registedEntry["deviceKey"];
                                Debug.Print("IoT Hub Service Availabled - IoTHubEndpoint=" + IoTHoLConfig.IoTHubEndpoint + ",deviceKey=" + IoTHoLConfig.DeviceKey);
                            }
                        }
                        registed = true;
                        break;
                    }
                }
            }
            if (!registed)
            {
                var entry = new Models.DeviceEntry()
                {
                    DeviceId         = deviceId.ToString(),
                    ServiceAvailable = false,
                    DeviceKey        = "",
                    IoTHubEndpoint   = ""
                };
                var insertedItem = mobileService.Insert(DeviceEntryTableName, entry);
            }
#else
#if (ACCESS_IOT_HUB)
            IoTServiceAvailabled = true;
#endif
#endif

            /**
             * 9センサを稼動させるためにsensorReadingsクラスを拡張する必要がある
             **/
            if (IoTServiceAvailabled)
            {
                // srMax = 60000 / 2000
                srMax = (int)(uploadIntervalMSec / measureIntervalMSec);
                // sensorReadingsオブジェクトを30(srMax)個生成
                sensorReadings = new PinKitIoTApp.Models.SensorReading[srMax];
                for (int i = 0; i < srMax; i++)
                {
                    sensorReadings[i] = new PinKitIoTApp.Models.SensorReading();
                }
                srCount = 0;
            }
        }