mc-Things
mc-Platform => MQTT => Topic started 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?
-
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?
-
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.
-
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.
-
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?
-
Yes and every 10 seconds
-
So what is the difference between MQTT.BeaconPublish and SendBeacon commands?
-
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!!!
-
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)
-
Did you create an MQTT class yourself?
-
Oh yeah. Let me check. I'm using Nick's libraries maybe he created that class.
-
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