Embedding the Ioto Agent
The Ioto agent is provided as library with a stand-alone command line program.
The Ioto agent can be embedded two ways:
- Use your own main and code and link with the Ioto library.
- Use the Ioto main and provide ioStart and ioStop functions that link to your code.
If you need to embed Ioto in your own main program, you will chose option (1). If you are running on a generic Linux system, you may find option (2) attractive.
Embed in Your Main Program
The first way to integrate Ioto with your code is to create your own main program and link with the Ioto library. This method is desirable if you are using an RTOS like FreeRTOS and need to integrate Ioto into your main program.
To embed Ioto into your main program, you need to do the following things:
- Add #include "ioto.h" to the relevant source files.
- Provide a main().
- Invoke ioStartRuntime and ioRun from your main().
- Build your app and references the libioto.a library.
- Create or edit the Ioto ioto.json5 configuration file and other Ioto config files to suit your needs.
The following code demonstrates providing your own main().
If this source is contained in a file called main.c, you can build this sample and link with the Ioto library and the OpenSSL library:
Use the Ioto Command Program
The second way to integrate Ioto is to use the Ioto main program and provide your own ioStart and ioStop functions. These functions are invoked by Ioto during startup and shutdown.
To build with your start/stop functions you need to do the following things:
- Add #include "ioto.h" to the relevant source files.
- Provide ioStart and ioStop functions.
- Add the libioto.a library to the build/link target in your Makefile.
- Build your application.
- Create or edit the Ioto ioto.json5 and other Ioto config files to suit your needs.
Embedding API
The following code demonstrates the Ioto embedding API.
If this source is contained in a file called main.c, you can build this sample and link with the Ioto library:
If you are building on Mac OS, you will need to install openssl and provide a -L /opt/homebrew/lib library directory option.
Samples
The link-agent-main sample demonstrates linking with the Ioto library.
The own-main sample demonstrates linking with your own main.
More Details
For more details about the Ioto API, please consult the Ioto APIs.