Merge pull request #299 from pycom/pymesh_v1.0.1

[pymesh] adapted for release v.1.0.1, pybytes v1.5.2 (fw 1.20.2.rc11)
This commit is contained in:
Catalin Ioana
2020-07-14 10:15:23 +03:00
committed by GitHub
6 changed files with 103 additions and 66 deletions

View File

@@ -8,14 +8,12 @@ Below there is a code example that should be implemented in the main.py file. Th
```python
import time
import pycom
if pybytes is not None:
if pybytes.__pymesh:
pymesh = pybytes.__pymesh
if pybytes.__pymesh and pybytes.__pymesh.__pymesh:
pymesh = pybytes.__pymesh.__pymesh
while True:
free_mem = pycom.get_free_heap()
pkt = "Hello, from " + str(pymesh.__pymesh.mac()) + ", time " + str(time.time()) + ", mem " + str(free_mem)
pkt = "Hello, from " + str(pymesh.mac())
pybytes.send_signal(1, pkt)
time.sleep(20)
```
@@ -23,3 +21,5 @@ if pybytes is not None:
Every time a data is sent trough Pymesh, the node's monitoring data is also sent. This monitoring data contains information as the number of neighbors, loRa mac, IP, role, age, and location.
Some of this information can be seen in the Pymesh Monitoring view or in section Signal, in the device interface in Pybytes.
For additional `pymesh` methods, check the open-source [Pymesh Library](https://github.com/pycom/pycom-libraries/tree/master/pymesh/pymesh_frozen) and the corresponding [Pymesh documentation](/pymesh/).

View File

@@ -15,7 +15,7 @@ Mesh networks essentially get rid of gateways, which decentralises the network's
Pymesh works on all of our LoRa supporting development boards, the LoPy4 and FiPy as well as on our OEM modules, L01 and L04.
_**Note: For obtaining the Pymesh firmware please follow the steps from [Pymesh LICENCE page](/pymesh/licence).**_
_**Note: For obtaining the Pymesh firmware please follow the steps from [Pybytes - Pymesh integration](/pybytes/pymeshintegration/).**_
## What does Pymesh offer you?

View File

@@ -8,7 +8,7 @@ aliases:
This Micropython library is included as frozen scripts in the Pymesh firmware release.
The code is open-sourced in [pycom-libraries repository](https://github.com/pycom/pycom-libraries/tree/master/lib/pymesh).
The code is open-sourced in [pycom-libraries repository](https://github.com/pycom/pycom-libraries/blob/master/pymesh/pymesh_frozen/lib/pymesh.py).
It is easily customisable and contributions are welcome using [Github PRs](https://github.com/pycom/pycom-libraries/pulls).

View File

@@ -6,11 +6,16 @@ aliases:
## Overview
The Pymesh micropython library is included as a `frozen python script` in the Pymesh firmware releases.
The Pymesh micropython library is included as a `frozen python script` in the Pymesh firmware releases. It is also available as [open-source micropython script](https://github.com/pycom/pycom-libraries/blob/master/pymesh/pymesh_frozen/lib/cli.py).
Instead of REPL, a specific Pymesh CLI interprets commands. This is shown by `>`.
Instead of REPL, a specific Pymesh CLI interprets commands. This is shown by `>`. The CLI is executed on a separate thread inside the Pymesh library.
{{% hint style="info" %}}
* The CLI needs to be started using the `pymesh.cli_start()` method.
* In the CLI the `h` command will print the list of available commands.
* The command `stop` will break the CLI thread.
{{% /hint %}}
The CLI is executed on a separate thread inside the Pymesh library.
For example:
```
@@ -21,32 +26,47 @@ mesh_mac_list [1, 6, 2]
## Internal CLI
```
>>> pymesh.cli_start()
>h
List of available commands
ip - display current IPv6 unicast addresses
mac - set or display the current LoRa MAC address
self - display all info about current node
mml - display the Mesh Mac List (MAC of all nodes inside this Mesh)
mp - display the Mesh Pairs (pairs of all nodes connections)
s - send message
ws - verifies if the message sent was acknowledged
rm - verifies if any message was received
sleep - deep-sleep
br - enable/disable or display the current Border Router functionality
brs - send packet for Mesh-external, to BR, if any
rst - reset NOW, including NVM Pymesh IPv6
buf - display buffer info
ot - sends command to openthread internal CLI
debug - set debug level
config - print config file contents
debug - set debug level
gps - get/set location coordinates
h - help, list of commands
ip - display current IPv6 unicast addresses
mac - set or display the current LoRa MAC address
mml - display the Mesh Mac List (MAC of all nodes inside this Mesh), also inquires Leader
mp - display the Mesh Pairs (Pairs of all nodes connections), also inquires Leader
ot - sends command to openthread internal CLI
pause - suspend Pymesh
resume - resume Pymesh
rm - verifies if any message was received
rst - reset NOW, including NVM Pymesh IPv6
s - send message
self - display all info about current node
sleep - deep-sleep
stop - close this CLI
tx_pow - set LoRa TX power in dBm (2-20)
ws - verifies if message sent was acknowledged
```
### Debug commands
```
>stop
CLI stopped
>>>
```
This command stops the CLI thread.
```
> debug
5
```
This sets the debug level. Possible values are:
This command displays or sets the debug level. Possible values are:
```
# recommended debug levels, from the most verbose to off
DEBUG_DEBG = const(5)
@@ -57,6 +77,16 @@ DEBUG_CRIT = const(1)
DEBUG_NONE = const(0)
```
```
>pause
Pymesh pausing
>resume
Pymesh resuming
```
This pair of commands stops temporarily and resumes the Pymesh executing threads.
A possible application is to use LoRaWAN when Pymesh is paused. [An example is here](https://github.com/pycom/pycom-libraries/blob/master/pymesh/pymesh_frozen/lorawan/main.py).
```
>rst
Mesh Reset NVM settings ...

View File

@@ -1,47 +1,50 @@
---
title: "Pymesh Library CLI"
title: "Obtaining Pymesh"
aliases:
- pymesh/simple-example
---
## Licensing process
## Obtaining Pymesh
In order to receive access to the Pymesh firmware releases (for Lopy4, Fipy, L01 or L04), the next process should be followed:
1. Complete the <a href="/gitbook/assets/pymesh/Pymesh_Licence_Copyright_Notice.pdf" target="\_blank"> the Pymesh LICENCE PDF document</a>, sign it and send us by [this email](mailto:catalin@pycom.io?subject=[Pymesh_LICENCE]).
1. You will receive by email an archive containing the images for all boards.
1. Extract the corresponding image, for example Lopy4.tar.gz, and upload the firmware to your board, using the [Pycom Firmware Update Tool](https://pycom.io/downloads/), similar in the following image:
<img src="/gitbook/assets/pymesh/pymesh_firmware_update.png" alt="Pymesh Firmware Update" width="500"/>
In order to receive access to the Pymesh firmware releases (for Lopy4, Fipy, L01 or L04), please follow the steps from [Pybytes - Pymesh integration](/pybytes/pymeshintegration/).
## Test Pymesh firmware loading
### Method 1
The simplest way to check if the Pymesh class has been successfully installed is to try the following code, directly in REPL:
The simplest way to check if the Pymesh class has been successfully instantiated (and started inside Pybytes) is to try the following code, directly in REPL:
```python
>>> from network import LoRa
>>> lora = LoRa(mode=LoRa.LORA)
>>> mesh = lora.Mesh()
# todo: add try/except for checking pybytes object exists
>>> pymesh = pybytes.__pymesh.__pymesh
>>> pymesh.cli_start()
>h
List of available commands
br - enable/disable or display the current Border Router functionality
brs - send packet for Mesh-external, to BR, if any
buf - display buffer info
config - print config file contents
debug - set debug level
gps - get/set location coordinates
h - help, list of commands
ip - display current IPv6 unicast addresses
mac - set or display the current LoRa MAC address
mml - display the Mesh Mac List (MAC of all nodes inside this Mesh), also inquires Leader
mp - display the Mesh Pairs (Pairs of all nodes connections), also inquires Leader
ot - sends command to openthread internal CLI
pause - suspend Pymesh
resume - resume Pymesh
rm - verifies if any message was received
rst - reset NOW, including NVM Pymesh IPv6
s - send message
self - display all info about current node
sleep - deep-sleep
stop - close this CLI
tx_pow - set LoRa TX power in dBm (2-20)
ws - verifies if message sent was acknowledged
```
### Method 2
Upload the `main.py` from the [Simple Example](/pymesh/simple-example).
## FAQ
Q: **I've received an error, such as `(LoadProhibited). Exception was unhandled.`, what should I do?**
A: In some cases, the NVM partition needs to be formatted. For this a format of whole Flash Memory should be performed.
This can be done using the cli version of the `Firmware Update Tool`, so please navigate where the app was installed (search for pycom-fwtool-cli executable) and execute:
```
pycom-fwtool-cli -p <PORT> erase_all
```
`<PORT>` should be replaced with the actual USB COM port, for example:
* on Windows `COM10`
* on Linux `/dev/ttyACM0`
* on MacOS `/dev/tty.usbmodemPy8eaa911`

View File

@@ -6,16 +6,19 @@ aliases:
## What is Pymesh micropython library?
The Pymesh Micropython library is a set of frozen scripts in the Pymesh firmware binary release.
The Pymesh Micropython library is a set of frozen scripts in the Pymesh firmware binary release; the [open-source scripts are available on github](https://github.com/pycom/pycom-libraries/tree/master/pymesh/pymesh_frozen)
[Open-source on github](https://github.com/pycom/pycom-libraries/tree/master/pymesh/pymesh_frozen)
It allows users to access Pymesh in a few lines of code, as shown in the following code snippet.
Additionally, users can install the Pymesh mobile application which is available [here for both iOS and Android platforms](https://github.com/pycom/pycom-libraries/tree/master/pymesh/mobile_app). It allows users to connect over BLE to a Pymesh node and find out network information.
If Pybytes is used, then Pymesh is already started and pymesh object can be obtained by simply using (`main-pybytes.py` from github):
```python
# todo: add try/except for checking pybytes object exists
pymesh = pybytes.__pymesh.__pymesh
```
If Pybytes is not used, then the Pymesh network has to be started manually. The is shown in the following code snippet (`main.py` from github):
```python
import pycom
import time
@@ -52,9 +55,7 @@ pymesh_config = PymeshConfig.read_config()
#initialize Pymesh
pymesh = Pymesh(pymesh_config, new_message_cb)
mac = pymesh.mac()
# based on LoRa MAC address, some nodes could be forced to be
# sleep-end-devices (always Child) or to have increased Leader priority
# mac = pymesh.mac()
# if mac > 10:
# pymesh.end_device(True)
# elif mac == 5:
@@ -82,21 +83,24 @@ pymesh.send_mess(5, "Hello World")
# pymesh.br_set(PymeshConfig.BR_PRIORITY_NORM, new_br_message_cb)
# remove Border Router function from current node
#pymesh.br_remove()
# pymesh.br_remove()
# send data for Mesh-external, basically to the BR
# ip = "1:2:3::4"
# port = 5555
# pymesh.send_mess_external(ip, port, "Hello World")
print("done Pymesh init, forever loop, exit/stop with Ctrl+C multiple times")
# set BR with callback
print("done Pymesh init, CLI is started, h - help/command list, stop - CLI will be stopped")
pymesh.cli_start()
# while True:
# time.sleep(3)
while True:
time.sleep(3)
```
Additionally, users can install the Pymesh mobile application which is available [here for both iOS and Android platforms](https://github.com/pycom/pycom-libraries/tree/master/pymesh/mobile_app). It allows users to connect over BLE to a Pymesh node and find out network information.
## Output
An example of possible output is below.