Link to home
Start Free TrialLog in
Avatar of Star79
Star79Flag for United States of America

asked on

Pulling the voltage data from the website using C# code

We are working on building a application for IOT (internet of things) using Arduino and SmartcardWifi.
Arduino constantly sends the data to the website http://192.168.169.81/

Using C# we want to access the stream of data from the  website http://192.168.169.81/ and process it further.  Need C# code which can lets us capture the stream of data and allows us to store it in database.
Avatar of Kevin Cross
Kevin Cross
Flag of United States of America image

You probably want to look at https://msdn.microsoft.com/en-us/library/system.net.webclient.downloaddata(v=vs.110).aspx
or https://msdn.microsoft.com/en-us/library/system.net.webclient.downloadstring(v=vs.110).aspx

It is WebClient.DownloadData or WebClient.DownloadString where the former gets back a byte array and the latter a string.  Each also has an asynchronous method if you need that.  You then just parse the data and store in the database as necessary.
P.S. if you literally meant you want to access the Stream, you can do this:
WebClient wc = new WebClient();
Stream data = wc.OpenRead("http://your.web.page/url.html");
StreamReader reader = new StreamReader(data);

Open in new window

Avatar of Star79

ASKER

Thanks Kevin. The above solution is letting me pull all the information from the website but the problem is it renders all HTML and then again I need to parse for the required data.

Assuming the following data is sent to the website in the following order, I want to retrieve only the below data. Other than parsing the entire HTML, do I have any option?

 A1=15;
 A2=26;
 A3=13;
 A4=17;
 A5=12;
Is it writing the data in a specific format?  i.e., is each of the entries inside of a specific HTML tag.  If you have a sample HTML source that matches your sample data, it may be helpful especially if others jump in but one thought I have not seeing what it looks like is that HTML just is an XML document (at least it can be when well-formed); therefore, you could parse the document then use your XML (or XHTML) object to find the desired tag.

This may help you understand the concept if not give you solution: https://github.com/markbeaton/TidyManaged

I would think you need something like this anyway to loop through all the elements as you may have missed several updates and need to pull all elements whose ID isn't in your local system if the A1, ..., A5 will continue to be a unique ID moving forward.
Major pitfalls with sending data to a website, is that web sites data is stateless. Question is how do you know when the data has been updated? any web client will have to keep refreshing the data.  I would use web services for this rather than a website. The arduino should also send a time stamp.. or how will you know when the data was updated.
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.