astarte_device v0.11.1 Astarte.Device
A process that manages a device connection to Astarte. See Astarte.Device.start_link/1
for the options.
Link to this section Summary
Functions
Returns a specification to start this module under a supervisor.
See Supervisor
in Elixir v1.6+.
Returns the pid
of the Astarte.Device
process for the given realm/device_id
pair, or nil
if
there's no existing device for that pair.
Send a datastream value to Astarte.
Send a property value to Astarte.
Start an Astarte.Device
.
Blocks until the device succesfully connects to the broker, then returns :ok
.
Link to this section Types
device_option()
Link to this section Functions
child_spec(arg)
Returns a specification to start this module under a supervisor.
See Supervisor
in Elixir v1.6+.
connected(arg1, arg2, data)
connecting(arg1, arg2, data)
disconnected(arg1, arg2, data)
get_pid(realm, device_id)
get_pid( realm :: String.t(), device_id :: Astarte.Core.Device.encoded_device_id() ) :: pid() | nil
Returns the pid
of the Astarte.Device
process for the given realm/device_id
pair, or nil
if
there's no existing device for that pair.
Devices are registered to Astarte.Device.Registry
with key {realm, device_id}
when they are started.
no_certificate(arg1, arg2, data)
no_keypair(arg1, arg2, data)
send_datastream(pid, interface_name, path, value, opts \\ [])
send_datastream( pid :: pid(), interface_name :: String.t(), path :: String.t(), value :: term(), opts :: options ) :: :ok | {:error, reason :: term()} when options: [option], option: {:qos, qos :: Tortoise.qos()} | {:timestamp, timestamp :: DateTime.t()}
Send a datastream value to Astarte.
This call is blocking and waits for the message to be ACKed at the MQTT level.
set_property(pid, interface_name, path, value)
Send a property value to Astarte.
This call is blocking and waits for the message to be ACKed at the MQTT level.
start_link(device_options)
start_link(opts :: device_options()) :: :gen_statem.start_ret()
Start an Astarte.Device
.
Device Options
pairing_url
- URL of the Astarte Pairing API instance the device will connect to, up to (and including)/v1
. E.g.https://astarte.api.example.com/pairing/v1
orhttp://localhost:4003/v1
for a local installation.realm
- Realm which the device belongs to.device_id
- Device ID of the device. The device ID must be 128-bit long and must be encoded with url-safe base64 without padding. You can generate a random one with:crypto.strong_rand_bytes(16) |> Base.url_encode64(padding: false)
.credentials_secret
- The credentials secret obtained when registering the device using Pairing API (to register a device useAstarte.API.Pairing.Agent.register_device/2
or see https://docs.astarte-platform.org/latest/api/index.html?urls.primaryName=Pairing%20API#/agent/registerDevice).interface_provider
- A tuple{module, args}
wheremodule
is a module implementingAstarte.Device.InterfaceProvider
behaviour andargs
are the arguments passed to its init function. It's also possible to pass a path containing the JSON interfaces the device will use, and that path will be passed toAstarte.Device.FilesystemInterfaceProvider
.credential_storage
(optional) - A tuple{module, args}
wheremodule
is a module implementingAstarte.Device.CredentialStorage
behaviour andargs
are the arguments passed to its init function. If not provided,Astarte.Device.InMemoryStorage
will be used.handler
(optional) - A tuple{module, args}
wheremodule
is a module implementingAstarte.Device.Handler
behaviour andargs
are the arguments passed to itsinit_state
function. If not provided,Astarte.Device.DefaultHandler
will be used.ignore_ssl_errors
(optional) - Defaults tofalse
, iftrue
the device will ignore SSL errors during connection. Useful if you're using the Device to connect to a test instance of Astarte with self signed certificates, it is not recommended to leave thistrue
in production.
Blocks until the device succesfully connects to the broker, then returns :ok
.
Useful to ensure the device has established the initial connection before beginning to publish.