-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
106d8f3
commit 7dd968c
Showing
4 changed files
with
120 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
cmake_minimum_required(VERSION 3.20.0) | ||
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) | ||
project(rpc-sample) | ||
|
||
target_sources(app PRIVATE src/main.c) | ||
|
||
target_compile_options(app PRIVATE | ||
-Wall | ||
-Werror | ||
-Wno-unused-parameter | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
CONFIG_LOG=y | ||
CONFIG_SHELL=y | ||
CONFIG_SHELL_MINIMAL=y | ||
CONFIG_COAP_INIT_ACK_TIMEOUT_MS=4000 | ||
|
||
# Cellular connectivity | ||
CONFIG_NRF_MODEM_LIB=y | ||
CONFIG_NRF_MODEM_LIB_LOG_FW_VERSION_UUID=y | ||
CONFIG_LTE_LINK_CONTROL=y | ||
CONFIG_LTE_NETWORK_MODE_LTE_M_NBIOT=y | ||
CONFIG_LTE_MODE_PREFERENCE_LTE_M=y | ||
CONFIG_LTE_PSM_REQ=y | ||
CONFIG_LTE_EDRX_REQ=y | ||
CONFIG_NET_SOCKETS_OFFLOAD=y | ||
|
||
# Requirements for Thingsboard SDK | ||
CONFIG_COAP=y | ||
CONFIG_NETWORKING=y | ||
CONFIG_NET_IPV4=y | ||
CONFIG_NET_SOCKETS=y | ||
CONFIG_JSON_LIBRARY=y | ||
CONFIG_FLASH=y | ||
CONFIG_FLASH_MAP=y | ||
CONFIG_NVS=y | ||
CONFIG_SETTINGS=y | ||
|
||
# Thingsboard SDK | ||
CONFIG_THINGSBOARD=y | ||
CONFIG_THINGSBOARD_USE_PROVISIONING=n | ||
# Set server name and access token | ||
# CONFIG_COAP_SERVER_HOSTNAME="" | ||
# CONFIG_THINGSBOARD_ACCESS_TOKEN="" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#include <thingsboard.h> | ||
|
||
#include <modem/lte_lc.h> | ||
#include <modem/nrf_modem_lib.h> | ||
#include <zephyr/kernel.h> | ||
#include <zephyr/logging/log.h> | ||
#include <zephyr/settings/settings.h> | ||
#include <zephyr/shell/shell.h> | ||
|
||
#include <string.h> | ||
|
||
LOG_MODULE_REGISTER(main); | ||
|
||
static struct tb_fw_id fw_id = { | ||
.fw_title = "rpc-sample", .fw_version = "v1.0.0", .device_name = "sample-device"}; | ||
|
||
int main(void) | ||
{ | ||
int err = 0; | ||
|
||
LOG_INF("Initializing modem library"); | ||
err = nrf_modem_lib_init(); | ||
if (err) { | ||
LOG_ERR("Failed to initialize the modem library, error (%d): %s", err, | ||
strerror(-err)); | ||
return err; | ||
} | ||
|
||
err = lte_lc_func_mode_set(LTE_LC_FUNC_MODE_ACTIVATE_LTE); | ||
if (err) { | ||
LOG_ERR("Failed to activate LTE"); | ||
return err; | ||
} | ||
|
||
LOG_INF("Connecting to LTE network"); | ||
err = lte_lc_connect(); | ||
if (err) { | ||
LOG_ERR("Could not establish LTE connection, error (%d): %s", err, strerror(-err)); | ||
return err; | ||
} | ||
LOG_INF("LTE connection established"); | ||
|
||
LOG_INF("Connecting to Thingsboards"); | ||
err = thingsboard_init(NULL, &fw_id); | ||
if (err) { | ||
LOG_ERR("Could not initialize thingsboard connection, error (%d) :%s", err, | ||
strerror(-err)); | ||
return err; | ||
} | ||
} | ||
|
||
static void rpc_callback(const uint8_t *data, size_t len) | ||
{ | ||
LOG_HEXDUMP_INF(data, len, "RPC repsonse: "); | ||
} | ||
|
||
static int cmd_do_rpc(const struct shell *shell, size_t argc, char **argv) | ||
{ | ||
int err; | ||
|
||
const char *params = "{\"name\":\"gcx\"}"; | ||
err = thingsboard_rpc("hello", rpc_callback, params); | ||
if (err) { | ||
LOG_ERR("Could not send RPC, error (%d): %s", err, strerror(-err)); | ||
return err; | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
SHELL_CMD_REGISTER(rpc, NULL, "Send a RPC request", cmd_do_rpc); |