Script get local IP¶
Note
This example can only run on OAK POE devices. You need bootloader on/above version 0.0.15. You can flash bootloader by running python3 examples/bootloader/flash_bootloader.py
.
This example shows you how to get local IP (IP in the private network) of the device.
Demo¶
~/depthai-python/examples/Script$ python3 script_get_ip.py
Found device with name: 14442C1031425FD700-ma2480
Version: 0.0.15
Names of layers: ['fp16', 'uint8']
NNData size: 13
FP16 values: [1.0, 1.2001953125, 3.900390625, 5.5]
UINT8 values: [6, 9, 4, 2, 0]
Setup¶
Please run the install script to download all required dependencies. Please note that this script must be ran from git context, so you have to download the depthai-python repository first and then run the script
git clone https://github.com/luxonis/depthai-python.git
cd depthai-python/examples
python3 install_requirements.py
For additional information, please follow installation guide
Source code¶
Also available on GitHub
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | #!/usr/bin/env python3
import depthai as dai
# Start defining a pipeline
pipeline = dai.Pipeline()
# Script node
script = pipeline.create(dai.node.Script)
script.setProcessor(dai.ProcessorType.LEON_CSS)
script.setScript("""
import socket
import fcntl
import struct
def get_ip_address(ifname):
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
return socket.inet_ntoa(fcntl.ioctl(
s.fileno(),
-1071617759, # SIOCGIFADDR
struct.pack('256s', ifname[:15].encode())
)[20:24])
ip = get_ip_address('re0') # '192.168.0.110'
node.warn(f'IP of the device: {ip}')
node.io['end'].send(Buffer(32))
""")
xout = pipeline.create(dai.node.XLinkOut)
xout.setStreamName('end')
script.outputs['end'].link(xout.input)
# Connect to device with pipeline
with dai.Device(pipeline) as device:
device.getOutputQueue("end").get() # Wait for the "end" msg
|
Also available on GitHub
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | #include <iostream>
// Includes common necessary includes for development using depthai library
#include "depthai/depthai.hpp"
int main() {
using namespace std;
// Start defining a pipeline
dai::Pipeline pipeline;
// Script node
auto script = pipeline.create<dai::node::Script>();
script->setProcessor(dai::ProcessorType::LEON_CSS);
script->setScript(R"(
import socket
import fcntl
import struct
def get_ip_address(ifname):
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
return socket.inet_ntoa(fcntl.ioctl(
s.fileno(),
-1071617759, # SIOCGIFADDR
struct.pack('256s', ifname[:15].encode())
)[20:24])
ip = get_ip_address('re0') # '192.168.0.110'
node.warn(f'IP of the device: {ip}')
node.io['end'].send(Buffer(32))
)");
// XLinkOut
auto xout = pipeline.create<dai::node::XLinkOut>();
xout->setStreamName("end");
script->outputs["end"].link(xout->input);
// Connect to device with pipeline
dai::Device device(pipeline);
device.getOutputQueue("end")->get<dai::Buffer>();
return 0;
}
|