Author Topic: Long MQTT Subscription Delay  (Read 528 times)

InvisibleMan1002

  • Newbie
  • *
  • Posts: 7
    • View Profile
Long MQTT Subscription Delay
« on: June 24, 2016, 03:16:17 pm »
I'm having a problem with a Sketch dealing with MQTT.
I'm using GnatMQ as my MQTT Broker.
I have 3 .NET Client apps connected to the broker.
They are set to Publish and Subscribe.  I can click on the Publish button all day long and the messages show up in the other windows immediately.

After a lot of troubleshooting different events and such, I came to the conclusion that the Gateway does not check and or rebroadcast a Subscribed event as fast as it should.

I'm not sure if this is the exact issue or not, but With a Sketch programmed to a Module and Turning on the gateway the first time, the Subscribe events happen as fast as I could press the Publish button.
I was very happy about this.  Then I opened up mc-studio, connected gateways and such, I noticed my publish events are not happening.
After a lot of playing, I noticed it was taking like 45 seconds or more before my RED led turned on.
I thought it might have something to do with it sleeping, so I made the green LED turn on/off every 3 seconds.
It still took 45+ seconds for my red LED to turn on/off.

My MQTT Clients responds to all events immediately, as well as a test android app.  So I know the Broker is doings it job.
What would make the gateway stop responding to events in a timely manner?

Oddly enough, when I was publishing an event, it happened every 60 seconds like you'd expect, commented out below as in reality these modules will just only subscribing.

My versions:
mc-Module.
BIN File Download: V0.7-357         

mc-Gateway.
Application Processor BIN File Download: BIN FILE V0.6-357
Host Processor BIN File Download: BIN FILE V0.7-404

mc-Studio.
Application Download: mc-Studio Application V0.7-893

Sketch:
Code: [Select]
//
// This example logs the mc Unique IDentifier (mcUID) and the Temperature
// to IFTTT.
//
Class Temperature
    Shared Event Boot()
        Lplan.Subscribe("peckham/LIGHT")         
       
    End Event
   
    //   Shared Event GetTemp() RaiseEvent Every 1 Minutes
    //       Dim TempC As Float = TempSensor.GetTemp
    //       Dim TempF As Float = TempSensor.ToFarenheit(TempC)
    //       
    //       If TempF > 80.0 Then
    //           LedRed = True
    //       Else
    //           LedRed = False
    //       End If
    //       
    //       Dim payload As ListOfByte = New ListOfByte()
    //       payload.Add(TempF.ToString)
    //       Lplan.Publish("peckham/ART", payload)
    //   End Event
   
   
    Shared Event SubscriptionDelivery()
        Dim msg As Message = Lplan.GetDelivery()
        If msg.Topic= "peckham/LIGHT" Then
            Dim payload As ListOfByte = msg.PayLoad
           
            If payload(0) = 49 Then
                LedRed = Not LedRed
            End If
            If payload(0) = 50 Then
                LedGreen = Not LedGreen
            End If
        End If
    End Event
   
    Shared Event BlinkGreen() RaiseEvent Every 3000 milliSeconds
        LedGreen = Not LedGreen
    End Event
   
End Class


Thank you,
Trey

Share on Facebook Share on Twitter


kristofferis

  • Sr. Member
  • ****
  • Posts: 287
  • Location: Sweden
    • View Profile
Re: Long MQTT Subscription Delay
« Reply #1 on: June 24, 2016, 03:30:52 pm »
Hello.
I think you have to change the power mode to high, then both the mcModule and mcGateway could initiate a connection.
This will of course use more power.

You change it on the fly with this functions:
SetLowPowerMode(), SetMidPowerMode() and SetHighPowerMode()

From documentation:
High (V1.0) – is the power mode where both the gateway and the module
can initiate the connection. This mode consumes more power because the
device is always listening or sending. It is mostly used if the device has to
react quickly to something sent by the gateway like a relay.

mc-John

  • Global Moderator
  • Full Member
  • *****
  • Posts: 212
    • View Profile
Re: Long MQTT Subscription Delay
« Reply #2 on: June 25, 2016, 04:26:54 pm »
The high power mode is not implemented yet but you could use Mid power mode with 100mSec

InvisibleMan1002

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Long MQTT Subscription Delay
« Reply #3 on: June 27, 2016, 10:28:18 am »
Thank you, I went to give it a try, was going to add this function to my Boot() event, but I get this message.
"SetMidPowerMode is not a function or indexed class like lists."

Document says it is a function, so I guess I'm not sure how to initiate it.
The functions SetLowPowerMode(), SetMidPowerMode() and SetHighPowerMode()
specify the mode. This can be changed at run time.
Code: [Select]
    Shared Event Boot()
        SetMidPowerMode()//SetMidPowerMode(500),SetMidPowerMode("500")
        Lplan.Subscribe("peckham/LIGHT")         
    End Event

Thank you.

kristofferis

  • Sr. Member
  • ****
  • Posts: 287
  • Location: Sweden
    • View Profile
Re: Long MQTT Subscription Delay
« Reply #4 on: June 27, 2016, 10:40:26 am »
Hello.
You should add Lplan. Infront of the function.

Try that and let me know the result.

InvisibleMan1002

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Long MQTT Subscription Delay
« Reply #5 on: June 27, 2016, 10:57:55 am »
Ah,  Thank you.

That is working.
Code: [Select]
    Shared Event Boot()
        Lplan.SetMidPowerMode(500)
        Lplan.Subscribe("peckham/LIGHT")         
    End Event

kristofferis

  • Sr. Member
  • ****
  • Posts: 287
  • Location: Sweden
    • View Profile
Re: Long MQTT Subscription Delay
« Reply #6 on: June 27, 2016, 12:28:52 pm »
That's great.
No problem, let me know if you need any more assistance and I will do my best to help.