# Init Stage

The **init** stage is where the device initialisation happens. This stage is invoked with an empty state object. Use this stage to populate different parameters that the device will use in its lifetime. It is also a good place to set up device credentials or to configure some external resources. An example of an Init stage is given below.

#### init(state)

```javascript
{
    let serial = glob.get('serial_' + client());
    if (!serial)  //if serial is not found, then create one
    {
        serial = chance.guid();
        glob.set('serial_' + client(), serial);
    }
    state.serial = serial;
    next();
}
```

As a result of this code, each of your clients will be assigned a unique serial number which will remain persistent throughout all of the simulations. You could always delete the DBStore entries or modify them.

> Note that the Init stage is invoked before the connection is made to your backend server. This is an ideal place to setup any device credentials or set the server settings.

The Init stage does not need to return a value.&#x20;


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.iotify.io/concepts/understanding-a-test/stages-management/init-stage.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
