### Initialize Car to Run Mode using HTML GET Request Source: https://github.com/sunfounder/sunfounder_smart_video_car_kit_for_raspberrypi/blob/master/html_server/APIs.md This API initializes the camera and turning wheels to start the car in run mode. It is accessed via an HTTP GET request to the '/runmode' endpoint. ```http GET http://[Raspberry Pi IP address]:8000/runmode ``` -------------------------------- ### Install Python 2.7 (Windows) Source: https://github.com/sunfounder/sunfounder_smart_video_car_kit_for_raspberrypi/blob/master/README.md Instructions for downloading and installing Python version 2.7.11, which is a prerequisite for running certain calibration client scripts on Windows. ```bash https://www.python.org/downloads/release/python-2711/ ``` -------------------------------- ### Install Django with Pip Source: https://github.com/sunfounder/sunfounder_smart_video_car_kit_for_raspberrypi/blob/master/html_server/README.md Installs the Django framework using pip, a Python package installer. This is a prerequisite for running the HTML server. ```bash sudo pip install django ``` -------------------------------- ### Initialize Car to Calibration Mode using HTML GET Request Source: https://github.com/sunfounder/sunfounder_smart_video_car_kit_for_raspberrypi/blob/master/html_server/APIs.md This API initializes the camera and turning wheels to start the car in calibration mode. It is accessed via an HTTP GET request to the '/calibrationmode' endpoint. ```http GET http://[Raspberry Pi IP address]:8000/calibrationmode ``` -------------------------------- ### GPL Interactive Program Notice Example Source: https://github.com/sunfounder/sunfounder_smart_video_car_kit_for_raspberrypi/blob/master/mjpg-streamer/mjpg-streamer-experimental/www/LICENSE.txt An example of a short notice that an interactive program should display upon startup. It includes version information, copyright, warranty disclaimer, and how to access license details. ```text Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. ``` -------------------------------- ### Get Calibration Configuration using HTML GET Request Source: https://github.com/sunfounder/sunfounder_smart_video_car_kit_for_raspberrypi/blob/master/html_server/APIs.md This API retrieves the current calibration configuration from the server. It is accessed via an HTTP GET request to the '/calibrate/getconfig' endpoint. ```http GET http://[Raspberry Pi IP address]:8000/calibrate/getconfig ``` -------------------------------- ### Copyright Disclaimer Example Source: https://github.com/sunfounder/sunfounder_smart_video_car_kit_for_raspberrypi/blob/master/mjpg-streamer/mjpg-streamer-experimental/www/LICENSE.txt A sample copyright disclaimer that an employer or institution might sign to disclaim copyright interest in a program. This example is for a hypothetical program named 'Gnomovision'. ```text Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice ``` -------------------------------- ### Confirm and Save Calibration using HTML GET Request Source: https://github.com/sunfounder/sunfounder_smart_video_car_kit_for_raspberrypi/blob/master/html_server/APIs.md This API confirms and saves the current calibration configuration. It is accessed via an HTTP GET request to the '/calibrate/confirm' endpoint. ```http GET http://[Raspberry Pi IP address]:8000/calibrate/confirm ``` -------------------------------- ### GNU GPL Copyright Notice Example Source: https://github.com/sunfounder/sunfounder_smart_video_car_kit_for_raspberrypi/blob/master/mjpg-streamer/mjpg-streamer-experimental/www/LICENSE.txt This is a template for including the GNU General Public License (GPL) copyright notice in your source files. It should include the program's name, year, author, and a statement about its free software status under the GPL. ```text Copyright (C) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ``` -------------------------------- ### Run Django Development Server Source: https://github.com/sunfounder/sunfounder_smart_video_car_kit_for_raspberrypi/blob/master/html_server/README.md Starts the Django development server on a Raspberry Pi. This command should be executed within the http_server directory of the project. It makes the server accessible on the local network. ```bash sudo python manage.py runserver 0.0.0.0:8000 ``` -------------------------------- ### Reset Camera to Home Position using HTML GET Request Source: https://github.com/sunfounder/sunfounder_smart_video_car_kit_for_raspberrypi/blob/master/html_server/APIs.md This API resets the camera's pan and tilt servos to their home position. It is accessed via an HTTP GET request to the '/camera/home' endpoint. ```http GET http://[Raspberry Pi IP address]:8000/camera/home ``` -------------------------------- ### Set Motor to Run Forward in Calibration Mode using HTML GET Request Source: https://github.com/sunfounder/sunfounder_smart_video_car_kit_for_raspberrypi/blob/master/html_server/APIs.md This API sets the motor to run forward while in calibration mode. It is accessed via an HTTP GET request to the '/calibrate/motor/run' endpoint. ```http GET http://[Raspberry Pi IP address]:8000/calibrate/motor/run ``` -------------------------------- ### Stop Motor using HTML GET Request Source: https://github.com/sunfounder/sunfounder_smart_video_car_kit_for_raspberrypi/blob/master/html_server/APIs.md This API stops the motor of the smart car. It is accessed via an HTTP GET request to the '/motor/stop' endpoint. ```http GET http://[Raspberry Pi IP address]:8000/motor/stop ``` -------------------------------- ### Reverse Left Motor in Calibration Mode using HTML GET Request Source: https://github.com/sunfounder/sunfounder_smart_video_car_kit_for_raspberrypi/blob/master/html_server/APIs.md This API reverses the direction of the left motor while in calibration mode. It is accessed via an HTTP GET request to the '/calibrate/motor/left/reverse' endpoint. ```http GET http://[Raspberry Pi IP address]:8000/calibrate/motor/left/reverse ``` -------------------------------- ### Control Car Forward using HTML GET Request Source: https://github.com/sunfounder/sunfounder_smart_video_car_kit_for_raspberrypi/blob/master/html_server/APIs.md This API controls the smart car to move forward. It is accessed via an HTTP GET request to the specified Raspberry Pi IP address and port, followed by the '/motor/forward' endpoint. No specific programming language is required, as it can be executed directly from a web browser. ```http GET http://[Raspberry Pi IP address]:8000/motor/forward ``` -------------------------------- ### Reverse Right Motor in Calibration Mode using HTML GET Request Source: https://github.com/sunfounder/sunfounder_smart_video_car_kit_for_raspberrypi/blob/master/html_server/APIs.md This API reverses the direction of the right motor while in calibration mode. It is accessed via an HTTP GET request to the '/calibrate/motor/right/reverse' endpoint. ```http GET http://[Raspberry Pi IP address]:8000/calibrate/motor/right/reverse ``` -------------------------------- ### Stop Motor in Calibration Mode using HTML GET Request Source: https://github.com/sunfounder/sunfounder_smart_video_car_kit_for_raspberrypi/blob/master/html_server/APIs.md This API stops the motor while in calibration mode. It is accessed via an HTTP GET request to the '/calibrate/motor/stop' endpoint. ```http GET http://[Raspberry Pi IP address]:8000/calibrate/motor/stop ``` -------------------------------- ### Control Car Backward using HTML GET Request Source: https://github.com/sunfounder/sunfounder_smart_video_car_kit_for_raspberrypi/blob/master/html_server/APIs.md This API controls the smart car to move backward. It is accessed via an HTTP GET request to the specified Raspberry Pi IP address and port, followed by the '/motor/backward' endpoint. This command can be entered directly into a web browser's address bar. ```http GET http://[Raspberry Pi IP address]:8000/motor/backward ``` -------------------------------- ### Control Camera Tilt Increase using HTML GET Request Source: https://github.com/sunfounder/sunfounder_smart_video_car_kit_for_raspberrypi/blob/master/html_server/APIs.md This API increases the tilt servo position on the Y axis, moving the camera up. It is accessed via an HTTP GET request to the '/camera/increase/y' endpoint. ```http GET http://[Raspberry Pi IP address]:8000/camera/increase/y ``` -------------------------------- ### JavaScript: Dynamically Generate Input Controls Source: https://github.com/sunfounder/sunfounder_smart_video_car_kit_for_raspberrypi/blob/master/mjpg-streamer/mjpg-streamer/www/control.htm This function generates input controls for the smart video car kit based on data loaded from a JSON file. It supports various control types like integer spinboxes, boolean checkboxes, string text fields, dropdown menus, and buttons. It also handles the initial setup of resolution selection. This function is essential for creating the interactive control interface. ```javascript function addInput(plugin_id) { $.getJSON("input_"+plugin_id+".json", function(data) { $.each(data.controls, function(i,item){ $("").attr("id", "tr_"+item.group+"-"+item.id).appendTo("#controltable_"+plugin_id); $("").text(item.name).appendTo("#tr_"+item.group+"-"+item.id); $("").attr("id", "td_ctrl_"+item.group+"-"+item.id).appendTo("#tr_"+item.group+"-"+item.id); if((item.type == 1) || (item.type == 5)) { var options = {min: item.min, max: item.max, step: item.step} $("") .attr("value", item.value) .attr("id", "spinbox-"+item.id) .SpinButton(options) .bind("valueChanged", function() {setControl(1, plugin_id, item.id, item.group, $(this).val());}) .appendTo("#td_ctrl_"+item.group+"-"+item.id); } else if (item.type == 2) { if (item.value == "1") $("") .attr("type", "checkbox") .attr("checked", "checked") .change(function(){setControl_bool(item.group, plugin_id, item.id, ($(this).attr("checked")?1:0));}) .appendTo("#td_ctrl_"+item.group+"-"+item.id); else $("") .attr("type", "checkbox") .change(function(){setControl_bool(1, plugin_id, item.id, item.group ($(this).attr("checked")?1:0));}) .appendTo("#td_ctrl_"+item.group+"-"+item.id); } else if (item.type == 7) { $("").attr("value", item.value).appendTo("#td_ctrl_"+item.group+"-"+item.id); } else if (item.type == 3) { $("") .attr("type", "text") .attr("maxlength", item.max) .change(function(){setControl_string(1, plugin_id, item.id, item.group, $(this).text());}) .appendTo("#td_ctrl_"+item.group+"-"+item.id); } else { alert("Unknown control type: "+item.type); } }); $("").attr("id", "tr-status").appendTo("#control"); $("").appendTo("#tr-status"); $("").attr("id", "td-status").appendTo("#tr-status"); }); } /*$.getJSON("input.json", function(data) { $.each(data.formats, function(i,item){ if (item.current == "true") { $("") .attr("value", item.value) .attr("id", "spinbox-"+item.id) .SpinButton(options) .bind("valueChanged", function() {setControl(1, plugin_id, item.id, item.group, $(this).val());}) .appendTo("#td_ctrl_"+item.group+"-"+item.id); } else if (item.type == 2) { if (item.value == "1") $("") .attr("type", "checkbox") .attr("checked", "checked") .change(function(){setControl_bool(item.group, plugin_id, item.id, ($(this).attr("checked")?1:0));}) .appendTo("#td_ctrl_"+item.group+"-"+item.id); else $("") .attr("type", "checkbox") .change(function(){setControl_bool(1, plugin_id, item.id, item.group ($(this).attr("checked")?1:0));}) .appendTo("#td_ctrl_"+item.group+"-"+item.id); } else if (item.type == 7) { $("").attr("value", item.value).appendTo("#td_ctrl_"+item.group+"-"+item.id); } else if (item.type == 3) { $("") .attr("type", "text") .attr("maxlength", item.max) .change(function(){setControl_string(1, plugin_id, item.id, item.group, $(this).text());}) .appendTo("#td_ctrl_"+item.group+"-"+item.id); } else { alert("Unknown control type: "+item.type); } }); $("").attr("id", "tr-status").appendTo("#control"); $("").appendTo("#tr-status"); $("").attr("id", "td-status").appendTo("#tr-status"); }); } ``` -------------------------------- ### Manage Streaming State with JavaScript Source: https://github.com/sunfounder/sunfounder_smart_video_car_kit_for_raspberrypi/blob/master/mjpg-streamer/mjpg-streamer/www/javascript_motiondetection.html This JavaScript code snippet manages the streaming state of the video car kit. It checks the current image source and updates the window name to 'streaming' or 'paused' accordingly. This uses the browser's window.name property to persist state across reloads, though cookies or server-side scripting are suggested as cleaner alternatives. ```javascript if (img.src.indexOf("/?action=stream") !== -1) { img.src = "/?action=stream"; window.name = 'paused'; } else { img.src = "/?action=stream"; window.name = 'streaming'; } ``` -------------------------------- ### Running Tkinter GUI Client on Raspberry Pi (Python) Source: https://github.com/sunfounder/sunfounder_smart_video_car_kit_for_raspberrypi/blob/master/README.md This snippet demonstrates the typical Tkinter initialization that leads to a _tkinter.TclError when executed remotely without a display. The error occurs because Tkinter requires a graphical environment (a DISPLAY variable) which is typically absent in SSH or remote command-line sessions. ```python from Tkinter import Tk top = Tk() # Create a top window # ... rest of the GUI code ```