Author Topic: Lplan.Subscribe error  (Read 367 times)

helge

  • Newbie
  • *
  • Posts: 27
    • View Profile
Re: Lplan.Subscribe error
« on: July 23, 2016, 09:14:43 am »
I've tested the following code and it does work, the module does not freeze in runtime mode. I didn't try to debug it.

Sometimes my MQTT server doesn't get the external publish, don't know why yet. Maybe a mosquitto bug, dunno.

Code: [Select]
Class MQTTSubscribeExample
    Const DeviceId As String = "mc-001"
    Const SubscribeTopicLED1 As String = "mcThings/ioT/" + DeviceId + "/led1"
    Const SubscribeTopicLED2 As String = "mcThings/ioT/" + DeviceId + "/led2"
   
    Shared Event Boot()
        Lplan.SetLowPowerMode(1) ' CAUTION: do not use 1 second interval in production
        Lplan.Subscribe(SubscribeTopicLED1)
        Lplan.Subscribe(SubscribeTopicLED2)
    End Event
   
    Shared Event SubscriptionDelivery()
        Dim msg As Message = Lplan.GetDelivery()
        If msg.Topic= SubscribeTopicLED1 Then
            Dim payload As ListOfByte = msg.PayLoad
            If payload(0) = 0x31 Then
                LedGreen = True
            Else
                LedGreen = False
            End If
        ElseIf msg.Topic= SubscribeTopicLED2 Then
            Dim payload As ListOfByte = msg.PayLoad
            If payload(0) = 0x31 Then
                LedRed = True
            Else
                LedRed = False
            End If
        End If
    End Event
End Class