LwM2M Environment Runbook
This runbook shows how to create a full environment with the LwM2M stack, admit one emulator device, and verify that the device registered.
What you get
The LwM2M stack has three parts.
-
ftacsis the Auto Configuration Server (ACS). Use an LwM2M-capable tag. -
bsis the LwM2M server that devices connect to. -
iotEmulatoris the device emulator that you use for the test.
The environment also needs hazelcast. The environment must be a full environment. A partial environment cannot contain bs. The Environment Manager returns HTTP 400 for a partial environment that includes bs.
ArgoCD applies the chart. Do not run helm install or helm upgrade on the environment. The seed Job (see Device admission: the seed Job) is an ArgoCD hook, and a plain Helm run treats it as an ordinary immutable resource.
Known-good tags
| Component | Tag |
|---|---|
|
|
|
|
The ftacs tag must be LwM2M-capable. Another ftacs build can lack LwM2M support.
Create the environment
-
Open the Environment Manager Web UI.
-
Click the Create tab.
-
Enter the environment name. Use lowercase letters, numbers and hyphens.
-
Select the environment type Full.
-
Select the database: MySQL or Oracle.
-
Select the components
ftacs,bs,iotEmulatorandhazelcast. -
Select a Harbor tag for each component. Use the tags in the table above for
ftacsandbs. -
Click Create Environment.
-
Wait until ArgoCD shows all applications as Healthy.
The Environment Manager writes bs.enabled and the bs image tag to the values file of the environment. It does not expose the external UDP flag or the seed list. To change them, commit them to the values file of the environment (see Change the list and Optional: external UDP exposure).
What bs.enabled switches
If bs.enabled is true, the chart does the following:
-
It deploys
bswith six UDP ports (5680 to 5685) and two TCP ports (5880 and 5883). -
It turns on the
LWM2M_*environment offtacs. -
It turns on the
lwm2m.*Hazelcast map configurations. -
It turns on
ftacs.useImageConfig. -
It runs the seed Job.
The chart refuses to render in these cases:
-
bs.enabledistrueandhazelcast.enabledisfalse.bsneeds the own Hazelcast of the environment. -
bs.enabledistrueandftacs.enabledisfalse.bswaits forftacsand reads its IoT configuration. -
ftacs.https.enabledistruetogether withbs.enabled. The image configuration drops the keystore volume.
The Environment Manager refuses bs for a partial environment with HTTP 400.
If you enable bs on an existing environment, ArgoCD restarts the Hazelcast data member automatically. The restart loads the lwm2m.* map configurations.
In the Environment Manager, tick bs to deploy it. A change of the bs tag alone, without the bs selection, does not deploy bs.
| Key | Name | Port | Protocol |
|---|---|---|---|
|
|
5680 |
UDP |
|
|
5681 |
UDP |
|
|
5682 |
UDP |
|
|
5683 |
UDP |
|
|
5684 |
UDP |
|
|
5685 |
UDP |
|
|
5880 |
TCP |
|
|
5883 |
TCP |
The example file helm/ft-services/docs/examples/values-lwm2m-example.yaml sets bs.enabled: true, the bs tag and hazelcast.external.enabled: false.
Device admission: the seed Job
Credential encryption is off. This is a setting for development environments. bs admits only the endpoint names that the seed Job lists.
For each name in bs.seed.endpoints, the seed Job writes one row to the table lwm2m_security. The row has security mode 3 (NoSec), server type ALL, endpoint mask equal to the name, and location 0. The row admits direct registration on port 5683 and NoSec bootstrap on port 5680.
The default list is [lwm2m-emu-1]. The Job runs as an ArgoCD PostSync hook after all other resources are Healthy. It writes no row for a name that already has a mode 3 row.
Allowed endpoint names
A name must match this pattern:
^[A-Za-z0-9][A-Za-z0-9.:-]{0,254}$
-
Use letters, digits,
.,:and-. -
Start the name with a letter or a digit.
-
Use at most 255 characters.
-
Do not use wildcards,
%,_,\, quotes or spaces. The chart refuses such a name. -
Do not list a name twice. The duplicate check ignores case.
-
On MySQL, names are matched without regard to case. Use one spelling for each device.
Why multi-device emulator names are not admitted
The emulator appends <g><n> to the client ID when one configuration starts more than one device. In a stored name, _ acts as a wildcard, and the chart never writes wildcards. Start one device for each configuration and list its exact name.
Verify the Job
-
Read the Job log:
kubectl -n <env> logs job/bs-seed -
Check the lines. Each name gives one line, followed by a summary line.
seed endpoint=lwm2m-emu-1 action=inserted seed done count=1 -
If the name was in the table before, the action is
present. Thecountvalue includes thepresentnames.
While the table lwm2m_security is not readable, the Job writes seed waiting table=lwm2m_security waited=<n>s reason=<first client error line> every 10 seconds. The reason is none when the client wrote no error. If the table is still not readable after 1100 seconds, the Job writes seed wait-timeout table=lwm2m_security and fails. The Job deadline is 1200 seconds, so the timeout message appears before ArgoCD stops the Job.
Change the list
-
Edit the values file of the environment in the repository. Set
bs.seed.endpoints.bs: seed: endpoints: [site-a-1, site-a-2] -
Commit the change.
-
Wait for ArgoCD to sync. The Job runs again.
-
Verify the log as described above.
The Job does not correct a row that already exists (present). It also does not delete the row of a name that you remove from the list (see Optional: external UDP exposure for the SQL). Edit the table lwm2m_security yourself in both cases.
The optional values bs.seed.idBase (default 990100) and bs.seed.locationId (default 0) set the first row ID and the location. Set bs.seed.enabled: false to skip the Job.
Optional: external UDP exposure
By default bs is reachable only inside the cluster.
Before you turn the exposure on, replace the default seed name lwm2m-emu-1. The chart refuses to render if bs.external.enabled is true and the list still contains this name.
The seed Job only inserts rows. It never deletes a row. A row that an earlier sync inserted stays in the table after you remove its name from the list. Remove that row yourself. This applies to the default name and to every other name that you remove from the list.
-
Replace the seed list as described in Change the list.
-
Delete the seeded row of the default name. Repeat this for every name that you removed from the list:
DELETE FROM lwm2m_security WHERE endpoint_mask = 'lwm2m-emu-1' AND security_mode = 3 AND creator = 'ft-services-seed'; -
Commit the transaction on Oracle. The statement is the same on MySQL and Oracle.
-
Verify the deletion. The query must return 0 rows:
SELECT id FROM lwm2m_security WHERE endpoint_mask = 'lwm2m-emu-1' AND security_mode = 3 AND creator = 'ft-services-seed'; -
Add this to the values file of the environment:
bs: external: enabled: true seed: endpoints: [site-a-1] -
Commit the change and wait for ArgoCD.
-
Read the assigned ports:
kubectl -n <env> get svc bs-external
The service bs-external has the type NodePort and lists the UDP ports only. Kubernetes assigns the NodePorts. To pin a port, set bs.external.nodePorts, for example coapNoSec: 30083.
Keep hazelcast.external.enabled: false, as in the example file.
Optional: bootstrap rows
Direct registration on port 5683 needs only the seed row. Skip this section for that case.
Bootstrap on port 5680 also needs one row in each of the tables lwm2m_bs, lwm2m_bs_security and lwm2m_bs_server. The seed Job does not create them. Create them after bs has started and before the device bootstraps. The tables are created by bs at startup.
The statements come from the rig helper RigDb.provisionLwm2mBootstrapConfig. The same statements are valid on MySQL and Oracle. They give an explicit value for every ID, so Oracle needs no sequence. The rig fills the columns created and updated with the current time, and CURRENT_TIMESTAMP does the same here.
Replace these placeholders:
| Placeholder | Value |
|---|---|
|
Unused integer IDs for the three new rows. The rig uses 990010, 990011 and 990012. |
|
One of the seeded names. It must match the |
|
The |
|
The URI of the LwM2M server for the device, for example |
|
The short server ID as a string. The rig uses |
-
Read the ID of the seeded row:
SELECT id FROM lwm2m_security WHERE endpoint_mask = '<endpoint-name>' AND security_mode = 3; -
Insert the plan:
INSERT INTO lwm2m_bs (id, name, endpoint_mask, endpoint_mask_type, created, creator, updated, updator) VALUES (<bs-id>, '<plan-name>', '<endpoint-name>', 'LIKE', CURRENT_TIMESTAMP, 'operator', CURRENT_TIMESTAMP, 'operator'); -
Insert the Security instance:
INSERT INTO lwm2m_bs_security (id, bs_id, instance_id, os_instance_id, security_id, hold_off_time, server_uri, short_server_id, is_bootstrap, created, creator, updated, updator) VALUES (<security-row-id>, <bs-id>, 1, NULL, <seed-row-id>, 0, '<server-uri>', '<short-server-id>', 0, CURRENT_TIMESTAMP, 'operator', CURRENT_TIMESTAMP, 'operator'); -
Insert the Server instance:
INSERT INTO lwm2m_bs_server (id, bs_id, instance_id, lifetime, def_min_period, def_max_period, disable_timeout, notification_storing, binding, server_uri, short_server_id, created, creator, updated, updator) VALUES (<server-row-id>, <bs-id>, 0, 60, 1, 60, 86400, 1, 'U', '<server-uri>', '<short-server-id>', CURRENT_TIMESTAMP, 'operator', CURRENT_TIMESTAMP, 'operator'); -
Commit the transaction on Oracle.
Fill every column. The bs loader fails on a NULL in the Server row. Insert the three rows in the order above. If a plan exists without its two child rows, bs answers "There are no bootstrap resources" for the endpoint. Delete the three rows and insert them again.
Start one emulator device
-
Find the emulator service. The default API port is 8556.
kubectl -n <env> get svc -
Set the protocol to LwM2M with
POST /api/protocol/LWM2M. -
Send the configuration with
POST /api/config:{ "serverIp": "bs", "serverPort": 5683, "clientId": "lwm2m-emu-1", "clientsCount": 1, "concurrentClients": 1 } -
Send
POST /api/init. -
Send
POST /api/start.
The clientId must be exactly one of the seeded names. The emulator resolves the host name bs inside the cluster. If you set clientsCount or concurrentClients above 1, the emulator appends a suffix to the name and bs does not admit the device.
A second device model
An emulator device reports the manufacturer and the model of the emulator configuration (POST /api/config) in the resources /3/0/0 and /3/0/1. The ACS files the device under that manufacturer and model. To get a second LwM2M model without changing the shared configuration, start the device with POST /api/devices/startNew and set the options lwm2m.device.manufacturer and lwm2m.device.model in protocolOptions. An empty or missing option falls back to the configuration.
The options need an iotEmulator image built from the dev branch of oneiot_emulator at commit d75f00f4 or later, for example the tag 914d2d61a15076176ecc23ca7f649c636d93078e. The tag v2.1.0-b0.0.14 accepts the options and ignores them. The options are not listed in GET /api/protocolOptions, and GET /api/devices still shows the configuration values. Check GET /api/devices/<clientId>/parameters instead.
Verify the environment
-
Check the Hazelcast cluster. The line must show
size:3.kubectl -n <env> logs deploy/hazelcast | grep 'Members {size' -
Check the ACS web service. With the credentials
<ws-user>and<ws-password>,/acsstatsanswers HTTP 200. Without credentials it answers HTTP 401.curl -s -o /dev/null -w '%{http_code}\n' -u '<ws-user>:<ws-password>' https://<env>.rd.friendly-tech.com/acsstats curl -s -o /dev/null -w '%{http_code}\n' https://<env>.rd.friendly-tech.com/acsstats -
Check the emulator.
GET /api/deviceslists a device with yourclientId. -
Check the database as user
<db-user>with password<db-password>.-
The table
cpehas a row for the device withprotocol_idequal to 2. -
The table
cpe_pending_taskhas 0 rows for the device. -
The table
cpe_parameterhas rows for the device.
-
Optional: file server
The ui-backend File Management uploads firmware and other files to a WebDAV server, and devices download them from it. A new ui-backend database holds the stub address http://127.0.0.1/webdav/, so the upload fails with HTTP 500 and error code 9033 (HTTP upload failed: Connection refused).
The chart can run a WebDAV server inside the environment. It has no authentication and no Ingress. Only pods of the cluster reach it, at http://file-server.<env>.svc.cluster.local/webdav/. The Environment Manager does not expose it.
-
Add this to the values file of the environment:
fileServer: enabled: true -
Commit the change and wait until ArgoCD shows the deployment
file-serveras Healthy. -
Point the four file-server settings of each portal at the server. The settings are rows of the ui-backend table
iotw_server_details:mcandschave one set each. Read the IDs withPOST /iot-webservice/iotw/Setting/fileServer, logged in with the matching client type. Then sendPUT /iot-webservice/iotw/Setting/fileServerwith the rowsDownload FTP,Download HTTP,Upload FTPandUpload HTTP, each with the addresshttp://file-server.<env>.svc.cluster.local/webdav/. -
Check the settings with
POST /iot-webservice/iotw/Setting/fileServer/checkand the same body. Every row must answerisValid: true. -
Upload a file in File Management. It must show the state
Exists.
The emulator only simulates a firmware download unless the device option lwm2m.fw.http.download is true. With the option, it fetches the file with a plain GET.
Troubleshooting
| Symptom | Action |
|---|---|
|
|
|
Check the argument |
The seed Job does not start |
The PostSync hook waits until all other components of the environment are Healthy. Find the component that is not Healthy and fix it first. |
The seed Job failed |
Read the log with |
The device does not register |
Check that the |
A seeded row has wrong values |
The Job does not correct |
A change of the values file has no effect |
Only ArgoCD applies the chart. Check the sync state of the application. Do not run Helm yourself. |
Check the chart before you commit
Run these scripts from the repository root.
bash helm/ft-services/scripts/check-bs-chart.sh
bash helm/ft-services/scripts/check-bs-seed-sql.sh mysql oracle
-
check-bs-chart.shrenders the chart withhelm templateand checks thebsresources. Exit code 0 means that all checks passed. -
check-bs-seed-sql.shruns the real seed script against throwaway MySQL and Oracle containers. It needs Docker and Helm.