A “Hello World” Application Using OS-IoT for Linux

The follow C++ code uses the OS-IoT API to get a CSE-Base resource from a CSE. This is about the simplest possible use of OS-IoT. You can link this program to the OS-IoT library following the build instructions.

// test.cxx

#include <iostream>
#include "onem2m.hxx"

int main (int argc, char* argv[]) {

::onem2m::initialize();

// For Eclipse OM2M - modify for your CSE
 ::onem2m::setHostName("127.0.0.1:8080");
 ::std::string cse_root_addr = "/in-cse/in-name"; // SP-Relative address
 ::onem2m::setFrom("admin:admin");

long result;
 ::xml_schema::integer respObjType;
 std::unique_ptr< ::xml_schema::type > respObj;


// *** Retrieve a resource ***
 respObj = ::onem2m::retrieveResource(cse_root_addr, "1234", result, respObjType);
 std::cout << "Retrieve result:" << result << "\n";
 std::cout << "Obj Type#:" << respObjType << "\n";

::onem2m::terminate();

}

For more information on the API see the documentation page.