Skip to content

The Examples

The examples contains a set of user cases for using the Software Development Kit (SDK) 💼.

Before You Begin

A solid understanding about SDK 💼 is required to understand the examples.

Upload Example

For this example, we'll send the voltage and current data to the cloud, which can be accessed by the API as the fields voltage and current respectively. The connection string we have received contains the following information:

yaml
dashboard:
  url: https://example.dev
  collection: data
  access-token: RoBoT

We want to send the data 12.4 and 420 out to the cloud for the voltage and current respectively. To add the data, we can make use of the Add() method of the CloudJson object. To send the upload command, we can use the Upload() method provided by the same object. For this example, our main.c file could look something like the this:

c
/* Include the Cloud Module SDK. */
#include <cloudmodule.h>

/* Make sure the cloudmodule structure is declared. */
CloudModule cloudmodule = CloudModule();

/* Provide a custom interface to send a CANOpen or UART message. */
void SendCan(uint16_t index, uint8_t subindex, uint32_t data) {
  /* TODO by you. */
}

int main(void) {
  /* Initialise the Cloud Module. */
  const CloudJson *json = cloudmodule.InitCan(SendCan);

  /* Provide the connection string to the Cloud Module. */
  json->SetUrl("https://example.dev/items/data?access_token=RoBoT")

  /* Provide the data set to the Cloud Module. */
  json->Add("voltage", 12.4)
      ->Add("current", 420)
      ->Upload();
}

Change Values Example

For this example, we'll keep track of an incrementor increment for every minute that has passed. We can make use of the Change() method provided by the CloudJson object. For this example, our main.c file could look something like the this:

c
/* Include the Cloud Module SDK. */
#include <cloudmodule.h>

/* Make sure the cloudmodule structure is declared. */
CloudModule cloudmodule = CloudModule();

static uin32_t increment = 0;

/* Provide a custom interface to send a CANOpen or UART message. */
void SendCan(uint16_t index, uint8_t subindex, uint32_t data) {
  /* TODO by you. */
}

int main(void) {
  /* You can keep store a reference of a value to change it later. */
  uint16_t ref = 0;

  /* Initialise the Cloud Module. */
  const CloudJson *json = cloudmodule.InitCan(SendCan);

  /* Provide the connection string to the Cloud Module. */
  json->SetUrl("https://example.dev/items/data?access_token=RoBoT");

  /* Provide the data set to the Cloud Module. */
  json->Add("increment", increment, &ref);

  /* Send data to the cloud every five minutes. */
  while(true) {
    
    /* you can change a value by using the Change method. */
    json->Change(ref, ++increment);

    /* Finally, you can upload the data to cloud by calling the Upload method. */
    json->Upload();

    wait_sec(300);
  }
  return 0;
}

Classical C Example

For this example, we'll send the voltage and current data to the cloud, but this time it uses a set of functions instead of using the builder pattern. Your main.c file will look something like this:

c
/* Include the Cloud Module SDK. */
#include <cloudmodule.h>

/* Make sure the cloudmodule structure is declared. */
CloudModule cloudmodule = CloudModule();

/* Provide a custom interface to send a CANOpen or UART message. */
void SendCan(uint16_t index, uint8_t subindex, uint32_t data) {
  /* TODO by you. */
}

int main(void) {
  /* Initialise the Cloud Module. */
  CloudModule_InitCan(SendCan);


  /* Provide the connection string to the Cloud Module. */
  CloudModule_SetUrl("https://example.dev/items/data?access_token=RoBoT");

  /* Provide the data set to the Cloud Module. */
  CloudModule_AddFloat("voltage", 12,4, (Ref){});
  CloudModule_AddUnsigned("current", 420, (Ref){});
  
  /* Upload the data set to the cloud */
  CloudModule_Upload();
}