simulator

package
v0.0.0-...-55fa497 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 26, 2026 License: MIT Imports: 35 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetCodecConfig

func SetCodecConfig(cfg *models.ServerConfig)

SetCodecConfig initialises the global codec registry from the server config before GetInstance() runs. Safe to call once at startup.

Types

type Simulator

type Simulator struct {
	State                 uint8               `json:"-"`                 // Runtime state: Stop, Running
	Devices               map[int]*dev.Device `json:"-"`                 // A collection of devices
	ActiveDevices         map[int]int         `json:"-"`                 // A collection of active devices
	ActiveGateways        map[int]int         `json:"-"`                 // A collection of active gateways
	ComponentsInactiveTmp int                 `json:"-"`                 // Number of inactive components
	Gateways              map[int]*gw.Gateway `json:"-"`                 // A collection of gateways
	Forwarder             f.Forwarder         `json:"-"`                 // Forwarder instance used for communication between devices and gateways
	NextIDDev             int                 `json:"nextIDDev"`         // Next device ID used for creating a new device
	NextIDGw              int                 `json:"nextIDGw"`          // Next gateway ID used for creating a new gateway
	NextIDIntegration     int                 `json:"nextIDIntegration"` // Next integration ID
	NextIDTemplate        int                 `json:"nextIDTemplate"`    // Next template ID
	NextIDCodec           int                 `json:"nextIDCodec"`       // Next codec ID
	BridgeAddress         string              `json:"bridgeAddress"`     // Bridge address used to connect to a network
	Resources             res.Resources       `json:"-"`                 // Resources used for managing the simulator
	Console               c.Console           `json:"-"`                 // Console instance, used for logging in the web terminal
	// Integration management (like Devices/Gateways pattern)
	Integrations       map[int]*integration.Integration `json:"-"` // A collection of integrations
	IntegrationClients map[int]*chirpstack.Client       `json:"-"` // ChirpStack clients for each integration
	ThingsBoardClients map[int]*thingsboard.Client      `json:"-"` // ThingsBoard clients for each integration
	// Template management (like Devices/Gateways pattern)
	Templates map[int]*template.DeviceTemplate `json:"-"` // A collection of device templates
	// DeviceStartJitterMs controls per-device randomized startup spread.
	// If > 0, each device's start delay is drawn from a triangular distribution
	// on [0, DeviceStartJitterMs] ms, peaked at the midpoint.
	// Transient per-run setting; reset after Run().
	DeviceStartJitterMs float64 `json:"-"`
}

Simulator is a model

func GetInstance

func GetInstance() *Simulator

func (*Simulator) AddCodec

func (s *Simulator) AddCodec(c *codec.Codec) error

AddCodec adds a custom codec

func (*Simulator) AddIntegration

func (s *Simulator) AddIntegration(name string, intType integration.IntegrationType, url, apiKey, tenantID, appID string) (int, error)

AddIntegration adds a new integration

func (*Simulator) AddTemplate

func (s *Simulator) AddTemplate(tmpl *template.DeviceTemplate) (int, error)

AddTemplate adds a new template

func (*Simulator) AddWebSocket

func (s *Simulator) AddWebSocket(WebSocket *socketio.Conn)

func (*Simulator) ChangeLocation

func (s *Simulator) ChangeLocation(l socket.NewLocation) bool

func (*Simulator) ChangePayload

func (s *Simulator) ChangePayload(pl socket.NewPayload) (string, bool)

func (*Simulator) CreateDevicesFromTemplate

func (s *Simulator) CreateDevicesFromTemplate(templateID int, count int, namePrefix string, baseLat, baseLng float64, baseAlt int32, spreadMeters float64) ([]int, error)

CreateDevicesFromTemplate creates multiple devices from a template. Optimized for bulk: defers JSON persistence, parallelizes ChirpStack provisioning, and uses hash sets for O(1) collision detection.

func (*Simulator) DeleteAllDevices

func (s *Simulator) DeleteAllDevices() (int, error)

DeleteAllDevices deletes all devices in bulk. Parallelizes ChirpStack deprovisioning and saves JSON once at the end.

func (*Simulator) DeleteCodec

func (s *Simulator) DeleteCodec(id int) error

DeleteCodec removes a codec by ID

func (*Simulator) DeleteDevice

func (s *Simulator) DeleteDevice(Id int) bool

func (*Simulator) DeleteDeviceFromChirpStack

func (s *Simulator) DeleteDeviceFromChirpStack(integrationID int, devEUI string) error

DeleteDeviceFromChirpStack removes a device from ChirpStack

func (*Simulator) DeleteDeviceFromThingsBoard

func (s *Simulator) DeleteDeviceFromThingsBoard(integrationID int, tbDeviceID string) error

DeleteDeviceFromThingsBoard removes a device from ThingsBoard by its UUID.

func (*Simulator) DeleteGateway

func (s *Simulator) DeleteGateway(Id int) bool

func (*Simulator) DeleteGatewayFromChirpStack

func (s *Simulator) DeleteGatewayFromChirpStack(integrationID int, gatewayID string) error

DeleteGatewayFromChirpStack removes a gateway from ChirpStack

func (*Simulator) DeleteIntegration

func (s *Simulator) DeleteIntegration(id int) error

DeleteIntegration removes an integration by ID

func (*Simulator) DeleteTemplate

func (s *Simulator) DeleteTemplate(id int) error

DeleteTemplate removes a template by ID

func (*Simulator) GetBridgeAddress

func (s *Simulator) GetBridgeAddress() models.AddressIP

GetBridgeAddress returns the bridge address stored in the simulator struct

func (*Simulator) GetCodec

func (s *Simulator) GetCodec(id int) (*codec.Codec, error)

GetCodec returns a specific codec by ID

func (*Simulator) GetCodecs

func (s *Simulator) GetCodecs() []codec.CodecMetadata

GetCodecs returns all available codec metadata

func (*Simulator) GetDeviceProfiles

func (s *Simulator) GetDeviceProfiles(id int) ([]integration.DeviceProfile, error)

GetDeviceProfiles returns a type-neutral {ID,Name} list of profiles for the given integration.

func (*Simulator) GetDevices

func (s *Simulator) GetDevices() []dev.Device

GetDevices returns an array of all devices in the simulator

func (*Simulator) GetDevicesUsingCodec

func (s *Simulator) GetDevicesUsingCodec(codecID int) []string

GetDevicesUsingCodec returns a list of device EUIs using the specified codec Also counts templates that use this codec

func (*Simulator) GetDevicesUsingIntegration

func (s *Simulator) GetDevicesUsingIntegration(integrationID int) []string

GetDevicesUsingIntegration returns a list of device EUIs using the specified integration (either ChirpStack or ThingsBoard side).

func (*Simulator) GetGateways

func (s *Simulator) GetGateways() []gw.Gateway

GetGateways returns an array of all gateways in the simulator

func (*Simulator) GetIntegration

func (s *Simulator) GetIntegration(id int) (*integration.Integration, error)

GetIntegration returns a specific integration by ID

func (*Simulator) GetIntegrations

func (s *Simulator) GetIntegrations() []*integration.Integration

GetIntegrations returns all integrations (without API keys for security)

func (*Simulator) GetTemplate

func (s *Simulator) GetTemplate(id int) (*template.DeviceTemplate, error)

GetTemplate returns a specific template by ID

func (*Simulator) GetTemplates

func (s *Simulator) GetTemplates() []*template.DeviceTemplate

GetTemplates returns all templates

func (*Simulator) GetThingsBoardCustomers

func (s *Simulator) GetThingsBoardCustomers(integrationID int) ([]thingsboard.Customer, error)

GetThingsBoardCustomers returns the customer list for a TB integration.

func (*Simulator) Print

func (s *Simulator) Print(content string, err error, printType int)

Print logs messages to the console and the web terminal based on the printType

func (*Simulator) ProvisionDevice

func (s *Simulator) ProvisionDevice(integrationID int, devEUI, name, deviceProfileID, appKey string, variables map[string]string) error

ProvisionDevice provisions a device to ChirpStack using OTAA. `variables` is written to the CS device's Variables map — pass nil for none.

func (*Simulator) ProvisionDeviceABP

func (s *Simulator) ProvisionDeviceABP(integrationID int, devEUI, name, deviceProfileID, devAddr, nwkSKey, appSKey string, variables map[string]string) error

ProvisionDeviceABP provisions a device to ChirpStack using ABP. `variables` is written to the CS device's Variables map — pass nil for none.

func (*Simulator) ProvisionDeviceToThingsBoard

func (s *Simulator) ProvisionDeviceToThingsBoard(integrationID int, devEUI, label, profileID, customerID string) (string, error)

ProvisionDeviceToThingsBoard creates a device in ThingsBoard and returns its UUID. Name = devEUI (hex), label = simulator-side friendly name, customerID optional.

func (*Simulator) ProvisionGateway

func (s *Simulator) ProvisionGateway(integrationID int, gatewayID, name string, lat, lng float64, alt int32) error

ProvisionGateway provisions a virtual gateway to ChirpStack

func (*Simulator) Run

func (s *Simulator) Run()

Run starts the simulation environment

func (*Simulator) SaveBridgeAddress

func (s *Simulator) SaveBridgeAddress(remoteAddr models.AddressIP) error

SaveBridgeAddress stores the bridge address in the simulator struct and saves it to the simulator.json file

func (*Simulator) SendMACCommand

func (s *Simulator) SendMACCommand(cid lorawan.CID, data socket.MacCommand)
func (s *Simulator) SendUplink(pl socket.NewPayload)

func (*Simulator) SetDevice

func (s *Simulator) SetDevice(device *dev.Device, update bool) (int, int, error)

func (*Simulator) SetGateway

func (s *Simulator) SetGateway(gateway *gw.Gateway, update bool) (int, int, error)

SetGateway adds or updates a gateway

func (*Simulator) SetupConsole

func (s *Simulator) SetupConsole()

SetupConsole attach the simulator console to devices and gateways

func (*Simulator) Stop

func (s *Simulator) Stop()

Stop terminates the simulation environment

func (*Simulator) TestIntegrationConnection

func (s *Simulator) TestIntegrationConnection(id int) error

TestIntegrationConnection tests connection to an integration

func (*Simulator) ToggleStateDevice

func (s *Simulator) ToggleStateDevice(Id int)

func (*Simulator) ToggleStateGateway

func (s *Simulator) ToggleStateGateway(Id int)

func (*Simulator) UnwatchDevice

func (s *Simulator) UnwatchDevice()

func (*Simulator) UpdateCodec

func (s *Simulator) UpdateCodec(id int, name string, script string) error

UpdateCodec updates an existing codec

func (*Simulator) UpdateIntegration

func (s *Simulator) UpdateIntegration(id int, name, url, apiKey, tenantID, appID string, enabled bool) error

UpdateIntegration updates an existing integration

func (*Simulator) UpdateTemplate

func (s *Simulator) UpdateTemplate(tmpl *template.DeviceTemplate) error

UpdateTemplate updates an existing template

func (*Simulator) WatchDevice

func (s *Simulator) WatchDevice(id int) []socket.ConsoleLog

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL