2016-02-27 51 views
0

我有一個Arduino MEGA 2560,我正在做一個聰明的家。 IT沒有WiFi或以太網端口,所以我寫了一個讀取串口的vb.net程序。但我不知道如何製作一個能夠顯示溫度傳感器價值的網站。VB.net網頁服務器

+0

This問題太廣泛了,以至於無法期待一個體面的答案。檢查[「如何提出一個好的問題呢?」](http://stackoverflow.com/help/how-to-ask) – Kris

回答

0

你可以嘗試這樣的事情.....

與AJAX定時器

簡單的HTML頁面....

<!DOCTYPE html> 
<html> 
<body> 

<p>A script on this page starts this clock:</p> 

<p id="demo"></p> 

<p><b>Status:</b> <span id="A1"></span></p> 
<p><b>Status text:</b> <span id="A2"></span></p> 
<p><b>Response:</b> <span id="A3"></span></p> 

<script> 
var myVar = setInterval(myTimer, 1000); 

function myTimer() { 
    var xhttp = new XMLHttpRequest(); 
    xhttp.onreadystatechange = function() { 
    if (xhttp.readyState == 4 && xhttp.status == 200) { 
     document.getElementById('A1').innerHTML = xhttp.status; 
     document.getElementById('A2').innerHTML = xhttp.statusText; 
     document.getElementById('A3').innerHTML = xhttp.responseText; 
    } 
    }; 
    xhttp.open("GET", 'TempXML.xml', true); 
    xhttp.send(); 
} 
</script> 

</body> 
</html> 

簡單的XML .....

<TempXML> 
<DateTime>28\02\2016 22:10:00 :: </DateTime> 
<body>31 &#186;C :: 87 &#186;F</body> 
</TempXML> 

現在,將XML保存爲SAME文件夾中的'TempXML.xml'作爲HTML頁面,然後將HTML加載到瀏覽器中.... HTML頁面中的計時器將每秒觸發並讀取XML,您只需要要做的是寫\保存dat從你的Arduino進入XML文件,HTML將用新的數據更新....

''''''''''''' 編輯 「」「」「」「」「」「」「」「」「」「」「」

下面是一個例子控制檯應用程序寫入到XML文件

Imports System.Xml 

Module Module1 

Sub Main() 
    Dim NewTemp = New TempData 

    ' Set you DateTime and Temp here 
    NewTemp.DateTime = DateTime.Now 
    NewTemp.fahrenheit = 80 ' Data from your Arduino 
    NewTemp.celsius = 36 ' Data from your Arduino 

    ' Create XmlWriterSettings. 
    Dim settings As XmlWriterSettings = New XmlWriterSettings() 
    settings.Indent = True 

    Using writer As Xml.XmlWriter = Xml.XmlWriter.Create("<Path to your XML Temp file>\TempXML.xml", settings) 
     ' Begin writing. 
     writer.WriteStartDocument() 
     writer.WriteStartElement("TempXML") ' Root. 

     writer.WriteElementString("DateTime", NewTemp.DateTime.ToString) 
     writer.WriteElementString("body", String.Format(" :: {0} °C :: {1} °F", NewTemp.celsius.ToString, NewTemp.fahrenheit.ToString)) 

     ' End document. 
     writer.WriteEndElement() 
     writer.WriteEndDocument() 
    End Using 
End Sub 

End Module 


Public Class TempData 

Private _DateTime As DateTime 
Public Property DateTime() As DateTime 
    Get 
     Return _DateTime 
    End Get 
    Set(ByVal value As DateTime) 
     _DateTime = value 
    End Set 
End Property 

Private _fahrenheit As Int32 
Public Property fahrenheit() As Int32 
    Get 
     Return _fahrenheit 
    End Get 
    Set(ByVal value As Int32) 
     _fahrenheit = value 
    End Set 
End Property 

Private _celsius As Int32 
Public Property celsius() As Int32 
    Get 
     Return _celsius 
    End Get 
    Set(ByVal value As Int32) 
     _celsius = value 
    End Set 
End Property 

End Class 

記住更改「Xml.XmlWriter.Create」行中適合您PC上位置的XML文件的路徑....

順便提一句,要獲得'°'degr ee符號(您在上面的代碼中看到)...將光標置於正確的位置,按住'Alt'鍵並鍵入0176,然後讓'Alt'開始.....

+0

@WtfArdDev我已經更新了我的答案,用一個示例控制檯應用程序來編寫DateTime&Temp數據添加到您的XML文件中,當您從Arduino接收到串行端口的數據時,您需要實現類似的功能 – Monty