Guten Tag zusammen,
ich realisiere gerade ein Projekt mit einem Raspberry Pi. Ich möchte diesen per WLAN fernsteuern können.
WLAN-AccessPoint habe ich eingerichtet, funktioniert alles. Vom Online-Projekt "BrickPi" gibt es eine Anleitung, den Raspi per HTML-Website fernzusteuern.
Dies funktionert vom Computer aus auch wirklich wunderbar.
Nur vom Smartphone aus funktioniert es leider nicht (ausprobiert mit 3 verschiedenen Browsern)
Ich kenne mich in dieser HTML-Seitenur mäßig aus, wie gesagt, sie kommt aus einer Anleitung. Meine Frage ist nun, was der Grund dafür sein könnte, dass sie auf dem Computer einwandfrei läuft und auf dem Smartphone nicht? Also dargestellt wird sie auch auf dem Smartphone einwandfrei. Sobald ich aber die IP-Adresse des Raspberry eingebe und auf den dafür vorgesehenen Bestätigungs-Button klicke, passiert nichts. Wenn ich das ganze am PC mache, bekomme ich auf meinem Raspi in der Konsole die entsprechenden Ausgaben.
Worin unterscheiden sich evtl. die Browser auf dem Computer zu denen auf dem Smartphone? Da kenne ich mich leider nicht aus.
Wie könnte ich dieses Problem evtl. beheben? Den Code der HTML Seite füge ich nachfolgend ein: Falls das nicht funktionieren sollte, ist er auch hier einzusehen:
https://github.com/DexterInd/B…/Browser_Client_Code.html
Die Anleitung selbst: http://www.dexterindustries.com/BrickPi/projects/browserbot/
Ich hoffe mir kann hier jemand helfen..
Mit freundlichen Grüßen
Tobias
<!-- ######################################################################## # Program Name: Browser_Client_Coder.html # ================================ # This code is for controlling a robot by a web browser using web sockets # http://www.dexterindustries.com/ # History # ------------------------------------------------ # Author Comments # Joshwa Initial Authoring # # These files have been made available online through a Creative Commons Attribution-ShareAlike 3.0 license. # (http://creativecommons.org/licenses/by-sa/3.0/) # ######################################################################## --> <!-- This code implements the web socket connection between client(web page on a Computer) and a server(raspberry pi) --> <!-- It sends data from web page using buttons and Keyboard presses to control the BrickPi robot --> <!DOCTYPE html> <html> <head> <title>WebSockets Client</title> <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script> </head> <body> </br></br> </br> <p> <!-- Creating press buttons on the webpage--> <input id="touch" style="height: 100px; width: 100px; position: absolute; left: 550px; top: 100px" type="button" value="Accelerate" onclick="accelerate(); " /> </p> <p> <input id="touch" style="height: 100px; width: 100px; position: absolute; left: 450px; top: 200px" type="button" value="Steer Left" onclick="steer_left(); " /> </p> <p> <input id="touch" style="height: 100px; width: 100px; position: absolute; left: 550px; top: 200px" type="button" value="Stop" onclick="stop(); " /> </p> <p> <input id="touch" style="height: 100px; width: 100px; position: absolute; left: 650px; top: 200px" type="button" value="Steer Right" onclick="steer_right(); " /> </p> <p> <input id="touch" style="height: 100px; width: 100px; position: absolute; left: 550px; top: 300px" type="button" value="Reverse" onclick="reverse(); " /> </p> </br></br></br></br> <div id="send"> </br></br></br></br></br></br></br></br></br></br></br></br> <p> Enter the hostname/ip address to make the websocket connection </p> <input type="text" id="data" size="100"/><br> <input id="clickMe" type="button" value="clickme" onclick="setup2()" /> </br></br> <p><span style="font-weight:bold">Instructions for keyboard controls:</span></p> <p>Press Up arrow key - Acceleraate </p> <p>Press Down arrow key - Reverse </p> <p>Press Right arrow key - Steer Right</p> <p>Press Left arrow key - Steer Left</p> <p>Press cltr/shift key to Stop</p> </div> </div> <div id="output"></div> <script> var up; var down; var left; var right; var brakes; // defines a variable that controls the forward movement function accelerate() { up = "u"; // when up == "u" the bot moves forward down = "aaa";left = "aaa";right = "aaa";brakes = "aaa"; // When up button is pressed other buttons(variables) should be turned off. setup2(); // Goes to websocket connection function } // defines a variable that controls the backward movement function reverse() { down = "d"; up = "aaa";left = "aaa";right = "aaa";brakes = "aaa"; setup2(); } // defines a variable that controls the left movement function steer_left() { left = "l"; up = "aaa";down = "aaa";right = "aaa";brakes = "aaa"; setup2(); } // defines a variable that controls the right movement function steer_right() { right = "r"; up = "aaa";down = "aaa";left = "aaa";brakes = "aaa"; setup2(); } // defines a variable that stops the robot function stop() { up = "aaa";down = "aaa";left = "aaa";right = "aaa";brakes = "b"; setup2(); } // Creates the websockets connection function setup2() { var $txt = $("#data"); // assigns the data(hostname/ip address) entered in the text box name = $txt.val(); // Variable name contains the string(hostname/ip address) entered in the text box var host = "ws://"+name+":9093/ws"; // combines the three string and creates a new string var socket = new WebSocket(host); var $txt = $("#data"); var $btnSend = $("#sendtext"); $txt.focus(); // event handlers for UI $btnSend.on('click',function() { var text = $txt.val(); if(text == "") { return; } $txt.val(""); }); $txt .keypress(function(evt) { if(evt.which == 13) { $btnSend.click(); } }); // event handlers for websocket if(socket) { var count =1; socket.onopen = function() { count = 0; arrows(); // function for detecting keyboard presses buttons(); // function for detecting the button press on webpage } //Send the button pressed backed to the Raspberry Pi function buttons() { if(up== "u") { socket.send("u"); } if(down== "d") { socket.send("d"); } if(left== "l") { socket.send("l"); } if(right== "r") { socket.send("r"); } if(brakes == "b") { socket.send("b"); } } function arrows() { document.onkeyup = KeyCheck; function KeyCheck() { var KeyID = event.keyCode; switch(KeyID) { case 16: socket.send("b"); break; case 17: socket.send("b"); break; case 37: socket.send("l"); break; case 38: socket.send("u"); break; case 39: socket.send("r"); break; case 40: socket.send("d"); break; } } } socket.onmessage = function(msg) { showServerResponse(msg.data); } socket.onclose = function() { //alert("connection closed...."); showServerResponse("The connection has been closed."); } } else { console.log("invalid socket"); } function showServerResponse(txt) { var p = document.createElement('p'); p.innerHTML = txt; document.getElementById('output').appendChild(p); } } </script> </body> </html> <script> jQuery(function($) { if (!("WebSocket" in window)) { alert("Your browser does not support web sockets"); } }); </script>