---
title: "Packet parser functions"
description: "TapHome Packet parser scripts: send HTTP requests and read the response, send TCP and UDP data, publish MQTT messages and transfer files over FTP."
url: "https://taphome.com/en/docs/script/packet-parser/"
language: en
lastmod: 2026-10-13
generator: hugo
ai:
  topics: ["packet-parser","http-requests","mqtt","ftp","tcp-udp","scripting-language"]
  questions: ["What functions are available in the TapHome Packet parser?","How do I send an HTTP request from a TapHome script?","What does SENDHTTPREQUEST return?","How do I add HTTP headers to a request?","How to publish an MQTT message in TapHome?","How do I download or upload a file via FTP in TapHome?","Where do I find documentation on the Packet parser?","How do I configure Modbus in TapHome?"]
---

# Packet parser functions

TapHome script Packet parser functions — HTTPREQUEST, SENDHTTPREQUEST, SENDDATA, MQTTPUBLISH, FTPDOWNLOAD, FTPUPLOAD, COMPLETESERVICEATTRIBUTE and COMPLETESERVICEACTION — for HTTP, TCP, UDP, MQTT and FTP.

Last updated: 2026-10-13

Packet parser functions talk to devices over HTTP, TCP, UDP, MQTT and FTP. They work only in the scripts of a Packet parser module or device whose protocol matches the function; elsewhere the script stops with *PacketParserFunction - PacketParserContext is null*. All of them need Core 2022.2 or newer. Setting up a Packet parser module is described in [Packet parser](https://taphome.com/en/docs/integration/packet-parser/); incoming messages are handled in [Listener scripts](https://taphome.com/en/docs/script/listener-scripts/), and Modbus devices have their own [Modbus functions](https://taphome.com/en/docs/script/modbus/).

## Protocols and scripts

Each protocol has its own functions and a typical split of work between the scripts.

| Protocol | Functions | Typical scripts |
|---|---|---|
| HTTP | `HTTPREQUEST`, `SENDHTTPREQUEST` | The module read script sends one request and stores the response in a module variable; device read scripts parse it. |
| TCP, UDP | `SENDDATA` | Read or write scripts send a request; the answer arrives in the [listener script](https://taphome.com/en/docs/script/listener-scripts/). |
| MQTT | `MQTTPUBLISH` | The listener script processes incoming messages; the write script publishes commands. |
| FTP | `FTPDOWNLOAD`, `FTPUPLOAD` | Read and write scripts transfer files. |

**Example — one HTTP request for all devices of a module**

```taphome
VAR response := SENDHTTPREQUEST("/status", "GET");
StatusJson := response.Content;
```

```taphome
PARSEJSON(StatusJson, "temperature");
```

The first script is the module read script, the second a device read script; `StatusJson` is a module variable.

## HTTPREQUEST

`HTTPREQUEST` builds an `httprequest` value whose path, method, body and headers can be changed before it is sent with [SENDHTTPREQUEST](https://taphome.com/en/docs/script/packet-parser/#sendhttprequest).

```text
HTTPREQUEST(path [, method [, body]])
```

**Remarks** — The default method is `GET`. The properties `PATH`, `METHOD`, `BODY` and `HEADERS` can be read and written; `HEADERS` is a collection of `"Name: value"` strings. The function only creates a value, so it works in every script.

**Example**

```taphome
VAR request := HTTPREQUEST("/api/v1/state", "POST", "{\"on\":true}");
request.HEADERS := {"Content-Type: application/json", "Authorization: Bearer " + token};
VAR response := SENDHTTPREQUEST(request);
```

## SENDHTTPREQUEST

`SENDHTTPREQUEST` sends an HTTP request, waits for the answer and returns it as an `httpresponse` value with the properties `Content`, `StatusCode`, `ReasonPhrase`, `IsSuccess` and `Headers`.

```text
SENDHTTPREQUEST(path [, method [, body [, header1, header2, …]]])
SENDHTTPREQUEST(request)
```

| Name | Type | Description |
|---|---|---|
| `path` | string | Path on the device set in the module, for example `"/status"`. |
| `method` | string, optional | `GET` (default), `POST`, `PUT`, … |
| `body` | string, optional | Request body. |
| `header1` … | string, optional | Up to 27 headers as `"Name: value"`. |
| `request` | `httprequest` | A request built with [HTTPREQUEST](https://taphome.com/en/docs/script/packet-parser/#httprequest). |

**Returns** — `httpresponse`:

| Property | Meaning |
|---|---|
| `Content` | The response body as text. |
| `StatusCode` | HTTP status code, for example 200. |
| `ReasonPhrase` | Status text, for example `OK`. |
| `IsSuccess` | `TRUE` for status codes 200 – 299. |
| `Headers` | Response headers as JSON text — an array of `{"Key": …, "Value": [ … ]}` — readable with `PARSEJSON`. |

**Remarks** — Only for a module with the HTTP protocol. The response may have at most 128 kB.

**Example**

```taphome
VAR response := SENDHTTPREQUEST("/status", "GET");   # send the request
IF response.IsSuccess
    StatusJson := response.Content;   # store the body on success
ELSE
    ADDERROR(response.StatusCode + " (" + response.ReasonPhrase + ")");   # report the status on failure
END
```

```taphome
SENDHTTPREQUEST("/doSomething", "POST", "someData", "header1: value1", "header2: value2");
```

**Errors** — *Response is too long (Nbytes). Maximum supported length is 128KB*; *PacketParserFunction - unable to use 'SENDHTTPREQUEST' with …* (the module uses another protocol).

## SENDDATA

`SENDDATA` sends a string or a byte collection over TCP or UDP and returns `TRUE`; the answer arrives in the [listener script](https://taphome.com/en/docs/script/listener-scripts/).

```text
SENDDATA(data)
```

**Remarks** — A string is sent as `iso-8859-1` bytes. A collection must be a `collection<uint8>`. Incoming data is delivered to the listener script in chunks of at most 4096 bytes.

**Example**

```taphome
SENDDATA(BYTECOLLECTION("0a dd ef a2"));
SENDDATA("STATUS?\r\n");
```

## MQTTPUBLISH

`MQTTPUBLISH` publishes a message with the given topic to the MQTT broker of the module and returns `Null`.

```text
MQTTPUBLISH(topic, data)
```

**Remarks** — `data` is a string or a `collection<uint8>`. An error reported by the broker stops the script with its text. The broker is set up in [MQTT Broker](https://taphome.com/en/docs/integration/packet-parser/mqtt-broker/).

**Example**

```taphome
MQTTPUBLISH("shellies/" + plugTopic + "/relay/0/command", IF(St > 0, "on", "off"));
```

## FTPDOWNLOAD

`FTPDOWNLOAD` downloads a file from the FTP server of the module and returns its content as a byte collection (`collection<uint8>`).

```text
FTPDOWNLOAD(path)
```

**Example**

```taphome
VAR data := FTPDOWNLOAD("/export/values.csv");
VAR csv := TOSTRING(data, "utf-8");
```

## FTPUPLOAD

`FTPUPLOAD` writes data to a file on the FTP server of the module — replacing the file with `"write"` (default) or adding to its end with `"append"`.

```text
FTPUPLOAD(path, data [, mode])
```

**Remarks** — `data` is a string or a `collection<uint8>`. `mode` must be lower case.

**Example**

```taphome
FTPUPLOAD("/path/to/file", "some data", "write");
FTPUPLOAD("/path/to/file", BYTECOLLECTION("a7 ff e2"), "append");
```

**Errors** — *FTPUPLOAD - invalid argument, upload mode must be 'append' or 'write'*.

## COMPLETESERVICEATTRIBUTE

`COMPLETESERVICEATTRIBUTE` delivers the value of a service attribute to the app from a TCP or UDP listener script, after the attribute script has sent the request with `SENDDATA`.

```text
COMPLETESERVICEATTRIBUTE(name, value [, error])
```

**Remarks** — `name` is the name of the service attribute. With `error` the attribute shows the error text instead of a value. Returns `Null`.

**Example**

```taphome
COMPLETESERVICEATTRIBUTE("Uptime", "2d:21h:43m");
COMPLETESERVICEATTRIBUTE("Status", "", "Device is offline");
```

## COMPLETESERVICEACTION

`COMPLETESERVICEACTION` reports the result of a service action to the app from a TCP or UDP listener script, after the action script has sent the request with `SENDDATA`.

```text
COMPLETESERVICEACTION(name, result)
```

**Example**

```taphome
COMPLETESERVICEACTION("Reboot", "Rebooted successfully");
```

**Errors** — *No service action with name X*.

**See also** — [Listener scripts](https://taphome.com/en/docs/script/listener-scripts/), [Parsing functions](https://taphome.com/en/docs/script/parsing-functions/), [Data type conversions](https://taphome.com/en/docs/script/data-type-conversions/).
