From e7b4c294f85902c3f356eec2035395ee3c2039c8 Mon Sep 17 00:00:00 2001 From: gijsio <67470426+gijsio@users.noreply.github.com> Date: Wed, 5 Aug 2020 17:51:54 +0200 Subject: [PATCH 1/8] included a frozen code section --- config.toml | 6 ++++++ content/advance/frozen.md | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 content/advance/frozen.md diff --git a/config.toml b/config.toml index c5afaf5..8960dde 100644 --- a/config.toml +++ b/config.toml @@ -1639,6 +1639,12 @@ theme = "doc-theme" identifier = "advance@encryption" parent = "advance" weight = 30 +[[menu.main]] + name = "Frozen code" + url = "/advance/frozen/" + identifier = "advance@frozen" + parent = "advance" + weight = 40 [[menu.main]] name="License" diff --git a/content/advance/frozen.md b/content/advance/frozen.md new file mode 100644 index 0000000..5dd4e5a --- /dev/null +++ b/content/advance/frozen.md @@ -0,0 +1,37 @@ +--- +title: 'Frozen' +--- +In this section, we discuss the usage of so called `Frozen` code. This is only useful when you build the firmware from source. + +What we call `Frozen` code, relates to a principle in MicroPython where you can include specific codeblocks or python module inside the firmware, such that you do not have to manually upload them. This can be very useful if you have a specific section of code you want to include on all your devices, without manually uploading it every time and risk losing it when formatting the file system. + +## How To use the Frozen section +1. Download the (latest) source code from our [Github Repository](https://github.com/pycom/pycom-micropython-sigfox) and extract the archive, or use the GitHub desktop tool. +2. Inside the folder `pycom-micropython-sigfox/esp32/frozen` you will find the `frozen` section. We already have frozen some of the python modules into the firmware, such as `sqnsupgrade.py` and `OTA.py`. +3. In here, you can also find `_main.py` and `_boot.py` files under `Base`. These are alternative `main.py` and `boot.py` files you can build into the source code, and they will run like you would expect. + > Note that if you add anything in the `_boot.py`, it will also run in safeboot mode, and you can only change it by reflashing the firmware. + + > The code already in `_boot.py` is pretty important to make the REPL show up, do not remove that + >```python + >import os + >from machine import UART + >os.dupterm(UART(0, 115200)) + >``` +4. For example add to the `_main.py`: + ```python + # _main.py + print("Hello from _main.py") + ``` +5. Now rebuild and reflashing the firmware. After reboot, the line will be printed in the REPL +6. You can also add files to the `Custom` folder, in this example, we make a `Block.py` with the following code: + ```python + # block.py + def Block(): + print("My Frozen codeblock") + ``` +7. After rebuilding and reflashing, you are able to: + ```python + >>> from block import Block + >>> Block() + My Frozen codeblock + ``` \ No newline at end of file From 6692de9e80725c3c8a40c6913f12d7b463f3e871 Mon Sep 17 00:00:00 2001 From: gijsio <67470426+gijsio@users.noreply.github.com> Date: Thu, 6 Aug 2020 11:55:42 +0200 Subject: [PATCH 2/8] changes to frozen --- content/advance/frozen.md | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/content/advance/frozen.md b/content/advance/frozen.md index 5dd4e5a..cc0bcd4 100644 --- a/content/advance/frozen.md +++ b/content/advance/frozen.md @@ -5,24 +5,21 @@ In this section, we discuss the usage of so called `Frozen` code. This is only u What we call `Frozen` code, relates to a principle in MicroPython where you can include specific codeblocks or python module inside the firmware, such that you do not have to manually upload them. This can be very useful if you have a specific section of code you want to include on all your devices, without manually uploading it every time and risk losing it when formatting the file system. -## How To use the Frozen section -1. Download the (latest) source code from our [Github Repository](https://github.com/pycom/pycom-micropython-sigfox) and extract the archive, or use the GitHub desktop tool. -2. Inside the folder `pycom-micropython-sigfox/esp32/frozen` you will find the `frozen` section. We already have frozen some of the python modules into the firmware, such as `sqnsupgrade.py` and `OTA.py`. -3. In here, you can also find `_main.py` and `_boot.py` files under `Base`. These are alternative `main.py` and `boot.py` files you can build into the source code, and they will run like you would expect. - > Note that if you add anything in the `_boot.py`, it will also run in safeboot mode, and you can only change it by reflashing the firmware. +## How To use the Frozen section (Without Pybytes) +1. Download the (latest) source code from our [Github Repository](https://github.com/pycom/pycom-micropython-sigfox) and extract the archive, or use the GitHub desktop tool. If you have never build firmware from the sourcecode before, you can find the setup guide on GitHub as well. - > The code already in `_boot.py` is pretty important to make the REPL show up, do not remove that - >```python - >import os - >from machine import UART - >os.dupterm(UART(0, 115200)) - >``` -4. For example add to the `_main.py`: +2. Inside the folder `pycom-micropython-sigfox/esp32/frozen` you will find the `frozen` section. We already have frozen some of the python modules into the firmware, such as `sqnsupgrade.py` and `OTA.py`. +3. In here, you can find the `_main.py` and `_boot.py` files in the `frozen/Base/` folder. These are similar to `main.py` and `boot.py` files you can build into the source code, with the exception that `_boot.py` will also run in safeboot mode. Moreover can only change the behaviour by rebuilding and reflashing the firmware. + > Note that if you add anything in the `_boot.py`, keep the code already in the boot file, as that enables the output to REPL. + + > When building firmware with `VARIANT=PYBYTES`, you can find the `_boot.py` and `_main.py` in the `frozen/Pybytes/` folder and the files in `Base` will **NOT** be used + +4. For example, add to the `_main.py`: ```python # _main.py print("Hello from _main.py") ``` -5. Now rebuild and reflashing the firmware. After reboot, the line will be printed in the REPL +5. Now rebuild and reflash the firmware. After reboot, the line will be printed in the REPL. 6. You can also add files to the `Custom` folder, in this example, we make a `Block.py` with the following code: ```python # block.py @@ -34,4 +31,6 @@ What we call `Frozen` code, relates to a principle in MicroPython where you can >>> from block import Block >>> Block() My Frozen codeblock - ``` \ No newline at end of file + ``` + +This concludes the section about Frozen code. You should now be able to include Frozen python code inside the firmware. \ No newline at end of file From 111e18f51ee281d4cffa004f8dabfd910b509d03 Mon Sep 17 00:00:00 2001 From: gijsio <67470426+gijsio@users.noreply.github.com> Date: Thu, 6 Aug 2020 14:10:50 +0200 Subject: [PATCH 3/8] add clarification --- content/advance/frozen.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/advance/frozen.md b/content/advance/frozen.md index cc0bcd4..02f6ee8 100644 --- a/content/advance/frozen.md +++ b/content/advance/frozen.md @@ -32,5 +32,5 @@ What we call `Frozen` code, relates to a principle in MicroPython where you can >>> Block() My Frozen codeblock ``` - +This works similar to `import machine` and the other built in modules. This concludes the section about Frozen code. You should now be able to include Frozen python code inside the firmware. \ No newline at end of file From 4867fe1a6567c7271c2ffc230952ccdf1eb6b1fa Mon Sep 17 00:00:00 2001 From: gijsio <67470426+gijsio@users.noreply.github.com> Date: Fri, 7 Aug 2020 10:12:04 +0200 Subject: [PATCH 4/8] minor changes --- content/advance/frozen.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/content/advance/frozen.md b/content/advance/frozen.md index 02f6ee8..7dd10e7 100644 --- a/content/advance/frozen.md +++ b/content/advance/frozen.md @@ -9,8 +9,8 @@ What we call `Frozen` code, relates to a principle in MicroPython where you can 1. Download the (latest) source code from our [Github Repository](https://github.com/pycom/pycom-micropython-sigfox) and extract the archive, or use the GitHub desktop tool. If you have never build firmware from the sourcecode before, you can find the setup guide on GitHub as well. 2. Inside the folder `pycom-micropython-sigfox/esp32/frozen` you will find the `frozen` section. We already have frozen some of the python modules into the firmware, such as `sqnsupgrade.py` and `OTA.py`. -3. In here, you can find the `_main.py` and `_boot.py` files in the `frozen/Base/` folder. These are similar to `main.py` and `boot.py` files you can build into the source code, with the exception that `_boot.py` will also run in safeboot mode. Moreover can only change the behaviour by rebuilding and reflashing the firmware. - > Note that if you add anything in the `_boot.py`, keep the code already in the boot file, as that enables the output to REPL. +3. You can find the `_main.py` and `_boot.py` files in the `frozen/Base/` folder. These are similar to `main.py` and `boot.py` files you can build into the source code, with the exception that `_boot.py` will also run in safeboot mode. Moreover can only change the behaviour by rebuilding and reflashing the firmware. + > Note that if you plan to make changes in the `_boot.py`, keep the code already in the file, as that enables the output to REPL. > When building firmware with `VARIANT=PYBYTES`, you can find the `_boot.py` and `_main.py` in the `frozen/Pybytes/` folder and the files in `Base` will **NOT** be used @@ -32,5 +32,5 @@ What we call `Frozen` code, relates to a principle in MicroPython where you can >>> Block() My Frozen codeblock ``` -This works similar to `import machine` and the other built in modules. +This works similar to `import machine` and the other built-in modules. This concludes the section about Frozen code. You should now be able to include Frozen python code inside the firmware. \ No newline at end of file From 1113dba9ebc6a5d19139d9f438e04fc0ee104d0f Mon Sep 17 00:00:00 2001 From: gijsio <67470426+gijsio@users.noreply.github.com> Date: Fri, 7 Aug 2020 13:17:33 +0200 Subject: [PATCH 5/8] fixed pybytes section --- content/advance/frozen.md | 2 +- content/tutorials/networks/sigfox.md | 15 +++++++-------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/content/advance/frozen.md b/content/advance/frozen.md index 7dd10e7..317a834 100644 --- a/content/advance/frozen.md +++ b/content/advance/frozen.md @@ -5,7 +5,7 @@ In this section, we discuss the usage of so called `Frozen` code. This is only u What we call `Frozen` code, relates to a principle in MicroPython where you can include specific codeblocks or python module inside the firmware, such that you do not have to manually upload them. This can be very useful if you have a specific section of code you want to include on all your devices, without manually uploading it every time and risk losing it when formatting the file system. -## How To use the Frozen section (Without Pybytes) +## How To use the Frozen section 1. Download the (latest) source code from our [Github Repository](https://github.com/pycom/pycom-micropython-sigfox) and extract the archive, or use the GitHub desktop tool. If you have never build firmware from the sourcecode before, you can find the setup guide on GitHub as well. 2. Inside the folder `pycom-micropython-sigfox/esp32/frozen` you will find the `frozen` section. We already have frozen some of the python modules into the firmware, such as `sqnsupgrade.py` and `OTA.py`. diff --git a/content/tutorials/networks/sigfox.md b/content/tutorials/networks/sigfox.md index 49dc93c..1f5de53 100644 --- a/content/tutorials/networks/sigfox.md +++ b/content/tutorials/networks/sigfox.md @@ -13,26 +13,25 @@ The following tutorials demonstrate how to register and get started with the SiP ```python from network import Sigfox import socket -​ + # init Sigfox for RCZ1 (Europe) sigfox = Sigfox(mode=Sigfox.SIGFOX, rcz=Sigfox.RCZ1) -​ + # create a Sigfox socket s = socket.socket(socket.AF_SIGFOX, socket.SOCK_RAW) -​ + # make the socket blocking s.setblocking(True) -​ + # configure it as uplink only s.setsockopt(socket.SOL_SIGFOX, socket.SO_RX, False) -​ + # send some bytes s.send(bytes([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12])) ``` -{{% hint style="danger" %}} -Please ensure that there is an antenna connected to your device before sending/receiving Sigfox messages as in proper use (e.g. without an antenna), may damage the device. -{{% /hint %}} +> Please ensure that there is an antenna connected to your device before sending/receiving Sigfox messages as in proper use (e.g. without an antenna), may damage the device. + ## Disengage Sequence Number From f62e75faffc3335d84cb23b98cf3918e45d9ef06 Mon Sep 17 00:00:00 2001 From: gijsio <67470426+gijsio@users.noreply.github.com> Date: Mon, 10 Aug 2020 15:15:58 +0200 Subject: [PATCH 6/8] updated sigfox links --- content/gettingstarted/registration/sigfox.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/content/gettingstarted/registration/sigfox.md b/content/gettingstarted/registration/sigfox.md index b5fcc82..e664d49 100644 --- a/content/gettingstarted/registration/sigfox.md +++ b/content/gettingstarted/registration/sigfox.md @@ -39,7 +39,7 @@ print(binascii.hexlify(sigfox.pac())) ## Creating account at Sigfox backend -You need to register to the Sigfox Backend. Navigate to [https://backend.sigfox.com/activate](https://backend.sigfox.com/activate) +You need to register to the Sigfox Backend. Navigate to [https://buy.sigfox.com/activate](https://buy.sigfox.com/activate) ![](/gitbook/assets/sigfoxactivate.png) @@ -79,4 +79,4 @@ Now you can see your new Sigfox PAC. ![](/gitbook/assets/newsigfoxpac.png) -Once you know your new Sigfox PAC go to [https://backend.sigfox.com/activate](https://backend.sigfox.com/activate) and register device with different account. +Once you know your new Sigfox PAC go to [https://buy.sigfox.com/activate](https://buy.sigfox.com/activate) and register device with different account. From 6a93466a3fb5e3026e255fae5643a6a83508cbde Mon Sep 17 00:00:00 2001 From: gijsio <67470426+gijsio@users.noreply.github.com> Date: Wed, 12 Aug 2020 17:38:50 +0200 Subject: [PATCH 7/8] Update frozen.md update pybytes --- content/advance/frozen.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/content/advance/frozen.md b/content/advance/frozen.md index 317a834..ce04e77 100644 --- a/content/advance/frozen.md +++ b/content/advance/frozen.md @@ -12,7 +12,12 @@ What we call `Frozen` code, relates to a principle in MicroPython where you can 3. You can find the `_main.py` and `_boot.py` files in the `frozen/Base/` folder. These are similar to `main.py` and `boot.py` files you can build into the source code, with the exception that `_boot.py` will also run in safeboot mode. Moreover can only change the behaviour by rebuilding and reflashing the firmware. > Note that if you plan to make changes in the `_boot.py`, keep the code already in the file, as that enables the output to REPL. - > When building firmware with `VARIANT=PYBYTES`, you can find the `_boot.py` and `_main.py` in the `frozen/Pybytes/` folder and the files in `Base` will **NOT** be used + > When building firmware with `VARIANT=PYBYTES`, you need to use the `frozen/Pybytes/_boot.py` and `frozen/Pybytes/_main.py`, and the files in `Base` will **NOT** be used. If you then enable Pybytes on boot with the following flag: + >```python + >import pycom; pycom.pybytes_on_boot(True) + >``` + > Not the `Pybytes/_main.py`, but the `Pybytes/_pybytes_main.py` will be used. + 4. For example, add to the `_main.py`: ```python From 82bea94a59f487f783b8bdbb95ce3b0e98720f88 Mon Sep 17 00:00:00 2001 From: gijsio <67470426+gijsio@users.noreply.github.com> Date: Wed, 12 Aug 2020 17:57:02 +0200 Subject: [PATCH 8/8] Update frozen.md rewrite to make it more clear. added exclusion note --- content/advance/frozen.md | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/content/advance/frozen.md b/content/advance/frozen.md index ce04e77..05d4efc 100644 --- a/content/advance/frozen.md +++ b/content/advance/frozen.md @@ -4,26 +4,22 @@ title: 'Frozen' In this section, we discuss the usage of so called `Frozen` code. This is only useful when you build the firmware from source. What we call `Frozen` code, relates to a principle in MicroPython where you can include specific codeblocks or python module inside the firmware, such that you do not have to manually upload them. This can be very useful if you have a specific section of code you want to include on all your devices, without manually uploading it every time and risk losing it when formatting the file system. +>It is only possible to include python files in the frozen section. Other filetypes (like `.json` or `.cert`) will not be added in the final binaries ## How To use the Frozen section 1. Download the (latest) source code from our [Github Repository](https://github.com/pycom/pycom-micropython-sigfox) and extract the archive, or use the GitHub desktop tool. If you have never build firmware from the sourcecode before, you can find the setup guide on GitHub as well. 2. Inside the folder `pycom-micropython-sigfox/esp32/frozen` you will find the `frozen` section. We already have frozen some of the python modules into the firmware, such as `sqnsupgrade.py` and `OTA.py`. 3. You can find the `_main.py` and `_boot.py` files in the `frozen/Base/` folder. These are similar to `main.py` and `boot.py` files you can build into the source code, with the exception that `_boot.py` will also run in safeboot mode. Moreover can only change the behaviour by rebuilding and reflashing the firmware. - > Note that if you plan to make changes in the `_boot.py`, keep the code already in the file, as that enables the output to REPL. - - > When building firmware with `VARIANT=PYBYTES`, you need to use the `frozen/Pybytes/_boot.py` and `frozen/Pybytes/_main.py`, and the files in `Base` will **NOT** be used. If you then enable Pybytes on boot with the following flag: - >```python - >import pycom; pycom.pybytes_on_boot(True) - >``` - > Not the `Pybytes/_main.py`, but the `Pybytes/_pybytes_main.py` will be used. - + > If you plan to make changes in the `_boot.py`, keep the code already in the file, as that enables the output to REPL. 4. For example, add to the `_main.py`: ```python # _main.py print("Hello from _main.py") ``` + > When building firmware with `VARIANT=PYBYTES`, you need to use the `_main.py` and `_boot.py` files in the `frozen/Pybytes` folder. The files in `frozen/Base` will **NOT** be used. + > Moreover, if you then enable the `pybytes_on_boot(True)`, the `_pybytes_main.py` will be used instead of the `_main.py`, as that contains the pybytes activation code. 5. Now rebuild and reflash the firmware. After reboot, the line will be printed in the REPL. 6. You can also add files to the `Custom` folder, in this example, we make a `Block.py` with the following code: ```python @@ -37,5 +33,5 @@ What we call `Frozen` code, relates to a principle in MicroPython where you can >>> Block() My Frozen codeblock ``` -This works similar to `import machine` and the other built-in modules. +This works similar to `import machine` and the other built-in modules. This concludes the section about Frozen code. You should now be able to include Frozen python code inside the firmware. \ No newline at end of file