90 minutes ⇒ Level: High
Project Setup (15 minutes)
- Begin by reviewing the project scenario. Emphasize that the primary goal is to establish communication between the Raspberry Pi and the 3D printer.
- Distribute a Raspberry Pi connected to the 3D printer to each group of students. If there are fewer 3D printers than groups, the groups can alternate usage of the 3D printers.
- Ensure all students have Node.js installed on their Raspberry Pi and can access the OctoPrint server. Also, ensure that Raspberry Pis are connected to the local network. Provide IP addresses of Raspberry Pis to students.
- In short, explain to students what an SSH connection is and why it is needed to communicate from our computers to a Raspberry Pi. Present an SSH client that will be used, such as PuTTY, and demonstrate how the connection between a computer and a Raspberry Pi is established.
- In short, explain how SCP functions and how we can develop on a headless Raspberry Pi. Furthermore, you could provide an example of a remote SSH extension for a specific code editor.
- Show the steps for setting up a Node.js project. ⇒ using slides (4.2-communication_implementation.pptx)
Implementing Communication with OctoPrint (60 minutes)
- Explain the main objective: Students will create a Node.js program that accomplishes the following:”
- Authenticates with the OctoPrint API.
- Uploads provided G-code files to OctoPrint.
- Starts a print job using the uploaded G-code file.
- Guide groups of students through the initialization of the Node.js project and package installations (e.g. Axios).
- Provide assistance as they write the code to upload G-code files, ensuring they understand how to form the POST request correctly.
- Help students write the code to initiate a print job, discussing how to reference the uploaded file and trigger the printing process.
- Encourage students to test their program, ensuring the 3D printer responds as expected. This hands-on testing is crucial for understanding the end-to-end process. The provided examples of G-code do not result in the printing of any specific product. Instead, they facilitate various types of motions for the 3D printer's extruder to reduce costs in the development process. G-code for printing actual 3D products can be made available to students.
Refactoring into a Function (15 minutes)
- Instruct students to refactor their working code into a single reusable function. This function should take parameters such as the file path of the G-code file and any other necessary information.
- Discuss the importance of modular code and how creating reusable functions can simplify future project development.
- Guide students through the process of encapsulating their code into a function, highlighting best practices in JavaScript function development.
- Encourage students to test their function to ensure it still performs as expected after refactoring.
- Wrap up by discussing how the skills learned in this session apply to real-world IoT and 3D printing scenarios.