脚本获取本地 IP
脚本获取本地 IP
此示例只能在 OAK POE 设备 上运行。您需要版本 0.0.15 或更高版本的 bootloader。您可以通过运行
python3 examples/bootloader/flash_bootloader.py 来刷写 bootloader。演示
Command Line
1~/depthai-python/examples/Script$ python3 script_get_ip.py
2 Found device with name: 14442C1031425FD700-ma2480
3 Version: 0.0.15
4
5 Names of layers: ['fp16', 'uint8']
6 NNData size: 13
7 FP16 values: [1.0, 1.2001953125, 3.900390625, 5.5]
8 UINT8 values: [6, 9, 4, 2, 0]设置
Command Line
1git clone https://github.com/luxonis/depthai-python.git
2cd depthai-python/examples
3python3 install_requirements.py源代码
Python
PythonGitHub
1#!/usr/bin/env python3
2import depthai as dai
3
4# Start defining a pipeline
5pipeline = dai.Pipeline()
6
7# Script node
8script = pipeline.create(dai.node.Script)
9script.setProcessor(dai.ProcessorType.LEON_CSS)
10script.setScript("""
11import socket
12import fcntl
13import struct
14
15def get_ip_address(ifname):
16 s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
17 return socket.inet_ntoa(fcntl.ioctl(
18 s.fileno(),
19 -1071617759, # SIOCGIFADDR
20 struct.pack('256s', ifname[:15].encode())
21 )[20:24])
22
23ip = get_ip_address('re0') # '192.168.0.110'
24node.warn(f'IP of the device: {ip}')
25node.io['end'].send(Buffer(32))
26""")
27
28xout = pipeline.create(dai.node.XLinkOut)
29xout.setStreamName('end')
30script.outputs['end'].link(xout.input)
31
32# Connect to device with pipeline
33with dai.Device(pipeline) as device:
34 device.getOutputQueue("end").get() # Wait for the "end" msgPipeline
需要帮助?
请前往 Discussion Forum 获取技术支持或提出您可能有的任何其他问题。