Skip to content

Commit 06cead2

Browse files
committed
Initial commit: telemetría MQTT/AWS IoT para nano ESP32, Pico W y Pi Zero W
Tres implementaciones equivalentes (MicroPython/Python) que leen sensores de un vehículo eléctrico (batería, corriente, temperatura, RPM) y publican por MQTT sobre mTLS a AWS IoT Core.
0 parents  commit 06cead2

29 files changed

Lines changed: 1470 additions & 0 deletions

.gitignore

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Configuración local con credenciales (WiFi, endpoint MQTT) - nunca se sube
2+
config.py
3+
4+
# Claves privadas y certificados de dispositivo (mTLS AWS IoT)
5+
# Las Root CA públicas (AmazonRootCA1.pem, root-CA.crt, amazon_ca.der.crt) SÍ se versionan.
6+
*.private.key
7+
*-private.pem.key
8+
*-public.pem.key
9+
*-certificate.pem.crt
10+
private.der.key
11+
certificate.der.crt
12+
Raspberry.cert.pem
13+
Raspberry.private.key
14+
15+
# Python
16+
__pycache__/
17+
*.pyc
18+
.venv/
19+
venv/
20+
21+
# Sistema
22+
.DS_Store

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2026 Miguel Garcia Barreiro
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Telemetría IoT para vehículo eléctrico
2+
3+
Sistema de telemetría en tiempo real para un vehículo eléctrico (batería, corriente, temperatura del motor, RPM de motor y rueda, acelerador y freno), con tres implementaciones equivalentes sobre distinto hardware. Cada nodo lee los sensores analógicos/digitales del vehículo y publica un mensaje JSON por MQTT sobre TLS mutuo (mTLS) a **AWS IoT Core**.
4+
5+
Proyecto desarrollado como parte de un Trabajo Fin de Máster (TFM).
6+
7+
## Arquitectura
8+
9+
```
10+
Sensores del vehículo → [nodo embebido] → MQTT sobre mTLS (TLS 1.2, cert. X.509) → AWS IoT Core
11+
```
12+
13+
Cada nodo se autentica con su propio certificado de dispositivo (mTLS), no con usuario/contraseña. Los tres nodos implementan la misma lógica de lectura de sensores y publicación, adaptada a las capacidades de cada plataforma:
14+
15+
| Carpeta | Placa | Lenguaje | Notas |
16+
|---|---|---|---|
17+
| `nanoesp32/` | Arduino Nano ESP32 | MicroPython | ADC interno de la placa |
18+
| `pipico-code/` | Raspberry Pi Pico W | MicroPython | ADC externo (ADC Pi); dos variantes: `main.py` y `main_python.py` (mismo hardware, publican en topics MQTT distintos) |
19+
| `pi_zerowh_code/` | Raspberry Pi Zero W | Python 3 | ADC externo (ADC Pi), usa el SDK oficial de AWS IoT |
20+
21+
## Configuración (obligatoria antes de ejecutar)
22+
23+
Ningún secreto (contraseña WiFi, certificados, claves privadas) está en el repositorio. Antes de usar cualquiera de los nodos:
24+
25+
1. **Credenciales de conexión** — en `nanoesp32/` y `pipico-code/`, copia `config.example.py` como `config.py` y rellena tu SSID/contraseña de WiFi y el endpoint de AWS IoT (Consola AWS IoT → *Configuración*). En `pi_zerowh_code/`, copia igualmente `config.example.py` como `config.py`.
26+
2. **Certificados del dispositivo** — crea una "Thing" (dispositivo) por nodo en AWS IoT Core, genera su certificado X.509 y su clave privada, adjúntale una policy (ver [`pi_zerowh_code/iot-policy.example.json`](pi_zerowh_code/iot-policy.example.json) como plantilla), y coloca los ficheros donde indica el `README.md` de cada subcarpeta de certificados (`cert_n/`, `cert_rpipico/`, `certs_n/`, `pi_zerowh_code/`).
27+
28+
Ninguno de estos ficheros (`config.py`, certificados, claves privadas) se sube a git — están excluidos vía `.gitignore`.
29+
30+
## Ejecución
31+
32+
- **nanoesp32 / pipico-code (MicroPython):** copia todos los ficheros de la carpeta (incluido tu `config.py` y tus certificados) a la placa, por ejemplo con [`mpremote`](https://docs.micropython.org/en/latest/reference/mpremote.html) o [`rshell`](https://github.com/dhylands/rshell). Al arrancar, `boot.py` conecta el WiFi y `main.py` publica telemetría por MQTT cada segundo.
33+
- **pi_zerowh_code (Python 3):**
34+
```bash
35+
pip install -r requirements.txt
36+
python3 main.py
37+
```
38+
`start.sh` es un script auxiliar (basado en el ejemplo oficial de AWS) para probar la conectividad pub/sub contra AWS IoT antes de lanzar `main.py`; requiere la variable de entorno `AWS_IOT_ENDPOINT`.
39+
40+
## Firmware
41+
42+
Para flashear MicroPython en la Raspberry Pi Pico W, descarga el `.uf2` oficial desde [micropython.org/download](https://micropython.org/download/RPI_PICO_W/).
43+
44+
## Licencia
45+
46+
MIT — ver [LICENSE](LICENSE).

nanoesp32/boot.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# boot.py -- run on boot-up
2+
import network
3+
import machine
4+
import config
5+
6+
7+
def connect_wifi(ssid, password):
8+
wlan = network.WLAN(network.STA_IF)
9+
wlan.active(True)
10+
wlan.connect(ssid, password)
11+
while not wlan.isconnected():
12+
machine.idle()
13+
14+
15+
def main():
16+
connect_wifi(config.WIFI_SSID, config.WIFI_PASSWORD)
17+
print("WIfi conectado.")
18+
19+
20+
if __name__ == "__main__":
21+
main()

nanoesp32/cert_n/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Certificados (formato DER)
2+
3+
Coloca aquí, tras generarlos en AWS IoT Core para este dispositivo, los siguientes ficheros (ignorados por git):
4+
5+
- `certificate.der.crt` — certificado del dispositivo (DER)
6+
- `private.der.key` — clave privada del dispositivo (DER)
7+
8+
`mazon_ca.der.crt` (Amazon Root CA en DER) ya está incluido: es un certificado público, no un secreto.

nanoesp32/cert_n/mazon_ca.der.crt

837 Bytes
Binary file not shown.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
-----BEGIN CERTIFICATE-----
2+
MIIDQTCCAimgAwIBAgITBmyfz5m/jAo54vB4ikPmljZbyjANBgkqhkiG9w0BAQsF
3+
ADA5MQswCQYDVQQGEwJVUzEPMA0GA1UEChMGQW1hem9uMRkwFwYDVQQDExBBbWF6
4+
b24gUm9vdCBDQSAxMB4XDTE1MDUyNjAwMDAwMFoXDTM4MDExNzAwMDAwMFowOTEL
5+
MAkGA1UEBhMCVVMxDzANBgNVBAoTBkFtYXpvbjEZMBcGA1UEAxMQQW1hem9uIFJv
6+
b3QgQ0EgMTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBALJ4gHHKeNXj
7+
ca9HgFB0fW7Y14h29Jlo91ghYPl0hAEvrAIthtOgQ3pOsqTQNroBvo3bSMgHFzZM
8+
9O6II8c+6zf1tRn4SWiw3te5djgdYZ6k/oI2peVKVuRF4fn9tBb6dNqcmzU5L/qw
9+
IFAGbHrQgLKm+a/sRxmPUDgH3KKHOVj4utWp+UhnMJbulHheb4mjUcAwhmahRWa6
10+
VOujw5H5SNz/0egwLX0tdHA114gk957EWW67c4cX8jJGKLhD+rcdqsq08p8kDi1L
11+
93FcXmn/6pUCyziKrlA4b9v7LWIbxcceVOF34GfID5yHI9Y/QCB/IIDEgEw+OyQm
12+
jgSubJrIqg0CAwEAAaNCMEAwDwYDVR0TAQH/BAUwAwEB/zAOBgNVHQ8BAf8EBAMC
13+
AYYwHQYDVR0OBBYEFIQYzIU07LwMlJQuCFmcx7IQTgoIMA0GCSqGSIb3DQEBCwUA
14+
A4IBAQCY8jdaQZChGsV2USggNiMOruYou6r4lK5IpDB/G/wkjUu0yKGX9rbxenDI
15+
U5PMCCjjmCXPI6T53iHTfIUJrU6adTrCC2qJeHZERxhlbI1Bjjt/msv0tadQ1wUs
16+
N+gDS63pYaACbvXy8MWy7Vu33PqUXHeeE6V/Uq2V8viTO96LXFvKWlJbYK8U90vv
17+
o/ufQJVtMVT8QtPHRh8jrdkPSHCa2XV4cdFyQzR1bldZwgJcJmApzyMZFo6IQ6XU
18+
5MsI+yMRQ+hDKXJioaldXgjUkK642M4UwtBV8ob2xJNDd2ZhwLnoQdeXeGADbkpy
19+
rqXRfboQnoZsG4q5WTP468SQvvG5
20+
-----END CERTIFICATE-----

nanoesp32/cert_rpipico/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Certificados (formato PEM)
2+
3+
Coloca aquí, tras generarlos en AWS IoT Core para este dispositivo, los siguientes ficheros (ignorados por git):
4+
5+
- `PiPico-certificate.pem.crt` — certificado del dispositivo
6+
- `PiPico-private.pem.key` — clave privada del dispositivo
7+
- `PiPico-public.pem.key` — clave pública del dispositivo
8+
9+
`AmazonRootCA1.pem` ya está incluido: es un certificado público, no un secreto.

nanoesp32/config.example.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Copia este fichero como "config.py" y rellena tus propios valores.
2+
# config.py NO se sube a git (ver .gitignore).
3+
4+
WIFI_SSID = "TU_SSID"
5+
WIFI_PASSWORD = "TU_PASSWORD"
6+
7+
# Endpoint de AWS IoT Core (Ajustes > Configuración en la consola de AWS IoT)
8+
MQTT_ENDPOINT = "tu-endpoint-ats.iot.tu-region.amazonaws.com"

nanoesp32/lib/ssl.mpy

745 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)