Skip to content

Building in Raspberry Pi or Linux

as-iotex edited this page Nov 10, 2021 · 3 revisions

Cloning the repository

git clone https://github.com/as-iotex/iotex-arduino
cd iotex-arduino

Building the library

Requires Cmake 3.1.0 or higher

mkdir build && cd build
cmake ..
make

If successful, build files are placed in the build directory

Building and running the unit tests

Building the unit tests

mkdir build && cd build
cmake -DUNIT_TEST=ON ..
make

Unit tests build files are placed in build/tests

Running the unit tests

cd build
./tests/iotex_unit_tests

Using the library in your application

Include the IoTeX-Client main header in your program:

#include <IoTeXClient.h>

Create the Connection object, passing the connection details:

const char ip[] = "gateway.iotexlab.io";
const char baseUrl[] = "iotexapi.APIService";
const int port = 10000;
Connection<Api> connection(ip, port, baseUrl);

You can find examples of most of the library methods under the examples directory

Debug logs

Debug logs are disabled by default. Follow the instructions below to enable them

Setting debug log level at compile time

This can be done by setting the LOG_LEVEL cmake variable before building. Eg:

cmake -DUNIT_TEST=ON -DLOG_LEVEL=DEBUG ..

The possible values for LOG_LEVEL are:

  • NONE (default)
  • ERROR
  • WARNING
  • INFO
  • DEBUG
  • TRACE

Setting debug log level at run time

The log level can also be set at runtime using the IotexHelpers global object

Setting per module log level

You can set the log level for a specific module. The existent log modules are:

  • "GENERAL"
  • "HTTP"
  • "CONTRACT"

Simply call the following method on the IotexHelpers global object:
void setModuleLogLevel(const std::string& module, IotexLogLevel level)

Eg. This will set the HTTP log level to DEBUG:
IotexHelpers.setModuleLogLevel("HTTP", IotexLogLevel::DEBUG);

Setting the log level globally

You can also set the log level globally for all modules.

Simply call the following method on the IotexHelpers global object:
void setGlobalLogLevel(IotexLogLevel level)

Eg. This will set the log level globally to DEBUG:
IotexHelpers.setGlobalLogLevel(IotexLogLevel::DEBUG);