User Tools

Site Tools


3dprinter:octoprint

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
3dprinter:octoprint [2023/04/30 05:30] Wulf Rajek3dprinter:octoprint [2023/05/29 11:55] (current) – external edit 127.0.0.1
Line 57: Line 57:
 </code> </code>
  
-====== Tuya Smart Plug ====== 
- 
-https://pypi.org/project/tinytuya/ 
-https://plugins.octoprint.org/plugins/tuyasmartplug/ 
  
 ====== Nexus AI ====== ====== Nexus AI ======
Line 112: Line 108:
 G28 Z0 ;move Z to min endstops G28 Z0 ;move Z to min endstops
 </code> </code>
 +
 +
 +
 +====== PSUControl + Tuya Plug/LED On/Off ======
 +
 +The following python scripts can be used to switch on/off a Tuya compatible smart plug in the local network and to trigger two flashes in red of a smart LED, then restoring the LED to the previous colour and state.
 +
 +Using the PSUControl plugin, these scripts can be triggered automatically:
 +https://github.com/kantlivelong/OctoPrint-PSUControl
 +
 +{{:3dprinter:pasted:20230501-123913.png}}
 +
 +{{:3dprinter:pasted:20230501-213901.png}}
 +
 +To locally control the Tuya devices, the tinytuya python module needs to be installed:
 +
 +<code>
 +pip install tinytuya
 +</code>
 +
 +The module provides local system scanning options and methods to obtain the local key required to control the devices. The devices may need to be connected to a Tuya cloud account first and an API account set up. However, this might only be required if the devices need to be controlled from tinytuya using the cloud option from outside the local network.
 +More information provided here: https://pypi.org/project/tinytuya/
 +
 +
 +Configure the slicer (Cura or others) to add gcode at the end of the sliced file to trigger shutting down the printer.
 +<code>
 +M81 ;switch off printer
 +</code>
 +
 +
 +<code python ~/.local/bin/3don.py>
 +#!/usr/bin/python
 +import tinytuya
 +
 +# 3D Printer Plug
 +d = tinytuya.OutletDevice(
 +    dev_id='07870772cc50e3d2fcf2',
 +    address='192.168.1.23',
 +    local_key='d7382aa465d40908',
 +    version=3.3)
 +
 +d.turn_on()
 +</code>
 +
 +<code python ~/.local/bin/3doff.py>
 +#!/usr/bin/python
 +import tinytuya
 +import time
 +
 +# Hall Light
 +
 +# Connect to Device
 +d = tinytuya.BulbDevice(
 +    dev_id='722168502cf4320a9d1e',
 +    address='192.168.1.11',
 +    local_key='3209036606016f40',
 +    version=3.1)
 +
 +# Optional: Keep socket open for multiple commands
 +d.set_socketPersistent(True)
 +#d.set_socketNODELAY(True)
 +#d.set_sendWait(0)
 +
 +# Get Status as dictionary
 +olddata = d.status()
 +olddps = olddata['dps']
 +
 +#Switch on
 +d.turn_on(nowait=True)
 +
 +d.set_scene(3, nowait=True)
 +
 +time.sleep(6)
 +
 +# restoring old data
 +for key, value in olddps.items():
 +    # print('%s : %s' % (key, value))
 +    if key == 1:
 +        continue
 +    d.set_value(key, value)
 +d.set_value(1, olddps['1'])
 +
 +# 'dps': {'1': True, '2': 'colour', '3': 135, '4': 255, '5': '301f000027ff2f', '6': 'cf38000168ffff', '7': 'ffff500100ff00', '8': 'ffff8003ff000000ff000000ff000000000000000000', '9': 'ffff5001ff0000', '10': 'ffff0505ff000000ff00ffff00ff00ff0000ff000000'}}
 +# Wulf Default:
 +d.set_value(2, "colour")
 +d.set_value(3, 135)
 +d.set_value(4, 255)
 +d.set_value(5, '301f000027ff2f')
 +d.set_value(6, 'cf38000168ffff')
 +d.set_value(7, 'ffff500100ff00')
 +d.set_value(8, 'ffff8003ff000000ff000000ff000000000000000000')
 +d.set_value(9, 'ffff5001ff0000')
 +d.set_value(10, 'ffff0505ff000000ff00ffff00ff00ff0000ff000000')
 +d.set_mode(mode='colour'      # white, colour, scene, music
 +d.set_value(1, olddps['1'])
 +
 +time.sleep(10)
 +
 +# 3D Printer Plug
 +p = tinytuya.OutletDevice(
 +    dev_id='07870772cc50e3d2fcf2',
 +    address='192.168.1.23',
 +    local_key='d7382aa465d40908',
 +    version=3.3)
 +
 +p.turn_off()
 +</code>
 +
 +<code>
 +chmod 755 ~/.local/bin/3don.py
 +chmod 755 ~/.local/bin/3doff.py
 +</code>
 +
 +
 +====== motion webcam ======
 +
 +https://motion-project.github.io/motion_config.html
 +https://forums.raspberrypi.com/viewtopic.php?t=324883
 +
 +<code>
 +sudo apt-get install motion
 +mkdir ~/.motion
 +vi ~/.motion/motion.conf
 +</code>
 +<code - ~/.motion/motion.conf>
 +videodevice /dev/video2
 +picture_output off
 +movie_output off
 +stream_quality 98
 +stream_grey off
 +stream_maxrate 5
 +stream_port 8090
 +stream_localhost off
 +stream_motion on
 +# stream_motion off #stream 1 fps when no motion detected
 +framerate 10
 +movie_codec mpeg4
 +# http://192.168.1.3:8080/webcam1.cgi
 +width 1280
 +height 720
 +auto_brightness off
 +vid_control_params "contrast"=0,"saturation"=0
 +#log_level 7
 +webcontrol_interface 0
 +webcontrol_localhost off
 +webcontrol_port 8091
 +#emulate_motion on #always save images even without motion
 +</code>
 +
 +Log Level 7 shows camera controls, e.g:
 +<code>
 +[1:ml1] [INF] [VID] v4l2_ctrls_list: ---------Controls---------
 +[1:ml1] [INF] [VID] v4l2_ctrls_list:   V4L2 ID   Name and Range
 +[1:ml1] [INF] [VID] v4l2_ctrls_list: ID09963776 Brightness, -64 to 64
 +[1:ml1] [INF] [VID] v4l2_ctrls_list: ID09963777 Contrast, 0 to 64
 +[1:ml1] [INF] [VID] v4l2_ctrls_list: ID09963778 Saturation, 0 to 128
 +[1:ml1] [INF] [VID] v4l2_ctrls_list: ID09963779 Hue, -40 to 40
 +[1:ml1] [INF] [VID] v4l2_ctrls_list: ID09963788 White Balance, Automatic, 0 to 1
 +[1:ml1] [INF] [VID] v4l2_ctrls_list: ID09963792 Gamma, 72 to 500
 +[1:ml1] [INF] [VID] v4l2_ctrls_list: ID09963795 Gain, 0 to 100
 +[1:ml1] [INF] [VID] v4l2_ctrls_list: ID09963800 Power Line Frequency, 0 to 2
 +[1:ml1] [INF] [VID] v4l2_ctrls_list:   menu item: Value 0 Disabled
 +[1:ml1] [INF] [VID] v4l2_ctrls_list:   menu item: Value 1 50 Hz
 +[1:ml1] [INF] [VID] v4l2_ctrls_list:   menu item: Value 2 60 Hz
 +[1:ml1] [INF] [VID] v4l2_ctrls_list: ID09963802 White Balance Temperature, 2800 to 6500
 +[1:ml1] [INF] [VID] v4l2_ctrls_list: ID09963803 Sharpness, 0 to 6
 +[1:ml1] [INF] [VID] v4l2_ctrls_list: ID09963804 Backlight Compensation, 0 to 2
 +[1:ml1] [INF] [VID] v4l2_ctrls_list: ID10094849 Auto Exposure, 0 to 3
 +[1:ml1] [INF] [VID] v4l2_ctrls_list:   menu item: Value 1 Manual Mode
 +[1:ml1] [INF] [VID] v4l2_ctrls_list:   menu item: Value 3 Aperture Priority Mode
 +[1:ml1] [INF] [VID] v4l2_ctrls_list: ID10094850 Exposure Time, Absolute, 1 to 5000
 +[1:ml1] [INF] [VID] v4l2_ctrls_list: ID10094851 Exposure, Dynamic Framerate, 0 to 1
 +[1:ml1] [INF] [VID] v4l2_ctrls_list: --------------------------
 +</code>
 +
 +Since the exact device number is set by the kernel upon boot, when there is more than one video device it is possible that the particular cameras that were assigned to /dev/video0 and /dev/video1 may switch. In order to set up Motion so that a particular camera is always assigned the same way, users can set up a symbolic link using udev rules. To do this a unique attribute must be identified for each camera. The camera attributes can be viewed by using the command <code>udevadm info -a -p $(udevadm info -q path -n /dev/video0)</code> while the camera is attached. Usually a serial number can be used. ("Usually" because some cameras have been observed to have the same serial number for different cameras)
 +
 +Once a unique attribute has been identified for each camera, edit or create the file /etc/udev/rules.d/99-local.rules.
 +Assuming that the unique attribute for the camera was name and was ''ATTR{name}=="Philips SPC 900NC webcam"'' you would add the following line to the 99-local.rules file: <code>KERNEL=="video[0-9]*", ATTR{name}=="Philips\ SPC\ 900NC*", SYMLINK+="video-webcam0"</code>
 +Once the change has been made and saved, reboot the computer and there should now be a "sticky" device called /dev/video-webcam0
 +
 +
 +URL for static current image: http://localhost:8090/current
 +
3dprinter/octoprint.1682829058.txt.gz · Last modified: 2023/05/29 11:53 (external edit)