Merge pull request #308 from pycom/frozen

Frozen
This commit is contained in:
Christian Ehlers
2020-08-12 18:09:44 +02:00
committed by GitHub
4 changed files with 52 additions and 10 deletions

View File

@@ -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"

37
content/advance/frozen.md Normal file
View File

@@ -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.
>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.
> 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
# 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
```
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.

View File

@@ -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.

View File

@@ -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