Volt Docs

Language

Networking

Wi-Fi, MQTT and HTTP are built in. Connect once, then publish, subscribe and fetch.

wifi, mqtt and http are part of every program. There’s nothing to declare.

main.volt
on mqtt.has_message() {
    let cmd: string = mqtt.payload()
    log("mqtt", mqtt.topic() + ": " + cmd)
}

every 60s when wifi.is_connected() {
    let body: string = http.get("http://example.com/status")
    log("http", body)
}

setup {
    wifi.connect("ssid", "password") or retry(5)
    mqtt.connect("mqtt://broker.local") or retry(3)
    mqtt.on_receive("home/cmd")
}

Wi-Fi

Connect in setup, with a fallback for when the network isn’t there. wifi.is_connected() tells you whether it’s up; use it with when to skip work while it’s down. wifi.get_ip() and wifi.get_rssi() give the address and signal strength.

Using Wi-Fi takes over ADC2 on the ESP32: analog pins 0, 2, 4, 12 to 15 and 25 to 27 stop reading. The compiler warns about any you’ve declared as Analog; ADC1 pins, 32 to 39, keep working.

MQTT

Connect to a broker with its URL, then publish to topics:

main.volt
hardware {
    device env: BME280
}

every 30s when mqtt.is_connected() {
    mqtt.send_float("home/temp", env.temperature())
    mqtt.send_float("home/humidity", env.humidity())
}

setup {
    wifi.connect("home", "secret") or retry(5)
    mqtt.connect("mqtt://broker.local") or retry(3)
}

To receive, subscribe with mqtt.on_receive(topic) and handle messages in an on mqtt.has_message() block. mqtt.payload() gives the latest message’s text and marks it read; mqtt.topic() says where it came from.

HTTP

http.get(url) and http.post(url, body) return the response body as a string: empty if the request failed, and cut at 1023 characters. They wait for the answer, so the compiler runs any task that uses them on its own, where waiting doesn’t hold anything else up.

Bluetooth

ble advertises the board and publishes values a phone can read. See Built-in objects.