GoEdge Core SDK Python Wrapper
Project description
GoEdge Core SDK Python Wrapper
This project provides a Python wrapper for the GoEdge Core C SDK. It uses ctypes to interface with the C library, allowing Python applications to leverage the functionality of the GoEdge ecosystem.
Project Structure
goedge-core-sdk-python/
├───.gitignore
├───poetry.lock
├───pyproject.toml
├───README.md
├───dist/ # 打包分发文件
├───example/ # 示例代码
│ ├───example_function.py
│ └───example.py
└───src/ # Python SDK 源码
└───goedge/
├───__init__.py
├───core.py
└───ge_storage.py
Installation
To use this wrapper, you first need to compile the C SDK into a shared library (e.g., libge-core.so and libge-storage.so on Linux). Then, you can install the Python package using Poetry:
poetry install
Usage
The following example demonstrates the basic flow of initializing the SDK, registering a device, reporting properties, and shutting down.
# -*- coding: utf-8 -*-
import sys
import os
import time
from goedge.core import (
core_init, core_exit,
register_and_online_by_device_name, device_offline,
report_properties,
GeDeviceData, GeDeviceCallback,
GET_PROPERTIES_CALLBACK, SET_PROPERTIES_CALLBACK, CALL_SERVICE_CALLBACK, TRIGGER_COLLECT_CALLBACK,
GE_TYPE_INT
)
# 1. Define callback functions (implementation omitted for brevity)
# def handle_get_properties(...): ...
# def handle_set_properties(...): ...
# def handle_call_service(...): ...
# def handle_trigger_collect(...): ...
if __name__ == "__main__":
# 2. Initialize the SDK
ret = core_init("NodeRED", 4, 7)
if ret != 0:
print(f"Failed to initialize SDK, error code: {ret}")
exit(1)
# 3. Create and fill the callback structure
device_callbacks = GeDeviceCallback(...) # Omitted for brevity
# 4. Register and bring the device online
product_key = "BSKjAAhUmor"
device_name = "BSKjAAhUmor"
dev_handle = register_and_online_by_device_name(product_key, device_name, device_callbacks)
if dev_handle < 0:
print(f"Failed to register device, error code: {dev_handle}")
core_exit()
exit(1)
try:
# 5. Loop to report properties
count = 0
while count < 20:
temp_property = GeDeviceData(
type=GE_TYPE_INT,
key=b"temperature",
value=str(20 + count % 10).encode(),
timestamp=int(time.time() * 1000)
)
report_properties(dev_handle, [temp_property])
time.sleep(2)
count += 1
finally:
# 6. Take the device offline and exit
device_offline(dev_handle)
core_exit()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file goedge_core_sdk_python-0.1.1.tar.gz.
File metadata
- Download URL: goedge_core_sdk_python-0.1.1.tar.gz
- Upload date:
- Size: 8.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.3 CPython/3.10.12 Linux/6.14.10-orbstack-00291-g1b252bd3edea
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9fad2303d98d41de5e26c1a79090e7317d72c028d0aecea8c36265f298a408ce
|
|
| MD5 |
6129171d42566674b2fe5d9a928ed394
|
|
| BLAKE2b-256 |
500b8fd96744f06543b664fb4fb84bec5674df47a47ba5ac33eaf0aa81b98008
|
File details
Details for the file goedge_core_sdk_python-0.1.1-py3-none-any.whl.
File metadata
- Download URL: goedge_core_sdk_python-0.1.1-py3-none-any.whl
- Upload date:
- Size: 9.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.3 CPython/3.10.12 Linux/6.14.10-orbstack-00291-g1b252bd3edea
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ee7b607ef1d535b5773821da1e594e0d815f00ee4359108ce45e35303b9709cd
|
|
| MD5 |
d64b523580b357e90e038e40730b5e8c
|
|
| BLAKE2b-256 |
ec539bda186f6dce60aa1cf8ad93c113f84e939e85d70ea225a5566256a3286d
|