From ba64670791771f1d6604e2afbfce27bea4469098 Mon Sep 17 00:00:00 2001 From: Guilherme Laurindo Schneck Date: Fri, 10 Apr 2026 23:52:48 +0200 Subject: [PATCH 01/10] ftespnow: Add library for transfering files through espnow. Signed-off-by: Guilherme Laurindo Schneck --- ftespnow/examples/client_side_example.py | 58 ++++++ ftespnow/examples/server_side_example.py | 56 ++++++ ftespnow/ftespnow-client/ftespnow/client.py | 212 ++++++++++++++++++++ ftespnow/ftespnow-client/manifest.py | 7 + ftespnow/ftespnow-server/ftespnow/server.py | 211 +++++++++++++++++++ ftespnow/ftespnow-server/manifest.py | 7 + ftespnow/ftespnow/__init__.py | 9 + ftespnow/ftespnow/ftespnow/__init__.py | 9 + ftespnow/ftespnow/manifest.py | 6 + ftespnow/manifest.py | 6 + 10 files changed, 581 insertions(+) create mode 100644 ftespnow/examples/client_side_example.py create mode 100644 ftespnow/examples/server_side_example.py create mode 100644 ftespnow/ftespnow-client/ftespnow/client.py create mode 100644 ftespnow/ftespnow-client/manifest.py create mode 100644 ftespnow/ftespnow-server/ftespnow/server.py create mode 100644 ftespnow/ftespnow-server/manifest.py create mode 100644 ftespnow/ftespnow/__init__.py create mode 100644 ftespnow/ftespnow/ftespnow/__init__.py create mode 100644 ftespnow/ftespnow/manifest.py create mode 100644 ftespnow/manifest.py diff --git a/ftespnow/examples/client_side_example.py b/ftespnow/examples/client_side_example.py new file mode 100644 index 000000000..90ccfada7 --- /dev/null +++ b/ftespnow/examples/client_side_example.py @@ -0,0 +1,58 @@ +import ftespnow + +# Initialize ESP-NOW client +esp = ftespnow.CLIENT() + +# Connect to ESP-NOW server +esp.connect("a4f00f772d15") # Change to actual server mac address + +# Send a message +message = "Hello" +sent = esp.send_message(message) +if sent: # Check if server received the data + print("Message received by server") +else: + print("Message not received by server") + +# Receive a message +received_data = esp.receive_message() +if received_data is None: # Check if any data was received + print("No message was received (timed out)") +else: + print(f"Here is the received data: {received_data}") + +# Send a .txt file +txt_sent = esp.send_txt("filepath/filename.txt") +if txt_sent: # Check if server received the data + print("File received by server") +else: + print("File not received by server") + +# Send a .json file +json_sent = esp.send_json("filepath/filename.json") +if json_sent: # Check if server received the data + print("File received by server") +else: + print("File not received by server") + +# Write received data to .txt file +txt_received = esp.receive_to_txt( + "filepath/filename.txt", mode="w" + ) # Set mode to 'w' so file is truncated before writing +if txt_received: + print("File received successfully") +else: + print("No file received. Destination file was not created/modified") + +# Write received data to .json file +json_received = esp.receive_to_json( + "filepath/filename.json", mode="w" + ) # Set mode to 'w' so file is truncated before writing +if json_received: + print("File received successfully") +else: + print("No file received. Destination file was not created/modified") + +# Write received data to a python dictionary +data_dict = esp.receive_to_dict() +print(data_dict) diff --git a/ftespnow/examples/server_side_example.py b/ftespnow/examples/server_side_example.py new file mode 100644 index 000000000..836030d4f --- /dev/null +++ b/ftespnow/examples/server_side_example.py @@ -0,0 +1,56 @@ +import ftespnow + +# Initialize ESP-NOW client +esp = ftespnow.SERVER() + +# Send a message +message = "Hello" +peer = "a4f00f772d15" # Mac address of the client that you want to send data to +sent = esp.send_message(peer, message) +if sent: # Check if client received the data + print("Message received by clientclient") +else: + print("Message not received by client") + +# Receive a message +received_data = esp.receive_message() +if received_data is None: # Check if any data was received + print("No message was received (timed out)") +else: + print(f"Here is the received data: {received_data}") + +# Send a .txt file +txt_sent = esp.send_txt(peer, "filepath/filename.txt") +if txt_sent: # Check if client received the data + print("File received by client") +else: + print("File not received by client") + +# Send a .json file +json_sent = esp.send_json(peer, "filepath/filename.json") +if json_sent: # Check if client received the data + print("File received by client") +else: + print("File not received by client") + +# Write received data to .txt file +txt_received = esp.receive_to_txt( + "filepath/filename.txt", mode="w" + ) # Set mode to 'w' so file is truncated before writing +if txt_received: + print("File received successfully") +else: + print("No file received. Destination file was not created/modified") + +# Write received data to .json file +json_received = esp.receive_to_json( + "filepath/filename.json", mode="w" + ) # Set mode to 'w' so file is truncated before writing +if json_received: # Check if any data was received + print("File received successfully") +else: + print("No file received. Destination file was not created/modified") + +# Write received data to a python dictionary +data_dict = esp.receive_to_dict() # Will return {} if no data was received +print(data_dict) diff --git a/ftespnow/ftespnow-client/ftespnow/client.py b/ftespnow/ftespnow-client/ftespnow/client.py new file mode 100644 index 000000000..4b931e658 --- /dev/null +++ b/ftespnow/ftespnow-client/ftespnow/client.py @@ -0,0 +1,212 @@ +import espnow +import json + + +class CLIENT: + def __init__(self, *, timeout: int = 5) -> None: + self.esp = espnow.ESPNow() + self.timeout = timeout + + def configure(self, *, timeout: int = 5) -> None: + self.timeout: int = timeout + + def connect(self, peer: str) -> None: + self.peer: str = peer + self.esp.active(True) + self.esp.add_peer(self.peer) + + def send_message(self, data: str) -> bool: + """ + Send a string + + Args: + + data (str): Data to be sent + + Returns: + + bool: Confirmation flag (`True` if data was received, `False` otherwise) + """ + + ack: bool = self.esp.send(self.peer, data) + return ack + + def receive_message(self, recv_timeout :int = 5) -> list | None: + """ + Receive a string + + Args: + + recv_timeout (int, optional): Reception timeout. Defaults to 5. + + Returns: + + list | None: `[, ]` | `None` if no message is received + """ + + received = self.esp.recv(recv_timeout) + if received[0] is None: + return + return received + + def send_txt(self, filename: str) -> bool: + """ + Parse and send a `.txt` file as a `string` + + Args: + + filename (str): Filepath of the desired file to be sent with file name and extension + + Returns: + + sent (bool): Confirmation flag (`True` if data was received, `False` otherwise) + """ + + with open(filename, "r") as f: + data: str = str(f.readlines()) + sent: bool = self.send_message(data) + return sent + + def send_json(self, filename: str, *, indent: int = 4) -> bool: + """ + Parse and send a `.json` file as a `string` + + Args: + + filename (str): Filepath of the desired file to be sent with file name and extension + + indent (int, optional): Desired indent of the resulting parsed `string` (for formatting purposes). Defaults to 4. + + Returns: + + sent (bool): Confirmation flag (`True` if data was received, `False` otherwise) + """ + + with open(filename, "r") as f: + unparsed = json.load(f) + parsed: str = json.dumps(unparsed, indent=indent) + sent: bool = self.send_message(parsed) + return sent + + def receive_to_txt(self, target_file: str, mode: str = "a") -> bool: + """ + Write received `string` into a `.txt` file. + + **Will not write or create file if no data is received** + + Args: + + target_file (str): Filepath of the destination file for the received data with file name and extension. + + mode (str, optional): Editing mode + + - `r` - Read only + + - `w` - Write only (truncates file before writing) + + - `x` - Create a new file and open it for writing (raises `FileExistsError` if file already exists) + + - `a` - Append to the end of the file (default) + + - `b` - Binary mode + + - `t` - Text mode + + - `+` - Update (read and write) + + Read `open()`_ for more information + + Returns: + + received (bool): Confirmation flag (`True` if data was received, `False` otherwise) + + .. _open(): https://docs.python.org/3/library/functions.html#open + """ + + if ".txt" not in target_file: + raise SyntaxError("File format must be .txt") + try: + received: bool = False + data: list | None = self.receive_message() + if data is None: + return received + data_list: list[str] = str(data[-1]).split("\n") + if data_list[-1] == "": + data_list = data_list[:-1] + with open(target_file, mode) as f: + f.writelines(data_list) + return not received + except SyntaxError: + raise + + def receive_to_json(self, target_file: str, mode: str = "a") -> bool: + """ + Write received `string` into a `.json` file. + + **Will not write or create file if no data is received** + + Args: + + target_file (str): Filepath of the destination file for the received data with file name and extension. + + mode (str, optional): Editing mode + + - `r` - Read only + + - `w` - Write only (truncates file before writing) + + - `x` - Create a new file and open it for writing (raises `FileExistsError` if file already exists) + + - `a` - Append to the end of the file (default) + + - `b` - Binary mode + + - `t` - Text mode + + - `+` - Update (read and write) + + Read `open()`_ for more information + + Returns: + + received (bool): Confirmation flag (`True` if data was received, `False` otherwise) + + .. _open(): https://docs.python.org/3/library/functions.html#open + """ + + if ".json" not in target_file: + raise SyntaxError("File format must be .json") + try: + received: bool = False + data: list | None = self.receive_message() + if data is None: + return received + mac: str = str(data[0]) + message = json.loads(str(data[-1])) + unparsed: dict = {"mac": mac, "message": message} + with open(target_file, mode) as f: + json.dump(unparsed, f) + return not received + except SyntaxError: + raise + + def receive_to_dict(self) -> dict: + """ + Unparses received `string` into a `dict` object + + Args: + + None: + + Returns: + + unparsed (dict): `dictionary` object containing unparsed equivalent of the received `.json` + """ + + data: list | None = self.receive_message() + if data is None: + return {} + mac: str = str(data[0]) + message = json.loads(str(data[-1])) + unparsed: dict = {"mac": mac, "message": message} + return unparsed diff --git a/ftespnow/ftespnow-client/manifest.py b/ftespnow/ftespnow-client/manifest.py new file mode 100644 index 000000000..66b5882bc --- /dev/null +++ b/ftespnow/ftespnow-client/manifest.py @@ -0,0 +1,7 @@ +metadata( + description="Client-side commands", + version="0.1.0", +) + +require("ftespnow") +package("ftespnow") diff --git a/ftespnow/ftespnow-server/ftespnow/server.py b/ftespnow/ftespnow-server/ftespnow/server.py new file mode 100644 index 000000000..9fdb61c3e --- /dev/null +++ b/ftespnow/ftespnow-server/ftespnow/server.py @@ -0,0 +1,211 @@ +import espnow +import json + +class SERVER: + def __init__(self, *, timeout: int = 5) -> None: + self.esp = espnow.ESPNow() + self.timeout = timeout + + def configure(self, *, timeout: int = 5) -> None: + self.timeout = timeout + + def send_message(self, peer: str, data: str) -> bool: + """ + Send a string + + Args: + + peer (str): client's mac address + + data (str): Data to be sent + + Returns: + + bool: Confirmation flag (`True` if data was received, `False` otherwise) + """ + + ack: bool = self.esp.send(peer, data) + return ack + + def receive_message(self, recv_timeout :int = 5) -> list | None: + """ + Receive a string + + Args: + + recv_timeout (int, optional): Reception timeout. Defaults to 5. + + Returns: + + list | None: `[, ]` | `None` if no message is received + """ + + received = self.esp.recv(recv_timeout) + if received[0] is None: + return + return received + + def send_txt(self, peer: str, filename: str) -> bool: + """ + Parse and send a `.txt` file as a `string` + + Args: + + peer (str): client's mac address + + filename (str): Filepath of the desired file to be sent with file name and extension + + Returns: + + sent (bool): Confirmation flag (`True` if data was received, `False` otherwise) + """ + + with open(filename, "r") as f: + data: str = str(f.readlines()) + sent: bool = self.send_message(peer, data) + return sent + + def send_json(self, peer: str, filename: str, *, indent: int = 4) -> bool: + """ + Parse and send a `.json` file as a `string` + + Args: + + peer (str): client's mac address + + filename (str): Filepath of the desired file to be sent with file name and extension + + indent (int, optional): Desired indent of the resulting parsed `string` (for formatting purposes). Defaults to 4. + + Returns: + + sent (bool): Confirmation flag (`True` if data was received, `False` otherwise) + """ + + with open(filename, "r") as f: + unparsed = json.load(f) + parsed: str = json.dumps(unparsed, indent=indent) + sent: bool = self.send_message(peer, parsed) + return sent + + def receive_to_txt(self, target_file: str, mode: str = "a") -> bool: + """ + Write received `string` into a `.txt` file. + + **Will not write or create file if no data is received** + + Args: + + target_file (str): Filepath of the destination file for the received data with file name and extension. + + mode (str, optional): Editing mode + + - `r` - Read only + + - `w` - Write only (truncates file before writing) + + - `x` - Create a new file and open it for writing (raises `FileExistsError` if file already exists) + + - `a` - Append to the end of the file (default) + + - `b` - Binary mode + + - `t` - Text mode + + - `+` - Update (read and write) + + Read `open()`_ for more information + + Returns: + + received (bool): Confirmation flag (`True` if data was received, `False` otherwise) + + .. _open(): https://docs.python.org/3/library/functions.html#open + """ + + if ".txt" not in target_file: + raise SyntaxError("File format must be .txt") + try: + data: list | None = self.receive_message() + if data is None: + return False + data_list: list[str] = str(data[-1]).split("\n") + if data_list[-1] == "": + data_list = data_list[:-1] + with open(target_file, mode) as f: + f.writelines(data_list) + return True + except SyntaxError: + raise + + def receive_to_json(self, target_file: str, mode: str = "a") -> bool: + """ + Write received `string` into a `.json` file. + + **Will not write or create file if no data is received** + + Args: + + target_file (str): Filepath of the destination file for the received data with file name and extension. + + mode (str, optional): Editing mode + + - `r` - Read only + + - `w` - Write only (truncates file before writing) + + - `x` - Create a new file and open it for writing (raises `FileExistsError` if file already exists) + + - `a` - Append to the end of the file (default) + + - `b` - Binary mode + + - `t` - Text mode + + - `+` - Update (read and write) + + Read `open()`_ for more information + + Returns: + + received (bool): Confirmation flag (`True` if data was received, `False` otherwise) + + .. _open(): https://docs.python.org/3/library/functions.html#open + """ + + if ".json" not in target_file: + raise SyntaxError("File format must be .json") + try: + received: bool = False + data: list | None = self.receive_message() + if data is None: + return received + mac: str = str(data[0]) + message = json.loads(str(data[-1])) + unparsed: dict = {"mac": mac, "message": message} + with open(target_file, mode) as f: + json.dump(unparsed, f) + return not received + except SyntaxError: + raise + + def receive_to_dict(self) -> dict: + """ + Unparses received `string` into a `dict` object + + Args: + + None: + + Returns: + + unparsed (dict): `dictionary` object containing unparsed equivalent of the received `.json` + """ + + data: list | None = self.receive_message() + if data is None: + return {} + mac: str = str(data[0]) + message = json.loads(str(data[-1])) + unparsed: dict = {"mac": mac, "message": message} + return unparsed diff --git a/ftespnow/ftespnow-server/manifest.py b/ftespnow/ftespnow-server/manifest.py new file mode 100644 index 000000000..add02364e --- /dev/null +++ b/ftespnow/ftespnow-server/manifest.py @@ -0,0 +1,7 @@ +metadata( + description="Server-side commands", + version="0.1.0", +) + +require("ftespnow") +package("ftespnow") diff --git a/ftespnow/ftespnow/__init__.py b/ftespnow/ftespnow/__init__.py new file mode 100644 index 000000000..f85254af3 --- /dev/null +++ b/ftespnow/ftespnow/__init__.py @@ -0,0 +1,9 @@ +try: + from .clinet import * +except ImportError: + pass + +try: + from.server import * +except ImportError: + pass \ No newline at end of file diff --git a/ftespnow/ftespnow/ftespnow/__init__.py b/ftespnow/ftespnow/ftespnow/__init__.py new file mode 100644 index 000000000..a4eccc5a1 --- /dev/null +++ b/ftespnow/ftespnow/ftespnow/__init__.py @@ -0,0 +1,9 @@ +try: + from .client import * +except ImportError: + pass + +try: + from .server import * +except ImportError: + pass diff --git a/ftespnow/ftespnow/manifest.py b/ftespnow/ftespnow/manifest.py new file mode 100644 index 000000000..9b87abb7c --- /dev/null +++ b/ftespnow/ftespnow/manifest.py @@ -0,0 +1,6 @@ +metadata( + description="Extends the micropython espnow module with methods to support file transfers.", + version="0.1.0", +) + +package("ftespnow") diff --git a/ftespnow/manifest.py b/ftespnow/manifest.py new file mode 100644 index 000000000..6591b0600 --- /dev/null +++ b/ftespnow/manifest.py @@ -0,0 +1,6 @@ +metadata( + description="Extends the micropython espnow module with methods to support file transfers.", + version="0.1.0", +) + +module("ftespnow") \ No newline at end of file From bb8d7011cc0591a6fba97665ca4a246fac66227d Mon Sep 17 00:00:00 2001 From: Guilherme Laurindo Schneck Date: Fri, 10 Apr 2026 23:58:23 +0200 Subject: [PATCH 02/10] ftespnow: Move library to correct folder. Signed-off-by: Guilherme Laurindo Schneck --- .../ftespnow}/examples/client_side_example.py | 0 .../ftespnow}/examples/server_side_example.py | 0 .../ftespnow}/ftespnow-client/ftespnow/client.py | 0 {ftespnow => micropython/ftespnow}/ftespnow-client/manifest.py | 0 .../ftespnow}/ftespnow-server/ftespnow/server.py | 0 {ftespnow => micropython/ftespnow}/ftespnow-server/manifest.py | 0 {ftespnow => micropython/ftespnow}/ftespnow/__init__.py | 0 {ftespnow => micropython/ftespnow}/ftespnow/ftespnow/__init__.py | 0 {ftespnow => micropython/ftespnow}/ftespnow/manifest.py | 0 {ftespnow => micropython/ftespnow}/manifest.py | 0 10 files changed, 0 insertions(+), 0 deletions(-) rename {ftespnow => micropython/ftespnow}/examples/client_side_example.py (100%) rename {ftespnow => micropython/ftespnow}/examples/server_side_example.py (100%) rename {ftespnow => micropython/ftespnow}/ftespnow-client/ftespnow/client.py (100%) rename {ftespnow => micropython/ftespnow}/ftespnow-client/manifest.py (100%) rename {ftespnow => micropython/ftespnow}/ftespnow-server/ftespnow/server.py (100%) rename {ftespnow => micropython/ftespnow}/ftespnow-server/manifest.py (100%) rename {ftespnow => micropython/ftespnow}/ftespnow/__init__.py (100%) rename {ftespnow => micropython/ftespnow}/ftespnow/ftespnow/__init__.py (100%) rename {ftespnow => micropython/ftespnow}/ftespnow/manifest.py (100%) rename {ftespnow => micropython/ftespnow}/manifest.py (100%) diff --git a/ftespnow/examples/client_side_example.py b/micropython/ftespnow/examples/client_side_example.py similarity index 100% rename from ftespnow/examples/client_side_example.py rename to micropython/ftespnow/examples/client_side_example.py diff --git a/ftespnow/examples/server_side_example.py b/micropython/ftespnow/examples/server_side_example.py similarity index 100% rename from ftespnow/examples/server_side_example.py rename to micropython/ftespnow/examples/server_side_example.py diff --git a/ftespnow/ftespnow-client/ftespnow/client.py b/micropython/ftespnow/ftespnow-client/ftespnow/client.py similarity index 100% rename from ftespnow/ftespnow-client/ftespnow/client.py rename to micropython/ftespnow/ftespnow-client/ftespnow/client.py diff --git a/ftespnow/ftespnow-client/manifest.py b/micropython/ftespnow/ftespnow-client/manifest.py similarity index 100% rename from ftespnow/ftespnow-client/manifest.py rename to micropython/ftespnow/ftespnow-client/manifest.py diff --git a/ftespnow/ftespnow-server/ftespnow/server.py b/micropython/ftespnow/ftespnow-server/ftespnow/server.py similarity index 100% rename from ftespnow/ftespnow-server/ftespnow/server.py rename to micropython/ftespnow/ftespnow-server/ftespnow/server.py diff --git a/ftespnow/ftespnow-server/manifest.py b/micropython/ftespnow/ftespnow-server/manifest.py similarity index 100% rename from ftespnow/ftespnow-server/manifest.py rename to micropython/ftespnow/ftespnow-server/manifest.py diff --git a/ftespnow/ftespnow/__init__.py b/micropython/ftespnow/ftespnow/__init__.py similarity index 100% rename from ftespnow/ftespnow/__init__.py rename to micropython/ftespnow/ftespnow/__init__.py diff --git a/ftespnow/ftespnow/ftespnow/__init__.py b/micropython/ftespnow/ftespnow/ftespnow/__init__.py similarity index 100% rename from ftespnow/ftespnow/ftespnow/__init__.py rename to micropython/ftespnow/ftespnow/ftespnow/__init__.py diff --git a/ftespnow/ftespnow/manifest.py b/micropython/ftespnow/ftespnow/manifest.py similarity index 100% rename from ftespnow/ftespnow/manifest.py rename to micropython/ftespnow/ftespnow/manifest.py diff --git a/ftespnow/manifest.py b/micropython/ftespnow/manifest.py similarity index 100% rename from ftespnow/manifest.py rename to micropython/ftespnow/manifest.py From 13cd54c16887cccdc894b405f08c798d65977f66 Mon Sep 17 00:00:00 2001 From: Guilherme Laurindo Schneck Date: Sat, 11 Apr 2026 00:01:11 +0200 Subject: [PATCH 03/10] ftespnow: Delete extra manifest.py file. Signed-off-by: Guilherme Laurindo Schneck --- micropython/ftespnow/manifest.py | 6 ------ 1 file changed, 6 deletions(-) delete mode 100644 micropython/ftespnow/manifest.py diff --git a/micropython/ftespnow/manifest.py b/micropython/ftespnow/manifest.py deleted file mode 100644 index 6591b0600..000000000 --- a/micropython/ftespnow/manifest.py +++ /dev/null @@ -1,6 +0,0 @@ -metadata( - description="Extends the micropython espnow module with methods to support file transfers.", - version="0.1.0", -) - -module("ftespnow") \ No newline at end of file From 58ca608f18ba9b557ec541dbfe9bb9dbc1914e95 Mon Sep 17 00:00:00 2001 From: Guilherme Laurindo Schneck Date: Sat, 11 Apr 2026 00:04:25 +0200 Subject: [PATCH 04/10] ftespnow: Fix spelling mistakes and code formatting issues. Signed-off-by: Guilherme Laurindo Schneck --- micropython/ftespnow/ftespnow/__init__.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/micropython/ftespnow/ftespnow/__init__.py b/micropython/ftespnow/ftespnow/__init__.py index f85254af3..a4eccc5a1 100644 --- a/micropython/ftespnow/ftespnow/__init__.py +++ b/micropython/ftespnow/ftespnow/__init__.py @@ -1,9 +1,9 @@ try: - from .clinet import * + from .client import * except ImportError: pass try: - from.server import * + from .server import * except ImportError: - pass \ No newline at end of file + pass From a28e4c586efc266b466bb1b95d51ae79fda88f69 Mon Sep 17 00:00:00 2001 From: Guilherme Laurindo Schneck Date: Sat, 11 Apr 2026 00:06:28 +0200 Subject: [PATCH 05/10] ftespnow: Delete extra init file. Signed-off-by: Guilherme Laurindo Schneck --- micropython/ftespnow/ftespnow/__init__.py | 9 --------- 1 file changed, 9 deletions(-) delete mode 100644 micropython/ftespnow/ftespnow/__init__.py diff --git a/micropython/ftespnow/ftespnow/__init__.py b/micropython/ftespnow/ftespnow/__init__.py deleted file mode 100644 index a4eccc5a1..000000000 --- a/micropython/ftespnow/ftespnow/__init__.py +++ /dev/null @@ -1,9 +0,0 @@ -try: - from .client import * -except ImportError: - pass - -try: - from .server import * -except ImportError: - pass From 5b17fcf5e36ea219513bd307168bbf854b7af67c Mon Sep 17 00:00:00 2001 From: Guilherme Laurindo Schneck Date: Sat, 11 Apr 2026 00:18:10 +0200 Subject: [PATCH 06/10] ftespnow: Fix code formatting errors. Signed-off-by: Guilherme Laurindo Schneck --- .../ftespnow/examples/client_side_example.py | 4 +- .../ftespnow/examples/server_side_example.py | 6 +-- .../ftespnow-client/ftespnow/client.py | 46 +++++++++---------- .../ftespnow-server/ftespnow/server.py | 42 ++++++++--------- 4 files changed, 49 insertions(+), 49 deletions(-) diff --git a/micropython/ftespnow/examples/client_side_example.py b/micropython/ftespnow/examples/client_side_example.py index 90ccfada7..e12ae3219 100644 --- a/micropython/ftespnow/examples/client_side_example.py +++ b/micropython/ftespnow/examples/client_side_example.py @@ -38,7 +38,7 @@ # Write received data to .txt file txt_received = esp.receive_to_txt( "filepath/filename.txt", mode="w" - ) # Set mode to 'w' so file is truncated before writing +) # Set mode to 'w' so file is truncated before writing if txt_received: print("File received successfully") else: @@ -47,7 +47,7 @@ # Write received data to .json file json_received = esp.receive_to_json( "filepath/filename.json", mode="w" - ) # Set mode to 'w' so file is truncated before writing +) # Set mode to 'w' so file is truncated before writing if json_received: print("File received successfully") else: diff --git a/micropython/ftespnow/examples/server_side_example.py b/micropython/ftespnow/examples/server_side_example.py index 836030d4f..44f506587 100644 --- a/micropython/ftespnow/examples/server_side_example.py +++ b/micropython/ftespnow/examples/server_side_example.py @@ -7,7 +7,7 @@ message = "Hello" peer = "a4f00f772d15" # Mac address of the client that you want to send data to sent = esp.send_message(peer, message) -if sent: # Check if client received the data +if sent: # Check if client received the data print("Message received by clientclient") else: print("Message not received by client") @@ -36,7 +36,7 @@ # Write received data to .txt file txt_received = esp.receive_to_txt( "filepath/filename.txt", mode="w" - ) # Set mode to 'w' so file is truncated before writing +) # Set mode to 'w' so file is truncated before writing if txt_received: print("File received successfully") else: @@ -45,7 +45,7 @@ # Write received data to .json file json_received = esp.receive_to_json( "filepath/filename.json", mode="w" - ) # Set mode to 'w' so file is truncated before writing +) # Set mode to 'w' so file is truncated before writing if json_received: # Check if any data was received print("File received successfully") else: diff --git a/micropython/ftespnow/ftespnow-client/ftespnow/client.py b/micropython/ftespnow/ftespnow-client/ftespnow/client.py index 4b931e658..7688eedbc 100644 --- a/micropython/ftespnow/ftespnow-client/ftespnow/client.py +++ b/micropython/ftespnow/ftespnow-client/ftespnow/client.py @@ -3,19 +3,19 @@ class CLIENT: - def __init__(self, *, timeout: int = 5) -> None: + def __init__(self, *, timeout :int = 5) -> None: self.esp = espnow.ESPNow() self.timeout = timeout - def configure(self, *, timeout: int = 5) -> None: + def configure(self, *, timeout :int = 5) -> None: self.timeout: int = timeout - def connect(self, peer: str) -> None: + def connect(self, peer :str) -> None: self.peer: str = peer self.esp.active(True) self.esp.add_peer(self.peer) - def send_message(self, data: str) -> bool: + def send_message(self, data :str) -> bool: """ Send a string @@ -28,7 +28,7 @@ def send_message(self, data: str) -> bool: bool: Confirmation flag (`True` if data was received, `False` otherwise) """ - ack: bool = self.esp.send(self.peer, data) + ack :bool = self.esp.send(self.peer, data) return ack def receive_message(self, recv_timeout :int = 5) -> list | None: @@ -49,7 +49,7 @@ def receive_message(self, recv_timeout :int = 5) -> list | None: return return received - def send_txt(self, filename: str) -> bool: + def send_txt(self, filename :str) -> bool: """ Parse and send a `.txt` file as a `string` @@ -63,11 +63,11 @@ def send_txt(self, filename: str) -> bool: """ with open(filename, "r") as f: - data: str = str(f.readlines()) - sent: bool = self.send_message(data) + data :str = str(f.readlines()) + sent :bool = self.send_message(data) return sent - def send_json(self, filename: str, *, indent: int = 4) -> bool: + def send_json(self, filename :str, *, indent :int = 4) -> bool: """ Parse and send a `.json` file as a `string` @@ -84,11 +84,11 @@ def send_json(self, filename: str, *, indent: int = 4) -> bool: with open(filename, "r") as f: unparsed = json.load(f) - parsed: str = json.dumps(unparsed, indent=indent) - sent: bool = self.send_message(parsed) + parsed :str = json.dumps(unparsed, indent=indent) + sent :bool = self.send_message(parsed) return sent - def receive_to_txt(self, target_file: str, mode: str = "a") -> bool: + def receive_to_txt(self, target_file :str, mode :str = "a") -> bool: """ Write received `string` into a `.txt` file. @@ -126,11 +126,11 @@ def receive_to_txt(self, target_file: str, mode: str = "a") -> bool: if ".txt" not in target_file: raise SyntaxError("File format must be .txt") try: - received: bool = False - data: list | None = self.receive_message() + received :bool = False + data :list | None = self.receive_message() if data is None: return received - data_list: list[str] = str(data[-1]).split("\n") + data_list :list[str] = str(data[-1]).split("\n") if data_list[-1] == "": data_list = data_list[:-1] with open(target_file, mode) as f: @@ -139,7 +139,7 @@ def receive_to_txt(self, target_file: str, mode: str = "a") -> bool: except SyntaxError: raise - def receive_to_json(self, target_file: str, mode: str = "a") -> bool: + def receive_to_json(self, target_file :str, mode :str = "a") -> bool: """ Write received `string` into a `.json` file. @@ -177,13 +177,13 @@ def receive_to_json(self, target_file: str, mode: str = "a") -> bool: if ".json" not in target_file: raise SyntaxError("File format must be .json") try: - received: bool = False - data: list | None = self.receive_message() + received :bool = False + data :list | None = self.receive_message() if data is None: return received - mac: str = str(data[0]) + mac :str = str(data[0]) message = json.loads(str(data[-1])) - unparsed: dict = {"mac": mac, "message": message} + unparsed :dict = {"mac": mac, "message": message} with open(target_file, mode) as f: json.dump(unparsed, f) return not received @@ -203,10 +203,10 @@ def receive_to_dict(self) -> dict: unparsed (dict): `dictionary` object containing unparsed equivalent of the received `.json` """ - data: list | None = self.receive_message() + data :list | None = self.receive_message() if data is None: return {} - mac: str = str(data[0]) + mac :str = str(data[0]) message = json.loads(str(data[-1])) - unparsed: dict = {"mac": mac, "message": message} + unparsed :dict = {"mac": mac, "message": message} return unparsed diff --git a/micropython/ftespnow/ftespnow-server/ftespnow/server.py b/micropython/ftespnow/ftespnow-server/ftespnow/server.py index 9fdb61c3e..218b27956 100644 --- a/micropython/ftespnow/ftespnow-server/ftespnow/server.py +++ b/micropython/ftespnow/ftespnow-server/ftespnow/server.py @@ -2,14 +2,14 @@ import json class SERVER: - def __init__(self, *, timeout: int = 5) -> None: + def __init__(self, *, timeout :int = 5) -> None: self.esp = espnow.ESPNow() self.timeout = timeout - def configure(self, *, timeout: int = 5) -> None: + def configure(self, *, timeout :int = 5) -> None: self.timeout = timeout - def send_message(self, peer: str, data: str) -> bool: + def send_message(self, peer :str, data :str) -> bool: """ Send a string @@ -24,7 +24,7 @@ def send_message(self, peer: str, data: str) -> bool: bool: Confirmation flag (`True` if data was received, `False` otherwise) """ - ack: bool = self.esp.send(peer, data) + ack :bool = self.esp.send(peer, data) return ack def receive_message(self, recv_timeout :int = 5) -> list | None: @@ -45,7 +45,7 @@ def receive_message(self, recv_timeout :int = 5) -> list | None: return return received - def send_txt(self, peer: str, filename: str) -> bool: + def send_txt(self, peer :str, filename :str) -> bool: """ Parse and send a `.txt` file as a `string` @@ -61,11 +61,11 @@ def send_txt(self, peer: str, filename: str) -> bool: """ with open(filename, "r") as f: - data: str = str(f.readlines()) - sent: bool = self.send_message(peer, data) + data :str = str(f.readlines()) + sent :bool = self.send_message(peer, data) return sent - def send_json(self, peer: str, filename: str, *, indent: int = 4) -> bool: + def send_json(self, peer :str, filename :str, *, indent :int = 4) -> bool: """ Parse and send a `.json` file as a `string` @@ -84,11 +84,11 @@ def send_json(self, peer: str, filename: str, *, indent: int = 4) -> bool: with open(filename, "r") as f: unparsed = json.load(f) - parsed: str = json.dumps(unparsed, indent=indent) - sent: bool = self.send_message(peer, parsed) + parsed :str = json.dumps(unparsed, indent=indent) + sent :bool = self.send_message(peer, parsed) return sent - def receive_to_txt(self, target_file: str, mode: str = "a") -> bool: + def receive_to_txt(self, target_file :str, mode :str = "a") -> bool: """ Write received `string` into a `.txt` file. @@ -126,10 +126,10 @@ def receive_to_txt(self, target_file: str, mode: str = "a") -> bool: if ".txt" not in target_file: raise SyntaxError("File format must be .txt") try: - data: list | None = self.receive_message() + data :list | None = self.receive_message() if data is None: return False - data_list: list[str] = str(data[-1]).split("\n") + data_list :list[str] = str(data[-1]).split("\n") if data_list[-1] == "": data_list = data_list[:-1] with open(target_file, mode) as f: @@ -138,7 +138,7 @@ def receive_to_txt(self, target_file: str, mode: str = "a") -> bool: except SyntaxError: raise - def receive_to_json(self, target_file: str, mode: str = "a") -> bool: + def receive_to_json(self, target_file :str, mode :str = "a") -> bool: """ Write received `string` into a `.json` file. @@ -176,13 +176,13 @@ def receive_to_json(self, target_file: str, mode: str = "a") -> bool: if ".json" not in target_file: raise SyntaxError("File format must be .json") try: - received: bool = False - data: list | None = self.receive_message() + received :bool = False + data :list | None = self.receive_message() if data is None: return received - mac: str = str(data[0]) + mac :str = str(data[0]) message = json.loads(str(data[-1])) - unparsed: dict = {"mac": mac, "message": message} + unparsed :dict = {"mac": mac, "message": message} with open(target_file, mode) as f: json.dump(unparsed, f) return not received @@ -202,10 +202,10 @@ def receive_to_dict(self) -> dict: unparsed (dict): `dictionary` object containing unparsed equivalent of the received `.json` """ - data: list | None = self.receive_message() + data :list | None = self.receive_message() if data is None: return {} - mac: str = str(data[0]) + mac :str = str(data[0]) message = json.loads(str(data[-1])) - unparsed: dict = {"mac": mac, "message": message} + unparsed :dict = {"mac": mac, "message": message} return unparsed From b7cf370dc1d980fa8522b546a5ee46ab35c0ea6a Mon Sep 17 00:00:00 2001 From: Guilherme Laurindo Schneck Date: Sat, 11 Apr 2026 00:22:01 +0200 Subject: [PATCH 07/10] ftespnow: Fix code formatting errors. Signed-off-by: Guilherme Laurindo Schneck --- .../ftespnow-client/ftespnow/client.py | 28 +++++++++---------- .../ftespnow-server/ftespnow/server.py | 28 +++++++++---------- 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/micropython/ftespnow/ftespnow-client/ftespnow/client.py b/micropython/ftespnow/ftespnow-client/ftespnow/client.py index 7688eedbc..9b40bc63d 100644 --- a/micropython/ftespnow/ftespnow-client/ftespnow/client.py +++ b/micropython/ftespnow/ftespnow-client/ftespnow/client.py @@ -63,8 +63,8 @@ def send_txt(self, filename :str) -> bool: """ with open(filename, "r") as f: - data :str = str(f.readlines()) - sent :bool = self.send_message(data) + data: str = str(f.readlines()) + sent: bool = self.send_message(data) return sent def send_json(self, filename :str, *, indent :int = 4) -> bool: @@ -84,8 +84,8 @@ def send_json(self, filename :str, *, indent :int = 4) -> bool: with open(filename, "r") as f: unparsed = json.load(f) - parsed :str = json.dumps(unparsed, indent=indent) - sent :bool = self.send_message(parsed) + parsed: str = json.dumps(unparsed, indent=indent) + sent: bool = self.send_message(parsed) return sent def receive_to_txt(self, target_file :str, mode :str = "a") -> bool: @@ -126,11 +126,11 @@ def receive_to_txt(self, target_file :str, mode :str = "a") -> bool: if ".txt" not in target_file: raise SyntaxError("File format must be .txt") try: - received :bool = False - data :list | None = self.receive_message() + received: bool = False + data: list | None = self.receive_message() if data is None: return received - data_list :list[str] = str(data[-1]).split("\n") + data_list: list[str] = str(data[-1]).split("\n") if data_list[-1] == "": data_list = data_list[:-1] with open(target_file, mode) as f: @@ -177,13 +177,13 @@ def receive_to_json(self, target_file :str, mode :str = "a") -> bool: if ".json" not in target_file: raise SyntaxError("File format must be .json") try: - received :bool = False - data :list | None = self.receive_message() + received: bool = False + data: list | None = self.receive_message() if data is None: return received - mac :str = str(data[0]) + mac: str = str(data[0]) message = json.loads(str(data[-1])) - unparsed :dict = {"mac": mac, "message": message} + unparsed: dict = {"mac": mac, "message": message} with open(target_file, mode) as f: json.dump(unparsed, f) return not received @@ -203,10 +203,10 @@ def receive_to_dict(self) -> dict: unparsed (dict): `dictionary` object containing unparsed equivalent of the received `.json` """ - data :list | None = self.receive_message() + data: list | None = self.receive_message() if data is None: return {} - mac :str = str(data[0]) + mac: str = str(data[0]) message = json.loads(str(data[-1])) - unparsed :dict = {"mac": mac, "message": message} + unparsed: dict = {"mac": mac, "message": message} return unparsed diff --git a/micropython/ftespnow/ftespnow-server/ftespnow/server.py b/micropython/ftespnow/ftespnow-server/ftespnow/server.py index 218b27956..fb13021e7 100644 --- a/micropython/ftespnow/ftespnow-server/ftespnow/server.py +++ b/micropython/ftespnow/ftespnow-server/ftespnow/server.py @@ -24,7 +24,7 @@ def send_message(self, peer :str, data :str) -> bool: bool: Confirmation flag (`True` if data was received, `False` otherwise) """ - ack :bool = self.esp.send(peer, data) + ack: bool = self.esp.send(peer, data) return ack def receive_message(self, recv_timeout :int = 5) -> list | None: @@ -61,8 +61,8 @@ def send_txt(self, peer :str, filename :str) -> bool: """ with open(filename, "r") as f: - data :str = str(f.readlines()) - sent :bool = self.send_message(peer, data) + data: str = str(f.readlines()) + sent: bool = self.send_message(peer, data) return sent def send_json(self, peer :str, filename :str, *, indent :int = 4) -> bool: @@ -84,8 +84,8 @@ def send_json(self, peer :str, filename :str, *, indent :int = 4) -> bool: with open(filename, "r") as f: unparsed = json.load(f) - parsed :str = json.dumps(unparsed, indent=indent) - sent :bool = self.send_message(peer, parsed) + parsed: str = json.dumps(unparsed, indent=indent) + sent: bool = self.send_message(peer, parsed) return sent def receive_to_txt(self, target_file :str, mode :str = "a") -> bool: @@ -126,10 +126,10 @@ def receive_to_txt(self, target_file :str, mode :str = "a") -> bool: if ".txt" not in target_file: raise SyntaxError("File format must be .txt") try: - data :list | None = self.receive_message() + data: list | None = self.receive_message() if data is None: return False - data_list :list[str] = str(data[-1]).split("\n") + data_list: list[str] = str(data[-1]).split("\n") if data_list[-1] == "": data_list = data_list[:-1] with open(target_file, mode) as f: @@ -176,13 +176,13 @@ def receive_to_json(self, target_file :str, mode :str = "a") -> bool: if ".json" not in target_file: raise SyntaxError("File format must be .json") try: - received :bool = False - data :list | None = self.receive_message() + received: bool = False + data: list | None = self.receive_message() if data is None: return received - mac :str = str(data[0]) + mac: str = str(data[0]) message = json.loads(str(data[-1])) - unparsed :dict = {"mac": mac, "message": message} + unparsed: dict = {"mac": mac, "message": message} with open(target_file, mode) as f: json.dump(unparsed, f) return not received @@ -202,10 +202,10 @@ def receive_to_dict(self) -> dict: unparsed (dict): `dictionary` object containing unparsed equivalent of the received `.json` """ - data :list | None = self.receive_message() + data: list | None = self.receive_message() if data is None: return {} - mac :str = str(data[0]) + mac: str = str(data[0]) message = json.loads(str(data[-1])) - unparsed :dict = {"mac": mac, "message": message} + unparsed: dict = {"mac": mac, "message": message} return unparsed From a3df973f5935b6adba4bec545b27a7faa1793bab Mon Sep 17 00:00:00 2001 From: Guilherme Laurindo Schneck Date: Sat, 11 Apr 2026 00:26:51 +0200 Subject: [PATCH 08/10] ftespnow: Fix code formatting errors. Signed-off-by: Guilherme Laurindo Schneck --- .../ftespnow-client/ftespnow/client.py | 20 +++++++++---------- .../ftespnow-server/ftespnow/server.py | 16 +++++++-------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/micropython/ftespnow/ftespnow-client/ftespnow/client.py b/micropython/ftespnow/ftespnow-client/ftespnow/client.py index 9b40bc63d..f0bccbe69 100644 --- a/micropython/ftespnow/ftespnow-client/ftespnow/client.py +++ b/micropython/ftespnow/ftespnow-client/ftespnow/client.py @@ -3,19 +3,19 @@ class CLIENT: - def __init__(self, *, timeout :int = 5) -> None: + def __init__(self, *, timeout: int = 5) -> None: self.esp = espnow.ESPNow() self.timeout = timeout - def configure(self, *, timeout :int = 5) -> None: + def configure(self, *, timeout: int = 5) -> None: self.timeout: int = timeout - def connect(self, peer :str) -> None: + def connect(self, peer: str) -> None: self.peer: str = peer self.esp.active(True) self.esp.add_peer(self.peer) - def send_message(self, data :str) -> bool: + def send_message(self, data: str) -> bool: """ Send a string @@ -28,10 +28,10 @@ def send_message(self, data :str) -> bool: bool: Confirmation flag (`True` if data was received, `False` otherwise) """ - ack :bool = self.esp.send(self.peer, data) + ack: bool = self.esp.send(self.peer, data) return ack - def receive_message(self, recv_timeout :int = 5) -> list | None: + def receive_message(self, recv_timeout: int = 5) -> list | None: """ Receive a string @@ -49,7 +49,7 @@ def receive_message(self, recv_timeout :int = 5) -> list | None: return return received - def send_txt(self, filename :str) -> bool: + def send_txt(self, filename: str) -> bool: """ Parse and send a `.txt` file as a `string` @@ -67,7 +67,7 @@ def send_txt(self, filename :str) -> bool: sent: bool = self.send_message(data) return sent - def send_json(self, filename :str, *, indent :int = 4) -> bool: + def send_json(self, filename: str, *, indent: int = 4) -> bool: """ Parse and send a `.json` file as a `string` @@ -88,7 +88,7 @@ def send_json(self, filename :str, *, indent :int = 4) -> bool: sent: bool = self.send_message(parsed) return sent - def receive_to_txt(self, target_file :str, mode :str = "a") -> bool: + def receive_to_txt(self, target_file: str, mode: str = "a") -> bool: """ Write received `string` into a `.txt` file. @@ -139,7 +139,7 @@ def receive_to_txt(self, target_file :str, mode :str = "a") -> bool: except SyntaxError: raise - def receive_to_json(self, target_file :str, mode :str = "a") -> bool: + def receive_to_json(self, target_file: str, mode: str = "a") -> bool: """ Write received `string` into a `.json` file. diff --git a/micropython/ftespnow/ftespnow-server/ftespnow/server.py b/micropython/ftespnow/ftespnow-server/ftespnow/server.py index fb13021e7..a9645744f 100644 --- a/micropython/ftespnow/ftespnow-server/ftespnow/server.py +++ b/micropython/ftespnow/ftespnow-server/ftespnow/server.py @@ -2,14 +2,14 @@ import json class SERVER: - def __init__(self, *, timeout :int = 5) -> None: + def __init__(self, *, timeout: int = 5) -> None: self.esp = espnow.ESPNow() self.timeout = timeout - def configure(self, *, timeout :int = 5) -> None: + def configure(self, *, timeout: int = 5) -> None: self.timeout = timeout - def send_message(self, peer :str, data :str) -> bool: + def send_message(self, peer: str, data: str) -> bool: """ Send a string @@ -27,7 +27,7 @@ def send_message(self, peer :str, data :str) -> bool: ack: bool = self.esp.send(peer, data) return ack - def receive_message(self, recv_timeout :int = 5) -> list | None: + def receive_message(self, recv_timeout: int = 5) -> list | None: """ Receive a string @@ -45,7 +45,7 @@ def receive_message(self, recv_timeout :int = 5) -> list | None: return return received - def send_txt(self, peer :str, filename :str) -> bool: + def send_txt(self, peer: str, filename: str) -> bool: """ Parse and send a `.txt` file as a `string` @@ -65,7 +65,7 @@ def send_txt(self, peer :str, filename :str) -> bool: sent: bool = self.send_message(peer, data) return sent - def send_json(self, peer :str, filename :str, *, indent :int = 4) -> bool: + def send_json(self, peer: str, filename: str, *, indent: int = 4) -> bool: """ Parse and send a `.json` file as a `string` @@ -88,7 +88,7 @@ def send_json(self, peer :str, filename :str, *, indent :int = 4) -> bool: sent: bool = self.send_message(peer, parsed) return sent - def receive_to_txt(self, target_file :str, mode :str = "a") -> bool: + def receive_to_txt(self, target_file: str, mode: str = "a") -> bool: """ Write received `string` into a `.txt` file. @@ -138,7 +138,7 @@ def receive_to_txt(self, target_file :str, mode :str = "a") -> bool: except SyntaxError: raise - def receive_to_json(self, target_file :str, mode :str = "a") -> bool: + def receive_to_json(self, target_file: str, mode: str = "a") -> bool: """ Write received `string` into a `.json` file. From e334e65f9d6b69c723737847a4c67ec386120b8a Mon Sep 17 00:00:00 2001 From: Guilherme Laurindo Schneck Date: Sat, 11 Apr 2026 00:27:49 +0200 Subject: [PATCH 09/10] ftespnow: Fix code formatting errors. Signed-off-by: Guilherme Laurindo Schneck --- micropython/ftespnow/ftespnow-server/ftespnow/server.py | 1 + 1 file changed, 1 insertion(+) diff --git a/micropython/ftespnow/ftespnow-server/ftespnow/server.py b/micropython/ftespnow/ftespnow-server/ftespnow/server.py index a9645744f..840cff10e 100644 --- a/micropython/ftespnow/ftespnow-server/ftespnow/server.py +++ b/micropython/ftespnow/ftespnow-server/ftespnow/server.py @@ -1,6 +1,7 @@ import espnow import json + class SERVER: def __init__(self, *, timeout: int = 5) -> None: self.esp = espnow.ESPNow() From 52934dd99989659a6bd5516c9978e74c9b12ca7c Mon Sep 17 00:00:00 2001 From: Guilherme Laurindo Schneck Date: Sat, 11 Apr 2026 00:29:45 +0200 Subject: [PATCH 10/10] ftespnow/examples: Fix code formatting errors. Signed-off-by: Guilherme Laurindo Schneck --- micropython/ftespnow/examples/server_side_example.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/micropython/ftespnow/examples/server_side_example.py b/micropython/ftespnow/examples/server_side_example.py index 44f506587..cfa2b7658 100644 --- a/micropython/ftespnow/examples/server_side_example.py +++ b/micropython/ftespnow/examples/server_side_example.py @@ -46,7 +46,7 @@ json_received = esp.receive_to_json( "filepath/filename.json", mode="w" ) # Set mode to 'w' so file is truncated before writing -if json_received: # Check if any data was received +if json_received: # Check if any data was received print("File received successfully") else: print("No file received. Destination file was not created/modified")