mc-Things

mc-Platform => MQTT => Topic started by: kbrooking on October 15, 2017, 12:11:00 pm

Title: Sending Beacon Data Over MQTT
Post by: kbrooking 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?
Title: Re: Sending Beacon Data Over MQTT
Post by: kbrooking 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?
Title: Re: Sending Beacon Data Over MQTT
Post by: mc-John 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.
Title: Re: Sending Beacon Data Over MQTT
Post by: mc-John 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.
Title: Re: Sending Beacon Data Over MQTT
Post by: kbrooking 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?
Title: Re: Sending Beacon Data Over MQTT
Post by: mc-John on October 16, 2017, 04:36:37 pm
Yes and every 10 seconds
Title: Re: Sending Beacon Data Over MQTT
Post by: kbrooking on October 17, 2017, 09:52:32 am
So what is the difference between MQTT.BeaconPublish and SendBeacon commands?
Title: Re: Sending Beacon Data Over MQTT
Post by: mc-John 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!!!
Title: Re: Sending Beacon Data Over MQTT
Post by: kbrooking 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)
Title: Re: Sending Beacon Data Over MQTT
Post by: mc-John on October 18, 2017, 09:49:03 am
Did you create an MQTT class yourself?
Title: Re: Sending Beacon Data Over MQTT
Post by: kbrooking on October 18, 2017, 09:58:11 am
Oh yeah. Let me check. I'm using  Nick's libraries maybe he created that class.
Title: Re: Sending Beacon Data Over MQTT
Post by: bdevlin 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