我們試圖使用官方的Arduino Wifi Shield將連續的數據流從Arduino Uno發送到網頁。 Arduino充當服務器,編寫網頁降價並從引腳發送數據。我們需要AJAX讓數據在不刷新頁面的情況下不斷更新 - 所以我們使用的是socket.io。我們可以將客戶端socket.io代碼寫入網頁,但我們也需要能夠在Arduino Uno上創建套接字。Arduino WebServer和socket.io
我們嘗試使用WebServer示例,但失敗了。任何幫助,將不勝感激。
基地socket.io以下代碼:
client.println("HTTP/1.1 200 OK");
client.println("Content-type:text/html");
client.println();
//change updating
client.print("<HEAD>");
client.print("<TITLE />3 Phase Relay</title>");
client.println("</head>");
client.println("<script src=\"/socket.io/socket.io.js\"></script>");
client.println("<script>");
client.println("var socket = io.connect('http://192.168.11.2');");
client.println("socket.on('news', function (data) {");
client.println("console.log(data);");
client.println("socket.emit('my other event', { my: 'data' });");
client.println("});");
client.println("</script>");
// the content of the HTTP response follows the header:
client.print("Peak Voltage Reading: ");
client.println(peak);
client.print("Phase Time Reading: ");
client.println(phasetime);