---
title: Device Mode vs Gateway Mode
description: Device Mode vs Gateway Mode, SDK Modes
---

[Skip to content](https://portal.sandgrain.eu/knowledge-base/device-mode-vs-gateway-mode#main-content)

English

Show submenu for translations

![SandGrain\_Logo\_RGB\_white-bijgesneden (1)](https://portal.sandgrain.eu/hs-fs/hubfs/SandGrain_Logo_RGB_white-bijgesneden%20(1).png?width=427&height=83&name=SandGrain_Logo_RGB_white-bijgesneden%20(1).png)

Open main navigation

Close main navigation

- English
  
  Show submenu for translations
- [Contact us](https://portal.sandgrain.eu/login)

[Contact us](https://portal.sandgrain.eu/login?hsLang=en)

 How can we help you?

- There are no suggestions because the search field is empty.

1. [Knowledge Base](https://portal.sandgrain.eu/knowledge-base?hsLang=en)
2. [SDK](https://portal.sandgrain.eu/knowledge-base/sdk?hsLang=en)
3. [SandGrain SDK](https://portal.sandgrain.eu/knowledge-base/sdk?hsLang=en#sandgrain-sdk)

October 6, 2026

# Device Mode vs Gateway Mode

**Who this is for:** Developers who need to understand what they're actually building and running. This shapes every walkthrough.

**What you'll accomplish:** Know the difference between the two SDK modes, when to use each, and what functions each one includes.

### One codebase, two builds

The SandGrain SDK is a single portable C codebase. A **compile-time** parameter, `SDK_MODE`, selects which functions and port implementations are compiled into a given binary:

- **`DEVICE_MODE`** builds `test_device`, runs on the unit that holds the SandGrain Token.
- **`GATEWAY_MODE`** builds `test_gw`, runs on the relay/orchestrator node.

There's also a **Cloud SDK agent** written in Python, which provides the cloud-side counterpart. If `SDK_MODE` is not defined, the SDK deliberately fails to compile with an error.

### What each mode does

|  | Device mode (`test_device`) | Gateway mode (`test_gw`) |
| --- | --- | --- |
| **Runs on** | The unit holding the Token | The relay / orchestrator node |
| **Crypto Token** | **Always required** (USB/SPI) | Optional (`GW_CRYPTO_ENABLED`) |
| **Key functions** | `SGR_SDK_Initialize`, `SGR_SDK_Authenticate_Via_GW`, `SGR_SDK_Verification_FW`, `SGR_SDK_Installation` | `SGR_SDK_Initialize`, `SGR_SDK_Authentication_Token_To_Server`, `SGR_SDK_Authentication_Server_To_Token`, `SGR_SDK_GW_Run` |
| **Extra startup work** | Initializes the middleware | Also initializes the authentication database and registers all whitelisted devices |

### When to use which

- Use **`DEVICE_MODE`** on the unit that physically holds the SandGrain chip.
- Use **`GATEWAY_MODE`** on the relay/orchestrator node that sits between devices and the cloud.
- `SGR_SDK_GW_Run` is the recommended entry point for the Gateway application loop, it polls all device channels and routes each request to the right handler.

#### Good to know

- Both modes **build the same way** (`make`) and run on the same set of operating systems.
- Only the device node strictly needs the USB/SPI Token attached.
- `GW_CRYPTO_ENABLED` has **no effect in `DEVICE_MODE`**, the Token is always required there.

### Maintenance note

The `sdk_fw/` core directory should **not** be modified, with one exception: `src/services/database/auth_db_whitelist.c` (the device whitelist). After pulling new device-side code, rebuild the firmware with `make clean && make`.

### Bluetooth LE variant

There is a Bluetooth LE build of the Gateway, used when the devices are Nordic boards rather than USB Tokens. In that variant the Gateway runs as the **BLE central**: it scans for boards advertising as `SandGrain-Dev`, serves one board per channel, and is built with `make GW_BLE=1 GW_BLE_DEVICES=<n>` (default 2 channels). The device SDK, meanwhile, is flashed onto the Nordic board rather than compiled on a PC. The gateway-to-cloud MQTT path and the TrustBridge stack are unchanged.

See [*Nordic nRF54L15 Boards over Bluetooth LE*](https://portal.sandgrain.eu/knowledge-base/what-question-is-your-article-answeringwalkthrough-nordic-nrf54l15-boards-over-bluetooth-le?hsLang=en).

### Single-board (cellular) variant

The cellular variant collapses both roles onto one board. A Nordic nRF9151-DK is built with `SDK_MODE=GATEWAY_MODE` and `GW_CRYPTO_ENABLED=1`, wires its own SGT1001 chip over SPI, and authenticates its own token against the cloud over LTE (the Token-to-Server / Server-to-Token path). This is a development shortcut: there's no separate device node, and the board is both the thing being proven and the thing doing the proving. Production keeps device and gateway separate.

See [*Nordic nRF9151-DK over LTE / Cellular*](https://portal.sandgrain.eu/knowledge-base/walkthrough-nordic-nrf9151-dk-over-lte-/-cellular?hsLang=en).

| [Access & Credentials](https://portal.sandgrain.eu/knowledge-base/access-credentials-your-cyberrock-access-package?hsLang=en) | [Choosing Your Setup Path](https://portal.sandgrain.eu/knowledge-base/choosing-your-setup-path?hsLang=en) |
| --- | --- |

 

- [User Documentation](https://portal.sandgrain.eu/knowledge-base/user-documentation?hsLang=en#main-content)

    - [Quick Starter Guide](https://portal.sandgrain.eu/knowledge-base/user-documentation?hsLang=en#quick-starter-guide)
    - [User Manual](https://portal.sandgrain.eu/knowledge-base/user-documentation?hsLang=en#user-manual)
    - [Whitepaper](https://portal.sandgrain.eu/knowledge-base/user-documentation?hsLang=en#whitepaper)
    - [Token Leaflet](https://portal.sandgrain.eu/knowledge-base/user-documentation?hsLang=en#token-leaflet)
    - [Claim Token Procedure](https://portal.sandgrain.eu/knowledge-base/user-documentation?hsLang=en#claim-token-procedure)
    - [Daisy Chain](https://portal.sandgrain.eu/knowledge-base/user-documentation?hsLang=en#daisy-chain)
    - [Release Note](https://portal.sandgrain.eu/knowledge-base/user-documentation?hsLang=en#release-note)
    - [Naming Convention](https://portal.sandgrain.eu/knowledge-base/user-documentation?hsLang=en#naming-convention)
    - [SandGrain SDK](https://portal.sandgrain.eu/knowledge-base/user-documentation?hsLang=en#sandgrain-sdk)
    - [TrustBridge](https://portal.sandgrain.eu/knowledge-base/user-documentation?hsLang=en#trustbridge)
- [API Documentation](https://portal.sandgrain.eu/knowledge-base/api-documentation?hsLang=en#main-content)

    - [Device API Integration](https://portal.sandgrain.eu/knowledge-base/api-documentation?hsLang=en#device-api-integration)
    - [Daisy Chain and Attestation](https://portal.sandgrain.eu/knowledge-base/api-documentation?hsLang=en#daisy-chain-and-attestation)
- [SDK](https://portal.sandgrain.eu/knowledge-base/sdk?hsLang=en#main-content)

    - [Core Functions](https://portal.sandgrain.eu/knowledge-base/sdk?hsLang=en#core-functions)
    - [SandGrain SDK](https://portal.sandgrain.eu/knowledge-base/sdk?hsLang=en#sandgrain-sdk)

[![SandGrain\_Logo\_RGB\_white-bijgesneden (1)-1](https://portal.sandgrain.eu/hs-fs/hubfs/SandGrain_Logo_RGB_white-bijgesneden%20(1)-1.png?width=427&height=83&name=SandGrain_Logo_RGB_white-bijgesneden%20(1)-1.png "SandGrain_Logo_RGB_white-bijgesneden (1)-1")](https://portal.sandgrain.eu/?hsLang=en)

<https://www.facebook.com/> <https://www.twitter.com/> <https://www.instagram.com/> <https://podcasts.apple.com/> [mailto:email@email.com](mailto:email@email.com)

Copyright © 2026, sandgrain.eu