This sample application demonstrates how to connect with Golioth and publish simple Hello messages.
- Golioth credentials
- Network connectivity
Golioth offers two authentication methods: Pre-Shared Keys (PSK) or Public Key Cryptography using Certificates (certs). Normally, it is the responsibility of the Golioth SDK user to load these credentials at runtime. For simplicity, we provide facilities to hardcode these credentials or set them at runtime for our samples.
Configure the following Kconfig options based on your Golioth credentials:
GOLIOTH_SAMPLE_HARDCODED_PSK_ID
- PSK ID of registered deviceGOLIOTH_SAMPLE_HARDCODED_PSK
- PSK of registered device
by adding these lines to configuration file (e.g. prj.conf
):
CONFIG_GOLIOTH_SAMPLE_HARDCODED_PSK_ID="my-psk-id"
CONFIG_GOLIOTH_SAMPLE_HARDCODED_PSK="my-psk"
We provide an option for setting Golioth credentials through the Zephyr shell. This is based on the Zephyr Settings subsystem.
Enable the settings shell by including the following configuration overlay file:
$ west build -- -DEXTRA_CONF_FILE=${ZEPHYR_GOLIOTH_MODULE_DIR}/samples/common/runtime_settings.conf
Alternatively, you can add the following options to prj.conf
:
CONFIG_GOLIOTH_SAMPLE_HARDCODED_CREDENTIALS=n
CONFIG_FLASH=y
CONFIG_FLASH_MAP=y
CONFIG_NVS=y
CONFIG_SETTINGS=y
CONFIG_SETTINGS_RUNTIME=y
CONFIG_GOLIOTH_SAMPLE_PSK_SETTINGS=y
CONFIG_GOLIOTH_SAMPLE_SETTINGS_AUTOLOAD=y
CONFIG_GOLIOTH_SAMPLE_SETTINGS_SHELL=y
At runtime, configure PSK-ID and PSK using the device shell based on your Golioth credentials:
uart:~$ settings set golioth/psk-id <my-psk-id@my-project>
uart:~$ settings set golioth/psk <my-psk>
uart:-$ kernel reboot cold
Configure the following Kconfig options based on your Golioth credentials:
CONFIG_GOLIOTH_AUTH_METHOD_CERT
- use certificate-based authenticationCONFIG_GOLIOTH_SAMPLE_HARDCODED_CRT_PATH
- device certificateCONFIG_GOLIOTH_SAMPLE_HARDCODED_KEY_PATH
- device private key
by adding these lines to configuration file (e.g. prj.conf
):
CONFIG_GOLIOTH_AUTH_METHOD_CERT=y
CONFIG_GOLIOTH_SAMPLE_HARDCODED_CRT_PATH="keys/device.crt.der"
CONFIG_GOLIOTH_SAMPLE_HARDCODED_KEY_PATH="keys/device.key.der"
This application has been built and tested with QEMU x86 (qemu_x86).
On your Linux host computer, open a terminal window, locate the source code
of this sample application (i.e., samples/hello
) and type:
$ west build -b qemu_x86 samples/hello
$ west build -t run
See Networking with QEMU on how to setup networking on host and configure NAT/masquerading to access Internet.
Configure the following Kconfig options based on your WiFi AP credentials:
- GOLIOTH_SAMPLE_WIFI_SSID - WiFi SSID
- GOLIOTH_SAMPLE_WIFI_PSK - WiFi PSK
by adding these lines to configuration file (e.g. prj.conf
or
board/esp32_devkitc_wroom.conf
):
CONFIG_GOLIOTH_SAMPLE_WIFI_SSID="my-wifi"
CONFIG_GOLIOTH_SAMPLE_WIFI_PSK="my-psk"
On your host computer open a terminal window, locate the source code of this
sample application (i.e., samples/hello
) and type:
$ west build -b esp32_devkitc_wroom samples/hello
$ west flash
See ESP32-DEVKITC-WROOM for details on how to use ESP32 board.
This subsection documents using nRF52840 DK running Zephyr with offloaded ESP-AT WiFi driver and ESP32-WROOM-32 module based board (such as ESP32 DevkitC rev. 4) running WiFi stack. See AT Binary Lists for links to ESP-AT binaries and details on how to flash ESP-AT image on ESP chip. Flash ESP chip with following command:
esptool.py write_flash --verify 0x0 PATH_TO_ESP_AT/factory/factory_WROOM-32.bin
Connect nRF52840 DK and ESP32-DevKitC V4 (or other ESP32-WROOM-32 based board) using wires:
nRF52840 DK | ESP32-WROOM-32 | ESP32-WROVER-32 |
---|---|---|
P1.01 (RX) | IO17 (TX) | IO22 (TX) |
P1.02 (TX) | IO16 (RX) | IO19 (RX) |
P1.03 (CTS) | IO14 (RTS) | IO14 (RTS) |
P1.04 (RTS) | IO15 (CTS) | IO15 (CTS) |
P1.05 | EN | EN |
GND | GND | GND |
Configure the following Kconfig options based on your WiFi AP credentials:
- GOLIOTH_SAMPLE_WIFI_SSID - WiFi SSID
- GOLIOTH_SAMPLE_WIFI_PSK - WiFi PSK
by adding these lines to configuration file (e.g. prj.conf
or
board/nrf52840dk_nrf52840.conf
):
CONFIG_GOLIOTH_SAMPLE_WIFI_SSID="my-wifi"
CONFIG_GOLIOTH_SAMPLE_WIFI_PSK="my-psk"
On your host computer open a terminal window, locate the source code of this
sample application (i.e., samples/hello
) and type:
$ west build -b nrf52840dk_nrf52840 samples/hello
$ west flash
On your host computer open a terminal window, locate the source code of this
sample application (i.e., samples/hello
) and type:
$ west build -b nrf9160dk_nrf9160_ns samples/hello
$ west flash
This is the output from the serial console:
[00:00:00.000,000] <inf> golioth_hello: Initializing golioth client
[00:00:00.000,000] <inf> golioth_hello: Golioth client initialized
[00:00:00.000,000] <inf> golioth_hello: Sending hello! 0
[00:00:00.000,000] <wrn> golioth_hello: Failed to send hello!
[00:00:00.000,000] <inf> golioth_hello: Starting connect
[00:00:00.000,000] <inf> golioth_hello: Client connected!
[00:00:05.010,000] <inf> golioth_hello: Sending hello! 1
[00:00:05.020,000] <dbg> golioth_hello: Payload
48 65 6c 6c 6f 20 6d 61 72 6b |Hello ma rk
[00:00:10.030,000] <inf> golioth_hello: Sending hello! 2
[00:00:10.030,000] <dbg> golioth_hello: Payload
48 65 6c 6c 6f 20 6d 61 72 6b |Hello ma rk
Responses to Hello messages are printed above as a hexdump of "Hello mark". This means that communication with Golioth is working.