Package: dtn7zero
dtn7zeroThis is a DTN7RFC9171compliant python implementation (work-in-progress) with aNetworkZerolike API.The current features are:a full bundle protocol agent (without fragment, CRC, and status-report generation support -> todo)a minimal TCP convergence layeradtn7-rsconvergence layer, using theHTTP/RESTinterfaceautomatic local-network node-discovery via IPND modulea standalone 'external' endpoint (which connects to adtn7-rsvia theHTTP/REST) interfacea simplifiedNetworkZerolike API to easily get startedfull MicroPython support (tested on an ESP32-GENERIC)experimental ESPNOW cla (details can be found in the source code:dtn7zero/convergence_layer_adapters/espnow_cla.py)(currently uses epidemic routing and in-memory storage managing)(with extendability for new convergence layer adapters, routing algorithms, and storage managers)Getting StartedTo use dtn7zero in your CPython environment, simply install it via pip (or pip3 on linux):$pipinstall--upgradedtn7zeroThe most simple example on what you can do:importtimefromdtn7zeroimportsetup,start_background_update_threadnode_endpoint=setup("dtn://node1/",print)start_background_update_thread()node_endpoint.send(b'hello world',"dtn://node1/")time.sleep(1)Further examples for the 'simple' API can be found under./examplesin the GitHub repository.For a deeper dive into the underlying concepts and the full-fledged dtn implementation, take a look at thedtn7zero.apimodule implementation and the tests under./test.MicroPython Installation GuideInstallation has been successfully tested on Windows and Linux (x86_64 and arm64). The requiredmpy-crosshas been shown to have installation issues on Mac M1s
under Mac OS X and may have to be built and installed manually.This whole project was tested on an ESP32 (GENERIC) and this installation guide is tailored for the ESP32.
If you plan to use another microcontroller you might need to do adjustments
(most certainly the MicroPython installation, and the MPY_MARCH in esp-deployment.py).Important note for linux: it may be that mpremote assumes another USB device with higher priority than the ESP32.
In that case all mpremote commands (especially inside esp-deployment.py) will fail as no communication is possible.
Check all USB devices mpremote considers in priority order withmpremote devs.First Time MicroPython Installation For ESP32 (GENERIC)download the newestfirmwareinstall the esp flash tool:pip install esptoolconnect your ESP32 via USB and start a terminal at the location of the downloaded firmwarestart the following command (with the correct USB port):esptool --chip esp32 --port /dev/ttyUSB0 erase_flash(you may have to invoke esptool withesptool.py --chip ...here and subsequently, you may also have holdbootto enter the bootloader on the ESP32)start the following command (with the correct USB port and firmware name):esptool --chip esp32 --port /dev/ttyUSB0 --baud 460800 write_flash -z 0x1000 esp32-20220618-v1.19.1.bin(you may have holdbootagain to enter the bootloader on the ESP32)done, you may now connect to it via:mpremote(installation via pip:pip install mpremote)Update To New MicroPython Versiondownload the newestfirmwarestart the following command (with the correct USB port and firmware name):esptool --chip esp32 --port /dev/ttyUSB0 --baud 460800 write_flash -z 0x1000 esp32-20220618-v1.19.1.bin(you may have holdbootto enter the bootloader on the ESP32)doneFirst Time dtn7zero Deploymentmake sure you check out the repository and the submodules (especially py-dtn7)install the mpremote tool:pip install mpremoteinstall the mpy-cross compiler tool:pip install mpy-cross(this may not work on Mac M1s under Mac OS X)populate wlan.json with an appropriate hostname and at least one ssid -> password mappingcheck your connection to the ESP32 with:mpremotecopy wlan.json to your ESP32:mpremote fs cp wlan.json :wlan.jsoncopy boot.py to your ESP32:mpremote fs cp boot.py :boot.pydeploy the dtn7zero and dependencies onto the ESP32 (this can take a while):python scripts/esp-deployment.pyinstall required packages:mpremote mip install urequestsandmpremote mip install datetimedoneContinuous dtn7zero Deploymentcheck your connection to the ESP32 with:mpremotedeploy the changes of dtn7zero and dependencies onto the ESP32 (this can take a while):python scripts/esp-deployment.pydoneFirst dtn7zero Functionality Check On MicroPythonyou may check that wlan is connecting correctly (connect viampremoteand pressenablefor a soft reset)you may also check that you can import dtn7zero (connect viampremoteandimport dtn7zero)you can also check that everything works (run the test scriptmpremote run examples/local_ping_echo.py)Additional MicroPython Tips & TricksThe mpremote tool is normally interrupted by usingctrl+c. A special case is the REPL (simply callmpremote), which
can be exited by usingctrl+~(tested on Windows) orctrl+](Linux).If you start a script on MicroPython (mpremote run ...) and disconnect the console (mpremote->ctrl+c) then the script
keeps running.If you must access the REPL via mpremote, but a script is blocking, then callmpremoteand press EN (enable) on the
ESP32 for a soft-reset. Pressctrl+ca few times to interrupt theboot.pyormain.pyscript execution. The session
state is stored, so any subsequentmpremotecall will start at REPL as long as no power disconnect is performed.You can deploy a script asmain.pyon MicroPython to be run every time the microcontroller gets power.You can also remove the script. MicroPython will only execute the script if it is present.$mpremotefscpexamples/remote_echo_callback.py:main.py
$mpremotefsrm:main.pyRegardingboot.py: it is used for user-specific setup code and this framework uses a generic boot script that adjusts
the ESP32's frequency and connects to a Wi-Fi network (blocking until success). MicroPython will create a dummyboot.pyif none is present. MicroPython will not create a dummymain.pyif none is present. MicroPython will first execute
theboot.pyand then themain.pyif it is present.Development InformationDevelopment ModeYou can install this project locally to directly reflect code changes in your environment.
Simply run this in the project root folder (requires at least pip v21.1):$python-mpipinstall--editable.BuildTo build this project yourself you need the pythonbuildtool, as well assetuptools:$pipinstall--upgradesetuptools
$pipinstall--upgradebuildThen you can simply run this command to build the project:$python-mbuildPublishTo publish this project you will probably update the version inpyproject.toml,buildthe project, and then usetwineto upload the build:$pipinstall--upgradetwine$python-mtwineuploaddist/*Useful Linksthe DTN7 website:https://dtn7.github.iodtn7 go implementation:https://github.com/dtn7/dtn7-godtn7 rust implementation:https://github.com/dtn7/dtn7-rsdtn7 python bundle implementation and dtn7rs-rest-api access:https://github.com/teschmitt/py-dtn7Bundle Protocol 7 RFC:https://datatracker.ietf.org/doc/html/rfc9171Bundle Protocol Security (BPSec) RFC:https://datatracker.ietf.org/doc/html/rfc9172Default Security Contexts for BPSec RFC:https://datatracker.ietf.org/doc/html/rfc9173TCP Convergence-Layer Protocol Version 4 RFC:https://datatracker.ietf.org/doc/html/rfc9174Minimal TCP Convergence-Layer Protocol RFC (draft):https://datatracker.ietf.org/doc/html/draft-ietf-dtn-mtcpcl-01UDP Convergence Layer RFC (draft):https://datatracker.ietf.org/doc/html/draft-sipos-dtn-udpcl-01Outdated Standards:DTN URI Scheme:https://www.ietf.org/archive/id/draft-irtf-dtnrg-dtn-uri-scheme-00.htmlFurther ResearchThis is some information gathered about future mesh extensions:ESP-Mesh(ESP-WIFI-Mesh)a special mesh standard which is based of Wi-Fi and uses the special AP_STA modeno micropython implementation knownESP-NOWa special p2p mode, which is based of Wi-Fi and can send data to neighbouring devices via MAC addressingno mesh protocol, but broadcast is possible, looks promising to build an esp32-dtn-meshnon-official, but tested micropythonlibraryavailable, as well asbuildswith the current firmwareAlternative: AP_STA mode for simultaneous AP and STA without explicit ESP-MESH usageonly available forArduino+CpainlessMeshalso uses this mode to build its meshOpen End Topics / Known Issuesfragment, CRC, status-report generation supportdtn7rs-rest-cla and in-memory storage together use too much RAM for MicroPython (therefore the dtn7rs-rest-cla is disabled in the simple API)public documentation (currently all information must be gathered from doc-strings and examples)