Package: hm-pyhelper
Helium Python HelperA helper module used across various Nebra repos to reduce redundant features.This package is used in a number of Nebra software repos:hm-pktfwdhm-confighm-diaghm-dashboard (private repo)Hotspot-Production-Tool (private repo)The package is available on PyPI and PyPI test repos:PyPI hm-pyhelperPyPI Test hm-pyhelperHelium Hardware Definitionsfromhm_pyhelper.hardware_definitionsimportvariant_definitionsThis 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 HotspotsModelENV IdentifierSPI BusReset PinStatus LEDButtonTypeCellularNotesNebra Indoor Hotspot Gen 1NEBHNT-IN11.2382526FullFalseCM3 basedNebra Outdoor Hotspot Gen 1NEBHNT-OUT11.2382524FullTrueCM3 basedNebra Pi 0 Light Hotspot SNEBHNT-LGT-ZS1.2222423LightFalseSPI Based EthernetNebra Pi 0 Light Hotspot XNEBHNT-LGT-ZX1.2222423LightFalseUSB Based EthernetNebra Beaglebone Light HotspotNEBHNT-BBB1.0603130LightFalseIn PlanningNebra Pocket Beagle Light HotspotNEBHNT-PBB1.0603130LightFalseIn PlanningNebra Hotspot HAT ROCK Pi 4 IndoorNEBHNT-HHRK432766.0149156 (Physical pin 18)154 (Physical pin 16)FullFalseIn PlanningNebra Hotspot HAT ROCK Pi 4 OutdoorNEBHNT-HHRK4-OUT32766.0149156 (Physical pin 18)154 (Physical pin 16)FullTrueIn PlanningNebra Hotspot HAT RPiNEBHNT-HHRPI0.0222423FullFalseShould be compatible with 3+ & 4Nebra Hotspot HAT RPi LIGHTNEBHNT-HHRPL0.0222423LightFalseLight is compatible with all 40 pin headersNebra Hotspot HAT Tinkerboard 2NEBHNT-HHTK2.0167163162FullFalseLight would be compatible on TK1Third Party HotspotsWe 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.ModelSOC/SBCENV IdentifierSPI BusReset PinStatus LEDButtonTypeCellularNotesRak Hotspot MinerBCM2711 (Pi4 2gb RAM)COMP-RAKHM0.0172021FullFalseOnly Compatible with V2 hotspots with ECC Key.OG Helium HotspotBCM2711 (Pi4 2gb RAM)COMP-HELIUM0.0172021FullFalseSyncrobit Hotspot 1 (Pi)FullFalseSyncrobit Hotspot 2 (RK)FullFalseBobcat Miner 300FullFalseSenseCAP M1BCM2711 (Pi4 2gb RAM)COMP-SENSECAPM10.0172021FullFalseDIY HotspotsThe following DIY options are also supported for light hotspot software only.Please note, DIY Hotspots do not earn HNT.ModelSOC/SBCENV IdentifierSPI BusReset PinStatus LEDButtonTypeCellularNotesPi Supply IoT LoRa Gateway HATRPiDIY-PISLGH0.022LightFalseAny pi with 40 pin headerRAK2287RPiDIY-RAK22870.017LightFalseAny pi with 40 pin headerhardware_definitionsvariant_definitionsA 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.loggerfromhm_pyhelper.loggerimportget_loggerLOGGER=get_logger(__name__)LOGGER.debug("message to log")miner_paramretry_get_region(region_override, region_filepath)Return the region from envvar region_override or
from the contents of region_filepathfromhm_pyhelper.miner_paramimportretry_get_regionprint(retry_get_region("US915","/invalid/path"))# US915# echo "EU868" > /var/pktfwd/regionprint(retry_get_region("","/var/pktfwd/region"))# EU868gateway-mfr-rs (gateway_mfr)This helper module brings in the armv6 build ofgateway-mfr-rs (gateway_mfr)which allows us to program the ECC secure element chips in production.We have a GitHub action in this repo calledupdate-gateway-mfr-rs.ymlwhich 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 onworkflow_dispatch:meaning you can also manually trigger it from theactions tab.LockSingletonLockSingletonprevents the concurrent access to a resource across threads.MethodsLockSingleton()Creates a newLockSingletonobject.acquire(timeout = DEFAULT_TIMEOUT)Waits until the resource is available. DEFAULT_TIMEOUT = 2 secondsrelease()Release the resource.locked()Check if there is an available resource.Usagelock = 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_eccdecorator@lock_ecc(timeout=DEFAULT_TIMEOUT, raise_resource_busy_exception=True):This is the convenient decorator wrapping around theLockSingleton.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 msgUsage@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)helium/miner RPCSend RPC commands to the miner container.create_add_gateway_txnReturn ablockchain_txn_add_gateway_v1_pb2signed by the gateway
and formatted the same way as thesmartphone app expects.Usage:While using miner container, use json rpc client
client = MinerClient()
While using gateway-rs container, use grpc client
client = GatewayClient()
result = client.create_add_gateway_txn('owner_address', 'payer_address', 'gateway_address')gateway_addressis optional and will only be used to validate the returned payload if supplied.TestingTo run tests:poetryinstall--withdev
poetryrunpytest--cov=hm_pyhelper--cov-fail-under=90Referencing a branch for developmentIt 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
theinstall_requiressection ofsetup.py. Then add the following lines to the
project's Dockerfile.RUNpip3installsetuptoolswheelRUNpip3install--target="$OUTPUTS_DIR"git+https://github.com/NebraLtd/hm-pyhelper@BRANCH_NAMEReleasingTo release, use theGithub new release flow.Create a new tag in formatvX.Y.Z. You can use a previously tagged commit, but this is not necessary.Make sure the tag you created matches the value in setup.py.Selectmasteras the target branch. If you do not select the master branch, the tag should be in formatvX.Y.Z-rc.N.Title:Release vX.Y.Z.Body:Note: you can create the release notes automatically by selecting the "Auto-generate release notes" option on the releases page.## What's Changed
* Foo
* Bar

**Full Changelog**: https://github.com/NebraLtd/hm-pyhelper/compare/v0.0.A...v0.0.ZRelease strategyThe automated GitHub Actions in this repo do the following:all pushes / PRs, regardless of branch, trigger a build of the wheels and python package which are released as build artifacts (see below section)pushes to master with an updated version number insetup.pyare pushed to Test PyPI as well as being uploaded as build artifacts (note that if the version number isn't properly updated and is a duplicate of a previous one then the push to Test PyPI will fail)any tagged releases on master branch (see releasing process above) are built and published to PyPI as well as being uploaded as build artifactsTest release artifactsNote that artifacts (wheels and source) are uploaded to the GitHub Actions artifacts even when the build fails or isn't pushed to PyPI/Test PyPI due to not being on the master branch.For example,this failed build, has artifacts uploadedhere.These artifacts can be useful for testing releases without needing to bump version numbers.