ChatGPT has provded the following working principle of your Python Script of your application:
Python Sript:
import datetime
import threading
from arduino.app_utils import App, Bridge
from arduino.app_bricks.web_ui import WebUI
print("Python ready", flush=True)
web = WebUI()
_lock = threading.Lock()
_state = {
"lat": None,
"long": None,
"jour": None,
"mois": None,
"annee": None,
"heure": None,
"minute": None,
"seconde": None,
"numsat": None,
"altitude": None,
}
def now_utc_iso():
#ISO 8601 UTC, ex: 2026-03-01T08:22:29Z
return datetime.datetime.now(datetime.timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ")
def update_gps(lat,long, jour, mois, annee, heure, minute,seconde, numsat, altitude):
with _lock:
_state["lat"] = float(lat)
_state["long"] = float(long)
_state["jour"] = int(jour)
_state["mois"] = int(mois)
_state["annee"] = int(annee)
_state["heure"] = int(heure)
_state["minute"] = int(minute)
_state["seconde"] = int(seconde)
_state["numsat"] = int(numsat)
_state["altitude"] = float(altitude)
Bridge.provide("update_gps", update_gps)
#Bridge.provide("presence_mm", presence_mm)
def api_state(_req=None):
with _lock:
payload = {
"now_utc": now_utc_iso(),
"lat": _state["lat"],
"long": _state["long"],
"jour": _state["jour"],
"mois": _state["mois"],
"annee": _state["annee"],
"heure": _state["heure"],
"minute": _state["minute"],
"seconde": _state["seconde"],
"numsat": _state["numsat"],
"altitude": _state["altitude"],
}
return payload
web.expose_api("GET", "/api/state", api_state)
App.run()
1. Importing required modules
import datetime
import threading
from arduino.app_utils import App, Bridge
from arduino.app_bricks.web_ui import WebUI
Purpose
| Module |
Purpose |
datetime |
work with date and time |
threading |
prevent data corruption |
Bridge |
communication between MCU and Python |
WebUI |
creates a web server |
App |
runs the application |
So this program will communicate with MCU and also run a web server.
2. Startup message
print("Python ready", flush=True)
This prints a message so you know the Python program has started.
flush=True forces the text to appear immediately.
3. Creating the WebUI server
web = WebUI()
This creates a web server object.
Later you can open a browser and access its API.
4. Thread safety lock
_lock = threading.Lock()
This creates a mutual exclusion lock (mutex).
Why needed?
Two things may access the data at the same time:
- MCU updating GPS data
- Web browser requesting data
The lock ensures only one process changes the data at a time.
5. State dictionary (data storage)
_state = {
"lat": None,
"long": None,
"jour": None,
"mois": None,
"annee": None,
"heure": None,
"minute": None,
"seconde": None,
"numsat": None,
"altitude": None,
}
This dictionary stores the latest GPS information.
Meaning of fields:
| Field |
Meaning |
| lat |
latitude |
| long |
longitude |
| jour |
day |
| mois |
month |
| annee |
year |
| heure |
hour |
| minute |
minute |
| seconde |
second |
| numsat |
number of satellites |
| altitude |
height |
Initially all values are None.
6. Function to generate current UTC time
def now_utc_iso():
This function returns the current time in ISO 8601 format.
Example output:
2026-03-01T08:22:29Z
This format is widely used in web APIs.
7. Function that receives GPS data
def update_gps(lat,long, jour, mois, annee, heure, minute,seconde, numsat, altitude):
This function is called from the MCU through Bridge.
Inside:
with _lock:
The lock ensures safe data update.
Then values are stored:
_state["lat"] = float(lat)
_state["long"] = float(long)
Type conversion is done because values arriving from Bridge are strings.
So they are converted to:
8. Making the function callable from MCU
Bridge.provide("update_gps", update_gps)
This registers the function with the Bridge.
Now the Arduino sketch can call it like:
Bridge.call("update_gps", lat,long,...)
Flow:
MCU → Bridge → Python function update_gps()
9. API function for the web page
def api_state(_req=None):
This function returns the current GPS state.
Again it uses the lock:
with _lock:
Then builds a dictionary called payload.
Example payload returned:
{
"now_utc": "2026-03-01T08:22:29Z",
"lat": 23.7456,
"long": 90.4213,
"numsat": 8,
"altitude": 21.4
}
10. Exposing the API to the web
web.expose_api("GET", "/api/state", api_state)
This creates a REST API endpoint.
So if a browser requests:
http://device-ip/api/state
The function api_state() runs and returns JSON data.
11. Starting the application
App.run()
This starts:
- the Bridge service
- the WebUI server
- the event loop
The program then runs continuously.
Complete System Operation
GPS sensor
│
▼
MCU (Arduino sketch)
│
│ Bridge.call("update_gps")
▼
Python program
(update_gps function)
│
│ stores data in _state
▼
Web API
/api/state
│
▼
Browser / dashboard
Example Real Workflow
GPS module sends data to MCU
MCU extracts latitude, longitude etc
MCU calls
Bridge.call("update_gps", ...)
Python stores the values
Browser requests
GET /api/state
Python returns JSON data
In one sentence
This script receives GPS data from the MCU through Bridge, stores it safely, and serves it to a web dashboard via a REST API.