DepthAI Tutorials
DepthAI API References

ON THIS PAGE

  • Script HTTP client
  • Demo
  • Setup
  • Source code
  • Pipeline

Script HTTP client

This example will send an HTTP request to the http://api.ipify.org and print your public IP.

Demo

Command Line
1~/depthai-python/examples/Script$ python3 script_http_client.py
2    Sending http GET request...
3    200 OK
4    Public IP: b'123.123.123.123'

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
Command Line
1git clone https://github.com/luxonis/depthai-python.git
2cd depthai-python/examples
3python3 install_requirements.py
For additional information, please follow the installation guide.

Source code

Python
C++

Python

Python
GitHub
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("""
11    import http.client
12    import time
13
14    node.warn('Sending http GET request...')
15    h1 = http.client.HTTPConnection('api.ipify.org', 80)
16    h1.request("GET", "/")
17    r1 = h1.getresponse()
18    node.warn(f'{r1.status} {r1.reason}')
19    data1 = r1.read()
20    node.warn(f'Public IP: {data1}')
21
22    node.io['end'].send(Buffer(32))
23""")
24
25xout = pipeline.create(dai.node.XLinkOut)
26xout.setStreamName('end')
27script.outputs['end'].link(xout.input)
28
29# Connect to device with pipeline
30with dai.Device(pipeline) as device:
31    device.getOutputQueue("end").get() # Wait for the "end" msg

Pipeline

Need assistance?

Head over to Discussion Forum for technical support or any other questions you might have.