:::info Sample code
Browse the Lua plugin examples on GitHub — [nodejs/plugin](https://github.com/obniz/obniz/tree/master/examples/nodejs/plugin).
:::

While obnizOS automatically handles communication with the obnizCloud, you have the flexibility to filter transmitted data, modify its content, or change the transmission timing.

**Note**: This section covers advanced, low-level mechanisms of the system.

---

## on_upstream()

By defining the `on_upstream()` function, you can intercept data just before obnizOS adds it to the transmission queue for the cloud.

The function must return an integer that determines how the data should be processed:

| Return Value | Description |
| :--- | :--- |
| **0** | **Discard**: The data will not be sent. |
| **1** | **Normal**: The data is added to the queue and sent according to the standard queue timing. |
| **2** | **Immediate**: The data is added to the queue, and the queue is flushed (sent) immediately. |

### Example

```lua
-- Parameters: func(int), module(int), data(string as uint8 array)
function on_upstream(func, module, data)
  if necessary then
    -- Proceed with standard transmission
    return 1;
  elseif rightnow then
    -- Send immediately
    return 2;
  elseif mustDrop then
    -- Discard original data and send custom data instead
    cloud.upstreamEnqueue(1, 2, "modified data"); 
    cloud.upstreamFlush(); -- Optional: Trigger immediate send
    return 0;
  end
end

```

---

## cloud.upstreamEnqueue(function, module, data)

This function manually inserts data into the cloud transmission queue. When used in combination with `on_upstream()`, it allows you to filter outgoing data, convert it into different commands, or apply custom compression.

### Usage

```lua
-- Inserts specific data into the upstream queue
cloud.upstreamEnqueue(1, 2, "my data");

```

---

## cloud.upstreamFlush()

This function forces the system to immediately transmit all data currently stored in the upstream queue.

### Usage

```lua
-- Trigger an immediate upload of the current queue
cloud.upstreamFlush()

```