Elektroda.com
Elektroda.com
X
Elektroda.com

how to make mqtt connection stable

manivalaguru1 240 9
  • #1
    manivalaguru1
    Level 1  
    @p.kaczmarek2
    i have been using your sdk for wbsl board(smart light) using openbk7231T sdk i can able to control the light and all and changed the formot to support our own broker but problem is it disconnects and reconnects every 60 seconds is there any way to make this connection stable below is the log of disconnection and connection

    Info:MAIN:Time 60, free 102664, MQTT 1, bWifi 1, secondsWithNoPing 0, socks 1/38

    Info:GEN:dhcp=0 ip=192.168.1.102 gate=192.168.1.1 mask=255.255.255.0 mac=d4:a6:51:f3:33:51

    Info:MQTT:MQTT_STATUS=256
    Info:MQTT:MQTT_STATUS=256
    Info:MQTT:my_mac="50:33:f3:51:a6:d4"
    Info:MQTT:blub_data={"RED":0,"BLUE":0,"GREEN":0,"WHITE":10}
    Info:MQTT:mqtt_connection_cb: Disconnected, reason: 256


    Info:MAIN:Main_OnWiFiStatusChange - WIFI_STA_CONNECTED

    Info:MAIN:came to run mqtt every second update

    Info:MAIN:Timer discovers disconnected mqtt 1

    Info:MAIN:CAME TO MAIN

    Info:MAIN:CAME HERE AFTER 60 seconds

    Info:MAIN:Time 62, free 102664, MQTT 0, bWifi 1, secondsWithNoPing 1, socks 1/38

    Info:MAIN:came to run mqtt every second update

    Info:MAIN:Timer discovers disconnected mqtt 2

    Info:MAIN:CAME TO MAIN

    Info:MAIN:CAME HERE AFTER 60 seconds

    Info:MAIN:Time 63, free 102664, MQTT 0, bWifi 1, secondsWithNoPing 2, socks 1/38

    Info:MAIN:came to run mqtt every second update

    Info:MAIN:Timer discovers disconnected mqtt 3

    Info:MAIN:CAME TO MAIN

    Info:MAIN:CAME HERE AFTER 60 seconds

    Info:MAIN:Time 64, free 102664, MQTT 0, bWifi 1, secondsWithNoPing 3, socks 1/38

    Info:MAIN:came to run mqtt every second update

    Info:MAIN:Timer discovers disconnected mqtt 4

    Info:MAIN:CAME TO MAIN

    Info:MAIN:CAME HERE AFTER 60 seconds

    Info:MAIN:Time 65, free 102664, MQTT 0, bWifi 1, secondsWithNoPing 4, socks 1/38

    Info:MAIN:came to run mqtt every second update

    Info:MAIN:Timer discovers disconnected mqtt 5

    Info:MAIN:CAME TO MAIN

    Info:MAIN:CAME HERE AFTER 60 seconds

    Info:MAIN:Time 66, free 102664, MQTT 0, bWifi 1, secondsWithNoPing 5, socks 1/38

    Info:MAIN:came to run mqtt every second update



    Info:MAIN:Timer discovers disconnected mqtt 6

    Info:MAIN:CAME TO MAIN

    Info:MAIN:CAME HERE AFTER 60 seconds

    Info:MAIN:Time 67, free 102664, MQTT 0, bWifi 1, secondsWithNoPing 6, socks 1/38

    Info:MAIN:came to run mqtt every second update

    Info:MAIN:Timer discovers disconnected mqtt 7

    Info:MAIN:CAME TO MAIN

    Info:MAIN:CAME HERE AFTER 60 seconds

    Info:MAIN:Time 68, free 102664, MQTT 0, bWifi 1, secondsWithNoPing 7, socks 1/38

    Info:MAIN:came to run mqtt every second update

    Info:MAIN:Timer discovers disconnected mqtt 8

    Info:MAIN:CAME TO MAIN

    Info:MAIN:CAME HERE AFTER 60 seconds

    Info:MAIN:Time 69, free 102664, MQTT 0, bWifi 1, secondsWithNoPing 8, socks 1/38

    sta: 1, softap: 0, b/g/n
    sta:rssi=-64,ssid=twtest1,bssid=44:d9:e7:59:f4:2a ,channel=6,cipher_type:MIXED
    Info:MAIN:came to run mqtt every second update

    Info:MAIN:Timer discovers disconnected mqtt 9

    Info:MAIN:CAME TO MAIN

    Info:MAIN:CAME HERE AFTER 60 seconds

    Info:MAIN:Time 70, free 102664, MQTT 0, bWifi 1, secondsWithNoPing 9, socks 1/38

    Info:GEN:dhcp=0 ip=192.168.1.102 gate=192.168.1.1 mask=255.255.255.0 mac=d4:a6:51:f3:33:51

    Info:MAIN:came to run mqtt every second update

    Info:MAIN:Timer discovers disconnected mqtt 10

    Info:MAIN:came here to connect again

    Info:MQTT:my_mac="50:33:f3:51:a6:d4"
    Info:MQTT:blub_data={"RED":0,"BLUE":0,"GREEN":0,"WHITE":10}
    Info:CFG:g_cfg.mqtt_pass=demo@2018
    Info:MQTT:pub_payload={"STATUS":"OFFLINE","S_NO":"3350","FWV":11,"MAC":"50:33:f3:51:a6:d4","CONF":{"RED":0,"BLUE":0,"GREEN":0,"WHITE":10}}
    Info:MQTT:mqtt_userName twdemo
    mqtt_pass demo@2018
    mqtt_clientID 3350
    mqtt_host 3.6.105.29:1883

    Info:MAIN:status="OFFLINE"
    Info:MQTT:client_id 3350

    Info:MQTT:client_pass demo@2018

    Info:MQTT:client_user twdemo

    Info:MQTT:mqtt_client_info.keep_alive 30

    Info:MAIN:CAME TO MAIN

    Info:MAIN:CAME HERE AFTER 60 seconds

    Info:MAIN:Time 71, free 102456, MQTT 0, bWifi 1, secondsWithNoPing 10, socks 1/38

    Info:MQTT:MQTT_STATUS=0
    Info:MQTT:MQTT_STATUS=0
    Info:MQTT:my_mac="50:33:f3:51:a6:d4"
    Info:MQTT:blub_data={"RED":0,"BLUE":0,"GREEN":0,"WHITE":10}
    Info:MQTT:mqtt_connection_cb: Successfully connected
    thanks and regards
    manikandan v
  • #2
    p.kaczmarek2
    Level 27  
    manivalaguru1 wrote:
    and all and changed the formot to support our own broker but problem is it disconnects and reconnects every 60

    manivalaguru1 wrote:

    Info:MQTT:blub_data={"RED":0,"BLUE":0,"GREEN":0,"WHITE":10}

    I can clearly see that you are using a modified version of our SDK. Can you provide us more information on:
    1. what exactly was modified (where are you calling the publish from, are you calling it once per frame, or maybe call it too often and exceed the buffers limit?); maybe could you show us your Github repository?
    2. was is working correctly before, before your changes?

    MQTT might disconnect if you are, for example, doing a publish every frame or doing lots of publishes very often
  • #3
    manivalaguru1
    Level 1  
    hello ,
    thanks for you reply i have tired to connect with my broker without any changes that code also disconnect's and reconnects every minute.
    i have added ble functionality to sdk other than that everything pretty much the same here is my code base https://github.com/manivalaguru/wbl3/tree/master
    can you please check and get back to me

    thanks and regards
    manikandan v
  • #4
    p.kaczmarek2
    Level 27  
    Would it be possible for you to submit your code as a fork of my repository, instead of doing a "fresh" upload?

    I am asking because I wanted to analyze your code but there is no "Diff" (differences since my commits) view and it's hard for me to find all changes.

    Is msg_processor.c the file you added?

    Also, if you need an extra feature, why don't you create a pull request for OpenBeken, then I also could help you with testing on my devices.

    Also, is this an attempt of adding a Domoticz support?
  • #5
    manivalaguru1
    Level 1  
    @p.kaczmarek2
    hello thanks for your reply i have created a pull request in your repo https://github.com/openshwprojects/OpenBK7231T_App/pull/209
    can you please check and get back to me for stable mqtt connection
    have you got time to check this i have got everything else for requirement this is the only thing that pending
    thanks and regards
    manikandan v
  • #6
    p.kaczmarek2
    Level 27  
    That's really lots of changes. Have you made them yourself?

    You've also broke compatibility with lots of stuff, even the Channel_OnChanged are changed now.

    What is the point of adding linux/lib/rbtree.c to SDK?

    Also many, many changes to new_mqtt and to user_main....

    Well, I'd start with doing a simple test
    I'd suggest you getting latest OBK codebase and hardcoding it to publish your MQTT string, that one:
    Code:

        snprintf(blub_data, sizeof(blub_data), "{\"RED\":%d,\"BLUE\":%d,\"GREEN\":%d,\"WHITE\":%d}",smartblub_config_data.r_brightness,smartblub_config_data.b_brightness,smartblub_config_data.g_brightness, smartblub_config_data.w_brightness)

    Hardcode all values, make it publish that string every, idk, 30 seconds, and then see if the unchanged SDK also disconnects.
    This will allow us to determine whether the issue is also in the original SDK or it happens only in your fork.
  • #7
    manivalaguru1
    Level 1  
    hello thanks for your reply
    1)yes right now i am only one working on this i have modified mqtt,user main,new_cfg files also added ble functionality so that we can configure wifi and mqtt cerdentials using ble i have also tested OTA that also working fine.
    2) like you said i have tested this with latest obk case but mqtt still disconnects every minute here is the log of connection, disconnection and connection i have only changed wifi and mqtt cerdentials..

    LOG:
    sta: 1, softap: 0, b/g/n
    sta:rssi=-61,ssid=twtest1,bssid=44:d9:e7:59:f4:2a ,channel=1,cipher_type:MIXED
    Info:MAIN:Time 410, free 103456, MQTT 1, bWifi 1, secondsWithNoPing 349, socks 2

    Info:GEN:dhcp=0 ip=192.168.1.109 gate=192.168.1.1 mask=255.255.255.0 mac=c8:47:8

    Info:MAIN:Time 411, free 103456, MQTT 1, bWifi 1, secondsWithNoPing 350, socks 2

    Info:MAIN:Time 412, free 103456, MQTT 1, bWifi 1, secondsWithNoPing 351, socks 2

    Info:MAIN:Time 413, free 103456, MQTT 1, bWifi 1, secondsWithNoPing 352, socks 2

    Info:MAIN:Time 414, free 103456, MQTT 1, bWifi 1, secondsWithNoPing 353, socks 2

    Info:MAIN:Time 415, free 103456, MQTT 1, bWifi 1, secondsWithNoPing 354, socks 2

    Info:MAIN:Time 416, free 103456, MQTT 1, bWifi 1, secondsWithNoPing 355, socks 2

    Info:MAIN:Time 417, free 103456, MQTT 1, bWifi 1, secondsWithNoPing 356, socks 2

    Info:MAIN:Time 418, free 103456, MQTT 1, bWifi 1, secondsWithNoPing 357, socks 2

    Info:MAIN:Time 419, free 103456, MQTT 1, bWifi 1, secondsWithNoPing 358, socks 2

    sta: 1, softap: 0, b/g/n
    sta:rssi=-62,ssid=twtest1,bssid=44:d9:e7:59:f4:2a ,channel=1,cipher_type:MIXED
    Info:MAIN:Time 420, free 103456, MQTT 1, bWifi 1, secondsWithNoPing 359, socks 2

    Info:GEN:dhcp=0 ip=192.168.1.109 gate=192.168.1.1 mask=255.255.255.0 mac=c8:47:8

    Info:MQTT:mqtt_connection_cb: Disconnected, reason: 256

    Info:MAIN:Time 421, free 103456, MQTT 0, bWifi 1, secondsWithNoPing 360, socks 2

    Info:MAIN:wl_status 11

    Info:MAIN:Main_OnWiFiStatusChange - WIFI_STA_CONNECTED

    Info:MAIN:Time 422, free 103456, MQTT 0, bWifi 1, secondsWithNoPing 361, socks 2

    Info:MAIN:Time 423, free 103456, MQTT 0, bWifi 1, secondsWithNoPing 362, socks 2

    Info:MAIN:Time 424, free 103456, MQTT 0, bWifi 1, secondsWithNoPing 363, socks 2

    Info:MAIN:Time 425, free 103456, MQTT 0, bWifi 1, secondsWithNoPing 364, socks 2

    Info:MAIN:Time 426, free 103456, MQTT 0, bWifi 1, secondsWithNoPing 365, socks 2

    Info:MAIN:Time 427, free 103456, MQTT 0, bWifi 1, secondsWithNoPing 366, socks 2

    Info:MAIN:Time 428, free 103456, MQTT 0, bWifi 1, secondsWithNoPing 367, socks 2

    Info:MAIN:Time 429, free 103456, MQTT 0, bWifi 1, secondsWithNoPing 368, socks 2

    sta: 1, softap: 0, b/g/n
    sta:rssi=-63,ssid=twtest1,bssid=44:d9:e7:59:f4:2a ,channel=1,cipher_type:MIXED
    Info:MAIN:Time 430, free 103456, MQTT 0, bWifi 1, secondsWithNoPing 369, socks 2

    Info:GEN:dhcp=0 ip=192.168.1.109 gate=192.168.1.1 mask=255.255.255.0 mac=c8:47:8

    Info:MQTT:mqtt_userName twdemo
    mqtt_pass demo@2018
    mqtt_clientID obk8C000000
    mqtt_host 3.6.105.29:1883

    Info:MAIN:Time 431, free 103248, MQTT 0, bWifi 1, secondsWithNoPing 370, socks 2

    Info:MQTT:mqtt_connection_cb: Successfully connected

    Info:MQTT:mqtt_subscribed to obk8C000000/+/set

    Info:MQTT:mqtt_subscribed to cmnd/obk8C000000/+

    Info:MQTT:MQTT client "obk8C000000" request cb: err 0

    Info:MQTT:MQTT client "obk8C000000" request cb: err 0

    Info:MAIN:Time 432, free 103456, MQTT 1, bWifi 1, secondsWithNoPing 371, socks 2

    Info:MAIN:Time 433, free 103456, MQTT 1, bWifi 1, secondsWithNoPing 372, socks 2

    Info:MAIN:Time 434, free 103456, MQTT 1, bWifi 1, secondsWithNoPing 373, socks 2

    Info:MAIN:Time 435, free 103456, MQTT 1, bWifi 1, secondsWithNoPing 374, socks 2

    Info:MAIN:Time 436, free 103456, MQTT 1, bWifi 1, secondsWithNoPing 375, socks 2

    Info:MAIN:Time 437, free 103456, MQTT 1, bWifi 1, secondsWithNoPing 376, socks 2

    Info:MAIN:Time 438, free 103456, MQTT 1, bWifi 1, secondsWithNoPing 377, socks 2

    Info:MAIN:Time 439, free 103456, MQTT 1, bWifi 1, secondsWithNoPing 378, socks 2

    sta: 1, softap: 0, b/g/n
    sta:rssi=-64,ssid=twtest1,bssid=44:d9:e7:59:f4:2a ,channel=1,cipher_type:MIXED
    Info:MAIN:Time 440, free 103456, MQTT 1, bWifi 1, secondsWithNoPing 379, socks 2

    Info:GEN:dhcp=0 ip=192.168.1.109 gate=192.168.1.1 mask=255.255.255.0 mac=c8:47:8

    Info:MAIN:Time 441, free 103456, MQTT 1, bWifi 1, secondsWithNoPing 380, socks 2

    Info:MAIN:Time 442, free 103456, MQTT 1, bWifi 1, secondsWithNoPing 381, socks 2

    Info:MAIN:Time 443, free 103456, MQTT 1, bWifi 1, secondsWithNoPing 382, socks 2

    Info:MAIN:Time 444, free 103456, MQTT 1, bWifi 1, secondsWithNoPing 383, socks 2

    thanks and regards
    Manikandan V
  • #8
    p.kaczmarek2
    Level 27  
    manivalaguru1 wrote:

    2) like you said i have tested this with latest obk case but mqtt still disconnects every minute here is the log of connection, disconnection and connection i have only changed wifi and mqtt cerdentials..

    Are you saying that the latest OBK build disconnects from your MQTT broker without any changes to our codebase?

    What kind of MQTT broker do you have?
  • #9
    manivalaguru1
    Level 1  
    yes base code also connecting and disconnecting,i am using mosquitto non sql here is my cerdentials
    strcpy(g_cfg.mqtt_host, "3.6.105.29");
    strcpy(g_cfg.mqtt_userName, "twdemo");
    strcpy(g_cfg.mqtt_pass,"demo@2018");can you check with your code and get back to me

    thanks and regards
  • #10
    manivalaguru1
    Level 1  
    can you able to recreate the issue?