locked
Downstream Device to Edge Gateway routing message infinite times RRS feed

  • Question

  • I am trying to send messages from downstream device to edge enabled transparent gateway. But when I send a single message to the gateway, the gateway routes a single message to the dedicated module infinite times. 

    Downstream device sdk code
    
    
    
    import time
    from iothub_client import IoTHubClient
    from iothub_client import IoTHubTransportProvider
    from iothub_client import IoTHubClientRetryPolicy, IoTHubMessage
    
    PROTOCOL_SDK = IoTHubTransportProvider.MQTT
    CONNECTION_STRING_SDK = "HostName=<hubName>;DeviceId=<deviceId>;ModuleId=<moduleId>;SharedAccessKey=<shared access key>=;GatewayHostName=<GatewayName>"
    
    
    MESSAGE_TIMEOUT = 1000
    
    #Inilization Method
    def iothub_client_init():
        # prepare iothub client
        print("[INFO] Making SDK Client Gateway Connection ")
        print("[INFO] Connection String: %d",CONNECTION_STRING_SDK)
        client = IoTHubClient(CONNECTION_STRING_SDK, PROTOCOL_SDK)
        print(CONNECTION_STRING_SDK)
        # set the time until a message times out
        client.set_option("messageTimeout", MESSAGE_TIMEOUT)
      
        if client.protocol == IoTHubTransportProvider.MQTT:
            client.set_option("logtrace", 0)
        
    
        
    
        retryPolicy = IoTHubClientRetryPolicy.RETRY_INTERVAL
        retryInterval = 100
        client.set_retry_policy(retryPolicy, retryInterval)
        print ( "[INFO] SetRetryPolicy to: retryPolicy = %d" %  retryPolicy)
        print ( "[INFO] SetRetryPolicy to: retryTimeoutLimitInSeconds = %d" %  retryInterval)
        retryPolicyReturn = client.get_retry_policy()
        print ( "[INFO] GetRetryPolicy returned: retryPolicy = %d" %  retryPolicyReturn.retryPolicy)
        print ( "[INFO] GetRetryPolicy returned: retryTimeoutLimitInSeconds = %d" %  retryPolicyReturn.retryTimeoutLimitInSeconds)
        return client
    
    def send_confirmation_callback(message, result, user_context):
        
        print ( "Confirmation[%d] received for message with result = %s" % (user_context, result) )
        map_properties = message.properties()
        key_value_pair = map_properties.get_internals()
        print ( "    Properties: %s" % key_value_pair )
        
    
    if __name__ == '__main__':
        
        print ( "IoT Hub Client for Python" )
    
        print ( "Starting the IoT Hub Python sample..." )
        print ( "    Protocol %s" % PROTOCOL_SDK )
        print ( "    Connection string=%s" % CONNECTION_STRING_SDK )
    
        client=iothub_client_init()
        while True:
            star=1
            message="hello from the other side %d"%star
            message_iothub=IoTHubMessage(message)
            client.send_event_async(message_iothub,send_confirmation_callback,star)
            time.sleep(50)
            star=star+1
    
    

    Routes:

    EdgeHub Logs:

    checkPorts Logs:

    Monday, September 17, 2018 10:05 PM

Answers

  • Hello ArshSharma,

    After looking at the code you shared, the message has the same text but is not always the same message. You should move star=1 outside the While:true loop.

    Let us know if it worked.

    ==========================================================

    If this answer was helpful, click “Mark as Answer” or Up-Vote. To provide additional feedback on your forum experience, click here

    Thursday, September 20, 2018 11:33 AM