Пример #1
0
        public Publisher(bool ignoreProxy)
        {
            string awsAccessKey = ConfigurationManager.AppSettings["AWSAccessKey"];
            string awsSecretKey = ConfigurationManager.AppSettings["AWSSecretKey"];

            AWSCredentials      credentials = new BasicAWSCredentials(awsAccessKey, awsSecretKey);
            AmazonIotDataConfig config      = new AmazonIotDataConfig();
            string endPoint = ConfigurationManager.AppSettings["AWSIoTEndPoint"];

            config.ServiceURL = "https://" + endPoint;

            string proxyHost     = ConfigurationManager.AppSettings["ProxyHost"];
            string proxyPort     = ConfigurationManager.AppSettings["ProxyPort"];
            string proxyUser     = ConfigurationManager.AppSettings["ProxyUser"];
            string proxyPassword = ConfigurationManager.AppSettings["ProxyPassword"];

            if (!ignoreProxy && !string.IsNullOrEmpty(proxyHost))
            {
                config.ProxyHost = proxyHost;
                config.ProxyPort = int.Parse(proxyPort);
                if (!string.IsNullOrEmpty(proxyUser))
                {
                    config.ProxyCredentials = new NetworkCredential(proxyUser, proxyPassword);
                }
                _usingProxy = true;
            }
            client = new AmazonIotDataClient(credentials, config);

            topic = ConfigurationManager.AppSettings["AWSIoTTopic"];
        }
Пример #2
0
        public static AmazonIotDataClient CreateAmazonIotDataClient()
        {
            var mqttBrokerEndpoint = Environment.GetEnvironmentVariable("MQTTBroker");
            var clientConfig       = new AmazonIotDataConfig {
                ServiceURL = mqttBrokerEndpoint
            };

            return(new AmazonIotDataClient(clientConfig));
        }
    public Thing(string thingName)
    {
        var fileText            = Resources.Load <TextAsset>("accesskeys").text;
        var lines               = fileText.Split('\n');
        var secrets             = lines[1].Split(',');
        var awsAccessKeyId      = secrets[0].Trim();
        var awsSecretAccessKey  = secrets[1].Trim();
        var amazonIotDataConfig = new AmazonIotDataConfig
        {
            ServiceURL = "https://a2soq6ydozn6i0-ats.iot.us-west-2.amazonaws.com/"
        };

        _thingName  = thingName;
        _dataClient = new AmazonIotDataClient(awsAccessKeyId, awsSecretAccessKey, amazonIotDataConfig);
    }
Пример #4
0
        public void Start()
        {
            AmazonIotDataConfig amazonIotDataConfig = new AmazonIotDataConfig();

            amazonIotDataConfig.RegionEndpoint = RegionEndpoint.EUWest1;
            //amazonIotDataConfig.UseHttp = false;
            //amazonIotDataConfig.SignatureVersion = "4";
            amazonIotDataConfig.ServiceURL = amazonIotDataConfig.DetermineServiceURL();

            Client = new AmazonIotDataClient(awsAccessKeyId, awsSecretAccessKey, amazonIotDataConfig);


            Monitorings = new List <Monitoring>();


            HardDriveSmartMonitoring hardDriveSmartMonitoring = new HardDriveSmartMonitoring((data) =>
            {
                var payload = new
                {
                    state = new
                    {
                        reported = new
                        {
                            Monitoring = new
                            {
                                HardDriveSmart = data
                            }
                        }
                    }
                };


                var request       = new UpdateThingShadowRequest();
                request.ThingName = thingName;
                request.Payload   = new MemoryStream(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(payload)));

                var response = Client.UpdateThingShadow(request);
            });

            Monitorings.Add(hardDriveSmartMonitoring);


            HardDriveSpaceMonitoring hardDriveSpaceMonitoring = new HardDriveSpaceMonitoring((data) =>
            {
                var payload = new
                {
                    state = new
                    {
                        reported = new
                        {
                            Monitoring = new
                            {
                                HardDriveSpace = data
                            }
                        }
                    }
                };


                var request       = new UpdateThingShadowRequest();
                request.ThingName = thingName;
                request.Payload   = new MemoryStream(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(payload)));

                var response = Client.UpdateThingShadow(request);
            });

            Monitorings.Add(hardDriveSpaceMonitoring);


            Monitorings.ForEach((monitoring) => monitoring.Start());
        }