Introducing The Sweep: OX’s New Live Security Research Series
Register Now
Breaking: The 2026 Vulnpocalypse Hits PHP: Four Critical RCEs, but How Dangerous Are They?
Read the Report
Are you exposed? Connect your apps in minutes.
Scan your apps free

milesight-gateway-api

Latest version: v0.2.0b1

Overview

Last scanned
24 Nov 2026
Published
24 Nov 2026
PyPI package Publisher: StefanKnaak
2 Stars
0 Forks
3 Versions
224 Downloads
Python Repo language

Scan summary

milesight-gateway-api was last scanned on 24 Nov 2026 at version 0.2.0b1. Risk score 0 of 100. No malicious behavior was detected.

  • Releases: 3 versions; the latest 2 were published on 24 Nov 2026.
  • Findings: No rules fired in version 0.2.0b1.
  • Downloads: 224 downloads.

Versions

3 versions published
Versions and the rules that fired in each
VersionPublishedStatus
0.2.0b1 LATEST 24 Nov 2026 No rules fired
0.1.0 24 Nov 2026 No rules fired
0.0.2 28 Oct 2026 No rules fired

No rules fired in 0.2.0b1

Findings

Findings for v0.2.0b1. The score is a capped sum of the weights of the rules that fired — not CVSS, not exploitability, and not a probability. It is not comparable across packages with different scan coverage.

The score describes 0.2.0b1; other versions have their own rules, not their own score.

README

The publisher’s own README, as collected from the registry.

Milesight Gateway API

GitHub Release pip Release PyPI - Python Version License

Supports aarch64 Architecture Supports amd64 Architecture Supports armhf Architecture Supports armv7 Architecture Supports i386 Architecture

The Milesight Gateway API is a Python client that provides an interface for interacting with Milesight Gateways through various REST API endpoints. It supports fetching device data, network server settings, packet forwarder information, profiles, payload codecs, and more.

This is a beta release!

Use at your own risk.

Why

There are some feature missing in the original firmware from Milesight, which can become a problem, especially in large installations with several gateways.

For example:

  • [x] Its not possible to export the device list. -> Fixed
  • [x] Its not possible to export the custom payload codecs. -> Fixed

ToDo:

  • [x] use all get endpoints
  • [x] send downlinks to devices
  • [ ] use post endpoints to write on gateways
  • [ ] IoT Developer Api
  • [ ] state engine to use this API for receiving the actuall sensor values.

Requirements

The Milesight Gateway firmware must be 60.0.0.42-r5/56.0.0.4 or higher. (from May 28, 2024 )

Table of Contents

  • Installation
  • Features
  • Usage
    • Basic Usage
    • Getting JWT Token
    • Fetching Devices
    • Fetching Applications
    • Fetching Payload Codecs
    • Fetching Profiles
    • Fetching Gateway Fleet
  • License

Installation

To install the package from PyPI, simply run:

pip install Milesight-Gateway-API

Milesight-Gateway-API on pypi.org

Features

The MilesightGatewayClient class provides the following features:

  • Fetch Devices: Fetch devices and their details with pagination and search options.
  • Fetch Network Server Settings: Get network server settings from the Milesight Gateway.
  • Packet Forwarder Information: Retrieve information about the packet forwarder and connected servers.
  • Fetch Applications: Retrieve all applications with pagination.
  • Data Transmission Integration: Fetch integration details by ID and transmission type (HTTP or MQTT).
  • Fetch Payload Codecs: Fetch default or custom payload codecs with pagination and optional search.
  • Fetch Profiles: Fetch profiles for an organization and application, with optional profileID for specific content search.
  • Fetch Gateway Fleet: Retrieve gateway details with optional search by name or gateway ID.
  • Network Server Status: Gateways with their link state, applications, codec settings and the newest entries of the packet log, one request each.
  • Send Downlinks: Queue a command for a device; the gateway encodes it with the device's payload codec.
  • Web Interface: Read the gateway's model, firmware, serial number, CPU load, free memory and storage, and uptime.
  • Firmware: Find the newest gateway firmware on Milesight's download page.

Usage

See /tests/test_client.py how to use all functions.

Basic Usage

First, import the MilesightGatewayClient class and configure it with your credentials. Ensure you have the required environment variables or load them from a .env file. You can copy .env_eample to .env and change the IP, Username and Password.

from milesight_gateway_api.milesight_gateway_client import MilesightGatewayClient
import os
from aiohttp import ClientSession

# Load environment variables (e.g., USERNAME, PASSWORD, etc.)
username = os.getenv('USERNAME') # admin
password = os.getenv('PASSWORD') # the WebUI Login Password
secret_key = bytes(os.getenv('SECRET_KEY'), 'utf-8')
iv = bytes(os.getenv('IV'), 'utf-8')
base_url = os.getenv('BASE_URL')
port = os.getenv('PORT')

client = MilesightGatewayClient(username, password, secret_key, iv, base_url, port)

Getting JWT Token

You must retrieve the JWT token before making other requests. Use the get_jwt_token method:

async with ClientSession() as session:
    jwt_token = await client.get_jwt_token(session)    

Fetching Devices

You can fetch all devices with pagination or search for a specific device by providing the search parameter.

# Fetch all devices
all_devices, devices_total_count = await client.get_all_devices(session)
print(f"Total Devices: {devices_total_count}")
print(all_devices)

Search for a specific device

search_device_string = "device_id_here"
search_device = await client.get_device(session, search_device_string)
print(f"Search Results for {search_device_string}:")
print(search_device)

Fetching Applications

To fetch all applications:

# Fetch all applications with pagination
applications, total_applications = await client.get_all_applications(session)
print(f"Total Applications: {total_applications}")
print(applications)

Fetching Payload Codecs

You can fetch payload codecs by type (default or custom) with optional search functionality.

# Fetch all default payload codecs
payload_codecs, codecs_total_count = await client.get_payload_codecs(session, codec_type='default')
print(f"Total Payload Codecs: {codecs_total_count}")
print(payload_codecs)

Search for a custom payload codec

search_payload_codecs, codecs_total_count = await client.get_payload_codecs(session, codec_type='custom', search="custom_codec_name")
print(f"Search Results: {search_payload_codecs}")

Fetching Profiles

You can fetch profiles for an organization and application, with an optional profile_id to search for specific profile content.

# Fetch profiles
organization_id = "1"
application_id = "5"
profiles, total_profiles = await client.get_profiles(session, organization_id, application_id)
print(f"Total Profiles: {total_profiles}")
print(profiles)
# Fetch specific profile by profileID
profile_id = "your_profile_id"
profiles_by_id, total_profiles = await client.get_profiles(session, organization_id, application_id, profile_id=profile_id)
print(f"Profiles for profileID {profile_id}: {profiles_by_id}")

Fetching Gateway Fleet

Fetch the gateway fleet with optional search by gateway name or ID.

# Fetch gateway fleet
organization_id = "1"
gateway_fleet, total_gateways = await client.get_gateway_fleet(session, organization_id)
print(f"Total Gateways: {total_gateways}")
print(gateway_fleet)

Search for a gateway by name or ID

gateway_fleet_search, total_gateways = await client.get_gateway_fleet(session, organization_id, search="gateway_name_or_id")
print(f"Search Results: {gateway_fleet_search}")

Sending a Downlink

The gateway runs the device's assigned encoder over the command, so the keys are that encoder's vocabulary. The device picks the downlink up after its next uplink.

await client.enqueue_downlink(session, "24E1247140000001", {"report_interval": 10})

Reading the Web Interface

The web interface has its own session login with the same account. The client keeps the session and renews it when the gateway forgets it. After one refused login it does not try again, because the gateway locks an account after a few failed logins; it raises WebLoginRefusedError instead.

info = await client.get_login_status(session)    # model, firmware ("rtver"); no login needed
system = await client.get_system_info(session)   # sn, uptime, cpu_load, memory_avail_percent, ...

Finding the Newest Firmware

from milesight_gateway_api import get_latest_firmware

release = await get_latest_firmware(session, "60")  # 60 is the UG65 and UG67 family
print(release.version, release.download_url)

Decoding Uplinks

The package bundles Milesight's own payload decoders for every model in Milesight-IoT/codec (MIT) and runs them with dukpy, so raw uplink bytes decode exactly as on the gateway. Install the extra:

pip install "Milesight-Gateway-API[decoder]"
from milesight_gateway_api import decoder

decoder.decode("ws203", bytes.fromhex("01754003674400046871050000"))
# {'battery': 64, 'temperature': 6.8, 'humidity': 56.5, 'occupancy': 0}
decoder.models()["ws203"]["fields"]["occupancy"]   # type, unit, value names

Enumerations come back as raw numbers; the model's fields name them. scripts/update_codecs.py refreshes the bundle from Milesight's release branch.

Encoding takes the same vocabulary and returns the bytes for a downlink on FPort 85. Nested settings use dotted keys through nest():

decoder.encode("wt101", {"report_status": 1})                 # b'\xff\x28\x00'
decoder.encode("wt101", decoder.nest({"temperature_control.enable": 0}))

Usefull Links

License

This project is licensed under the MIT License. See the LICENSE file for more details.

OX Radar and Response Center

Find threats in your stack.

OX Radar can check high-priority threats, like critical package CVEs, against your context.

Each incident is marked Detected or Not Detected with a remediation plan and proof all tracked in the Response Center.

Where it’s listed

The probe returned only these fields for this server — auth requirement, protocol and tool list weren’t observed, so they’re not shown (never guessed).

  • pypi-releases milesight-gateway-api

References

The publisher’s own links, as the registry reports them. These are not sources for the assessment on this page.

Scan your whole stack

Group 1261154050 1
Group 1261154050
 

From OX Research Newsroom

Plug and Pray: Your AI Agents Are Taking Orders From Strangers
Research

Plug and Pray: Your AI Agents Are Taking Orders From Strangers

Cry2Wolf: How to Tell a Real Bug from a Nothingburger
AI & VibeSec

Cry2Wolf: Not Every Branded Bug Deserves a Fire Drill

Vulnerability Insights

Compromised Claude Code extensions (versions 2.1.312 & 2.1.313) in Cursor try to install a backdoor

Frame 2085668439 (1)
Group 1261154229