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,

View File

@@ -8,11 +8,12 @@
"wifi_dns": "8.8.8.8",
"comm_key": "YOUR_32_CHAR_KEY________________",
"comm_iv": "YOUR_16_CHAR_IV_",
"tenant_id": 1,
"node_id": 0,
"tenant_id": "1",
"node_id": "0",
"node_type": "access_control",
"node_label": "terminal-01",
"identity_iot_url": "https://api.parta.app/API/V1/identity_layer/identity_iot/",
"identity_tag_url": "https://api.parta.app/API/V1/identity_layer/identity_tag/",
"identity_node_url": "https://api.parta.app/API/V1/identity_tag/",
"data_destination_url": ""
}

View File

@@ -50,7 +50,8 @@ class IdentityIoT:
app_id: str = 'identity_iot',
node_type: str = 'sensor',
node_label: str = None,
tenant_id: int = 0,
tenant_id = 0,
node_id: str = None,
comm_key: bytes = None,
comm_iv: bytes = None,
wifi_ssid: str = None,
@@ -61,6 +62,7 @@ class IdentityIoT:
self.node_type = node_type
self.node_label = node_label
self.tenant_id = tenant_id
self.node_id = node_id
self._comm_key = comm_key
self._comm_iv = comm_iv
self._wifi_ssid = wifi_ssid
@@ -96,7 +98,7 @@ class IdentityIoT:
node_uid = self._get_node_uid()
resp = self._post({'request': 'challenge', 'node_uid': node_uid})
resp = self._post({'request': 'challenge', 'node_uid': node_uid, 'tenant_id': self.tenant_id})
if resp.get('status') != 'ok':
raise Exception('challenge failed: ' + str(resp))
@@ -113,6 +115,7 @@ class IdentityIoT:
'challenge_id': challenge_id,
'signature_b64': sig_b64,
'node_uid': node_uid,
'tenant_id': self.tenant_id,
})
if resp.get('status') != 'ok':
raise Exception('verify_signature failed: ' + str(resp))