class M2X::MQTT::Device
Wrapper for AT&T M2X
Device
API m2x.att.com/developer/documentation/v2/device
Constants
- PATH
Public Class Methods
Create a new device
m2x.att.com/developer/documentation/v2/device#Create-Device
# File lib/m2x/mqtt/device.rb, line 11 def create!(client, params) client.post(PATH, params) new(client, params) end
Public Instance Methods
Return a list of recently received commands.
Most commonly, this method can be used to fetch unacknowledged commands by filtering by delivery status, using the parameters:
{ status: “sent” }
MQTT clients that are subscribed to command delivery notifications should still use this method periodically to check for unacknowledged commands that were missed while offline or during a network partition.
m2x.att.com/developer/documentation/v2/commands#Device-List-of-Received-Commands
# File lib/m2x/mqtt/device.rb, line 38 def commands(params={}) @client.get("#{path}/commands", params) res = @client.get_response commands = res["body"]["commands"] if res["status"] < 300 commands.map { |data| M2X::MQTT::Command.new(@client, data) } if commands end
# File lib/m2x/mqtt/device.rb, line 18 def path @path ||= "#{ PATH }/#{ URI.encode(@attributes.fetch("id")) }" end
Post Device
Update (Single Value to Multiple Streams)
This method allows posting a single value to multiple streams belonging to a device and optionally, the device's location.
All the streams should be created before posting values using this method.
The `params` parameter accepts a Hash which can contain the following keys:
- values: A Hash in which the keys are the stream names and the values hold the stream values. - location: (optional) A hash with the current location of the specified device. - timestamp: (optional) The timestamp for all the passed values and location. If ommited, the M2X server's time will be used. { values: { temperature: 30, humidity: 80 }, location: { name: "Storage Room", latitude: -37.9788423562422, longitude: -57.5478776916862, elevation: 5 } }
m2x.att.com/developer/documentation/v2/device#Post-Device-Update–Single-Values-to-Multiple-Streams-
# File lib/m2x/mqtt/device.rb, line 113 def post_update(params) @client.post("#{path}/update", params) end
Post Device
Updates (Multiple Values to Multiple Streams)
This method allows posting multiple values to multiple streams belonging to a device and optionally, the device location.
All the streams should be created before posting values using this method.
The `values` parameter contains an object with one attribute per each stream to be updated. The value of each one of these attributes is an array of timestamped values.
{ temperature: [ { "timestamp": <Time in ISO8601>, "value": x }, { "timestamp": <Time in ISO8601>, "value": y }, ], humidity: [ { "timestamp": <Time in ISO8601>, "value": x }, { "timestamp": <Time in ISO8601>, "value": y }, ] }
The optional location attribute can contain location information that will be used to update the current location of the specified device
# File lib/m2x/mqtt/device.rb, line 80 def post_updates(params) @client.post("#{path}/updates", params) end
# File lib/m2x/mqtt/device.rb, line 22 def stream(name) M2X::MQTT::Stream.new(@client, self, "name" => name) end
Update the current location of the specified device.
m2x.att.com/developer/documentation/v2/device#Update-Device-Location
# File lib/m2x/mqtt/device.rb, line 50 def update_location(params) @client.put("#{path}/location", params) end