github.com/factory24/signalhive-go — the Go client for the SignalHive device-connectivity
platform. Standard library only: no protobuf, no gRPC, no transitive dependencies. Every type is
owned here, and nothing names the technology delivering the connectivity.
The package is connectivity:
import connectivity "github.com/factory24/signalhive-go"go get github.com/factory24/signalhive-go
Client |
PlatformClient |
|
|---|---|---|
| Credential | an operator token (OIDC) | one network's API key |
| Scope | every network in the business | the one network the key is bound to |
| For | consoles, internal tooling | a customer's own backend |
A network API key is not a device key. The key on a device gates that device's traffic and is set
through SetKey; the network API key authenticates your service to us.
// Explicit
client := connectivity.New("https://api.example.com/v1",
connectivity.NewClientCredentialsTokenSource(tokenURL, clientID, clientSecret))
// Or from the environment
client, err := connectivity.NewFromEnv()| Variable | Meaning |
|---|---|
CONNECTIVITY.BASE_URL |
API root including /v1 (required) |
CONNECTIVITY.API_TOKEN |
static bearer token, or the three below |
CONNECTIVITY.TOKEN_URL |
OpenID token endpoint (client-credentials grant) |
CONNECTIVITY.CLIENT_ID / CONNECTIVITY.CLIENT_SECRET |
the service account |
CONNECTIVITY.BUSINESS_ID |
only for staff principals acting for one business |
Underscored spellings (CONNECTIVITY_BASE_URL) work too. connectivity.NewDisabled(reason)
returns a client whose every call fails with that reason — wire it unconditionally and let
unconfigured environments degrade per call instead of failing at boot.
dev, err := client.RegisterDevice(ctx, connectivity.RegisterDeviceRequest{
NetworkID: networkID, DeviceID: "0102030405060708",
Name: "Meter 4", DeviceClassID: classID,
})
// Credentials are write-only. There is no read-back, by design.
err = client.SetDeviceSecret(ctx, dev.DeviceID, "00112233445566778899aabbccddeeff")
// Commands carry opaque bytes; the platform never interprets them.
commandID, err := client.SendCommand(ctx, dev.DeviceID, payload,
connectivity.CommandOptions{Port: 10, Confirmed: true})
pending, err := client.ListPendingCommands(ctx, dev.DeviceID)
retracted, err := client.ClearCommands(ctx, dev.DeviceID)
// Moving a device: same bearer, and a device class on the destination network.
dev, err = client.UpdateDevice(ctx, connectivity.UpdateDeviceRequest{
DeviceID: dev.DeviceID, NetworkID: otherNetworkID, DeviceClassID: otherClassID,
})| Area | Methods |
|---|---|
| Networks | CreateNetwork ListNetworks GetNetwork UpdateNetwork DeleteNetwork GetNetworkOverview GetNetworkApplication |
| Device classes | CreateDeviceClass ListDeviceClasses UpdateDeviceClass DeleteDeviceClass |
| Devices | RegisterDevice GetDevice GetDeviceState UpdateDevice DeleteDevice ListDevices SetDeviceSecret |
| Cellular gate | DeviceAccess SetDeviceKey ClearDeviceKey EnableDevice DisableDevice |
| Diagnosis | DeviceFrames DeviceLogs GetDeviceActivity GetDeviceMetrics GetDeviceRadioMetrics InspectPayload |
| Commands | SendCommand ListPendingCommands ClearCommands |
| Access points | RegisterAccessPoint ListAccessPoints GetAccessPoint UpdateAccessPoint DeleteAccessPoint GetAccessPointRadioMetrics |
| Keys | CreateDeviceKey ListDeviceKeys RevokeDeviceKey |
| API keys | CreateApiKey ListApiKeys RevokeApiKey |
| Destinations (integrations) | CreateIntegration ListIntegrations UpdateIntegration DeleteIntegration TestIntegration Deliveries RetryDelivery · DecodeMessage for a queue consumer |
| Your platforms | ListDestinations CreateDestination UpdateDestination DeleteDestination |
| Watches | CreateEventRule ListEventRules DeleteEventRule NetworkAlerts |
| Billing | ListPlans GetSubscription ListInvoices ListCheckoutMethods GetUsage |
| Business | GetOverview GetAuditLog ListApplications ListApplicationDevices |
staff.go holds the routes that need a platform-staff principal rather than a
customer one (ListUnclaimedDevices, StaffBillingSummary, the plan and
assignment calls). A customer token is refused there with 403.
Credentials are returned exactly once. CreateApiKey is the only call that
ever carries a Token; afterwards only its Prefix is readable. SetDeviceKey,
SetDeviceSecret, a destination's AuthSecret and a queue destination's Token
have no read-back at all.
Two calls report failure with a nil error. TestIntegration and
RetryDelivery answer 200 whether or not the delivery landed: the call
succeeded, the delivery is what failed. Branch on res.Success, not on err.
res, err := client.TestIntegration(ctx, networkID, integrationID)
if err != nil { return err } // we could not ask
if !res.Success { ... } // we asked; your endpoint refusedPaging backwards, not by page. DeviceFrames and DeviceLogs take a
FrameQuery{Limit, Before} and answer with HasMore. Do not re-derive the end
of history by counting rows against your limit — a page is cut on a whole
second, so a short page can still have history behind it.
p, err := connectivity.NewPlatformFromEnv("CELLULAR") // CONNECTIVITY.CELLULAR.API_KEY
net, err := p.Network(ctx) // fails loudly if the key is for another network
dev, err := p.CreateDevice(ctx, connectivity.CreatePlatformDeviceRequest{
DeviceID: "867329050123456", Name: "Meter 4",
DeviceClassID: classID, Key: deviceKeyHex, Enabled: true,
})
dev, err = p.UpdateDevice(ctx, dev.DeviceID, connectivity.UpdatePlatformDeviceRequest{Name: "Meter 5"})
access, err := p.SetKey(ctx, dev.DeviceID, newKeyHex) // no read-back
access, err = p.Enable(ctx, dev.DeviceID) // conflict names what is missing
frames, err := p.Frames(ctx, dev.DeviceID, connectivity.FrameQuery{Limit: 50})
// Low-power networks: registers, or updates if already there. The key decides the network.
ap, err := p.RegisterAccessPoint(ctx, connectivity.RegisterAccessPointRequest{
AccessPointID: "54d0b4fffe45a496", Name: "Kibera North",
})
aps, err := p.AccessPoints(ctx)| Variable | Meaning |
|---|---|
CONNECTIVITY.BASE_URL |
API root including /v1 |
CONNECTIVITY.<NETWORK>.API_KEY |
the network's API key |
CONNECTIVITY.<NETWORK>.NETWORK_ID |
checked on first use, so a key in the wrong variable fails loudly |
CONNECTIVITY.BUSINESS_ID |
checked, not sent |
Messages are delivered to you, not polled. MessageHandler is the endpoint you register as your
platform URL; it authenticates every request and refuses everything when the secret is empty
rather than accepting anything.
http.Handle("/connectivity/messages", connectivity.MessageHandler(
"X-Message-Secret", os.Getenv("MESSAGE_SECRET"),
func(ctx context.Context, up connectivity.Message) (*connectivity.Reply, error) {
reading := decode(up.Payload) // your bytes, undecoded on the way to you
return &connectivity.Reply{Payload: ack(reading)}, nil
}))On the cellular bearer the Reply is written back on the socket the device is holding open. An
error from your handler answers 500, and the reading is then recorded on our side as received but
not accepted by you.
On the low-power bearer a Message also carries Sequence (the device's own message counter) and
AccessPoints (every access point that heard it, strongest first, with RSSI and SNR).
A network's destination can be a broker topic instead of, or as well as, an endpoint
(IntegrationQueue). Both bearers are delivered there — a cellular device with a queue destination
and no platform is answered from its command queue alone.
in, err := client.CreateIntegration(ctx, networkID, connectivity.IntegrationQueue, connectivity.QueueConfig{
BrokerURL: "pulsar+ssl://broker.example:6651", Topic: "persistent://public/default/uplinks",
Token: brokerToken, // write-only, kept on updates that omit it
Envelope: connectivity.EnvelopeEvent, // {topic, eventType, timestamp, payload}
EventType: "uplink.cellular", // what a MESSAGE is typed as; events carry their own
}.Config())
// In your consumer, whatever the destination publishes:
ev, err := connectivity.DecodeMessage(msg.Payload())
switch ev.Kind {
case connectivity.KindMessage: store(ev.Message)
case connectivity.KindCommand: markSent(ev.Command.Reference, ev.Command.Event) // command.queued/sent/failed/retracted
case connectivity.KindAlert: page(ev.Alert) // device.quiet, device.recovered, ...
}Integration.Backlog is how many deliveries are waiting to be retried: a destination that was
down is caught up automatically, in order, once it answers. Integration.HasSecret says a token or
AuthSecret is stored, since Config never carries one back.
A command you queue with CommandOptions{Reference: yourID} is echoed as Reference on the pending
list and on every command.* event on the network's destinations, so command.sent can be matched
to your own record without a lookup table. On cellular, command.sent is emitted the moment the
command is written to the device's socket in place of the platform's answer.
Non-2xx answers come back as *connectivity.APIError carrying Status, Code and Message.
connectivity.IsNotFound(err) and connectivity.IsConflict(err) cover the two cases callers
branch on most (a conflict is e.g. a device with no active key, or a class still in use).
IsConflict is every 409, including a plan's allowance being reached; to make a create safe to
retry, branch on connectivity.IsAlreadyExists(err), which is only the duplicate.
- No
GetDeviceSecret, noGetKey. The platform has no read-back route: a credential that can be fetched leaks through any read-only role. Hold your own copy if you need one. GetUsagetakes no date range — the endpoint always reports the current billing period.- Messages are delivered, not polled. There is no "list messages" call here.
- No
GetDeviceSecret. Same reason as the key: there is no read-back route.
This repository is published from the SignalHive monorepo; main tracks the platform's source of
truth. Pin a tag. Breaking changes take a new major version, and a tag is never moved.