Developer Portal Community

    cancel
    Showing results for 
    Search instead for 
    Did you mean: 

    Getting disconnected from mqtt

    Gautham
    Member

    Getting disconnected from mqtt

    ScreenShot.PNG

    Hi, I'm trying to send the data using mqtt but for some reason its getting disconneted from mqtt whenever it has to send the data. Please check the attached image for code and error message.

    Thanks for your time.

    Tags (3)
    1 REPLY 1
    Mahalingam
    Occasional Contributor

    Re: Getting disconnected from mqtt

    Hello Gautham

    The problem could be in your  broker setup. I have tested with "test.mosquitto.org" broker.

    I am able to send data over mqtt successfully. Please find the code below which I have used for testing,

     

    package main;
    import platforms.xdk110;
    
    setup ppWlan : WLAN{
    	authentication=Personal(psk = "xxx" );
    	ssid = "xxx";
    }
    
    setup ppMqtt : MQTT{
    	transport = ppWlan;
    	url = "mqtt://test.mosquitto.org:1883";
    	clientId = "ppMQTT";
    	var publishMsg = topic("hello/world");
    }
    
    every 100 milliseconds{
    	print("Publish sensor data\n");
    	ppMqtt.publishMsg.write("sensor data"); 
    }

     

     

    Able to connect to Mqtt broker successfully. Please find the test results below,

     

     INFO | Connection to port 'COM12' established
     INFO | XDK DEVICE 1: [INFO, C:/Users/mvs5cob/XDK-Workspace/EclipseMitaApplication/src-gen/base/ConnectivityWLANPpWlan.c:98] init WlanNetworkConnect succeeded
     INFO | XDK DEVICE 1: [INFO, C:/Users/mvs5cob/XDK-Workspace/EclipseMitaApplication/src-gen/base/ConnectivityWLANPpWlan.c:113] setting DHCP succeeded
     INFO | XDK DEVICE 1: [INFO, C:/Users/mvs5cob/XDK-Workspace/EclipseMitaApplication/src-gen/base/ConnectivityWLANPpWlan.c:121] Connecting to personal network: honor 7C
     INFO | XDK DEVICE 1: [INFO, C:/Users/mvs5cob/XDK-Workspace/EclipseMitaApplication/src-gen/base/ConnectivityWLANPpWlan.c:155] Connected to WLAN. IP address of this device is: 192.168.43.50
     INFO | XDK DEVICE 1: [INFO, C:/Users/mvs5cob/XDK-Workspace/EclipseMitaApplication/src-gen/main.c:134] enable ConnectivityWLANPpWlan succeeded
     INFO | XDK DEVICE 1: [INFO, C:/Users/mvs5cob/XDK-Workspace/EclipseMitaApplication/src-gen/main.c:144] enable ConnectivityMQTTPpMqtt succeeded
     INFO | XDK DEVICE 1: Publish sensor data
     INFO | XDK DEVICE 1: Publish sensor data

     

     

    Mqtt connection is automatically Re-established, If the Mqtt connection got failed. Please find the test results below,

     

     INFO | XDK DEVICE 1: Publish sensor data
     INFO | XDK DEVICE 1: [INFO, C:/Users/mvs5cob/XDK-Workspace/EclipseMitaApplication/src-gen/base/ConnectivityMQTTPpMqtt.c:234] MQTT_Write : Reconnecting...
     INFO | XDK DEVICE 1: 	Package ID: 153
     INFO | XDK DEVICE 1: 	Module ID: 0
     INFO | XDK DEVICE 1: 	Severity code: 2
     INFO | XDK DEVICE 1: 	Error code: 12
     INFO | XDK DEVICE 1: [ERROR, C:/Users/mvs5cob/XDK-Workspace/EclipseMitaApplication/src-gen/base/ConnectivityMQTTPpMqtt.c:388] MQTT_Connect : Failed to connect
     INFO | XDK DEVICE 1: [ERROR, C:/Users/mvs5cob/XDK-Workspace/EclipseMitaApplication/src-gen/base/ConnectivityMQTTPpMqtt.c:240] MQTT_Write : Connection failed!
     INFO | XDK DEVICE 1: Publish sensor data
     INFO | XDK DEVICE 1: [INFO, C:/Users/mvs5cob/XDK-Workspace/EclipseMitaApplication/src-gen/base/ConnectivityMQTTPpMqtt.c:234] MQTT_Write : Reconnecting...
     INFO | XDK DEVICE 1: [INFO, C:/Users/mvs5cob/XDK-Workspace/EclipseMitaApplication/src-gen/base/ConnectivityMQTTPpMqtt.c:237] MQTT_Write : Connected.
     INFO | XDK DEVICE 1: Publish sensor data
     INFO | XDK DEVICE 1: [INFO, C:/Users/mvs5cob/XDK-Workspace/EclipseMitaApplication/src-gen/base/ConnectivityMQTTPpMqtt.c:237] MQTT_Write : Connected.
     INFO | XDK DEVICE 1: Publish sensor data
     INFO | XDK DEVICE 1: Publish sensor data

     

     

    Icon--AD-black-48x48Icon--address-consumer-data-black-48x48Icon--appointment-black-48x48Icon--back-left-black-48x48Icon--calendar-black-48x48Icon--center-alignedIcon--Checkbox-checkIcon--clock-black-48x48Icon--close-black-48x48Icon--compare-black-48x48Icon--confirmation-black-48x48Icon--dealer-details-black-48x48Icon--delete-black-48x48Icon--delivery-black-48x48Icon--down-black-48x48Icon--download-black-48x48Ic-OverlayAlertIcon--externallink-black-48x48Icon-Filledforward-right_adjustedIcon--grid-view-black-48x48IC_gd_Check-Circle170821_Icons_Community170823_Bosch_Icons170823_Bosch_Icons170821_Icons_CommunityIC-logout170821_Icons_Community170825_Bosch_Icons170821_Icons_CommunityIC-shopping-cart2170821_Icons_CommunityIC-upIC_UserIcon--imageIcon--info-i-black-48x48Icon--left-alignedIcon--Less-minimize-black-48x48Icon-FilledIcon--List-Check-grennIcon--List-Check-blackIcon--List-Cross-blackIcon--list-view-mobile-black-48x48Icon--list-view-black-48x48Icon--More-Maximize-black-48x48Icon--my-product-black-48x48Icon--newsletter-black-48x48Icon--payment-black-48x48Icon--print-black-48x48Icon--promotion-black-48x48Icon--registration-black-48x48Icon--Reset-black-48x48Icon--right-alignedshare-circle1Icon--share-black-48x48Icon--shopping-bag-black-48x48Icon-shopping-cartIcon--start-play-black-48x48Icon--store-locator-black-48x48Ic-OverlayAlertIcon--summary-black-48x48tumblrIcon-FilledvineIc-OverlayAlertwhishlist