Author Topic: Sending Beacon Data Over MQTT  (Read 1271 times)

kbrooking

  • Full Member
  • ***
  • Posts: 104
    • View Profile
Sending Beacon Data Over MQTT
« on: October 15, 2017, 12:11:00 pm »
Is it possible to use beacons to send temperature and battery level data every 10 seconds over MQTT and still maintain 2 years battery life? If so, do you have any sample code that shows how to do this?

Share on Facebook Share on Twitter


kbrooking

  • Full Member
  • ***
  • Posts: 104
    • View Profile
Re: Sending Beacon Data Over MQTT
« Reply #1 on: October 16, 2017, 09:46:06 am »
I guess what I'm really asking here is what is the difference in power consumption wise between sending a regular beacon and sending a beacon over MQTT if any?

mc-John

  • Global Moderator
  • Full Member
  • *****
  • Posts: 212
    • View Profile
Re: Sending Beacon Data Over MQTT
« Reply #2 on: October 16, 2017, 09:59:58 am »
There is a large difference in power consumption between sending a beacon or sending to the MQTT server. It is probably 20-times lower power. To lower the power you should limit the connection time to 5 minutes. There are beacon commands to fill the 8 bytes beacon message. See the user manual for the commands, just search beacon in the pdf. Also read the white paper about beaconing which describes the format.

mc-John

  • Global Moderator
  • Full Member
  • *****
  • Posts: 212
    • View Profile
Re: Sending Beacon Data Over MQTT
« Reply #3 on: October 16, 2017, 10:07:19 am »
Quote
sending a regular beacon and sending a beacon over MQTT

Beacons are always send, with or without data in it. You can set the frequency yourself, see user manual. I think that the default is 10-sec.
If a gateway receives a beacon and has valid MQTT broker and the box "Send Beacons" is on it will send the beacons to the MQTT broker.

kbrooking

  • Full Member
  • ***
  • Posts: 104
    • View Profile
Re: Sending Beacon Data Over MQTT
« Reply #4 on: October 16, 2017, 02:46:19 pm »
So if I have a MQTT server defined in the GW configuration, every time I issue a "SendBecaon" command the mcGateway will relay this to the MQTT server?

mc-John

  • Global Moderator
  • Full Member
  • *****
  • Posts: 212
    • View Profile
Re: Sending Beacon Data Over MQTT
« Reply #5 on: October 16, 2017, 04:36:37 pm »
Yes and every 10 seconds

kbrooking

  • Full Member
  • ***
  • Posts: 104
    • View Profile
Re: Sending Beacon Data Over MQTT
« Reply #6 on: October 17, 2017, 09:52:32 am »
So what is the difference between MQTT.BeaconPublish and SendBeacon commands?

mc-John

  • Global Moderator
  • Full Member
  • *****
  • Posts: 212
    • View Profile
Re: Sending Beacon Data Over MQTT
« Reply #7 on: October 17, 2017, 02:56:22 pm »
I don't know what you mean with MQTT.BeaconPublish.

In the class LpLan there is SendBeacon(), SetBeacon(time, data), SetBeaconTime(time), SetBeaconData(data)

There is no MQTT class!!!

kbrooking

  • Full Member
  • ***
  • Posts: 104
    • View Profile
Re: Sending Beacon Data Over MQTT
« Reply #8 on: October 18, 2017, 09:21:38 am »
Hmmm. Not sure where I got that. Wonder why it doesn't give an error.

For instance, I use this line of code and builds without any errors:

MQTT.BeaconPublish(dataType.TEMPERATURE, TempF, BattVolt)

mc-John

  • Global Moderator
  • Full Member
  • *****
  • Posts: 212
    • View Profile
Re: Sending Beacon Data Over MQTT
« Reply #9 on: October 18, 2017, 09:49:03 am »
Did you create an MQTT class yourself?

kbrooking

  • Full Member
  • ***
  • Posts: 104
    • View Profile
Re: Sending Beacon Data Over MQTT
« Reply #10 on: October 18, 2017, 09:58:11 am »
Oh yeah. Let me check. I'm using  Nick's libraries maybe he created that class.

bdevlin

  • Newbie
  • *
  • Posts: 38
    • View Profile
Re: Sending Beacon Data Over MQTT
« Reply #11 on: October 23, 2017, 08:31:34 pm »
Here's a snippet of code that works. I use it for versioning the MC-110/120 modules. This way I can see in the ide which ones have the latest code.

Class mqtt_json
    Shared version As Float
    Shared Event Boot()
        '############ This is your mcMod software version. You can see the version in the first byte of beacon data in Device maintenence and Connections under the ->Tools->Devices menu.
        version = 2
        '############ Add the version to the first byte of beacon data.
        Dim beacondata As ListOfByte = New ListOfByte()
        beacondata.Add(version.ToByte)
        Lplan.SetBeaconData(beacondata)
       
       
        '### Write out boot acknowledgement for debugging. Not required for the beacon, but picked up in an MQTT subscription
        Dim id As String = Device.mcUID().ToString("x8")
        Lplan.Publish("mqtt/boot", ("{Boot:" + id + ",Version:" + version.ToString+ "}").ToListOfByte, QoS.AtLeastOnce)       
    End Event

Useful Useful x 1 View List