This commit is contained in:
ludruda 2020-11-10 12:25:45 +01:00
Родитель b381d64379
Коммит 8f13fa8b00
4 изменённых файлов: 12 добавлений и 20 удалений

Просмотреть файл

@ -103,9 +103,9 @@ _'certPhrase'_ is optional and represents the password for the certificate if an
#### SAS
```py
scopeId = 'scopeID';
device_id = 'device_id';
sasKey = 'masterKey'; # or use device key directly
scopeId = 'scopeID'
device_id = 'device_id'
sasKey = 'masterKey' # or use device key directly
iotc = IoTCClient(device_id, scopeId,
IOTCConnectType.IOTC_CONNECT_SYMM_KEY, sasKey)
@ -221,7 +221,7 @@ Template Id can be found in the device explorer page of IoTCentral
Then call this method before connect():
```py
iotc.setModelId('<modelId>');
iotc.set_model_id('<modelId>')
```
### Manual approval (default)

Просмотреть файл

@ -14,13 +14,13 @@ if config['DEFAULT'].getboolean('Local'):
from iotc import IOTCConnectType, IOTCLogLevel, IOTCEvents
from iotc.aio import IoTCClient
device_id = config['DEVICE_A']['DeviceId']
scope_id = config['DEVICE_A']['ScopeId']
key = config['DEVICE_A']['DeviceKey']
device_id = config['DEVICE_M3']['DeviceId']
scope_id = config['DEVICE_M3']['ScopeId']
key = config['DEVICE_M3']['DeviceKey']
# optional model Id for auto-provisioning
try:
model_id = config['DEVICE_A']['ModelId']
model_id = config['DEVICE_M3']['ModelId']
except:
model_id = None
@ -40,7 +40,7 @@ async def on_enqueued_commands(command_name,command_data):
# change connect type to reflect the used key (device or group)
client = IoTCClient(device_id, scope_id,
IOTCConnectType.IOTC_CONNECT_DEVICE_KEY, key)
IOTCConnectType.IOTC_CONNECT_SYMM_KEY, key)
if model_id != None:
client.set_model_id(model_id)
@ -51,15 +51,6 @@ client.on(IOTCEvents.IOTC_ENQUEUED_COMMAND, on_enqueued_commands)
# iotc.setQosLevel(IOTQosLevel.IOTC_QOS_AT_MOST_ONCE)
async def command_loop(device_client):
while True:
# Wait for unknown method calls
method_request = (await device_client.receive_method_request())
print('Received command {}'.format(method_request.name))
await device_client.send_method_response(MethodResponse.create_from_method_request(
method_request, 200, {
'result': True, 'data': 'Command received'}
))
async def main():
await client.connect()

Просмотреть файл

@ -311,7 +311,7 @@ class IoTCClient(AbstractClient):
if self._model_id:
self._provisioning_client.provisioning_payload = {
'iotcmodel_id': self._model_id}
'iotcModelId': self._model_id}
try:
registration_result = self._provisioning_client.register()
assigned_hub = registration_result.registration_state.assigned_hub

Просмотреть файл

@ -198,8 +198,9 @@ class IoTCClient(AbstractClient):
provisioning_host=self._global_endpoint, registration_id=self._device_id, id_scope=self._scope_id, x509=x509)
if self._model_id:
print("Provision model Id")
self._provisioning_client.provisioning_payload = {
'iotcmodel_id': self._model_id}
'iotcModelId': self._model_id}
try:
registration_result = await self._provisioning_client.register()
assigned_hub = registration_result.registration_state.assigned_hub