Milesight-Gateway-API 0.0.1__tar.gz → 0.0.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {Milesight-Gateway-API-0.0.1 → milesight_gateway_api-0.0.2}/LICENSE +21 -21
- milesight_gateway_api-0.0.2/Milesight_Gateway_API.egg-info/PKG-INFO +248 -0
- {Milesight-Gateway-API-0.0.1 → milesight_gateway_api-0.0.2}/Milesight_Gateway_API.egg-info/SOURCES.txt +2 -1
- milesight_gateway_api-0.0.2/PKG-INFO +248 -0
- milesight_gateway_api-0.0.2/README.md +221 -0
- {Milesight-Gateway-API-0.0.1 → milesight_gateway_api-0.0.2}/milesight_gateway_api/__init__.py +2 -2
- {Milesight-Gateway-API-0.0.1 → milesight_gateway_api-0.0.2}/milesight_gateway_api/milesight_gateway_client.py +349 -349
- {Milesight-Gateway-API-0.0.1 → milesight_gateway_api-0.0.2}/setup.cfg +4 -4
- {Milesight-Gateway-API-0.0.1 → milesight_gateway_api-0.0.2}/setup.py +24 -24
- milesight_gateway_api-0.0.2/tests/test_client.py +142 -0
- Milesight-Gateway-API-0.0.1/Milesight_Gateway_API.egg-info/PKG-INFO +0 -36
- Milesight-Gateway-API-0.0.1/PKG-INFO +0 -36
- Milesight-Gateway-API-0.0.1/README.md +0 -18
- {Milesight-Gateway-API-0.0.1 → milesight_gateway_api-0.0.2}/Milesight_Gateway_API.egg-info/dependency_links.txt +0 -0
- {Milesight-Gateway-API-0.0.1 → milesight_gateway_api-0.0.2}/Milesight_Gateway_API.egg-info/requires.txt +0 -0
- {Milesight-Gateway-API-0.0.1 → milesight_gateway_api-0.0.2}/Milesight_Gateway_API.egg-info/top_level.txt +0 -0
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2024 Stefan Knaak
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Stefan Knaak
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: Milesight-Gateway-API
|
|
3
|
+
Version: 0.0.2
|
|
4
|
+
Summary: A python client for interacting with Milesight gateway REST API
|
|
5
|
+
Home-page: https://github.com/corgan2222/Milesight-Gateway-API
|
|
6
|
+
Author: Stefan Knaak
|
|
7
|
+
Author-email: stefan.knaak@e-shelter.io
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Requires-Python: >=3.9
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
Requires-Dist: aiohttp
|
|
15
|
+
Requires-Dist: pycryptodome
|
|
16
|
+
Requires-Dist: urllib3
|
|
17
|
+
Dynamic: author
|
|
18
|
+
Dynamic: author-email
|
|
19
|
+
Dynamic: classifier
|
|
20
|
+
Dynamic: description
|
|
21
|
+
Dynamic: description-content-type
|
|
22
|
+
Dynamic: home-page
|
|
23
|
+
Dynamic: license-file
|
|
24
|
+
Dynamic: requires-dist
|
|
25
|
+
Dynamic: requires-python
|
|
26
|
+
Dynamic: summary
|
|
27
|
+
|
|
28
|
+
# Milesight Gateway API
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
[![GitHub Release][release-shield]][release]
|
|
32
|
+
[![pip Release][pip-release-shield]][pip-release]
|
|
33
|
+

|
|
34
|
+
[![License][license-shield]](LICENSE.md)
|
|
35
|
+
|
|
36
|
+
![Supports aarch64 Architecture][aarch64-shield]
|
|
37
|
+
![Supports amd64 Architecture][amd64-shield]
|
|
38
|
+
![Supports armhf Architecture][armhf-shield]
|
|
39
|
+
![Supports armv7 Architecture][armv7-shield]
|
|
40
|
+
![Supports i386 Architecture][i386-shield]
|
|
41
|
+
|
|
42
|
+
The **Milesight Gateway API** is a Python client that provides an interface for interacting with Milesight Gateways through various REST API endpoints.
|
|
43
|
+
It supports fetching device data, network server settings, packet forwarder information, profiles, payload codecs, and more.
|
|
44
|
+
|
|
45
|
+
## This is a beta release!
|
|
46
|
+
|
|
47
|
+
Use at your own risk.
|
|
48
|
+
|
|
49
|
+
# Why
|
|
50
|
+
There are some feature missing in the original firmware from Milesight, which can become a problem, especially in large installations with several gateways.
|
|
51
|
+
|
|
52
|
+
For example:
|
|
53
|
+
- [x] Its not possible to export the device list. [-> Fixed](https://github.com/corgan2222/Milesight-Gateway-API/blob/main/examples/export_devices.py)
|
|
54
|
+
- [x] Its not possible to export the custom payload codecs. [-> Fixed](https://github.com/corgan2222/Milesight-Gateway-API/blob/main/examples/export_custom_codec.py)
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
# ToDo:
|
|
59
|
+
- [x] use all get endpoints
|
|
60
|
+
- [ ] use post endpoints to write on gateways
|
|
61
|
+
- [ ] IoT Developer Api
|
|
62
|
+
- [ ] state engine to use this API for receiving the actuall sensor values.
|
|
63
|
+
|
|
64
|
+
# Requirements
|
|
65
|
+
|
|
66
|
+
The Milesight Gateway firmware must be ```60.0.0.42-r5/56.0.0.4``` or higher. (from May 28, 2024 )
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
## Table of Contents
|
|
70
|
+
|
|
71
|
+
- [Installation](#installation)
|
|
72
|
+
- [Features](#features)
|
|
73
|
+
- [Usage](#usage)
|
|
74
|
+
- [Basic Usage](#basic-usage)
|
|
75
|
+
- [Getting JWT Token](#getting-jwt-token)
|
|
76
|
+
- [Fetching Devices](#fetching-devices)
|
|
77
|
+
- [Fetching Applications](#fetching-applications)
|
|
78
|
+
- [Fetching Payload Codecs](#fetching-payload-codecs)
|
|
79
|
+
- [Fetching Profiles](#fetching-profiles)
|
|
80
|
+
- [Fetching Gateway Fleet](#fetching-gateway-fleet)
|
|
81
|
+
- [License](#license)
|
|
82
|
+
|
|
83
|
+
## Installation
|
|
84
|
+
|
|
85
|
+
To install the package from PyPI, simply run:
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
pip install Milesight-Gateway-API
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
[Milesight-Gateway-API on pypi.org](https://pypi.org/project/Milesight-Gateway-API/)
|
|
92
|
+
|
|
93
|
+
# Features
|
|
94
|
+
|
|
95
|
+
The MilesightGatewayClient class provides the following features:
|
|
96
|
+
|
|
97
|
+
- Fetch Devices: Fetch devices and their details with pagination and search options.
|
|
98
|
+
- Fetch Network Server Settings: Get network server settings from the Milesight Gateway.
|
|
99
|
+
- Packet Forwarder Information: Retrieve information about the packet forwarder and connected servers.
|
|
100
|
+
- Fetch Applications: Retrieve all applications with pagination.
|
|
101
|
+
- Data Transmission Integration: Fetch integration details by ID and transmission type (HTTP or MQTT).
|
|
102
|
+
- Fetch Payload Codecs: Fetch default or custom payload codecs with pagination and optional search.
|
|
103
|
+
- Fetch Profiles: Fetch profiles for an organization and application, with optional profileID for specific content search.
|
|
104
|
+
- Fetch Gateway Fleet: Retrieve gateway details with optional search by name or gateway ID.
|
|
105
|
+
|
|
106
|
+
# Usage
|
|
107
|
+
|
|
108
|
+
See [/tests/test_client.py](https://github.com/corgan2222/Milesight-Gateway-API/blob/main/tests/test_client.py) how to use all functions.
|
|
109
|
+
|
|
110
|
+
## Basic Usage
|
|
111
|
+
|
|
112
|
+
First, import the MilesightGatewayClient class and configure it with your credentials.
|
|
113
|
+
Ensure you have the required environment variables or load them from a .env file.
|
|
114
|
+
You can copy .env_eample to [.env](https://github.com/corgan2222/Milesight-Gateway-API/blob/main/examples/.env_example) and change the IP, Username and Password.
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
```python
|
|
118
|
+
from milesight_gateway_api.milesight_gateway_client import MilesightGatewayClient
|
|
119
|
+
import os
|
|
120
|
+
from aiohttp import ClientSession
|
|
121
|
+
|
|
122
|
+
# Load environment variables (e.g., USERNAME, PASSWORD, etc.)
|
|
123
|
+
username = os.getenv('USERNAME') # admin
|
|
124
|
+
password = os.getenv('PASSWORD') # the WebUI Login Password
|
|
125
|
+
secret_key = bytes(os.getenv('SECRET_KEY'), 'utf-8')
|
|
126
|
+
iv = bytes(os.getenv('IV'), 'utf-8')
|
|
127
|
+
base_url = os.getenv('BASE_URL')
|
|
128
|
+
port = os.getenv('PORT')
|
|
129
|
+
|
|
130
|
+
client = MilesightGatewayClient(username, password, secret_key, iv, base_url, port)
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
## Getting JWT Token
|
|
134
|
+
|
|
135
|
+
You must retrieve the JWT token before making other requests. Use the get_jwt_token method:
|
|
136
|
+
|
|
137
|
+
```python
|
|
138
|
+
async with ClientSession() as session:
|
|
139
|
+
jwt_token = await client.get_jwt_token(session)
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
## Fetching Devices
|
|
143
|
+
|
|
144
|
+
You can fetch all devices with pagination or search for a specific device by providing the search parameter.
|
|
145
|
+
|
|
146
|
+
```python
|
|
147
|
+
# Fetch all devices
|
|
148
|
+
all_devices, devices_total_count = await client.get_all_devices(session)
|
|
149
|
+
print(f"Total Devices: {devices_total_count}")
|
|
150
|
+
print(all_devices)
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
## Search for a specific device
|
|
154
|
+
```python
|
|
155
|
+
search_device_string = "device_id_here"
|
|
156
|
+
search_device = await client.get_device(session, search_device_string)
|
|
157
|
+
print(f"Search Results for {search_device_string}:")
|
|
158
|
+
print(search_device)
|
|
159
|
+
```
|
|
160
|
+
## Fetching Applications
|
|
161
|
+
|
|
162
|
+
To fetch all applications:
|
|
163
|
+
|
|
164
|
+
```python
|
|
165
|
+
# Fetch all applications with pagination
|
|
166
|
+
applications, total_applications = await client.get_all_applications(session)
|
|
167
|
+
print(f"Total Applications: {total_applications}")
|
|
168
|
+
print(applications)
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
## Fetching Payload Codecs
|
|
172
|
+
|
|
173
|
+
You can fetch payload codecs by type (default or custom) with optional search functionality.
|
|
174
|
+
|
|
175
|
+
```python
|
|
176
|
+
# Fetch all default payload codecs
|
|
177
|
+
payload_codecs, codecs_total_count = await client.get_payload_codecs(session, codec_type='default')
|
|
178
|
+
print(f"Total Payload Codecs: {codecs_total_count}")
|
|
179
|
+
print(payload_codecs)
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
## Search for a custom payload codec
|
|
183
|
+
|
|
184
|
+
```python
|
|
185
|
+
search_payload_codecs, codecs_total_count = await client.get_payload_codecs(session, codec_type='custom', search="custom_codec_name")
|
|
186
|
+
print(f"Search Results: {search_payload_codecs}")
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
## Fetching Profiles
|
|
190
|
+
|
|
191
|
+
You can fetch profiles for an organization and application, with an optional profile_id to search for specific profile content.
|
|
192
|
+
|
|
193
|
+
```python
|
|
194
|
+
# Fetch profiles
|
|
195
|
+
organization_id = "1"
|
|
196
|
+
application_id = "5"
|
|
197
|
+
profiles, total_profiles = await client.get_profiles(session, organization_id, application_id)
|
|
198
|
+
print(f"Total Profiles: {total_profiles}")
|
|
199
|
+
print(profiles)
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
```python
|
|
203
|
+
# Fetch specific profile by profileID
|
|
204
|
+
profile_id = "your_profile_id"
|
|
205
|
+
profiles_by_id, total_profiles = await client.get_profiles(session, organization_id, application_id, profile_id=profile_id)
|
|
206
|
+
print(f"Profiles for profileID {profile_id}: {profiles_by_id}")
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
## Fetching Gateway Fleet
|
|
210
|
+
|
|
211
|
+
Fetch the gateway fleet with optional search by gateway name or ID.
|
|
212
|
+
|
|
213
|
+
```python
|
|
214
|
+
# Fetch gateway fleet
|
|
215
|
+
organization_id = "1"
|
|
216
|
+
gateway_fleet, total_gateways = await client.get_gateway_fleet(session, organization_id)
|
|
217
|
+
print(f"Total Gateways: {total_gateways}")
|
|
218
|
+
print(gateway_fleet)
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
## Search for a gateway by name or ID
|
|
222
|
+
|
|
223
|
+
```python
|
|
224
|
+
gateway_fleet_search, total_gateways = await client.get_gateway_fleet(session, organization_id, search="gateway_name_or_id")
|
|
225
|
+
print(f"Search Results: {gateway_fleet_search}")
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
# Usefull Links
|
|
229
|
+
|
|
230
|
+
- [Test Rest API with Postman](https://support.milesight-iot.com/support/solutions/articles/73000514150-how-to-test-milesight-gateway-http-api-by-postman-)
|
|
231
|
+
- [Milesight API Documentation](https://support.milesight-iot.com/helpdesk/attachments/73117065743)
|
|
232
|
+
- [Milesight-Gateway-API on pypi.org](https://pypi.org/project/Milesight-Gateway-API/)
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
# License
|
|
236
|
+
|
|
237
|
+
This project is licensed under the MIT License. See the LICENSE file for more details.
|
|
238
|
+
|
|
239
|
+
[aarch64-shield]: https://img.shields.io/badge/aarch64-yes-green.svg
|
|
240
|
+
[amd64-shield]: https://img.shields.io/badge/amd64-yes-green.svg
|
|
241
|
+
[armhf-shield]: https://img.shields.io/badge/armv7-yes-green.svg
|
|
242
|
+
[armv7-shield]: https://img.shields.io/badge/armv7-yes-green.svg
|
|
243
|
+
[i386-shield]: https://img.shields.io/badge/i386-no-red.svg
|
|
244
|
+
[release-shield]: https://img.shields.io/github/v/release/corgan2222/Milesight-Gateway-API
|
|
245
|
+
[release]: https://github.com/corgan2222/Milesight-Gateway-API/releases
|
|
246
|
+
[pip-release-shield]: https://img.shields.io/pypi/v/Milesight-Gateway-API
|
|
247
|
+
[pip-release]: https://pypi.org/project/Milesight-Gateway-API/
|
|
248
|
+
[license-shield]: https://img.shields.io/github/license/corgan2222/Milesight-Gateway-API
|
|
@@ -7,4 +7,5 @@ Milesight_Gateway_API.egg-info/dependency_links.txt
|
|
|
7
7
|
Milesight_Gateway_API.egg-info/requires.txt
|
|
8
8
|
Milesight_Gateway_API.egg-info/top_level.txt
|
|
9
9
|
milesight_gateway_api/__init__.py
|
|
10
|
-
milesight_gateway_api/milesight_gateway_client.py
|
|
10
|
+
milesight_gateway_api/milesight_gateway_client.py
|
|
11
|
+
tests/test_client.py
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: Milesight-Gateway-API
|
|
3
|
+
Version: 0.0.2
|
|
4
|
+
Summary: A python client for interacting with Milesight gateway REST API
|
|
5
|
+
Home-page: https://github.com/corgan2222/Milesight-Gateway-API
|
|
6
|
+
Author: Stefan Knaak
|
|
7
|
+
Author-email: stefan.knaak@e-shelter.io
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Requires-Python: >=3.9
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
Requires-Dist: aiohttp
|
|
15
|
+
Requires-Dist: pycryptodome
|
|
16
|
+
Requires-Dist: urllib3
|
|
17
|
+
Dynamic: author
|
|
18
|
+
Dynamic: author-email
|
|
19
|
+
Dynamic: classifier
|
|
20
|
+
Dynamic: description
|
|
21
|
+
Dynamic: description-content-type
|
|
22
|
+
Dynamic: home-page
|
|
23
|
+
Dynamic: license-file
|
|
24
|
+
Dynamic: requires-dist
|
|
25
|
+
Dynamic: requires-python
|
|
26
|
+
Dynamic: summary
|
|
27
|
+
|
|
28
|
+
# Milesight Gateway API
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
[![GitHub Release][release-shield]][release]
|
|
32
|
+
[![pip Release][pip-release-shield]][pip-release]
|
|
33
|
+

|
|
34
|
+
[![License][license-shield]](LICENSE.md)
|
|
35
|
+
|
|
36
|
+
![Supports aarch64 Architecture][aarch64-shield]
|
|
37
|
+
![Supports amd64 Architecture][amd64-shield]
|
|
38
|
+
![Supports armhf Architecture][armhf-shield]
|
|
39
|
+
![Supports armv7 Architecture][armv7-shield]
|
|
40
|
+
![Supports i386 Architecture][i386-shield]
|
|
41
|
+
|
|
42
|
+
The **Milesight Gateway API** is a Python client that provides an interface for interacting with Milesight Gateways through various REST API endpoints.
|
|
43
|
+
It supports fetching device data, network server settings, packet forwarder information, profiles, payload codecs, and more.
|
|
44
|
+
|
|
45
|
+
## This is a beta release!
|
|
46
|
+
|
|
47
|
+
Use at your own risk.
|
|
48
|
+
|
|
49
|
+
# Why
|
|
50
|
+
There are some feature missing in the original firmware from Milesight, which can become a problem, especially in large installations with several gateways.
|
|
51
|
+
|
|
52
|
+
For example:
|
|
53
|
+
- [x] Its not possible to export the device list. [-> Fixed](https://github.com/corgan2222/Milesight-Gateway-API/blob/main/examples/export_devices.py)
|
|
54
|
+
- [x] Its not possible to export the custom payload codecs. [-> Fixed](https://github.com/corgan2222/Milesight-Gateway-API/blob/main/examples/export_custom_codec.py)
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
# ToDo:
|
|
59
|
+
- [x] use all get endpoints
|
|
60
|
+
- [ ] use post endpoints to write on gateways
|
|
61
|
+
- [ ] IoT Developer Api
|
|
62
|
+
- [ ] state engine to use this API for receiving the actuall sensor values.
|
|
63
|
+
|
|
64
|
+
# Requirements
|
|
65
|
+
|
|
66
|
+
The Milesight Gateway firmware must be ```60.0.0.42-r5/56.0.0.4``` or higher. (from May 28, 2024 )
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
## Table of Contents
|
|
70
|
+
|
|
71
|
+
- [Installation](#installation)
|
|
72
|
+
- [Features](#features)
|
|
73
|
+
- [Usage](#usage)
|
|
74
|
+
- [Basic Usage](#basic-usage)
|
|
75
|
+
- [Getting JWT Token](#getting-jwt-token)
|
|
76
|
+
- [Fetching Devices](#fetching-devices)
|
|
77
|
+
- [Fetching Applications](#fetching-applications)
|
|
78
|
+
- [Fetching Payload Codecs](#fetching-payload-codecs)
|
|
79
|
+
- [Fetching Profiles](#fetching-profiles)
|
|
80
|
+
- [Fetching Gateway Fleet](#fetching-gateway-fleet)
|
|
81
|
+
- [License](#license)
|
|
82
|
+
|
|
83
|
+
## Installation
|
|
84
|
+
|
|
85
|
+
To install the package from PyPI, simply run:
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
pip install Milesight-Gateway-API
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
[Milesight-Gateway-API on pypi.org](https://pypi.org/project/Milesight-Gateway-API/)
|
|
92
|
+
|
|
93
|
+
# Features
|
|
94
|
+
|
|
95
|
+
The MilesightGatewayClient class provides the following features:
|
|
96
|
+
|
|
97
|
+
- Fetch Devices: Fetch devices and their details with pagination and search options.
|
|
98
|
+
- Fetch Network Server Settings: Get network server settings from the Milesight Gateway.
|
|
99
|
+
- Packet Forwarder Information: Retrieve information about the packet forwarder and connected servers.
|
|
100
|
+
- Fetch Applications: Retrieve all applications with pagination.
|
|
101
|
+
- Data Transmission Integration: Fetch integration details by ID and transmission type (HTTP or MQTT).
|
|
102
|
+
- Fetch Payload Codecs: Fetch default or custom payload codecs with pagination and optional search.
|
|
103
|
+
- Fetch Profiles: Fetch profiles for an organization and application, with optional profileID for specific content search.
|
|
104
|
+
- Fetch Gateway Fleet: Retrieve gateway details with optional search by name or gateway ID.
|
|
105
|
+
|
|
106
|
+
# Usage
|
|
107
|
+
|
|
108
|
+
See [/tests/test_client.py](https://github.com/corgan2222/Milesight-Gateway-API/blob/main/tests/test_client.py) how to use all functions.
|
|
109
|
+
|
|
110
|
+
## Basic Usage
|
|
111
|
+
|
|
112
|
+
First, import the MilesightGatewayClient class and configure it with your credentials.
|
|
113
|
+
Ensure you have the required environment variables or load them from a .env file.
|
|
114
|
+
You can copy .env_eample to [.env](https://github.com/corgan2222/Milesight-Gateway-API/blob/main/examples/.env_example) and change the IP, Username and Password.
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
```python
|
|
118
|
+
from milesight_gateway_api.milesight_gateway_client import MilesightGatewayClient
|
|
119
|
+
import os
|
|
120
|
+
from aiohttp import ClientSession
|
|
121
|
+
|
|
122
|
+
# Load environment variables (e.g., USERNAME, PASSWORD, etc.)
|
|
123
|
+
username = os.getenv('USERNAME') # admin
|
|
124
|
+
password = os.getenv('PASSWORD') # the WebUI Login Password
|
|
125
|
+
secret_key = bytes(os.getenv('SECRET_KEY'), 'utf-8')
|
|
126
|
+
iv = bytes(os.getenv('IV'), 'utf-8')
|
|
127
|
+
base_url = os.getenv('BASE_URL')
|
|
128
|
+
port = os.getenv('PORT')
|
|
129
|
+
|
|
130
|
+
client = MilesightGatewayClient(username, password, secret_key, iv, base_url, port)
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
## Getting JWT Token
|
|
134
|
+
|
|
135
|
+
You must retrieve the JWT token before making other requests. Use the get_jwt_token method:
|
|
136
|
+
|
|
137
|
+
```python
|
|
138
|
+
async with ClientSession() as session:
|
|
139
|
+
jwt_token = await client.get_jwt_token(session)
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
## Fetching Devices
|
|
143
|
+
|
|
144
|
+
You can fetch all devices with pagination or search for a specific device by providing the search parameter.
|
|
145
|
+
|
|
146
|
+
```python
|
|
147
|
+
# Fetch all devices
|
|
148
|
+
all_devices, devices_total_count = await client.get_all_devices(session)
|
|
149
|
+
print(f"Total Devices: {devices_total_count}")
|
|
150
|
+
print(all_devices)
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
## Search for a specific device
|
|
154
|
+
```python
|
|
155
|
+
search_device_string = "device_id_here"
|
|
156
|
+
search_device = await client.get_device(session, search_device_string)
|
|
157
|
+
print(f"Search Results for {search_device_string}:")
|
|
158
|
+
print(search_device)
|
|
159
|
+
```
|
|
160
|
+
## Fetching Applications
|
|
161
|
+
|
|
162
|
+
To fetch all applications:
|
|
163
|
+
|
|
164
|
+
```python
|
|
165
|
+
# Fetch all applications with pagination
|
|
166
|
+
applications, total_applications = await client.get_all_applications(session)
|
|
167
|
+
print(f"Total Applications: {total_applications}")
|
|
168
|
+
print(applications)
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
## Fetching Payload Codecs
|
|
172
|
+
|
|
173
|
+
You can fetch payload codecs by type (default or custom) with optional search functionality.
|
|
174
|
+
|
|
175
|
+
```python
|
|
176
|
+
# Fetch all default payload codecs
|
|
177
|
+
payload_codecs, codecs_total_count = await client.get_payload_codecs(session, codec_type='default')
|
|
178
|
+
print(f"Total Payload Codecs: {codecs_total_count}")
|
|
179
|
+
print(payload_codecs)
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
## Search for a custom payload codec
|
|
183
|
+
|
|
184
|
+
```python
|
|
185
|
+
search_payload_codecs, codecs_total_count = await client.get_payload_codecs(session, codec_type='custom', search="custom_codec_name")
|
|
186
|
+
print(f"Search Results: {search_payload_codecs}")
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
## Fetching Profiles
|
|
190
|
+
|
|
191
|
+
You can fetch profiles for an organization and application, with an optional profile_id to search for specific profile content.
|
|
192
|
+
|
|
193
|
+
```python
|
|
194
|
+
# Fetch profiles
|
|
195
|
+
organization_id = "1"
|
|
196
|
+
application_id = "5"
|
|
197
|
+
profiles, total_profiles = await client.get_profiles(session, organization_id, application_id)
|
|
198
|
+
print(f"Total Profiles: {total_profiles}")
|
|
199
|
+
print(profiles)
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
```python
|
|
203
|
+
# Fetch specific profile by profileID
|
|
204
|
+
profile_id = "your_profile_id"
|
|
205
|
+
profiles_by_id, total_profiles = await client.get_profiles(session, organization_id, application_id, profile_id=profile_id)
|
|
206
|
+
print(f"Profiles for profileID {profile_id}: {profiles_by_id}")
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
## Fetching Gateway Fleet
|
|
210
|
+
|
|
211
|
+
Fetch the gateway fleet with optional search by gateway name or ID.
|
|
212
|
+
|
|
213
|
+
```python
|
|
214
|
+
# Fetch gateway fleet
|
|
215
|
+
organization_id = "1"
|
|
216
|
+
gateway_fleet, total_gateways = await client.get_gateway_fleet(session, organization_id)
|
|
217
|
+
print(f"Total Gateways: {total_gateways}")
|
|
218
|
+
print(gateway_fleet)
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
## Search for a gateway by name or ID
|
|
222
|
+
|
|
223
|
+
```python
|
|
224
|
+
gateway_fleet_search, total_gateways = await client.get_gateway_fleet(session, organization_id, search="gateway_name_or_id")
|
|
225
|
+
print(f"Search Results: {gateway_fleet_search}")
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
# Usefull Links
|
|
229
|
+
|
|
230
|
+
- [Test Rest API with Postman](https://support.milesight-iot.com/support/solutions/articles/73000514150-how-to-test-milesight-gateway-http-api-by-postman-)
|
|
231
|
+
- [Milesight API Documentation](https://support.milesight-iot.com/helpdesk/attachments/73117065743)
|
|
232
|
+
- [Milesight-Gateway-API on pypi.org](https://pypi.org/project/Milesight-Gateway-API/)
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
# License
|
|
236
|
+
|
|
237
|
+
This project is licensed under the MIT License. See the LICENSE file for more details.
|
|
238
|
+
|
|
239
|
+
[aarch64-shield]: https://img.shields.io/badge/aarch64-yes-green.svg
|
|
240
|
+
[amd64-shield]: https://img.shields.io/badge/amd64-yes-green.svg
|
|
241
|
+
[armhf-shield]: https://img.shields.io/badge/armv7-yes-green.svg
|
|
242
|
+
[armv7-shield]: https://img.shields.io/badge/armv7-yes-green.svg
|
|
243
|
+
[i386-shield]: https://img.shields.io/badge/i386-no-red.svg
|
|
244
|
+
[release-shield]: https://img.shields.io/github/v/release/corgan2222/Milesight-Gateway-API
|
|
245
|
+
[release]: https://github.com/corgan2222/Milesight-Gateway-API/releases
|
|
246
|
+
[pip-release-shield]: https://img.shields.io/pypi/v/Milesight-Gateway-API
|
|
247
|
+
[pip-release]: https://pypi.org/project/Milesight-Gateway-API/
|
|
248
|
+
[license-shield]: https://img.shields.io/github/license/corgan2222/Milesight-Gateway-API
|