Ir al contenido

Análisis de código

Análisis del código Cloudtainer — Repositorio Xiao_Cloudtainer

Sección titulada «Análisis del código Cloudtainer — Repositorio Xiao_Cloudtainer»

Repositorio: https://github.com/Lucosiar/geo_Cloudtainer
Rama: master
Última etiqueta: v1.0.0 argentina
Análisis: 2026-04-24


Xiao_Cloudtainer/
├── CMakeLists.txt — Configuración build Zephyr
├── README.md — Instrucciones build
├── prj.conf — Opciones Kconfig (BLE, I2C, ADC, PWM)
├── note-zephyr — Submodule driver Blues Notecard
├── xiao_nrf54l15_nrf54l15_cpuapp.overlay — Configuración pines XIAO
└── src/
├── main.c — Entrada, secuencia init
├── thread.c — 4 threads + BLE
├── notecard.c/h — Driver I2C Notecard
├── pwm_servo.c/h — Control PWM servo
├── ds3231.c/h — Driver RTC
├── adc.c/h — Lectura voltaje batería
├── led.c/h — Control LEDs
└── variables.h — Estructuras eventos

Board: xiao_nrf54l15/nrf54l15/cpuapp

Pines:

FunciónPinPeriférico
I2C SDA (Notecard + RTC)P1.10i2c22
I2C SCLP1.11i2c22
PWM servoP1.06pwm20 ch0
ADC batería (divisor 220k/100k)P1.05AIN1

I2C: Notecard (0x17) + RTC (0x68) en mismo bus @ 400 kHz.

PWM servo:

  • CLOSED: 1000 µs
  • OPEN: 1450 µs
  • OFF: 0 µs
  • Hold time: 7 segundos en OPEN

1. k_sleep(10s) — Estabilizar voltaje
2. pwm_servo_init() — Iniciar PWM, servo a CLOSED
3. ble_init() — Habilitar Bluetooth, advertising
4. bat_adc_init() — Iniciar ADC batería
5. notecard_configure() — Enviar hub.set, card.voltage, note.template
6. k_sleep(15s) — Dar tiempo a Notecard conectar
7. ds3231_get_datetime() — Leer RTC, sincronizar si necesario
8. threads_start() — Arrancar 4 threads de trabajo
9. Loop infinito: k_sleep(10s)
ThreadPrioridadStackPeríodoFunción
sat_init3204860s pollDetecta sesión satélite, da semáforo SAT_READY
collector4204830sRecopila voltaje (ADC), GPS (Notecard), timestamp (RTC)
gsm5204860sEnvía evento vía cellular a cloudtainer-event.qos (hasta 5 reintentos)
sat52048300sEnvía evento reducido vía satélite a cloudtainer-event-sat.qos

Celular (cloudlock_event_body):

{
float voltage; // Voltaje batería
float battery_percentage; // 0-100%
float uptime; // Uptime dispositivo
bool vusb; // USB conectado
double lat; // GPS latitud
double lng; // GPS longitud
uint64_t timestamp; // Unix time RTC
char gps_status[256]; // Estado GPS
char motion_status[32]; // "idle", "face-down", etc
char event_type[32]; // "monitor" o "open-door"
char user_id[32]; // Quién abrió (o "unknown")
}

Satélite (cloudlock_event_body_sat) — versión reducida:

{
float voltage;
double lat;
double lng;
uint64_t uptime;
char gps_status[256];
}

Service UUID: b1d00001-630a-4c52-952a-4ba220000001

Características:

  • Open (write) b1d00004-... — Recibe token de 8 caracteres
  • Status (read) b1d00005-... — Devuelve “closed”

Tokens (hardcodeados):

BLE_UNLOCK_TOKEN_1 = "jsnf9233" → user_id "SUP0012025"
BLE_UNLOCK_TOKEN_2 = "kqtm4816" → user_id "SUP0022025"

🔴 Seguridad — Credenciales hardcodeadas en GitHub

Sección titulada «🔴 Seguridad — Credenciales hardcodeadas en GitHub»

En notecard_variables.h en texto plano:

  • Tokens de desbloqueo (jsnf9233, kqtm4816)
  • UUID Notehub project
  • Direcciones I2C y configuración

Riesgo: Cualquiera con acceso a GitHub puede:

  • Desbloquear cualquier Cloudlock (tokens BLE son públicos)
  • Monitorizar tráfico del proyecto (UUID público)

Fijo: Usar #include "secrets.h" gitignored, mover tokens a NVRAM del device.

Coordinadas se almacenan con 10+ dígitos decimales (~1 cm precisión). Para logística marítima, 6 dígitos (~10 cm) es suficiente.

Fijo: Redondear a 6 dígitos antes de enviar:

lat = round(lat * 1e6) / 1e6;
lng = round(lng * 1e6) / 1e6;

🟡 Servo — Sin verificación de posición

Sección titulada «🟡 Servo — Sin verificación de posición»

Código asume que servo alcanza posición OPEN/CLOSED en tiempo especificado. Sin sensor de posición, no hay feedback si falla.

Fijo: Añadir reed switch para detectar posición real.

Transporte se reporta como "cell", "ntn", "wifi-cell-ntn", etc. Notehub UI simplifica a “cellular” incluso si es realmente “cell-ntn” (celular con respaldo satélite).

Acción: Verificar campo transport en eventos _session.qo en Notehub para distinguir real de reportado.


  1. MOSFET para servo — Desconectar servo cuando está en posición CLOSED (ver 07_schematic_review_ES.md)
  2. Wake-on-motion GPS — Usar acelerómetro LIS2DH12 para encender GPS solo al movimiento
  3. Reducir período collector — 30s es mucho para un dispositivo con batería 1-3 meses
  4. PSM en Notecard — Usar Power Save Mode de Notecard para ciclos más largos entre sync

  • Esquema electrónico
  • Diseño low-power
  • Análisis RF