# Helium Python Helper
A helper module used across various Nebra repos to reduce redundant features.
This package is used in a number of Nebra software repos:
- [hm-pktfwd](https://github.com/NebraLtd/hm-pktfwd/)
- [hm-config](https://github.com/NebraLtd/hm-config/)
- [hm-diag](https://github.com/NebraLtd/hm-diag/)
- [hm-dashboard (private repo)](https://github.com/NebraLtd/hm-dashboard)
- [Hotspot-Production-Tool (private repo)](https://github.com/NebraLtd/Hotspot-Production-Tool)
The package is available on PyPI and PyPI test repos:
- [PyPI hm-pyhelper](https://pypi.org/project/hm-pyhelper)
- [PyPI Test hm-pyhelper](https://test.pypi.org/project/hm-pyhelper)
## Helium Hardware Definitions
```python
from hm_pyhelper.hardware_definitions import variant_definitions
```
This repository contains the python file that contains a GPIO map for all of the different hardware combinations to be supported by the Nebra Helium Hotspot Software.
All numbers below are their GPIO / BCM Numbers, not physical pin numbers.
Note: Light hotspot software will also work on all models listed as type "full".
### Nebra Hotspots
| Model | ENV Identifier | SPI Bus | Reset Pin | Status LED | Button |Type | Cellular | Notes |
| --- | --- | --- | --- | --- | --- | --- | --- | --- |
| Nebra Indoor Hotspot Gen 1 | NEBHNT-IN1 | 1.2 | 38 | 25 | 26 | Full | False | CM3 based |
| Nebra Outdoor Hotspot Gen 1 | NEBHNT-OUT1 | 1.2 | 38 | 25 | 24 | Full | True | CM3 based |
| Nebra Pi 0 Light Hotspot S | NEBHNT-LGT-ZS | 1.2 | 22 | 24 | 23 | Light | False | SPI Based Ethernet |
| Nebra Pi 0 Light Hotspot X | NEBHNT-LGT-ZX | 1.2 | 22 | 24 | 23 | Light | False | USB Based Ethernet |
| Nebra Beaglebone Light Hotspot | NEBHNT-BBB | 1.0 | 60 | 31 | 30 | Light | False | In Planning |
| Nebra Pocket Beagle Light Hotspot | NEBHNT-PBB | 1.0 | 60 | 31 | 30 | Light | False | In Planning |
| Nebra Hotspot HAT ROCK Pi 4 Indoor | NEBHNT-HHRK4 | 32766.0 | 149 | 156 (Physical pin 18) | 154 (Physical pin 16) | Full | False | In Planning |
| Nebra Hotspot HAT ROCK Pi 4 Outdoor | NEBHNT-HHRK4-OUT | 32766.0 | 149 | 156 (Physical pin 18) | 154 (Physical pin 16)| Full | True | In Planning |
| Nebra Hotspot HAT RPi | NEBHNT-HHRPI | 0.0 | 22 | 24 | 23 | Full | False | Should be compatible with 3+ & 4 |
| Nebra Hotspot HAT RPi LIGHT | NEBHNT-HHRPL | 0.0 | 22 | 24 | 23 | Light | False | Light is compatible with all 40 pin headers |
| Nebra Hotspot HAT Tinkerboard 2 | NEBHNT-HHTK | 2.0 | 167 | 163 | 162 | Full | False | Light would be compatible on TK1 |
### Third Party Hotspots
We may be adding in support for other vendor's hotspots to use our software soon. Here are the variables for those.
These would also depend on their SOCs being supported by Balena.
| Model | SOC/SBC | ENV Identifier | SPI Bus | Reset Pin | Status LED | Button |Type | Cellular | Notes |
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
| Rak Hotspot Miner | BCM2711 (Pi4 2gb RAM) | COMP-RAKHM | 0.0 | 17 | 20 | 21 | Full | False | Only Compatible with V2 hotspots with ECC Key. |
| OG Helium Hotspot | BCM2711 (Pi4 2gb RAM) | COMP-HELIUM | 0.0 | 17 | 20 | 21 | Full | False | |
| Syncrobit Hotspot 1 (Pi) | | | | | | | Full | False | |
| Syncrobit Hotspot 2 (RK) | | | | | | | Full | False | |
| Bobcat Miner 300 | | | | | | | Full | False | |
| SenseCAP M1 | BCM2711 (Pi4 2gb RAM) | COMP-SENSECAPM1 | 0.0 | 17 | 20 | 21 | Full | False | |
### DIY Hotspots
The following DIY options are also supported for light hotspot software only.
Please note, DIY Hotspots do not earn HNT.
| Model | SOC/SBC | ENV Identifier | SPI Bus | Reset Pin | Status LED | Button |Type | Cellular | Notes |
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
| Pi Supply IoT LoRa Gateway HAT | RPi | DIY-PISLGH | 0.0 | 22 | | | Light | False | Any pi with 40 pin header |
| RAK2287 | RPi | DIY-RAK2287 | 0.0 | 17 | | | Light | False | Any pi with 40 pin header |
## hardware_definitions
### variant_definitions
A dictionary of all known Nebra hotspot variants.
Not all variants are fully supported.
### get_variant_attribute(variant_name, variant_attribute)
Returns the value of an attribute from a specific variant.
Raises UnknownVariantException and UnknownVariantAttributeException if invalid params supplied.
## logger
```python
from hm_pyhelper.logger import get_logger
LOGGER = get_logger(__name__)
LOGGER.debug("message to log")
```
## miner_param
### retry_get_region(region_override, region_filepath)
Return the region from envvar region_override or
from the contents of region_filepath
```python
from hm_pyhelper.miner_param import retry_get_region
print(retry_get_region("US915", "/invalid/path"))
# US915
# echo "EU868" > /var/pktfwd/region
print(retry_get_region("", "/var/pktfwd/region"))
# EU868
```
## gateway-mfr-rs (gateway_mfr)
This helper module brings in the armv6 build of [gateway-mfr-rs (gateway_mfr)](https://github.com/helium/gateway-mfr-rs) which allows us to program the ECC secure element chips in production.
We have a GitHub action in this repo called [update-gateway-mfr-rs.yml](https://github.com/NebraLtd/hm-pyhelper/blob/master/.github/workflows/update-gateway-mfr-rs.yml) which checks the upstream repo for updated release versions every Sunday at midnight and if a new release is found it triggers a new PR in this repo to update the version number. This action also can be triggered on `workflow_dispatch:` meaning you can also manually trigger it from the [actions tab](https://github.com/NebraLtd/hm-pyhelper/actions).
## LockSingleton
`LockSingleton` prevents the concurrent access to a resource across threads.
### Methods
**LockSingleton()**
Creates a new `LockSingleton` object.
**acquire(timeout = DEFAULT_TIMEOUT)**
Waits until the resource is available. DEFAULT_TIMEOUT = 2 seconds
**release()**
Release the resource.
**locked()**
Check if there is an available resource.
### Usage
```
lock = LockSingleton()
try:
# try to acquire the resource or may raise an exception
lock.acquire()
# do some work
print("Starting work...")
sleep(5)
print("Finished work!")
# release the resource
lock.release()
except ResourceBusyError:
print("The resource is busy now.")
```
### `@lock_ecc` decorator
`@lock_ecc(timeout=DEFAULT_TIMEOUT, raise_resource_busy_exception=True):`
This is the convenient decorator wrapping around the `LockSingleton`.
- timeout: timeout value. DEFAULT_TIMEOUT = 2 seconds.
- raise_resource_busy_exception: set True to raise exception in case of timeout or some error, otherwise just log the error msg
Usage
```
@lock_ecc()
def run_gateway_mfr():
return subprocess.run(
[gateway_mfr_path, "key", "0"],
capture_output=True,
check=True
)
gateway_mfr_result = run_gateway_mfr()
log_stdout_stderr(gateway_mfr_result)
```
## Testing
To run tests:
```bash
pip install -r requirements.txt
pip install -r test-requirements.txt
PYTHONPATH=./ pytest
```
## Referencing a branch for development
It is sometimes convenient to use recent changes in hm-pyhelper before an official release.
To do so, first double check that you've added any relevant dependencies to
the `install_requires` section of `setup.py`. Then add the following lines to the
project's Dockerfile.
```Dockerfile
RUN pip3 install setuptools wheel
RUN pip3 install --target="$OUTPUTS_DIR" git+https://github.com/NebraLtd/hm-pyhelper@BRANCH_NAME
``````
## Releasing
To release, use the [Github new release flow](https://github.com/NebraLtd/hm-pyhelper/releases/new).
1. Create a new tag in format `vX.Y.Z`. You can use a previously tagged commit, but this is not necessary.
2. Make sure the tag you created matches the value in setup.py.
3. Select `master` as the target branch. If you do not select the master branch, the tag should be in format `vX.Y.Z-rc.N`.
4. Title: `Release vX.Y.Z`.
5. Body:
**Note: you can create the release notes automatically
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
共33个文件
py:22个
txt:4个
pkg-info:2个
资源分类:Python库 所属语言:Python 资源全名:hm_pyhelper-0.12.1.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
资源推荐
资源详情
资源评论
收起资源包目录
hm_pyhelper-0.12.1.tar.gz (33个子文件)
hm_pyhelper-0.12.1
MANIFEST.in 32B
PKG-INFO 10KB
LICENSE 1KB
setup.cfg 38B
setup.py 682B
hm_pyhelper
main.py 0B
lock_singleton.py 2KB
logger.py 689B
diagnostics
__init__.py 156B
diagnostic.py 604B
diagnostics_report.py 3KB
tests
test_logger.py 1KB
test_hardware_definitions.py 3KB
test_lock_singleton.py 5KB
__init__.py 0B
test_miner_param.py 6KB
test_diagnostic_report.py 2KB
test_miner_json_rpc.py 6KB
test_get_mac_address.py 1KB
gateway_mfr 4.38MB
miner_param.py 9KB
miner_json_rpc
client.py 2KB
__init__.py 76B
exceptions.py 365B
__init__.py 0B
hardware_definitions.py 10KB
exceptions.py 392B
README.md 9KB
hm_pyhelper.egg-info
PKG-INFO 10KB
requires.txt 51B
SOURCES.txt 974B
top_level.txt 12B
dependency_links.txt 1B
共 33 条
- 1
资源评论
挣扎的蓝藻
- 粉丝: 13w+
- 资源: 15万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功