# Build A LoRaWAN Device

> Tutorial for building and testing a custom LoRaWAN device on the Helium Network using a Heltec CubeCell board.

Many commercially produced LoRaWAN devices come pre-provisioned and ready to use out of the box.
However, understanding how devices are onboarded, programmed, and connected unlocks the full
potential of building custom IoT solutions on the Helium Network.

This guide walks through the process of creating a custom device from scratch using a real-world
development device remotely configured through the widgets on this page.

## Provisioning a Device

Every LoRaWAN device requires a unique set of cryptographic keys for authentication and encryption.
Pre-built devices typically come with these keys already configured, but for custom devices, you
must generate and provision them yourself.

Click the button below to generate a new set of device keys:

<figure className="screensnippet-wrapper">
  <CreateDevice />
</figure>

Behind the scenes, these keys are registered with a LoRaWAN Network Server (LNS). The Join EUI is
shared with the Helium Packet Router (HPR), which allows any Hotspot in the world to route messages
from this device to the correct LNS. The cryptographic keys ensure end-to-end encryption between the
device and the LNS.

## Programming the Device

The example below uses a [Heltec CubeCell](https://heltec.org/project/htcc-ab01/) development board
with PlatformIO. Copy the keys generated above into the `devEui`, `appEui`, and `appKey` variables:

<figure className="screensnippet-wrapper">
  <DocslabCodeBlock
    hardshare="heliumdev/cubecell-draw-demo"
    className="language-cpp"
    command="source .platformio/penv/bin/activate && cd m/Heltec-CubeCell-Board/examples/cubecell-helium-us915-basic && pio run -t upload && pio device monitor"
    destpath="m/Heltec-CubeCell-Board/examples/cubecell-helium-us915-basic/src/main.cpp"
    repoUrl="https://github.com/helium/longfi-platformio.git"
    urlfile="https://raw.githubusercontent.com/helium/longfi-platformio/master/Heltec-CubeCell-Board/examples/cubecell-helium-us915-oled/src/main.cpp"
  />
</figure>

Once compiled and uploaded, the device will attempt to join the network and begin transmitting data.

## Viewing Device Events

When your device transmits, a Hotspot on the Helium Network receives the radio signal and forwards
it through the Packet Router to the LNS. The LNS then delivers the data here, to this page, in real
time.

<figure className="screensnippet-wrapper">
  <DeviceEventLogger />
</figure>

If uplinks appear in the logger, you're seeing the complete data path in action. Your device
transmits, the Helium Network routes, and your application receives. This same flow can deliver data
to any backend you build: a database, a dashboard, an alerting system, or an API.

## Next Steps

Once data reaches the LNS, it can be forwarded to your application using integrations such as HTTP
webhooks, MQTT, or cloud platforms like AWS IoT and Azure IoT Hub. See
[LoRaWAN Network Servers](/iot/lorawan-network-servers) for more information on available LNS
options.

## Experiments

Try modifying the device behavior to deepen your understanding:

1. **Change the payload**: The device sends data in hexadecimal format. How would you transmit
   "Hello, World!"? Tools like [asciitohex.com](https://www.asciitohex.com/) can help with
   conversions.
2. **Use different ports**: LoRaWAN's `FPort` field allows you to separate data types. Send sensor
   readings on one port and status updates (like battery level) on another.
3. **Adjust the transmission interval**: The device currently sends data every 30 seconds. Try
   changing it to 10 seconds. Consider how this affects battery life and network usage.
