Ioto API
The Ioto library provides some utility routines and cloud helper functions.
Most of the Ioto API is provided by the following component libraries:
Extensions
Aws | AWS Support. |
Ioto | Ioto control structure. |
Functions
int | aws(Url *up, cchar *region, cchar *service, cchar *target, cchar *body, ssize bodyLen, cchar *headers, ...) |
Invoke an AWS API request. | |
int | awsPutFileToS3(cchar *region, cchar *bucket, cchar *key, cchar *filename) |
Put a file to AWS S3. | |
int | awsPutToS3(cchar *region, cchar *bucket, cchar *key, cchar *data, ssize dataLen) |
Put a data block to AWS S3. | |
char* | awsSign(cchar *region, cchar *service, cchar *target, cchar *method, cchar *path, cchar *query, cchar *body, ssize bodyLen, cchar *headers, ...) |
Create a set of signed headers to use with AWS SigV4 REST APIs. | |
int | ioConfig(Json *config) |
User config entry point. | |
cchar* | ioGetShadow(cchar *key, cchar *defaultValue) |
Get a value from the shadow state. | |
void | ioInit(cchar *profile) |
Initialize Ioto. | |
void | ioRestartWeb(void) |
Restart the web server. | |
void | ioSaveShadow(void) |
Save the shadow state immediately. | |
void | ioSetShadow(cchar *key, cchar *value, bool save) |
Set a key value in the shadow. | |
int | ioStart(void) |
User start entry point. | |
void | ioStop(void) |
User stop entry point. | |
void | ioTerm(void) |
Terminate Ioto. | |
ssize | webWriteItem(Web *web, const DbItem *item) |
Write a database item as part of a web response. | |
ssize | webWriteItems(Web *web, const DbGrid *items) |
Write a grid of database items as part of a web response. |
Typedefs
Defines
#define | IO_CERTIFICATE "ioto.crt" |
Name of the AWS thing certificate file. | |
#define | IO_CONFIG_FILE "ioto.json5" |
Primary Ioto config file. | |
#define | IO_DEVICE_FILE "config/device.json5" |
Name of the device identification config file. | |
#define | IO_KEY "ioto.key" |
Name of the AWS thing key file. | |
#define | IO_LOCAL_FILE "config/local.json5" |
Development overrides. | |
#define | IO_LOG_FILE "ioto.log" |
Name of the ioto log file. | |
#define | IO_LOG_GROUP "ioto" |
AWS log group name. | |
#define | IO_LOG_LINGER 5000 |
Delay before flushing log events to the cloud. | |
#define | IO_LOG_MAX_EVENTS 1000 |
Max log events to buffer. | |
#define | IO_LOG_MAX_SIZE 32767 |
Max size of log events to buffer. | |
#define | IO_LOG_STREAM "agent" |
AWS log stream name. | |
#define | IO_MAX_URL 256 |
Sanity length of a URL. | |
#define | IO_MESSAGE_SIZE 128 * 1024 * 1024 |
Maximum MQTT message size. | |
#define | IO_PROVISION_FILE "provision.json5" |
Name of the device provisioning config file. | |
#define | IO_SAVE_DELAY 5000 |
Delay before saving updated shadow state. | |
#define | IO_SHADOW_FILE "shadow.json5" |
Name of the persisted AWS shadow state file. | |
#define | IO_SIGNATURES_FILE "config/signatures.json5" |
Name of the optional REST API signatures file. | |
#define | IO_TEST_FILE "config/test.json5" |
Test suites. | |
#define | IO_WEB_FILE "config/web.json5" |
Name of the web server config file. |
Aws
Aws
AWS Support.
- Description:
- This is suite of AWS helper routines that implement AWS SigV4 signed REST API requests.
- API Stability:
- Evolving.
- See Also:
- aws, awsPutFileToS3, awsPutToS3, awsSign
- Fields:
-
int
aws
(Url *up, cchar *region, cchar *service, cchar *target, cchar *body, ssize bodyLen, cchar *headers, ...)
Invoke an AWS API request.
- Parameters:
-
up Url object allocated via urlAlloc. region AWS Region to target. service AWS Service name. E.g. "s3". target AWS Target name. If not supplied, this is deduced from the service name and the "x-amz-target" header. body Request body data. bodyLen Length of the request body. headers Format string containing HTTP headers. This format string can use printf embedded tokens that will be expanded to form the HTTP headers. The header format is of the form: "Key:Value\n..." with an extra new line at the end. ... Headers arguments.
- API Stability:
- Evolving.
- See Also:
- awsPutFileToS3, awsPutToS3, awsSign
Put a file to AWS S3.
- Parameters:
-
region AWS Region to target. bucket AWS S3 bucket name. key AWS S3 bucket key (filename). If set to null, the key is set to the filename. filename File name to put to S3.
- API Stability:
- Evolving.
- See Also:
- aws, awsPutToS3, awsSign
Put a data block to AWS S3.
- Parameters:
-
region AWS Region to target. bucket AWS S3 bucket name. key AWS S3 bucket key (filename). data Data block to write to S3. dataLen Length of the data block.
- API Stability:
- Evolving.
- See Also:
- aws, awsPutFileToS3, awsSign
char *
awsSign
(cchar *region, cchar *service, cchar *target, cchar *method, cchar *path, cchar *query, cchar *body, ssize bodyLen, cchar *headers, ...)
Create a set of signed headers to use with AWS SigV4 REST APIs.
- Description:
- The AWS SDK is big and relatively slow. If you only need a few AWS APIs, you can use the AWS REST APIs and avoid the AWS SDK. This routine processes HTTP request parameters to create a set of signed HTTP headers that can be used with the URL HTTP client.
- Parameters:
-
region AWS Region to target. service AWS Service name. E.g. "s3". target AWS Target name. If not supplied, this is deduced from the service name and the "x-amz-target" header. method HTTP method to utilize. path URL request path. query URL request query. body Request body data. bodyLen Length of the request body. headers Format string containing HTTP headers. This format string can use printf embedded tokens that will be expanded to form the HTTP headers. The header format is of the form: "Key:Value\n..." with an extra new line at the end. ... Headers arguments.
- Returns:
- The HTTP headers to use with a URL HTTP client request. Caller must free.
- API Stability:
- Evolving.
- See Also:
- aws, awsPutFileToS3, awsPutToS3
Ioto
Ioto
Ioto control structure.
- API Stability:
- Evolving.
- Fields:
-
cchar * accountId Owning manager accountId. cchar * api Device cloud API endpoint. cchar * apiToken Device cloud API authentication token. Json * auth Auth configuraiton. cchar * awsAccess AWS temp creds. Time awsExpires AWS cred expiry. cchar * awsRegion Default AWS region. cchar * awsSecret AWS cred secret. cchar * awsToken AWS cred token. cchar * builder Builder API endpoint. Json * config Configuration. cchar * configFile Path to the ioto.json5 config file. Db * db Structured state database. cchar * endpoint Device cloud API endpoint. int errors Enforce strict signature compliance. cchar * id Builder cloud claim token. Claim ID. char * instance Test iterations. EC2 instance. int iterations Network error count. bool keyService Manufacturing serialization. cchar * loadPath Database file to load. struct IotoLog * log Configuration max age of the sync log. Cloud Watch Log object. cchar * logDir Directory for Ioto log files. RList * logs Log file ingestion list. bool logService AWS IAM key generation. ssize maxSyncSize Limit of buffered database changes. Mqtt * mqtt Mqtt object. bool mqttService Log file ingest to CloudWatch logs. bool nolocal MQTT service. bool nosave Do not use local.json. cchar * productToken Product token. cchar * profile Run profile. Defaults to ioto.json5:profile. bool provisionService Do not save. i.e. run in-memory. bool registered Web server. bool registerService Cloud provisioning service. RList * rr Outstanding MQTT request / response list. bool serializeService Embedded database service. Json * shadow Shadow state. cchar * shadowName AWS IoT shadow name. bool shadowService Device registration service. char * shadowTopic AWS IoT shadow topic. bool shortInit AWS IoT core shadows. Json * signatures Web Rest API signatures. cchar * stateDir Directory for state files. bool strictSignatures Device has been registered. Ticks syncDelay Delay to flush database changes to the cloud. Ticks syncDue When due to emit sync changes. REvent syncEvent Schedule synchronization event. RHash * syncHash Hash of database change records. FILE * syncLog Sync log file descriptor. bool syncService Short initialization for command line commands. ssize syncSize Size of buffered database changes. Json * template Properties for templates. cchar * thing Device Thing Name (same as claim ID). cchar * version Your software version number (not Ioto version). WebHost * webHost Web server host. bool webService Sync device state to AWS.
int
ioConfig
(Json *config)
User config entry point.
- Description:
- The ioConfig function is invoked when Ioto has read its configuration into ioto->config and before Ioto initializes services. Users can provide their own ioConfig function and link with the Ioto library. Ioto will then invoke the user's ioConfig for custom configuratoiun.
- API Stability:
- Evolving.
Get a value from the shadow state.
- Parameters:
-
key Property key value. May contain dots. defaultValue Default value to return if the key is not found.
- API Stability:
- Evolving.
- See Also:
void
ioInit
(cchar *profile)
Initialize Ioto.
- Parameters:
-
profile Configuration profile. Defaults to "prod".
- API Stability:
- Evolving.
- See Also:
void
ioRestartWeb
(void )
Restart the web server.
- API Stability:
- Evolving.
- See Also:
void
ioSaveShadow
(void )
Save the shadow state immediately.
- API Stability:
- Evolving.
- See Also:
Set a key value in the shadow.
- Parameters:
-
key Property key value. May contain dots. value Value to set. save Set to true to persist immediately.
- API Stability:
- Evolving.
- See Also:
int
ioStart
(void )
User start entry point.
- Description:
- The ioStart function is invoked when Ioto is fully initialized and ready to start. Users can provide their own ioStart and ioStop functions and link with the Ioto library. Ioto will then invoke the user's ioStart for custom initialization.
- API Stability:
- Evolving.
void
ioStop
(void )
void
ioTerm
(void )
Terminate Ioto.
- API Stability:
- Evolving.
- See Also:
Write a database item as part of a web response.
- Description:
- This routine serialize a database item into JSON and write it as a response.
- Parameters:
-
web Web object. item Database item.
- Returns:
- The number of bytes written.
- API Stability:
- Evolving.
- See Also:
Write a grid of database items as part of a web response.
- Description:
- This routine serializes a database grid into JSON and write it as a response.
- Parameters:
-
web Web object. items Grid of database items.
- Returns:
- The number of bytes written.
- API Stability:
- Evolving.
- See Also: