GETTING STARTED

Set up your Raspberry Pi:

If you are new to Raspberry Pi then we recommend you to follow Raspberry Pi’s step by step Quick Start guide to set up your board first.

Once your board is up and running, it is recommended to update your Pi by running the following command from its terminal:

sudo apt-get update

App42 SDK uses cURL internally to make https requests to the server, so before moving ahead we should install cURL first by running the following command from Pi’s terminal:

apt-get install libcurl4-openssl-dev
Download and Integrate the App42 SDK:

Download the App42 Cloud SDK from our github repo, unzip the downloaded file. You can either download directly from the given link or you can run the following command from Pi’s terminal:

wget https://github.com/shephertz/App42_IoT_SDK

//To unzip the downloaded file

unzip master.zip

We have kept the SDK as open source to make the integration straight forward and even you can contribute to improve it.
Copy and paste the App42 folder to your project folder. Define the paths for source files in your makefile as follows:

program_C_SRCS += $(wildcard App42/App42HTTP/*.cpp) 
program_C_SRCS += $(wildcard App42/cJSON/*.cpp) 
program_C_SRCS += $(wildcard App42/Common/*.cpp) 
program_C_SRCS += $(wildcard App42/Crypto/*.cpp) 
program_C_SRCS += $(wildcard App42/Util/*.cpp) 
program_C_SRCS += $(wildcard App42/PushNotificationService/*.cpp) 
program_C_SRCS += $(wildcard App42/EventService/*.cpp) 
program_C_SRCS += $(wildcard App42/StorageService/*.cpp)

Note: You may have to add path parameters before App42 depending on App42 folder location.

Now add include paths as follows:

program_INCLUDE_DIRS := App42/App42HTTP 
program_INCLUDE_DIRS += App42/cJSON 
program_INCLUDE_DIRS += App42/Common 
program_INCLUDE_DIRS += App42/Crypto 
program_INCLUDE_DIRS += App42/Util 
program_INCLUDE_DIRS += App42/PushNotificationService 
program_INCLUDE_DIRS += App42/EventService 
program_INCLUDE_DIRS += App42/StorageService

As App42_IoT_SDK uses cURL so you also need to add curl in makefile as follows:

program_LIBRARIES := curl

Also add CPPFLAGS which is needed to compile App42 SDK as follows:

CPPFLAGS := -frtti -std=c++11 -fsigned-char -fexceptions

Now you can go ahead and run make command from your Pi’s terminal to build your project. You can also check out our Blink LED sample for reference.

Register to App42 Platform and Create App:

Here are the steps you need to follow in order to get started with the App42 platform

  • Register with the App42 platform.
  • Create an App once you are on quick start page
  • If you are already registered, login to the AppHQ console and create an App from the App Manager > Create App link
  • Once the App is created, you will get an API_KEY / SECRET_KEY that you will use in your app for initialization of the SDK
Initialize the App42 SDK

To start using the App42 Cloud APIs, the App42 SDK must be included and initialized using API_KEY and SECRET_KEY as follows:

Include App42API:

#include "App42API.h"

Initialize App42API:

App42API::Initialize("Your_Api_Key","Your_Secret_Key");
Using App42 Service:

After initializing the SDK, you have to build the target service that you want to use in your App. For example, to save data on the cloud you have to build Storage Service and then call the InsertJsonDocument API as follows:

//Building Storage service instance
StorageService *storageService = App42API::BuildStorageService();
const char* dbName = "Your_DB_Name";
const char* collectionName = "Your_Collection_Name";
const char* jsonDoc ="{\"name\":\"Nick\",\"age\":30,\"phone\":\"xxx-xxx-xxx\"}";
SampleClass *sampleClassInstance = new SampleClass();

//Calling to send data on App42 Cloud
storageService->InsertJsonDocument(dbName, collectionName,jsonDoc, app42callback(SampleClass::onStorageRequestCompleted, sampleClassInstance));

//Callback in which you will get the response of insertJsonDocument
void SampleClass::onStorageRequestCompleted(void *response)
{
    App42StorageResponse *storageResponse = (App42StorageResponse*)response;
    printf("\ncode=%d",storageResponse->getCode());
    printf("\nResponse Body=%s",storageResponse->getBody().c_str());
    
    if (storageResponse->isSuccess)
    {
           printf("\nTotalRecords=%d",storageResponse->getTotalRecords());
           for(std::vector::iterator it = storageResponse->storages.begin(); it != storageResponse->storages.end(); ++it)
           {
                printf("\n DbName=%s",it->dbName.c_str());
                printf("\n CollectionName=%s",it->collectionName.c_str());
                printf("\n RecordCount=%lf\n",it->recordCount);
            }
    }
    else
    {
            printf("\nerrordetails:%s",storageResponse->errorDetails.c_str());
            printf("\nerrorMessage:%s",storageResponse->errorMessage.c_str());
            printf("\nappErrorCode:%d",storageResponse->appErrorCode);
            printf("\nhttpErrorCode:%d",storageResponse->httpErrorCode);
    }
}

Note: Make sure the class where callback is defined must inherit App42CallBack class from the SDK. For example, in the above code snippet, the callback onStorageRequestCompleted is defined in SampleClass, therefore it must inherit App42CallBack class as follows:

  class SampleClass : public App42CallBack
{
public:
    void onStorageRequestCompleted( void *response);
};
Start Implementing Now