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.