Documentation
¶
Index ¶
- func SetCodecConfig(cfg *models.ServerConfig)
- type Simulator
- func (s *Simulator) AddCodec(c *codec.Codec) error
- func (s *Simulator) AddIntegration(name string, intType integration.IntegrationType, ...) (int, error)
- func (s *Simulator) AddTemplate(tmpl *template.DeviceTemplate) (int, error)
- func (s *Simulator) AddWebSocket(WebSocket *socketio.Conn)
- func (s *Simulator) ChangeLocation(l socket.NewLocation) bool
- func (s *Simulator) ChangePayload(pl socket.NewPayload) (string, bool)
- func (s *Simulator) CreateDevicesFromTemplate(templateID int, count int, namePrefix string, baseLat, baseLng float64, ...) ([]int, error)
- func (s *Simulator) DeleteAllDevices() (int, error)
- func (s *Simulator) DeleteCodec(id int) error
- func (s *Simulator) DeleteDevice(Id int) bool
- func (s *Simulator) DeleteDeviceFromChirpStack(integrationID int, devEUI string) error
- func (s *Simulator) DeleteDeviceFromThingsBoard(integrationID int, tbDeviceID string) error
- func (s *Simulator) DeleteGateway(Id int) bool
- func (s *Simulator) DeleteGatewayFromChirpStack(integrationID int, gatewayID string) error
- func (s *Simulator) DeleteIntegration(id int) error
- func (s *Simulator) DeleteTemplate(id int) error
- func (s *Simulator) GetBridgeAddress() models.AddressIP
- func (s *Simulator) GetCodec(id int) (*codec.Codec, error)
- func (s *Simulator) GetCodecs() []codec.CodecMetadata
- func (s *Simulator) GetDeviceProfiles(id int) ([]integration.DeviceProfile, error)
- func (s *Simulator) GetDevices() []dev.Device
- func (s *Simulator) GetDevicesUsingCodec(codecID int) []string
- func (s *Simulator) GetDevicesUsingIntegration(integrationID int) []string
- func (s *Simulator) GetGateways() []gw.Gateway
- func (s *Simulator) GetIntegration(id int) (*integration.Integration, error)
- func (s *Simulator) GetIntegrations() []*integration.Integration
- func (s *Simulator) GetTemplate(id int) (*template.DeviceTemplate, error)
- func (s *Simulator) GetTemplates() []*template.DeviceTemplate
- func (s *Simulator) GetThingsBoardCustomers(integrationID int) ([]thingsboard.Customer, error)
- func (s *Simulator) Print(content string, err error, printType int)
- func (s *Simulator) ProvisionDevice(integrationID int, devEUI, name, deviceProfileID, appKey string, ...) error
- func (s *Simulator) ProvisionDeviceABP(integrationID int, ...) error
- func (s *Simulator) ProvisionDeviceToThingsBoard(integrationID int, devEUI, label, profileID, customerID string) (string, error)
- func (s *Simulator) ProvisionGateway(integrationID int, gatewayID, name string, lat, lng float64, alt int32) error
- func (s *Simulator) Run()
- func (s *Simulator) SaveBridgeAddress(remoteAddr models.AddressIP) error
- func (s *Simulator) SendMACCommand(cid lorawan.CID, data socket.MacCommand)
- func (s *Simulator) SendUplink(pl socket.NewPayload)
- func (s *Simulator) SetDevice(device *dev.Device, update bool) (int, int, error)
- func (s *Simulator) SetGateway(gateway *gw.Gateway, update bool) (int, int, error)
- func (s *Simulator) SetupConsole()
- func (s *Simulator) Stop()
- func (s *Simulator) TestIntegrationConnection(id int) error
- func (s *Simulator) ToggleStateDevice(Id int)
- func (s *Simulator) ToggleStateGateway(Id int)
- func (s *Simulator) UnwatchDevice()
- func (s *Simulator) UpdateCodec(id int, name string, script string) error
- func (s *Simulator) UpdateIntegration(id int, name, url, apiKey, tenantID, appID string, enabled bool) error
- func (s *Simulator) UpdateTemplate(tmpl *template.DeviceTemplate) error
- func (s *Simulator) WatchDevice(id int) []socket.ConsoleLog
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) 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 (*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 ¶
DeleteAllDevices deletes all devices in bulk. Parallelizes ChirpStack deprovisioning and saves JSON once at the end.
func (*Simulator) DeleteCodec ¶
DeleteCodec removes a codec by ID
func (*Simulator) DeleteDevice ¶
func (*Simulator) DeleteDeviceFromChirpStack ¶
DeleteDeviceFromChirpStack removes a device from ChirpStack
func (*Simulator) DeleteDeviceFromThingsBoard ¶
DeleteDeviceFromThingsBoard removes a device from ThingsBoard by its UUID.
func (*Simulator) DeleteGateway ¶
func (*Simulator) DeleteGatewayFromChirpStack ¶
DeleteGatewayFromChirpStack removes a gateway from ChirpStack
func (*Simulator) DeleteIntegration ¶
DeleteIntegration removes an integration by ID
func (*Simulator) DeleteTemplate ¶
DeleteTemplate removes a template by ID
func (*Simulator) GetBridgeAddress ¶
GetBridgeAddress returns the bridge address stored in the simulator struct
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 ¶
GetDevices returns an array of all devices in the simulator
func (*Simulator) GetDevicesUsingCodec ¶
GetDevicesUsingCodec returns a list of device EUIs using the specified codec Also counts templates that use this codec
func (*Simulator) GetDevicesUsingIntegration ¶
GetDevicesUsingIntegration returns a list of device EUIs using the specified integration (either ChirpStack or ThingsBoard side).
func (*Simulator) GetGateways ¶
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 ¶
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) SaveBridgeAddress ¶
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 (*Simulator) SendUplink ¶
func (s *Simulator) SendUplink(pl socket.NewPayload)
func (*Simulator) SetGateway ¶
SetGateway adds or updates a gateway
func (*Simulator) SetupConsole ¶
func (s *Simulator) SetupConsole()
SetupConsole attach the simulator console to devices and gateways
func (*Simulator) TestIntegrationConnection ¶
TestIntegrationConnection tests connection to an integration
func (*Simulator) ToggleStateDevice ¶
func (*Simulator) ToggleStateGateway ¶
func (*Simulator) UnwatchDevice ¶
func (s *Simulator) UnwatchDevice()
func (*Simulator) UpdateCodec ¶
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