コード例 #1
0
ファイル: azure_service.py プロジェクト: shoko93/RumiCar-1
    def stdin_listener():
        iothub_registry_manager = IoTHubRegistryManager(
            IOTHUB_CONNECTION_STRING)
        twin = iothub_registry_manager.get_twin(DEVICE_ID)

        while True:
            selection = input("Q: quit, F: forward, S: stop/free\n")
            if selection == "Q" or selection == "q":
                print("Quitting...")
                break
            elif selection == "F" or selection == "f":
                twin_patch = Twin(properties=TwinProperties(
                    desired={'command': 'forward'}))
                twin = iothub_registry_manager.update_twin(
                    DEVICE_ID, twin_patch, twin.etag)
            elif selection == "S" or selection == "s":
                twin_patch = Twin(properties=TwinProperties(
                    desired={'command': 'stop'}))
                twin = iothub_registry_manager.update_twin(
                    DEVICE_ID, twin_patch, twin.etag)
    print_device_info("create_device", new_device)

    # Get device information
    device = iothub_registry_manager.get_device(device_id)
    print_device_info("get_device", device)

    # Update device information
    primary_key = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
    secondary_key = "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy"
    device_state = "disabled"
    device_updated = iothub_registry_manager.update_device_with_sas(
        device_id, device.etag, primary_key, secondary_key, device_state)
    print_device_info("update_device", device_updated)

    # Get device twin
    twin = iothub_registry_manager.get_twin(device_id)
    print(twin)
    print("")

    additional_props = twin.additional_properties
    if "modelId" in additional_props:
        print("Model id for digital twin is")
        print("ModelId:" + additional_props["modelId"])

    # # Replace twin
    new_twin = Twin()
    new_twin = twin
    new_twin.properties = TwinProperties(desired={"telemetryInterval": 9000})
    print(new_twin)
    print("")
コード例 #3
0
import asyncio
import time
import json
import os
import sys

from azure.iot.device.aio import IoTHubDeviceClient
from azure.iot.hub import IoTHubRegistryManager
from azure.iot.hub.models import Twin, TwinProperties, QuerySpecification, QueryResult

IOTHUB_CONNECTION_STRING = "HostName=programming-arduino.azure-devices.net;SharedAccessKeyName=service;SharedAccessKey=B0niIYnIrqW30ceXRfKMNaYhI68vriyVdybtMtTiZa8="
DEVICE_ID = "rpi"

CONNECTION_STR = "HostName=programming-arduino.azure-devices.net;DeviceId=rpi;SharedAccessKey=hZiVwRZTYig5xWgVr6vGVUgfzOyctlOSq1McMcaWY04="
iothub_registry_manager = IoTHubRegistryManager(IOTHUB_CONNECTION_STRING)
twin2 = iothub_registry_manager.get_twin(DEVICE_ID)

codes_start = 0


class LineUs:
    """An example class to show how to use the Line-us API"""
    def __init__(self, line_us_name):
        self.__line_us = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.__line_us.connect((line_us_name, 1337))
        self.__connected = True
        self.__hello_message = self.__read_response()

    def get_hello_string(self):
        if self.__connected:
            return self.__hello_message.decode()