简体   繁体   中英

IoT Edge Module - Remotely debugging python module issue

I have created two C# IoT edge modules one for the sender and another for the receiver using IoT module routing. It is working fine and I got the data in the receiver module. But I had to change the sender module as python instead of C#. For the Python module, I had to debug as attach remotely debugging. While debugging in remoteley it shows the error like

Failed to attach (connect ECONNREFUSED 127.0.0.1:5678)

My lauch.josn file like

      "name": "SenderPythonModule Remote Debug (Python)",
      "type": "python",
      "request": "attach",
      "port": 5678,
      "host": "localhost",
      "logToFile": true,
      "redirectOutput": true,
      "pathMappings": [
        {
          "localRoot": "${workspaceFolder}/modules/SenderPythonModule",
          "remoteRoot": "/app"
        }
      ],
      "windows": {
        "pathMappings": [
          {
            "localRoot": "${workspaceFolder}\\modules\\SenderPythonModule",
            "remoteRoot": "/app"
          }
        ]
      }
    }

My main.py file like

import time
import os
import sys
import asyncio
from six.moves import input
import threading
from azure.iot.device.aio import IoTHubModuleClient
import ptvsd
ptvsd.enable_attach(('0.0.0.0',  5678))

async def main():

    try: 
        if not sys.version >= "3.5.3":
            raise Exception( "The sample requires python 3.5.3+. Current version of Python: %s" % sys.version )
        print ( "IoT Hub Client for Python" )

        # The client object is used to interact with your Azure IoT hub.
        module_client = IoTHubModuleClient.create_from_edge_environment()       
        # connect the client.
        await module_client.connect()

        # define behavior for receiving an input message on input1
        async def input1_listener(module_client):
            ptvsd.break_into_debugger()
            while True:
                input_message = await module_client.receive_message_on_input("input1")  # blocking call
                print("the data in the message received on input1 was ")
                print(input_message.data)
                print("custom properties are")
                print(input_message.custom_properties)
                print("forwarding mesage to output1")

                await module_client.send_message_to_output(input_message, "output1")

        # define behavior for halting the application
        def stdin_listener():
            while True:
                try:
                    selection = input("Press Q to quit\n")
                    if selection == "Q" or selection == "q":
                        print("Quitting...")
                        break
                except:
                    time.sleep(10)

        # Schedule task for C2D Listener
        listeners = asyncio.gather(input1_listener(module_client))

        print ( "The sample is now waiting for messages. ")

        # Run the stdin listener in the event loop
        loop = asyncio.get_event_loop()
        user_finished = loop.run_in_executor(None, stdin_listener)

        # Wait for user to indicate they are done listening for messages
        await user_finished

        # Cancel listening
        listeners.cancel()

        # Finally, disconnect
        await module_client.disconnect()

    except Exception as e:
        print ( "Unexpected error %s " % e )
        raise

if __name__ == "__main__":
    loop = asyncio.get_event_loop()
    loop.run_until_complete(main())
    loop.close()

My routing like

"routes": {
          "SenderPythonModuleToIoTHub": "FROM /messages/modules/SenderPythonModule/outputs/*  INTO BrokeredEndpoint(\"/modules/ReceiverCSharpModule/inputs/input1\")",
          "sensorToReceiverCSharpModule": "FROM /messages/modules/SimulatedTemperatureSensor/outputs/temperatureOutput INTO BrokeredEndpoint(\"/modules/SenderPythonModule/inputs/input1\")",
          "ReceiverCSharpModuleToIoTHub": "FROM /messages/modules/ReceiverCSharpModule/outputs/* INTO $upstream",
        },

Can anyone help me to figure it out? I am using windows os system.

Iot Edge doesn't support, to the writing of this, using module on windows device and windows container. Your probably gettin an error that the "windows-amd64" dockerfile of your module is not found because the VS code command will not generate this file.

https://docs.microsoft.com/en-us/azure/iot-edge/tutorial-python-module#solution-scope

IoT Edge does not support Python modules for Windows devices.

If you have to work on windows, you have to enable linux containers in Docker and use amd64 as platform.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM