def clickedConnect():
     try:
         if App.nodeId.get() == '':
             messagebox.showwarning("Warging", 'nodeId is necessary')
             return
         selectTab = tabControl.tab(tabControl.select(), 'text')
         edgeAgentOptions = EdgeAgentOptions(nodeId=App.nodeId.get())
         if selectTab == 'MQTT':
             edgeAgentOptions.connectType = constant.ConnectType['MQTT']
             mqttOptions = MQTTOptions(hostName=App.hostName.get(),
                                       port=App.port.get(),
                                       userName=App.userName.get(),
                                       password=App.password.get())
             edgeAgentOptions.MQTT = mqttOptions
         elif selectTab == 'DCCS':
             edgeAgentOptions.connectType = constant.ConnectType['DCCS']
             dccsOptions = DCCSOptions(
                 apiUrl=App.apiUrl.get(),
                 credentialKey=App.credentialKey.get())
             edgeAgentOptions.DCCS = dccsOptions
         if self._edgeAgent is None:
             self._edgeAgent = EdgeAgent(edgeAgentOptions)
             self._edgeAgent.on_connected = on_connected
             self._edgeAgent.on_disconnected = on_disconnected
             self._edgeAgent.on_message = on_message
         self._edgeAgent.connect()
     except ValueError as error:
         messagebox.showwarning("Warging", str(error))
Example #2
0
        def connect():
            edgeAgentOptions = EdgeAgentOptions(nodeId="04f2206c-a6d5-44d5-ae02-375fc29b8079")
            edgeAgentOptions.connectType = constant.ConnectType['DCCS']
            dccsOptions = DCCSOptions(apiUrl="https://api-dccs-ensaas.sa.wise-paas.com/", credentialKey="c7b005554b8d527a1fdf2137aea055l7")
            edgeAgentOptions.DCCS = dccsOptions

            if self.edgeAgent is None:
                self.edgeAgent = EdgeAgent(edgeAgentOptions)
                self.edgeAgent.on_connected = onConnected
                self.edgeAgent.on_disconnected = onDisconnected
                self.edgeAgent.on_message = onMessage

            self.edgeAgent.connect()
Example #3
0
    deviceConfig.discreteTagList.append(discrete)

    text = TextTagConfig(name='TTag1',
                         description='TTag1',
                         readOnly=False,
                         arraySize=0)
    deviceConfig.textTagList.append(text)

    config.node.deviceList.append(deviceConfig)
    return config


_edgeAgent = None
edgeAgentOptions = EdgeAgentOptions(
    nodeId='568173b8-638b-46d6-a58f-ae7c8056f003')
edgeAgentOptions.connectType = constant.ConnectType['DCCS']
dccsOptions = DCCSOptions(apiUrl='https://api-dccs-ensaas.sa.wise-paas.com/',
                          credentialKey='b37a19560cc7473403444507b500ef0k')
edgeAgentOptions.DCCS = dccsOptions
_edgeAgent = EdgeAgent(edgeAgentOptions)
_edgeAgent.on_connected = on_connected
_edgeAgent.on_disconnected = on_disconnected
_edgeAgent.on_message = edgeAgent_on_message

_edgeAgent.connect()

time.sleep(5)  # Waiting for connection to be established

for i in range(1, 60):
    __sendData()
    time.sleep(1)
    MQTT=MQTTOptions(                                   # If connectType is MQTT, must fill this options
        hostName="127.0.0.1",
        port=1883,
        userName="******",
        password="******",
        # MQTT protocal (TCP, Websocket), default is TCP
        protocalType=constant.Protocol['TCP']
    ),
    DCCS=DCCSOptions(
        apiUrl="https://api-dccs-ensaas.sa.wise-paas.com/",         # DCCS API Url
        # credentialKey="c49fe0af415c5b79d6ab10d1b13acfp1"  # Creadential key
        credentialKey="fce6538e82e18a85a0560315652e03ti"  # Creadential key
    )
)

edge_agent = EdgeAgent(options=options)


def generate_data(data, device_id, tag_name, value):
    tag = EdgeTag(device_id, tag_name, value)
    data.tagList.append(tag)


def send_data(data):
    edge_agent.sendData(data=data)


def handler_on_connected(agent, isConnected):
    # Connected: when EdgeAgent is connected to IoTHub.
    print("Connected successfully")