> For the complete documentation index, see [llms.txt](https://docs.heisenware.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.heisenware.com/developers/vrpc/languages/arduino/api.md).

# API

## Required dependencies

* [ArduinoJSON](https://arduinojson.org/?utm_source=meta\&utm_medium=library.properties) by Benoit Blanchon
* [PubSubClient](https://pubsubclient.knolleary.net/) by Nick O’Leary
* [ArduinoUniqueId](https://github.com/ricaun/ArduinoUniqueID) by Luiz Henrique Cassettari

## Function adaptation macros

Use the macros described below to add remote access to regular functions.

#### 1. Global Functions

```cpp
VRPC_GLOBAL_FUNCTION(<returnType>, <functionName>[, <argTypes>])
```

Example:

```cpp
int foo () {
  // [...]
}

void bar (String& s, bool b) {
  // [...]
}

VRPC_GLOBAL_FUNCTION(int, foo)
VRPC_GLOBAL_FUNCTION(void, bar, String&, bool)
```

## class `VrpcAgent`

The agent allows existing code to be called from remote.

### Summary

| Members                                                                                                                                                                                                                                                                                        | Descriptions                                                       |
| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------ |
| `public inline` [`VrpcAgent`](https://github.com/heisenware/vrpc-arduino/blob/master/docs/api.md#classVrpcAgent_1ace51d7fc67e6cca3db088b229292ded7)`(int maxBytesPerMessage)`                                                                                                                  | Constructs an agent.                                               |
| <p><code>public template<></code><br><code>inline void</code> <a href="https://github.com/heisenware/vrpc-arduino/blob/master/docs/api.md#classVrpcAgent_1a5bcc3d82db137a8d4dd37f55ce83d53e"><code>begin</code></a><code>(T & netClient,const String & domain,const String & token)</code></p> | Initializes the object using a client class for network transport. |
| `public inline bool` [`connected`](https://github.com/heisenware/vrpc-arduino/blob/master/docs/api.md#classVrpcAgent_1aef4609a41a89bf7602011cca1fff5057)`()`                                                                                                                                   | Reports the current connectivity status.                           |
| `public inline void` [`connect`](https://github.com/heisenware/vrpc-arduino/blob/master/docs/api.md#classVrpcAgent_1afa4e6b81fcb0a990d5747b986adeecdb)`()`                                                                                                                                     | Connect the agent to the broker.                                   |
| `public inline void` [`loop`](https://github.com/heisenware/vrpc-arduino/blob/master/docs/api.md#classVrpcAgent_1a89c5b7c6a84bccc8470b4bb8ff29a4ff)`()`                                                                                                                                        | This function will send and receive VRPC packets.                  |

### Members

#### `public inline` [`VrpcAgent`](https://github.com/heisenware/vrpc-arduino/blob/master/docs/api.md#classVrpcAgent_1ace51d7fc67e6cca3db088b229292ded7)`(int maxBytesPerMessage)`

Constructs an agent.

**Parameter**

* `maxBytesPerMessage` \[optional, default: `1024`] Specifies the maximum size a single MQTT message may have

***

#### `public template<typename T>` `inline void` [`begin`](https://github.com/heisenware/vrpc-arduino/blob/master/docs/api.md#classVrpcAgent_1a5bcc3d82db137a8d4dd37f55ce83d53e)`(T& netClient, const String& domain, const String& token)`

Initializes the object using a client class for network transport.

**Parameter**

* `netClient` A client class following the interface as described [here](https://www.arduino.cc/en/Reference/ClientConstructor)
* `domain` \[optional, default: `"vrpc"`] The domain under which the agent-provided code is reachable
* `token` \[optional, default: `""`] Access token as generated by Heisenware GmbH, or MQTT password if own broker is used
* `broker` \[optional, default: `"vrpc.io"`] Address of the MQTT broker
* `username` \[optional] MQTT username (not needed when using the vrpc.io broker)

***

#### `public inline bool` [`connected`](https://github.com/heisenware/vrpc-arduino/blob/master/docs/api.md#classVrpcAgent_1aef4609a41a89bf7602011cca1fff5057)`()`

Reports the current connectivity status.

**Returns**

true when connected, false otherwise

***

#### `public inline void` [`connect`](https://github.com/heisenware/vrpc-arduino/blob/master/docs/api.md#classVrpcAgent_1afa4e6b81fcb0a990d5747b986adeecdb)`()`

Connect the agent to the broker.

The function will try to connect forever. Inspect the serial monitor to see the connectivity progress.

***

#### `public inline void` [`loop`](https://github.com/heisenware/vrpc-arduino/blob/master/docs/api.md#classVrpcAgent_1a89c5b7c6a84bccc8470b4bb8ff29a4ff)`()`

Send and receive VRPC packets.

{% hint style="info" %}
**NOTE**

This function should be called in every `loop`
{% endhint %}


---

# 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.heisenware.com/developers/vrpc/languages/arduino/api.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.
