I'm trying to change the light color according to the temperature. I can obtain the temperature value, but I can't change the color basing on its value.
I am using this code.
private async void button6_Click_1(object sender, EventArgs e) {
string weburl = "http://api.openweathermap.org/data/2.5/weather?q=" + textBox1.Text + "&mode=xml&units";
var client = new System.Net.WebClient();
var xml = await new WebClient().DownloadStringTaskAsync(new Uri(weburl));
XmlDocument doc = new XmlDocument();
doc.LoadXml(xml);
string szTemp = doc.DocumentElement.SelectSingleNode("temperature").Attributes["value"].Value;
double temp = (double.Parse(szTemp) - 32) * 5 / 9;
label1.Text = temp.ToString("N1") + " Celcius";
double degree = temp;
if (degree >= 20 && degree <30)
{
MessageBox.Show("hot");
var command = new LightCommand();
command.TurnOn().SetColor("000000");
command.Brightness = 128;
var result = await client.SendCommandAsync(command);
}
}
When I debug it, it gives me the following error.
WebClient does not contain a definition for 'SendCommandAsync' and no extension method 'SendCommandAsync' accepting a first argument of type 'WebClient' could not be found(are you missing a using directive or an assembly reference?)
How I can solve this error?
Under the button 6 code, can I make another button (let's say button 7) which changes color to red, and make this button 7 execute automatically when the temperature is greater than 20 degree Celsius?