feat: v0.3.4 — tenant_id as string, node_id in constructor, fix duplicate ensure_registered

This commit is contained in:
2026-06-07 13:17:30 +02:00
parent b6bad09a2b
commit 5970edd06a
3 changed files with 17 additions and 14 deletions

View File

@@ -175,6 +175,7 @@ def do_checkin(cfg):
node_type = cfg.get('node_type', 'access_control'),
node_label = cfg.get('node_label', ''),
tenant_id = cfg['tenant_id'],
node_id = cfg['node_id'],
comm_key = key,
comm_iv = iv,
wifi_ssid = cfg['wifi_ssid'],
@@ -184,26 +185,24 @@ def do_checkin(cfg):
# Register — retry loop
for attempt in range(3):
try:
_show(['CHECKIN', 'Registering...', 'attempt ' + str(attempt+1) + '/3', '', ''])
identity.ensure_registered()
_show(['CHECKIN', 'Registering IoT...', 'attempt ' + str(attempt+1) + '/3', '', ''])
reg = identity.ensure_registered()
break
except Exception as e:
print('[checkin] register attempt', attempt + 1, ':', e)
print('[checkin] IoT register attempt', attempt + 1, ':', e)
if attempt == 2:
_show_state('ERROR', 'Check network')
raise
utime.sleep(3)
# Seconda chiamata idempotente
reg = identity.ensure_registered()
uid_short = reg.get('node_uid', '')[:12] + '...'
_show(['CHECKIN', 'Node ' + reg.get('result', ''), uid_short, '', ''])
_show(['CHECKIN', 'IoT Node ' + reg.get('result', ''), uid_short, '', ''])
utime.sleep(1)
# Authenticate → JWT
_show(['CHECKIN', 'Challenge...', '', '', ''])
_show(['CHECKIN', 'IoT Challenge...', '', '', ''])
utime.sleep(0.5)
_show(['CHECKIN', 'Signing...', '', 'Please wait', ''])
_show(['CHECKIN', 'IoT Signing...', '', 'Please wait', ''])
token = identity.authenticate()
if not token:
@@ -213,7 +212,7 @@ def do_checkin(cfg):
print('[checkin] JWT issued')
# it_node_checkin su identity_tag con JWT
_show(['CHECKIN', 'Node checkin...', '', '', ''])
_show(['CHECKIN', 'IT Node checkin...', '', '', ''])
import urequests
from identity_iot_aes import aes_cbc_encrypt, aes_cbc_decrypt
@@ -227,7 +226,7 @@ def do_checkin(cfg):
for attempt in range(3):
try:
resp = urequests.post(
cfg['identity_tag_url'],
cfg['identity_node_url'],
headers={
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + token,