2017-05-10 37 views
-2

嗨,我目前正在制作自己的软件来控制一个带有Raspberry Pi的机器人。我想知道是否可以将ssh嵌入到HTML代码中,因此当用户输入Pi的IP地址时,它将通过ssh连接到pi。在网站中使用SSH

然后我想要做的是通过ssh发送命令,当他们点击一个按钮。例如。向后。

这意味着我可以通过python代码控制从树莓派的GPIO引脚,如果我可以通过数据。

我已经写了一些控制代码的介绍如下:

<html> 
<head> 
    <style type="text/css"> 
     #commands{ 
      text-align: center; 
      color: FF8300; 
      font-size: 100px; 
     } 
     .controllbox{ 
      width: 610px; 
      margin: 0 auto; 
     } 
     #arrowUp{ 
      text-align: center; 
      position: static; 
     } 
     #arrowRight{ 
      text-align: right; 
      position: static; 
      margin-top: 0; 
     } 
     #arrowDown{ 
      text-align: center; 
      position: static; 
     } 
     #arrowLeft{ 
      text-align: left; 
      position: static; 
      margin-top: -200px; 

     } 
     #stop{ 
      width: 120px; 
      height: auto; 
      margin: 0 auto; 
      margin-top: -65%; 
      margin-left: 34%; 
      text-align: center; 
      position: static; 


     } 
    </style> 
</head> 
<body> 

    <h1 id="commands">Controll Me!!</h1> 
    <div class="controllBox"> 
     <div id="arrowUp"><img src="arrowUp.jpg" class="controll" id="button1"></div> 
     <div id="arrowRight"><img src="arrowRight.jpg" class="controll" id="button2"></div> 
     <div id="arrowLeft"><img src="arrowLeft.jpg" class="controll" id="button3"></div> 
     <div id="arrowDown"><img src="arrowDown.jpg" class="controll" id="button4"></div> 
     <div id="stop"><img src="stop.jpg" class="controll" id="button5"></div> 
    </div> 
<script type="text/javascript"> 

     document.getElementById('button1').onclick = function(){ 
      document.getElementById('commands').innerHTML = 'Foward' 
     } 
     document.getElementById('button2').onclick = function(){ 
      document.getElementById('commands').innerHTML = 'Right' 
     } 
     document.getElementById('button3').onclick = function(){ 
      document.getElementById('commands').innerHTML = 'Left' 
     } 
     document.getElementById('button4').onclick = function(){ 
      document.getElementById('commands').innerHTML = 'Backwards' 
     } 
     document.getElementById('button5').onclick = function(){ 
      document.getElementById('commands').innerHTML = 'Stop' 
     } 

    </script> 
</body> 

它将如果你知道如何做到这一点还是因为我拉我的头发类似的东西将不胜感激,试图找出我如何做到这一点。

非常感谢您的帮助 James。

+1

https://en.wikipedia.org/wiki/Web-执行它based_SSH – CBroe

+0

https://github.com/aluzzardi/wssh – Bergi

+0

甚至https://chrome.google.com/webstore/detail/secure-shell/pnhechapfaindjhompbnflcldabbghjo?hl=en –

回答

2

你不能通过HTML或Javascript执行SSH命令(可能是JS,但比它更值得付出)。

我会推荐的,因为它更安全,更容易管理是使用PHP或Python或其他一些脚本语言将表单提交到您的网络服务器。

然后,您的Web服务器应该调用SSH来为您执行命令。

例如:

POST: example.com/forward.php?inst=backward&ip=1.2.3.4 

然后PHP将格式化的命令串来运行SSH,然后以exec()

+0

谢谢你,我是一个真正的新手这并不知道PHP是否还有其他的东西可以帮助我更容易地做到这一点,因为这看起来或者至少听起来很难 –