/// <summary> /// /// </summary> /// <returns>Last light level from ThingSpeak sent by light sensor (actually sent by Arduino or some other microcontroller that read the value (actually sent by Ethernet or WIFI shield/chip that got the data from microcontroler (actually... nvm))) </returns> private int GetLastLightLevel() { String url = BaseUrl + "/channels/%CHANNEL%/feeds.xml?results=1" .Replace("%CHANNEL%", Channel); WebClient webClient = new WebClient() { Encoding = Encoding.UTF8 }; String xmlString = webClient.DownloadString(url); xmlString = xmlString.Replace("<feed>", "<feed id=\"feed\">"); // That way we are avoiding traversing the xml tree which results in a shorter code. We can do it because we retrieve only the last feed XmlDocument xml = new XmlDocument(); xml.LoadXml(xmlString); XmlElement feed = ConfigurationFile.GetFirstElementById(xml, "feed"); XmlNode lightValueNode = feed.ChildNodes[2]; // We know that the light level is stored at third position String lightValueString = lightValueNode.InnerText; return(int.Parse(lightValueString)); }