go-api-bindings: github.com/Tinkerforge/go-api-bindings/ipconnection Index | Files

package ipconnection

import "github.com/Tinkerforge/go-api-bindings/ipconnection"

The IP Connection manages the communication between the API bindings and the Brick Daemon or a WIFI/Ethernet Extension. Before Bricks and Bricklets can be controlled using their API an IP Connection has to be created and its TCP/IP connection has to be established.

Index

Package Files

ipcon_handle.go

type ConnectReason Uses

type ConnectReason = uint8

This enum specifies the reason of a successful connection. It is generated by the connect callback.

const (
    // Connection established after request from user.
    ConnectReasonRequest ConnectReason = iota
    // Connection after auto-reconnect.
    ConnectReasonAutoReconnect
)

type ConnectionState Uses

type ConnectionState = uint8

State of the connection to the Brick Daemon or the WIFI/Ethernet Extension.

const (
    // No connection is established.
    ConnectionStateDisconnected ConnectionState = iota
    // A connection to the Brick Daemon or the WIFI/Ethernet Extension is established.
    ConnectionStateConnected
    // IP Connection is currently trying to connect.
    ConnectionStatePending
)

type DisconnectReason Uses

type DisconnectReason = uint8

This enum specifies the reason of a connections termination. It is generated by the disconnect callback.

const (
    // Disconnect was requested by user.
    DisconnectReasonRequest DisconnectReason = iota
    // Disconnect because of an unresolvable error.
    DisconnectReasonError
    // Disconnect initiated by Brick Daemon or WIFI/Ethernet Extension.
    DisconnectReasonShutdown
)

type EnumerationType Uses

type EnumerationType = uint8

Type of enumeration of a device.

const (
    // Device is available (enumeration triggered by user).
    // This enumeration type can occur multiple times for the same device.
    EnumerationTypeAvailable EnumerationType = iota
    // Device is newly connected (automatically send by Brick after establishing a communication connection).
    // This indicates that the device has potentially lost its previous configuration and needs to be reconfigured.
    EnumerationTypeConnected
    // Device is disconnected (only possible for USB connection). In this case only uid and enumerationType are valid.
    EnumerationTypeDisconnected
)

type IPConnection Uses

type IPConnection struct {
    // contains filtered or unexported fields
}

The IP Connection manages the communication between the API bindings and the Brick Daemon or a WIFI/Ethernet Extension. Before Bricks and Bricklets can be controlled using their API an IP Connection has to be created and its TCP/IP connection has to be established.

func New Uses

func New() IPConnection

Creates an IP Connection object that can be used to enumerate the available devices. It is also required for the constructor of Bricks and Bricklets.

func (*IPConnection) Authenticate Uses

func (ipcon *IPConnection) Authenticate(secret string) error

Performs an authentication handshake with the connected Brick Daemon or WIFI/Ethernet Extension. If the handshake succeeds the connection switches from non-authenticated to authenticated state and communication can continue as normal. If the handshake fails then the connection gets closed. Authentication can fail if the wrong secret was used or if authentication is not enabled at all on the Brick Daemon or the WIFI/Ethernet Extension.

See the authentication tutorial for more information.

func (*IPConnection) Close Uses

func (ipcon *IPConnection) Close()

Stops the IP Connection's goroutines.

func (*IPConnection) Connect Uses

func (ipcon *IPConnection) Connect(addr string) error

Creates a TCP/IP connection to the given `addr` with the form "host:port", as described here: https://golang.org/pkg/net/#Dial . The host and port can refer to a Brick Daemon or to a WIFI/Ethernet Extension.

Devices can only be controlled when the connection was established successfully.

func (*IPConnection) DeregisterConnectCallback Uses

func (ipcon *IPConnection) DeregisterConnectCallback(registrationID uint64)

Deregisters the connect callback with the given registration ID.

func (*IPConnection) DeregisterDisconnectCallback Uses

func (ipcon *IPConnection) DeregisterDisconnectCallback(registrationID uint64)

Deregisters the disconnect callback with the given registration ID.

func (*IPConnection) DeregisterEnumerateCallback Uses

func (ipcon *IPConnection) DeregisterEnumerateCallback(registrationID uint64)

Deregisters the enumerate callback with the given registration ID.

func (*IPConnection) Disconnect Uses

func (ipcon *IPConnection) Disconnect()

Disconnects the TCP/IP connection from the Brick Daemon or the WIFI/Ethernet Extension.

func (*IPConnection) Enumerate Uses

func (ipcon *IPConnection) Enumerate()

Broadcasts an enumerate request. All devices will respond with an enumerate event.

func (*IPConnection) GetAutoReconnect Uses

func (ipcon *IPConnection) GetAutoReconnect() bool

Returns true if auto-reconnect is enabled, false otherwise.

func (*IPConnection) GetConnectionState Uses

func (ipcon *IPConnection) GetConnectionState() ConnectionState

Queries the current connection state.

func (*IPConnection) GetInternalHandle Uses

func (ipcon *IPConnection) GetInternalHandle() interface{}

For internal use only.

func (*IPConnection) GetTimeout Uses

func (ipcon *IPConnection) GetTimeout() time.Duration

Returns the timeout as set by SetTimeout

func (*IPConnection) RegisterConnectCallback Uses

func (ipcon *IPConnection) RegisterConnectCallback(fn func(ConnectReason)) uint64

Callbacks registered to this event are called whenever the IP Connection got connected to a Brick Daemon or to a WIFI/Ethernet Extension. This function returns a registration ID which is used to deregister the callback when it should not be called anymore.

func (*IPConnection) RegisterDisconnectCallback Uses

func (ipcon *IPConnection) RegisterDisconnectCallback(fn func(DisconnectReason)) uint64

Callbacks registered to this event are called whenever the IP Connection got disconnected from a Brick Daemon or to a WIFI/Ethernet Extension. This function returns a registration ID which is used to deregister the callback when it should not be called anymore.

func (*IPConnection) RegisterEnumerateCallback Uses

func (ipcon *IPConnection) RegisterEnumerateCallback(fn func(uid string, connectedUID string, position rune, hardwareVersion [3]uint8, firmwareVersion [3]uint8, deviceIdentifier uint16, enumerationType EnumerationType)) uint64

Callbacks registered to this event are called whenever a enumerate event is received. This function returns a registration ID which is used to deregister the callback when it should not be called anymore. Parameters of the callback are:

* uid string - The UID of the device.

* connectedUID string - UID where the device is connected to.

For a Bricklet this will be a UID of the Brick where it is connected to.
For a Brick it will be the UID of the bottom Master Brick in the stack.
For the bottom Master Brick in a stack this will be "0".
With this information it is possible to reconstruct the complete network topology.

* position rune - For Bricks: '0' - '8' (position in stack). For Bricklets: 'a' - 'd' (position on Brick).

* hardwareVersion [3]uint8 - Major, minor and release number for hardware version.

* firmwareVersion [3]uint8 - Major, minor and release number for firmware version.

* deviceIdentifier uint16 - A number that represents the device.

The device identifier numbers can be found here: https://www.tinkerforge.com/en/doc/Software/Device_Identifier.html
There are also constants for these numbers named following this pattern:
<device-package>.DeviceIdentifier
For example: master_brick.DeviceIdentifier or ambient_light_bricklet.DeviceIdentifier.

* enumerationType EnumerationType - Type of enumeration.

func (*IPConnection) SetAutoReconnect Uses

func (ipcon *IPConnection) SetAutoReconnect(autoReconnectEnabled bool)

Enables or disables auto-reconnect. If auto-reconnect is enabled, the IP Connection will try to reconnect to the previously given host and port, if the currently existing connection is lost. Therefore, auto-reconnect only does something after a successful connect call.

Default value is true.

func (*IPConnection) SetTimeout Uses

func (ipcon *IPConnection) SetTimeout(timeout time.Duration)

Sets the timeout for getters and for setters for which the response expected flag is activated.

Default timeout is 2,5s.

Package ipconnection imports 3 packages (graph) and is imported by 137 packages. Updated 2019-08-28. Refresh now. Tools for package owners.