> For the complete documentation index, see [llms.txt](https://docs.iotify.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.iotify.io/concepts/understanding-a-test/stages-management/init-stage.md).

# 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
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
