Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
PYROBUSTA_VERSION := v0.5.0
PYROBUSTA_VERSION := v0.6.0
DEVICE ?= u0

SRC_DIR := src
Expand Down Expand Up @@ -126,6 +126,8 @@ redeploy: clean build clean-device deploy
# -----------------------------
.PHONY: publish
publish:
test -n "$(DIST_DIR)" && rm -rf "$(PWD)/$(DIST_DIR)"
mkdir -p "$(PWD)/$(DIST_DIR)"
@sed -E -i.bak 's/(PYROBUSTA_VERSION[[:space:]]*=[[:space:]]*)"[^"]*"/\1"$(PYROBUSTA_VERSION)"/' \
$(SRC_DIR)/pyrobusta/utils/config.py \
&& rm -f $(SRC_DIR)/pyrobusta/utils/config.py.bak
Expand Down
2 changes: 1 addition & 1 deletion assets/www/examples.html
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ <h2>Demo Application</h2>

<div class="footer">
<hr>
<address>PyRobusta v0.5.0 Web Server</address>
<address>PyRobusta v0.6.0 Web Server</address>
</div>
</body>
</html>
2 changes: 1 addition & 1 deletion assets/www/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ <h2>Available Resources</h2>

<div class="footer">
<hr>
<address>PyRobusta v0.5.0 Web Server</address>
<address>PyRobusta v0.6.0 Web Server</address>
</div>

</body>
Expand Down
105 changes: 77 additions & 28 deletions dist/pyrobusta/assets/www/examples.html
Original file line number Diff line number Diff line change
Expand Up @@ -64,44 +64,77 @@ <h2>Server configuration</h2>

<hr>

<h2>Simple Server Application</h2>
<p>The below example demonstrates how to set up a simple application, exposed at /app.</p>
<textarea readonly="true" rows="37">
<h2>Demo Application</h2>
<p>The below application demonstrates common use cases for handling headers, status codes, query parameters, and wilcard URLs.</p>
<ol>
<li><b>/version</b> returns the version of the application.
<br>Optionally, the server version is also included in the response if the 'detailed' query parameter is set to true.
</li>
<li><b>/app/version</b> or <b>/server/version</b> returns the designated version string, handled by a single endpoint definition with a wildcard URL.
</li>
</ol>
<textarea readonly="true" rows="62">
# /app.py

import asyncio
from gc import mem_free, mem_alloc

from pyrobusta.server.http_server import HttpServer
from pyrobusta.server import http_server
from pyrobusta.protocol.http import HttpEngine
from pyrobusta.utils import logging
from pyrobusta.utils.config import PYROBUSTA_VERSION

APP_VERSION = "v0.0.1"

@HttpEngine.route("/app", "GET")
def app(http_ctx, payload):
free = mem_free()
value_format = "bytes"

@HttpEngine.route("/version", "GET")
def version(http_ctx, _):
include_server_version = False

if http_ctx.query:
value_format = http_ctx.get_url_encoded_query_param(
http_ctx.query, "format", default="bytes"
)
if value_format not in ("%", "bytes"):
raise ValueError("invalid format")
is_detailed = http_ctx.get_url_encoded_query_param(
http_ctx.query, "detailed", default="false"
).lower()

if is_detailed not in ("true", "false"):
http_ctx.terminate(400, True)
return "text/plain", "Invalid query"

include_server_version = is_detailed.lower() == "true"

if http_ctx.headers.get("accept") == "application/json":
version_dict = {"app_version": APP_VERSION}
if include_server_version:
version_dict["server_version"] = PYROBUSTA_VERSION
return "application/json", version_dict

version_text = f"app_version: {APP_VERSION}\n"
if include_server_version:
version_text += f"server_version: {PYROBUSTA_VERSION}\n"
return "text/plain", version_text


@HttpEngine.route("/{app_or_server}/version", "GET")
def version(http_ctx, _):
include_server_version = False
resource = http_ctx.url.split(b"/")[1]

if resource not in (b"app", b"server"):
http_ctx.terminate(404, True)
return "text/plain", "Not found"

if value_format == "%":
free = round(100 * free / (free + mem_alloc()), 2)
version_string = APP_VERSION if resource == b"app" else PYROBUSTA_VERSION

return "text/plain", (f"Free memory [{value_format}]: {free}\n")
if http_ctx.headers.get("accept") == "application/json":
return "application/json", {"version": version_string}

async def run_server():
server = HttpServer()
return "text/plain", f"{version_string}\n"


async def main():
server = http_server.HttpServer()
asyncio.create_task(server.start_socket_server())
while True:
await asyncio.sleep(1)

def main():
asyncio.run(run_server())
</textarea>
<textarea readonly="true" rows="15">
# /boot.py
Expand Down Expand Up @@ -143,17 +176,33 @@ <h2>Simple Server Application</h2>
</textarea>

<p>Use curl to test your application.</p>
<textarea readonly="true" rows="6">
$ curl "http://192.168.1.101/app"
Free memory [bytes]: 115456
<textarea readonly="true" rows="22">
$ curl "http://192.168.1.101/version"
app_version: v0.0.1

$ curl "http://192.168.1.101/version?detailed=True"
app_version: v0.0.1
server_version: v0.5.0

$ curl -H "Accept: application/json" "http://192.168.1.101/version?detailed=True"
{"server_version": "v0.5.0", "app_version": "v0.0.1"}

$ curl "http://192.168.1.101/app/version"
v0.0.1

$ curl "http://192.168.1.101/server/version"
v0.5.0

$ curl -H "Accept: application/json" "http://192.168.1.101/server/version"
{"version": "v0.5.0"}

$ curl "http://192.168.1.101/app?format=%"
Free memory [%]: 71.76
$ curl 192.168.1.101/application/version
Not found
</textarea>

<div class="footer">
<hr>
<address>PyRobusta v0.5.0 Web Server</address>
<address>PyRobusta v0.6.0 Web Server</address>
</div>
</body>
</html>
2 changes: 1 addition & 1 deletion dist/pyrobusta/assets/www/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ <h2>Available Resources</h2>

<div class="footer">
<hr>
<address>PyRobusta v0.5.0 Web Server</address>
<address>PyRobusta v0.6.0 Web Server</address>
</div>

</body>
Expand Down
Binary file modified dist/pyrobusta/bindings/http_connection.mpy
Binary file not shown.
Binary file modified dist/pyrobusta/protocol/http.mpy
Binary file not shown.
Binary file modified dist/pyrobusta/protocol/http_file_server.mpy
Binary file not shown.
Binary file modified dist/pyrobusta/protocol/http_multipart.mpy
Binary file not shown.
Binary file modified dist/pyrobusta/server/http_server.mpy
Binary file not shown.
Binary file modified dist/pyrobusta/stream/buffer.mpy
Binary file not shown.
Binary file modified dist/pyrobusta/utils/config.mpy
Binary file not shown.
Binary file modified dist/pyrobusta/utils/helpers.mpy
Binary file not shown.
52 changes: 26 additions & 26 deletions docs/dimensioning/http_dimensioning.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,19 @@ with no active network traffic.

| id | http_mem_cap | http_multipart | socket_max_con | tls | footprint_bytes |
| --- | --- | --- | --- | --- | --- |
| base | 0.05 | False | 1 | False | 38512 |
| low_mem_cap_001 | 0.0127 | False | 1 | False | 38512 |
| low_mem_cap_002 | 0.0253 | False | 2 | False | 39728 |
| low_mem_cap_003 | 0.0505 | False | 4 | False | 42112 |
| high_mem_cap_001 | 0.0568 | False | 1 | False | 45680 |
| high_mem_cap_002 | 0.114 | False | 2 | False | 54064 |
| high_mem_cap_003 | 0.228 | False | 4 | False | 70832 |
| multipart_001 | 0.0127 | True | 1 | False | 40608 |
| multipart_002 | 0.0253 | True | 2 | False | 41824 |
| multipart_003 | 0.0505 | True | 4 | False | 44256 |
| tls_001 | 0.0127 | False | 1 | True | 41184 |
| tls_002 | 0.0253 | False | 2 | True | 42400 |
| tls_003 | 0.0505 | False | 4 | True | 44832 |
| base | 0.05 | False | 1 | False | 39200 |
| low_mem_cap_001 | 0.0127 | False | 1 | False | 39200 |
| low_mem_cap_002 | 0.0253 | False | 2 | False | 40416 |
| low_mem_cap_003 | 0.0505 | False | 4 | False | 42848 |
| high_mem_cap_001 | 0.0568 | False | 1 | False | 46368 |
| high_mem_cap_002 | 0.114 | False | 2 | False | 54752 |
| high_mem_cap_003 | 0.228 | False | 4 | False | 71520 |
| multipart_001 | 0.0127 | True | 1 | False | 43616 |
| multipart_002 | 0.0253 | True | 2 | False | 44832 |
| multipart_003 | 0.0505 | True | 4 | False | 47264 |
| tls_001 | 0.0127 | False | 1 | True | 41872 |
| tls_002 | 0.0253 | False | 2 | True | 43088 |
| tls_003 | 0.0505 | False | 4 | True | 45520 |

## Heap usage under network traffic
![image info](./img/esp32_c3/base.png)
Expand All @@ -53,19 +53,19 @@ with no active network traffic.
## Idle heap usage
| id | http_mem_cap | http_multipart | socket_max_con | tls | footprint_bytes |
| --- | --- | --- | --- | --- | --- |
| base | 0.05 | False | 1 | False | 45520 |
| low_mem_cap_001 | 0.000247 | False | 1 | False | 38352 |
| low_mem_cap_002 | 0.000493 | False | 2 | False | 39568 |
| low_mem_cap_003 | 0.000985 | False | 4 | False | 42000 |
| high_mem_cap_001 | 0.00111 | False | 1 | False | 45520 |
| high_mem_cap_002 | 0.00222 | False | 2 | False | 53904 |
| high_mem_cap_003 | 0.00443 | False | 4 | False | 70672 |
| multipart_001 | 0.000247 | True | 1 | False | 40528 |
| multipart_002 | 0.000493 | True | 2 | False | 41744 |
| multipart_003 | 0.000985 | True | 4 | False | 44176 |
| tls_001 | 0.000247 | False | 1 | True | 40736 |
| tls_002 | 0.000493 | False | 2 | True | 41952 |
| tls_003 | 0.000985 | False | 4 | True | 44384 |
| base | 0.05 | False | 1 | False | 45856 |
| low_mem_cap_001 | 0.000247 | False | 1 | False | 38688 |
| low_mem_cap_002 | 0.000493 | False | 2 | False | 39904 |
| low_mem_cap_003 | 0.000985 | False | 4 | False | 42336 |
| high_mem_cap_001 | 0.00111 | False | 1 | False | 45856 |
| high_mem_cap_002 | 0.00222 | False | 2 | False | 54240 |
| high_mem_cap_003 | 0.00443 | False | 4 | False | 71008 |
| multipart_001 | 0.000247 | True | 1 | False | 40896 |
| multipart_002 | 0.000493 | True | 2 | False | 42112 |
| multipart_003 | 0.000985 | True | 4 | False | 44544 |
| tls_001 | 0.000247 | False | 1 | True | 41072 |
| tls_002 | 0.000493 | False | 2 | True | 42288 |
| tls_003 | 0.000985 | False | 4 | True | 44720 |

## Heap usage under network traffic
![image info](./img/esp32_s3/base.png)
Binary file modified docs/dimensioning/img/esp32_c3/base.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/dimensioning/img/esp32_c3/high_mem_cap_001.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/dimensioning/img/esp32_c3/high_mem_cap_002.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/dimensioning/img/esp32_c3/high_mem_cap_003.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/dimensioning/img/esp32_c3/low_mem_cap_001.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/dimensioning/img/esp32_c3/low_mem_cap_002.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/dimensioning/img/esp32_c3/low_mem_cap_003.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/dimensioning/img/esp32_c3/multipart_001.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/dimensioning/img/esp32_c3/multipart_002.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/dimensioning/img/esp32_c3/multipart_003.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/dimensioning/img/esp32_c3/tls_001.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/dimensioning/img/esp32_c3/tls_002.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed docs/dimensioning/img/esp32_c3/tls_003.png
Binary file not shown.
Binary file modified docs/dimensioning/img/esp32_s3/base.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/dimensioning/img/esp32_s3/high_mem_cap_001.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/dimensioning/img/esp32_s3/high_mem_cap_002.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/dimensioning/img/esp32_s3/high_mem_cap_003.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/dimensioning/img/esp32_s3/low_mem_cap_001.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/dimensioning/img/esp32_s3/low_mem_cap_002.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/dimensioning/img/esp32_s3/low_mem_cap_003.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/dimensioning/img/esp32_s3/multipart_001.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/dimensioning/img/esp32_s3/multipart_002.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/dimensioning/img/esp32_s3/multipart_003.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/dimensioning/img/esp32_s3/tls_001.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/dimensioning/img/esp32_s3/tls_002.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/dimensioning/img/esp32_s3/tls_003.png
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "v0.5.0",
"version": "v0.6.0",
"urls": [
[
"pyrobusta/connectivity/wifi.mpy",
Expand Down
2 changes: 1 addition & 1 deletion src/pyrobusta/utils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def const(n): # pylint: disable=C0116

from .helpers import normalize_path

PYROBUSTA_VERSION = "v0.5.0"
PYROBUSTA_VERSION = "v0.6.0"
CONFIG_LOCATION = "pyrobusta.env"

# -------------------------------------------
Expand Down
Loading