来吧兄弟,一起玩一起讨论!
您需要 登录 才可以下载或查看,没有账号?注册
×
~接上篇,继续分享操作
6. 安装usb摄像头监控界面 sudo apt-get install motion 然后打开 motion daemon 守护进程,让他可以一直在后台运行: sudo nano /etc/default/motion #no修改成yes: start_motion_daemon=yes 修改motion的配置文件: sudo vim /etc/motion/motion.conf #deamon off 改成 on deamon on #设置分辨率 width 800 height 600 #关闭 localhost 的限制 webcam_localhost off 然后运行 motion: sudo motion 现在我们的摄像头已经变成了一台网络摄像头。在chrome浏览器下访问 http://[your.domain]:8081 即可看到摄像头当前拍摄的画面。 7. 简单修改novnc界面 在onvnc源码的app目录下面添加camera文件夹 这里是jq的一个小插件实现了一个可以拖动的小框框 链接:https://pan.baidu.com/s/1VZSh14pUXK36NcxrYTM1-A 提取码:swk9 最后修改vnc.html文件让我们把摄像头和远程界面合二为一 <!DOCTYPE html> <html lang="en" class="noVNC_loading"> <head> <!-- noVNC example: simple example using default UI Copyright (C) 2019 The noVNC Authors noVNC is licensed under the MPL 2.0 (see LICENSE.txt) This file is licensed under the 2-Clause BSD license (see LICENSE.txt). Connect parameters are provided in query string: or the fragment: --> <title>noVNC</title> <meta charset="utf-8"> <!-- Icons (see app/images/icons/Makefile for what the sizes are for) --> <link rel="icon" sizes="16x16" type="image/png" href="app/images/icons/novnc-16x16.png"> <link rel="icon" sizes="24x24" type="image/png" href="app/images/icons/novnc-24x24.png"> <link rel="icon" sizes="32x32" type="image/png" href="app/images/icons/novnc-32x32.png"> <link rel="icon" sizes="48x48" type="image/png" href="app/images/icons/novnc-48x48.png"> <link rel="icon" sizes="60x60" type="image/png" href="app/images/icons/novnc-60x60.png"> <link rel="icon" sizes="64x64" type="image/png" href="app/images/icons/novnc-64x64.png"> <link rel="icon" sizes="72x72" type="image/png" href="app/images/icons/novnc-72x72.png"> <link rel="icon" sizes="76x76" type="image/png" href="app/images/icons/novnc-76x76.png"> <link rel="icon" sizes="96x96" type="image/png" href="app/images/icons/novnc-96x96.png"> <link rel="icon" sizes="120x120" type="image/png" href="app/images/icons/novnc-120x120.png"> <link rel="icon" sizes="144x144" type="image/png" href="app/images/icons/novnc-144x144.png"> <link rel="icon" sizes="152x152" type="image/png" href="app/images/icons/novnc-152x152.png"> <link rel="icon" sizes="192x192" type="image/png" href="app/images/icons/novnc-192x192.png"> <!-- Firefox currently mishandles SVG, see #1419039 <link rel="icon" sizes="any" type="image/svg+xml" href="app/images/icons/novnc-icon.svg"> --> <!-- Repeated last so that legacy handling will pick this --> <link rel="icon" sizes="16x16" type="image/png" href="app/images/icons/novnc-16x16.png"> <!-- Apple iOS Safari settings --> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"> <meta name="apple-mobile-web-app-capable" content="yes"> <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent"> <!-- Home Screen Icons (favourites and bookmarks use the normal icons) --> <link rel="apple-touch-icon" sizes="60x60" type="image/png" href="app/images/icons/novnc-60x60.png"> <link rel="apple-touch-icon" sizes="76x76" type="image/png" href="app/images/icons/novnc-76x76.png"> <link rel="apple-touch-icon" sizes="120x120" type="image/png" href="app/images/icons/novnc-120x120.png"> <link rel="apple-touch-icon" sizes="152x152" type="image/png" href="app/images/icons/novnc-152x152.png"> <!-- Stylesheets --> <link rel="stylesheet" href="app/styles/base.css"> <script src="app/error-handler.js"></script> <script type="module" crossorigin="anonymous" src="app/ui.js"></script> <link rel="stylesheet" type="text/css" href="app/camera/css/normalize.css" /> <link href="app/camera/src/css/interactive.css" rel="stylesheet" /> <style> html, body { width: 100%; height: 100%; background-color: gainsboro; } .content { margin: 10px; } #element { height: 280px; width: 340px; top: 240px; left: 240px; background-color: #82ABC0; } </style> </head> <body> <!-- 摄像头显示框--> <div id="element" name="Close false"> <div class="content"> <img style="-webkit-user-select: none;margin: auto;" src="http://192.168.3.208:8081/"> </div> </div> <div id="noVNC_fallback_error" class="noVNC_center"> <div> <div>noVNC encountered an error:</div> <br> <div id="noVNC_fallback_errormsg"></div> </div> </div> <!-- noVNC Control Bar --> <div id="noVNC_control_bar_anchor" class="noVNC_vcenter"> <div id="noVNC_control_bar"> <div id="noVNC_control_bar_handle" title="Hide/Show the control bar"><div></div></div> <div class="noVNC_scroll"> <h1 class="noVNC_logo" translate="no"><span>no</span><br>VNC</h1> <!-- Drag/Pan the viewport --> <input type="image" alt="Drag" src="app/images/drag.svg" id="noVNC_view_drag_button" class="noVNC_button noVNC_hidden" title="Move/Drag Viewport"> <!--noVNC Touch Device only buttons--> <div id="noVNC_mobile_buttons"> <input type="image" alt="Keyboard" src="app/images/keyboard.svg" id="noVNC_keyboard_button" class="noVNC_button" title="Show Keyboard"> </div> <!-- Extra manual keys --> <input type="image" alt="Extra keys" src="app/images/toggleextrakeys.svg" id="noVNC_toggle_extra_keys_button" class="noVNC_button" title="Show Extra Keys"> <div class="noVNC_vcenter"> <div id="noVNC_modifiers" class="noVNC_panel"> <input type="image" alt="Ctrl" src="app/images/ctrl.svg" id="noVNC_toggle_ctrl_button" class="noVNC_button" title="Toggle Ctrl"> <input type="image" alt="Alt" src="app/images/alt.svg" id="noVNC_toggle_alt_button" class="noVNC_button" title="Toggle Alt"> <input type="image" alt="Windows" src="app/images/windows.svg" id="noVNC_toggle_windows_button" class="noVNC_button" title="Toggle Windows"> <input type="image" alt="Tab" src="app/images/tab.svg" id="noVNC_send_tab_button" class="noVNC_button" title="Send Tab"> <input type="image" alt="Esc" src="app/images/esc.svg" id="noVNC_send_esc_button" class="noVNC_button" title="Send Escape"> <input type="image" alt="Ctrl+Alt+Del" src="app/images/ctrlaltdel.svg" id="noVNC_send_ctrl_alt_del_button" class="noVNC_button" title="Send Ctrl-Alt-Del"> </div> </div> <!-- Shutdown/Reboot --> <input type="image" alt="Shutdown/Reboot" src="app/images/power.svg" id="noVNC_power_button" class="noVNC_button" title="Shutdown/Reboot..."> <div class="noVNC_vcenter"> <div id="noVNC_power" class="noVNC_panel"> <div class="noVNC_heading"> <img alt="" src="app/images/power.svg"> Power </div> <input type="button" id="noVNC_shutdown_button" value="Shutdown"> <input type="button" id="noVNC_reboot_button" value="Reboot"> <input type="button" id="noVNC_reset_button" value="Reset"> </div> </div> <!-- Clipboard --> <input type="image" alt="Clipboard" src="app/images/clipboard.svg" id="noVNC_clipboard_button" class="noVNC_button" title="Clipboard"> <div class="noVNC_vcenter"> <div id="noVNC_clipboard" class="noVNC_panel"> <div class="noVNC_heading"> <img alt="" src="app/images/clipboard.svg"> Clipboard </div> <textarea id="noVNC_clipboard_text" rows=5></textarea> <br> <input id="noVNC_clipboard_clear_button" type="button" value="Clear" class="noVNC_submit"> </div> </div> <!-- Toggle fullscreen --> <input type="image" alt="Fullscreen" src="app/images/fullscreen.svg" id="noVNC_fullscreen_button" class="noVNC_button noVNC_hidden" title="Fullscreen"> <!-- Settings --> <input type="image" alt="Settings" src="app/images/settings.svg" id="noVNC_settings_button" class="noVNC_button" title="Settings"> <div class="noVNC_vcenter"> <div id="noVNC_settings" class="noVNC_panel"> <ul> <li class="noVNC_heading"> <img alt="" src="app/images/settings.svg"> Settings </li> <li> <label><input id="noVNC_setting_shared" type="checkbox"> Shared Mode</label> </li> <li> <label><input id="noVNC_setting_view_only" type="checkbox"> View Only</label> </li> <li><hr></li> <li> <label><input id="noVNC_setting_view_clip" type="checkbox"> Clip to Window</label> </li> <li> <label for="noVNC_setting_resize">Scaling Mode:</label> <select id="noVNC_setting_resize" name="vncResize"> <option value="off">None</option> <option value="scale">Local Scaling</option> <option value="remote">Remote Resizing</option> </select> </li> <li><hr></li> <li> <div class="noVNC_expander">Advanced</div> <div><ul> <li> <label for="noVNC_setting_quality">Quality:</label> <input id="noVNC_setting_quality" type="range" min="0" max="9" value="6"> </li> <li> <label for="noVNC_setting_compression">Compression level:</label> <input id="noVNC_setting_compression" type="range" min="0" max="9" value="2"> </li> <li><hr></li> <li> <label for="noVNC_setting_repeaterID">Repeater ID:</label> <input id="noVNC_setting_repeaterID" type="text" value=""> </li> <li> <div class="noVNC_expander">WebSocket</div> <div><ul> <li> <label><input id="noVNC_setting_encrypt" type="checkbox"> Encrypt</label> </li> <li> <label for="noVNC_setting_host">Host:</label> <input id="noVNC_setting_host"> </li> <li> <label for="noVNC_setting_port">Port:</label> <input id="noVNC_setting_port" type="number"> </li> <li> <label for="noVNC_setting_path">Path:</label> <input id="noVNC_setting_path" type="text" value="websockify"> </li> </ul></div> </li> <li><hr></li> <li> <label><input id="noVNC_setting_reconnect" type="checkbox"> Automatic Reconnect</label> </li> <li> <label for="noVNC_setting_reconnect_delay">Reconnect Delay (ms):</label> <input id="noVNC_setting_reconnect_delay" type="number"> </li> <li><hr></li> <li> <label><input id="noVNC_setting_show_dot" type="checkbox"> Show Dot when No Cursor</label> </li> <li><hr></li> <!-- Logging selection dropdown --> <li> <label>Logging: <select id="noVNC_setting_logging" name="vncLogging"> </select> </label> </li> </ul></div> </li> <li class="noVNC_version_separator"><hr></li> <li class="noVNC_version_wrapper"> <span>Version:</span> <span class="noVNC_version"></span> </li> </ul> </div> </div> <!-- Connection Controls --> <input type="image" alt="Disconnect" src="app/images/disconnect.svg" id="noVNC_disconnect_button" class="noVNC_button" title="Disconnect"> </div> </div> <div id="noVNC_control_bar_hint"></div> </div> <!-- End of noVNC_control_bar --> <!-- Status Dialog --> <div id="noVNC_status"></div> <!-- Connect button --> <div class="noVNC_center"> <div id="noVNC_connect_dlg"> <div class="noVNC_logo" translate="no"><span>no</span>VNC</div> <div id="noVNC_connect_button"><div> <img alt="" src="app/images/connect.svg"> Connect </div></div> </div> </div> <!-- Password Dialog --> <div class="noVNC_center noVNC_connect_layer"> <div id="noVNC_credentials_dlg" class="noVNC_panel"><form> <ul> <li id="noVNC_username_block"> <label>Username:</label> <input id="noVNC_username_input"> </li> <li id="noVNC_password_block"> <label>Password:</label> <input id="noVNC_password_input" type="password"> </li> <li> <input id="noVNC_credentials_button" type="submit" value="Send Credentials" class="noVNC_submit"> </li> </ul> </form></div> </div> <!-- Transition Screens --> <div id="noVNC_transition"> <div id="noVNC_transition_text"></div> <div> <input type="button" id="noVNC_cancel_reconnect_button" value="Cancel" class="noVNC_submit"> </div> <div class="noVNC_spinner"></div> </div> <!-- This is where the RFB elements will attach --> <div id="noVNC_container"> <!-- Note that Google Chrome on Android doesn't respect any of these, html attributes which attempt to disable text suggestions on the on-screen keyboard. Let's hope Chrome implements the ime-mode style for example --> <textarea id="noVNC_keyboardinput" autocapitalize="off" autocomplete="off" spellcheck="false" tabindex="-1"></textarea> </div> <audio id="noVNC_bell"> <source src="app/sounds/bell.oga" type="audio/ogg"> <source src="app/sounds/bell.mp3" type="audio/mpeg"> </audio> <script src="app/camera/src/interactive.js"></script> <script> let options = {close: false }; interactive('element', options); </script> </body> </html> 8. 编写继电器控制脚本控制单片机上电 首先我们选用树莓派上的一个引脚来控制继电器,而继电器来控制单片机的通电与断电。脚本代码如下,大家可以选择不同的引脚进行控制,不再做过多的赘述。 # -*- coding: utf-8 -*- import RPi.GPIO as GPIO import time # BOARD编号方式,基于插座引脚编号 GPIO.setmode(GPIO.BOARD) # 输出模式 GPIO.setup(0, GPIO.OUT) GPIO.output(0, GPIO.HIGH) time.sleep(1) GPIO.output(0, GPIO.LOW) time.sleep(1) 这里运行这个代码以后我们会看到一个警告如下 RuntimeWarning: This channel is already in use, continuing anyway. Use GPIO.setwarnings(False) to disable warnings. 这个警告我们直接忽略就好~ 9. 内网穿透配置 我们可以先到下面的URL中下载花生壳软件,我们这里使用的是树莓派当然要使用树莓派版本的软件了。 https://hsk.oray.com/download/ 在下载软件的界面中我们有可以看到帮助选项,这里有很多我们可以参考的设置例子 安装第一步 sudo -s //切换到管理员权限 dpkg -i <安装包名称> //回车,等待安装完成。 我们可以使用下面的命令启动花生壳服务,更多命令可以到帮助网页中查看 phddns start //启动花生壳 phddns enable //设置花生壳开机自启 然后我们可以用过下面的网址远程设置花生壳 http://b.oray.com 首次登录,需先激活。提供扫码激活和密码激活两种方式
激活成功后,进入花生壳管理平台。
添加内网穿透映射时,点击页面上的“增加映射”按钮。根据页面提示填写映射所需的信息(10022端口)为例:
1:自定义;2:选择HTTP(因为我们要映射的部分都是网页);3:选择用作互联网访问的域名;4:选择动态端口;5:树莓派设备的内网IP地址;6:映射的服务类型对应端口;确认映射内容无误后,点击“确定”。 好了,完美实现远程开发51单片机,本次分享到这里!学习大家的耐心阅读。平时大家在工作学习中遇到没有公网IP情况下的远程访问时,都可以通过花生壳来进行内网穿透,像开发调试、游戏联机、NAS访问、FTP文件共享等,花生壳都可以实现。
|