class M2X::MQTT::Stream

Wrapper for AT&T M2X Data Streams API m2x.att.com/developer/documentation/v2/device

Public Class Methods

new(client, device, attributes) click to toggle source
# File lib/m2x/mqtt/stream.rb, line 5
def initialize(client, device, attributes)
  @client     = client
  @device     = device
  @attributes = attributes
end

Public Instance Methods

path() click to toggle source
# File lib/m2x/mqtt/stream.rb, line 11
def path
  @path ||= "#{@device.path}/streams/#{ URI.encode(@attributes.fetch("name")) }"
end
post_values(values) click to toggle source

Post multiple values to the stream

The `values` parameter is an array with the following format:

[
  { "timestamp": <Time in ISO8601>, "value": x },
  { "timestamp": <Time in ISO8601>, "value": y },
  [ ... ]
]

m2x.att.com/developer/documentation/v2/device#Post-Data-Stream-Values

# File lib/m2x/mqtt/stream.rb, line 48
def post_values(values)
  params = { values: values }

  @client.post("#{path}/values", params)
end
update!(params={}) click to toggle source

Update stream properties (if the stream does not exist it gets created).

m2x.att.com/developer/documentation/v2/device#Create-Update-Data-Stream

# File lib/m2x/mqtt/stream.rb, line 19
def update!(params={})
  @client.put(path, params)

  @attributes.merge!(params)
end
update_value(value, timestamp=nil) click to toggle source

Update the current value of the stream. The timestamp is optional. If ommited, the current server time will be used

m2x.att.com/developer/documentation/v2/device#Update-Data-Stream-Value

# File lib/m2x/mqtt/stream.rb, line 29
def update_value(value, timestamp=nil)
  params = { value: value }

  params[:timestamp] = timestamp if timestamp

  @client.put("#{path}/value", params)
end