Categorygithub.com/wavecomtech/omlox-client-go
modulepackage
0.0.0-20241125093711-00ba440d6b89
Repository: https://github.com/wavecomtech/omlox-client-go.git
Documentation: pkg.go.dev

# README

Omlox Hub Go Client Library

An Omlox Hub™ compatible Go client library and CLI tool.

Omlox is an open standard for precise real-time indoor localization systems. It specifies open interfaces for an interoperable localization system that enable industry to use a single infrastructure with different applications from different providers.

[!WARNING]
This library is currently being developed. Please try it out and give us feedback! Please do not use it in production or use at your own risk.

Contents

  1. Installation
  2. Examples
  3. Status
  4. Specification
  5. Community, discussion, contribution, and support
  6. Development
  7. Disclaimer

Installation

go get -u github.com/wavecomtech/omlox-client-go

[!NOTE]
For the CLI installation, follow the documentation at ./docs/omlox-cli.md.

Examples

Getting Started

Here is a simple example of using the library to query the trackables in the hub.

package main

import (
    "context"
	"log"
	"time"

	"github.com/wavecomtech/omlox-client-go"
)

func main() {
    client, err := omlox.New("https://localhost:7081/v2")
    if err != nil {
        log.Fatal(err)
    }

    trackables, err := client.Trackables.List(context.Background())
    if err != nil {
        log.Fatal(err)
    }

    log.Println("trackables retrieved:", trackables)
}

Websockets

Subscription

// Dials a Omlox Hub websocket interface, subscribes to
// the location_updates topic and listens to new
// location messages.

ctx, cancel := context.WithCancel(context.Background())
defer cancel()

client, err := omlox.Connect(ctx, "localhost:7081/v2")
if err != nil {
    log.Fatal(err)
}
defer client.Close()

sub, err := client.Subscribe(ctx, omlox.TopicLocationUpdates)
if err != nil {
    log.Fatal(err)
}

for location := range omlox.ReceiveAs[omlox.Location](sub) {
    _ = location // handle location update
}

Error Handling

Errors are returned when Omlox Hub responds with an HTTP status code outside of the 200 to 399 range. If a request fails due to a network error, a different error message will be returned.

In go>=1.13 you can use the new errors.As method:

trackables, err := client.Trackables.List(context.Background())
if err != nil {
    var e *omlox.Error
    if errors.As(err, &e) && e.Code == http.StatusNotFound {
        // special handling for 404 errors
    }
}

For older go versions, you can also do type assertions:

trackables, err := client.Trackables.List(context.Background())
if err != nil {
    if e, ok := err.(*omlox.Error); ok && e.Code == http.StatusNotFound {
        // special handling for 404 errors
    }
}

Status

This library is coded from scratch to match the specification of Omlox Hub API. We plan to auto-generate most of it, but the OpenAPI spec is currently invalid due to some technical decisions in the spec. For the meantime, this library will continue to be coded from scratch.

An older iteration of this library is currently being used internally in Wavecom Technologies. We plan to migrate to the open source version earlier next year. The CLI is currently used by the RTLS team as a support tool for our internal Omlox Hub instance.

Following is the current checklist of the implemented schemas and API methods.

Schemas

[!WARNING]
The provided schemas are prone to change. Optional fields with default values have been the most challenging thing to translate well in to Go. We are trying different options and see which feels better.

SchemaImplemented
Collision
CollisionEvent
Error
Fence
FenceEvent
LineString
LocatingRule
Location
LocationProvider
Point
Polygon
Proximity
Trackable
TrackableMotion
WebsocketError
WebsocketMessageAPI abstracted
WebSocketSubscriptionResponseAPI abstracted
WebsocketSubscriptionRequestAPI abstracted
Zone

Methods

MethodEndpointImplemented
GET/zones/summary
GET/zones
POST/zones
DELETE/zones
GET/zones/:zoneID
PUT/zones/:zoneID
DELETE/zones/:zoneID
PUT/zones/:zoneID/transform
GET/zones/:zoneID/createfence
MethodEndpointImplemented
GET/trackables/summary
GET/trackables
POST/trackables
DELETE/trackables
GET/trackables/:trackableID
DELETE/trackables/:trackableID
PUT/trackables/:trackableID
GET/trackables/:trackableID/fences
GET/trackables/:trackableID/location
GET/trackables/:trackableID/locations
GET/trackables/:trackableID/motion
GET/trackables/:trackableID/providers
GET/trackables/:trackableID/sensors
GET/trackables/motions
MethodEndpointImplemented
GET/providers/summary
GET/providers
POST/providers
DELETE/providers
GET/providers/:providerID
PUT/providers/:providerID
DELETE/providers/:providerID
PUT/providers/:providerID/location
GET/providers/:providerID/location
DELETE/providers/:providerID/location
GET/providers/:providerID/fences
PUT/providers/:providerID/sensors
GET/providers/:providerID/sensors
GET/providers/locations
PUT/providers/locations
DELETE/providers/locations
PUT/providers/:providerID/proximity
PUT/providers/proximities
MethodEndpointImplemented
GET/fences/summary
GET/fences
POST/fences
DELETE/fences
GET/fences/:fenceID
PUT/fences/:fenceID
DELETE/fences/:fenceID
GET/fences/:fenceID/providers
GET/fences/:fenceID/locations

Specification

The Hub specification can be found at: https://www.profibus.com/download/omlox-hub-specification-api-and-behavior.

Community, discussion, contribution, and support

Contributions are made to this repo via Issues and Pull Requests (PRs). If any part of the project has a bug or documentation mistakes, please let us know by opening an issue. The project is early in its development, so bugs and mistakes may appear.

To discuss API and feature suggestions, implementation insights and other things related to the implementation of the client, you can use Github's Discussions tab.

Before creating an issue, please check that an issue reporting the same problem does not already exist. Please try to create issues that are accurate and easy to understand. Maintainers might ask for further information to resolve the issue.

Code of conduct

By participating and contributing to this project, you agree to uphold our Code of Conduct.

Development

[!NOTE]
For an optimal developer experience, it is recommended to install Nix and direnv.

Installing Nix and direnv

Note: These are instructions that SHOULD work in most cases. Consult the links above for the official instructions for your OS.

Install Nix:

sh <(curl -L https://nixos.org/nix/install) --daemon

Consult the installation instructions to install direnv using your package manager.

On MacOS:

brew install direnv

Install from binary builds:

curl -sfL https://direnv.net/install.sh | bash

The last step is to configure your shell to use direnv. For example for bash, add the following lines at the end of your ~/.bashrc:

eval "\$(direnv hook bash)"

Then restart the shell.

For other shells, see https://direnv.net/docs/hook.html.

MacOS specific instructions

Nix may stop working after a MacOS upgrade. If it does, follow these instructions.


Otherwise, you can install the required dependencies with Go itself.

Be sure to use Go >= to the one defined in go.mod and have $GOPATH/bin in your $PATH, so you can run installed go binaries. You can see how to do that at setup-your-shell-to-run-go-installed-binaries.

Install development dependencies:

go install github.com/mailru/easyjson/...@latest
go install github.com/hashicorp/copywrite@latest

You should be good to go! If you have any trouble getting started, reach out to us by email (see the MAINTAINERS file).

Disclaimer

[!NOTE]
The code provided by this library is not certified by Omlox or the Profibus & Profinet International. Solutions using this library should go through the certification process defined by the Omlox™ consortium to be an "omlox certified solution".

# Packages

No description provided by the author

# Functions

Connect will attempt to connect to the Omlox™ Hub websockets interface.
GetDefaultOptions returns default configuration options for the client.
New returns a new client decorated with the given configuration options.
Create an infinite type of millisecond duration type.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
WithHTTPClient sets the HTTP client to use for all API requests.
WithRateLimiter configures how frequently requests are allowed to happen.
WithRequestTimeout, given a non-negative value, will apply the timeout to each request function unless an earlier deadline is passed to the request function through context.Context.

# Constants

Defines values for ElevationRefType.
Defines values for ElevationRefType.
Invalid payload data.
Not authorized.
Subscription failed.
Event type is unknown.
Unknown topic name.
Unsubscribe failed.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Inf is the constant value representing infite.
Defines values for LocationProviderType.
Defines values for LocationProviderType.
Defines values for LocationProviderType.
Defines values for LocationProviderType.
Defines values for LocationProviderType.
Defines values for LocationProviderType.
Defines values for LocationProviderType.
Checks trackable movements for collisions and sends collision events when trackables: start to collide, continue to collide and end a collision.
To inform subscribers about geofence entry and exit events.
Similar to fence events, but instead of an omlox™ FenceEvent object GeoJson feature collections are returned as payload.
For real-time location updates, as well as sending location updates to the hub.
To retrieve location information as GeoJson feature collection.
To receive movements of omlox™ Trackables.
Defines values for TrackableType.
Defines values for TrackableType.

# Variables

Errors.
Map between error codes and their text representation.
Errors.
No description provided by the author

# Structs

Client manages communication with Omlox™ Hub client.
/ ClientConfiguration is used to configure the creation of the client.
Duration is an Omlox type that provides infinite semantics for a time duration.
Error is the error returned when Omlox Hub responds with an HTTP status code outside of the 200 - 399 range.
The rule syntax is a simple Boolean expression consisting of AND connected expressions.
Location defines model for Location.
LocationProvider defines model for LocationProvider.
No description provided by the author
No description provided by the author
ProvidersAPI is a simple wrapper around the client for location provider requests.
Subcription represents a topic subscription to the websocket Hub interface.
Trackable defines model for Trackable.
TrackablesAPI is a simple wrapper around the client for trackables requests.
WebsocketError sent to the client on websocket server error.
WrapperObject is the wrapper object of websockets data exchanged between client and server.

# Type aliases

ClientOption is a configuration option to initialize a client.
An elevation reference hint for the position's z component.
ErrCode is an error code used by applications to discern the type of the websocket error.
event abstracts the possible events types in websocket messages.
The location provider type which triggered this location update.
Parameter is an optional key-value pair used on subscriptions.
Parameters represents the key-value pairs used in subscriptions.
Omlox Hub supports a a few topics to which clients can subscribe and publish.
Either 'omlox' or 'virtual'.