WisBlock Goes Blues.

RAKWireless RAKstar Blues

This library covers the communication between a RAKwireless WisCore module↗️ and a Blues.IO Notecard↗️ over I2C.

Blues offers a library with a wide functionality for the communication between a MCU and the Notecard, supporting different communication methods.

I decided to write a lightweight library just for the RAK13102 WisBlock Notecarrier IO module with the following differences:


Installation

The library is available in the Arduino library manager and in the PlatformIO library registry.

In the Arduino IDE the installation is done through the Arduino Library Manager using the keyword blues-minimal-i2c.

In PlatformIO the installation is done by adding

lib_deps = 
    beegee-tokyo/Blues-Minimal-I2C

in the platformio.ini file.


API calls

The API calls are split into 3 categories:


Initialization and execution


RAK_BLUES(byte addr)

Construct a new RAK_BLUES instance.

Example

#include <Arduino.h>
#include <blues-minimal-i2c.h>
// I2C functions for Blues NoteCard
RAK_BLUES rak_blues;

void setup()
{
    if (rak_blues.start_req((char *)"hub.set"))
    {
        if (rak_blues.send_req())
        {
            request_success = true;
            break;
        }
    }
}

void loop()
{
}

bool start_req(char * request)

Create a request structure to be sent to the NoteCard.

Parameters

Returns

true if request could be created

Returns

false if request could not be created

Example

#include <Arduino.h>
#include <blues-minimal-i2c.h>
// I2C functions for Blues NoteCard
RAK_BLUES rak_blues;

void setup()
{
    if (rak_blues.start_req((char *)"hub.set"))
    {
        if (rak_blues.send_req())
        {
            request_success = true;
            break;
        }
    }
}

void loop()
{
}

bool send_req(char * response,uint16_t resp_len)

Send a completed request to the NoteCard.

Parameters

Returns

true if request could be sent and the response does not have "err"

Returns

false if request could not be sent or the response did have "err"

Example

#include <Arduino.h>
#include <blues-minimal-i2c.h>
// I2C functions for Blues NoteCard
RAK_BLUES rak_blues;

void setup()
{
    if (rak_blues.start_req((char *)"hub.set"))
    {
        if (rak_blues.send_req())
        {
            request_success = true;
            break;
        }
    }
}

void loop()
{
}

Set request JSON object


void add_string_entry(char type,char value)

Add C-String entry to request.

Parameters

Example

#include <Arduino.h>
#include <blues-minimal-i2c.h>
// I2C functions for Blues NoteCard
RAK_BLUES rak_blues;

void setup()
{
    if (rak_blues.start_req((char *)"hub.set"))
    {
        rak_blues.add_string_entry((char *)"mode", (char *)"continuous");
        if (rak_blues.send_req())
        {
            request_success = true;
            break;
        }
    }
}

void loop()
{
}

void add_bool_entry(char * type,bool value)

Add boolean entry to request.

Parameters

Example

#include <Arduino.h>
#include <blues-minimal-i2c.h>
// I2C functions for Blues NoteCard
RAK_BLUES rak_blues;

void setup()
{
    if (rak_blues.start_req((char *)"card.motion.mode"))
    {
        rak_blues.add_bool_entry((char *)"start", true);
        if (rak_blues.send_req())
        {
            request_success = true;
            break;
        }
    }
}

void loop()
{
}

void add_int32_entry(char * type,int32_t value)

Add integer entry to request.

Parameters

Example

#include <Arduino.h>
#include <blues-minimal-i2c.h>
// I2C functions for Blues NoteCard
RAK_BLUES rak_blues;

void setup()
{
    if (rak_blues.start_req((char *)"card.motion.mode"))
    {
        rak_blues.add_int32_entry((char *)"sensitivity", 1);

        if (rak_blues.send_req())
        {
            request_success = true;
            break;
        }
    }
}

void loop()
{
}

void add_uint32_entry(char * type,uint32_t value)

Add unsigned integer entry to request.

Parameters

Example

#include <Arduino.h>
#include <blues-minimal-i2c.h>
// I2C functions for Blues NoteCard
RAK_BLUES rak_blues;

void setup()
{
    if (rak_blues.start_req((char *)"card.motion.mode"))
    {
        rak_blues.add_uint32_entry((char *)"sensitivity", 1);

        if (rak_blues.send_req())
        {
            request_success = true;
            break;
        }
    }
}

void loop()
{
}

void add_float_entry(char * type,float value)

Add float entry to request.

Parameters

Example

#include <Arduino.h>
#include <blues-minimal-i2c.h>
// I2C functions for Blues NoteCard
RAK_BLUES rak_blues;

void setup()
{
    if (rak_blues.start_req((char *)"card.motion.mode"))
    {
        rak_blues.add_float_entry((char *)"sensitivity", 324.56);

        if (rak_blues.send_req())
        {
            request_success = true;
            break;
        }
    }
}

void loop()
{
}

void add_nested_string_entry(char type,char nested,char * value)

Add nested C-String entry to request.

Parameters

Example

#include <Arduino.h>
#include <blues-minimal-i2c.h>
// I2C functions for Blues NoteCard
RAK_BLUES rak_blues;

 void setup()
 {
    if (rak_blues.start_req((char *)"note.add"))
    {
        char node_id[24];
        sprintf(node_id, "%02x%02x%02x%02x%02x%02x%02x%02x",
            g_lorawan_settings.node_device_eui[0], g_lorawan_settings.node_device_eui[1],
            g_lorawan_settings.node_device_eui[2], g_lorawan_settings.node_device_eui[3],
            g_lorawan_settings.node_device_eui[4], g_lorawan_settings.node_device_eui[5],
            g_lorawan_settings.node_device_eui[6], g_lorawan_settings.node_device_eui[7]);
        rak_blues.add_nested_string_entry((char *)"body", (char *)"dev_eui", node_id);

        if (!rak_blues.send_req())
        {
            return false;
        }
        return true;
    }
 }

void loop()
{
}

void add_nested_int32_entry(char type,char nested,int32_t value)

Add nested integer entry to request.

Parameters

Example

#include <Arduino.h>
#include <blues-minimal-i2c.h>
// I2C functions for Blues NoteCard
RAK_BLUES rak_blues;

 void setup()
 {
    if (rak_blues.start_req((char *)"note.add"))
    {
        rak_blues.add_nested_int32_entry((char *)"body", (char *)"number", -65534);

        if (!rak_blues.send_req())
        {
            return false;
        }
        return true;
    }
 }

void loop()
{
}

void add_nested_uint32_entry(char type,char nested,uint32_t value)

Add nested unsigned integer entry to request.

Parameters

Example

#include <Arduino.h>
#include <blues-minimal-i2c.h>
// I2C functions for Blues NoteCard
RAK_BLUES rak_blues;

 void setup()
 {
    if (rak_blues.start_req((char *)"note.add"))
    {
        rak_blues.add_nested_uint32_entry((char *)"body", (char *)"number", 65534);

        if (!rak_blues.send_req())
        {
            return false;
        }
        return true;
    }
 }

void loop()
{
}

void add_nested_bool_entry(char type,char nested,bool value)

Add nested bool entry to request.

Parameters

Example

#include <Arduino.h>
#include <blues-minimal-i2c.h>
// I2C functions for Blues NoteCard
RAK_BLUES rak_blues;

 void setup()
 {
    if (rak_blues.start_req((char *)"note.add"))
    {
        rak_blues.add_nested_bool_entry((char *)"body", (char *)"valid", false);

        if (!rak_blues.send_req())
        {
            return false;
        }
        return true;
    }
 }

void loop()
{
}

void add_nested_float_entry(char type,char nested,float value)

Add nested float entry to request.

Parameters

Example

#include <Arduino.h>
#include <blues-minimal-i2c.h>
// I2C functions for Blues NoteCard
RAK_BLUES rak_blues;

 void setup()
 {
    if (rak_blues.start_req((char *)"note.add"))
    {
        rak_blues.add_nested_float_entry((char *)"body", (char *)"temperature", 32.8);

        if (!rak_blues.send_req())
        {
            return false;
        }
        return true;
    }
 }

void loop()
{
}

void add_2lv_nested_string_entry(char type,char nested,char nested2,char value)

Add 2 level nested C-String entry to request

Parameters

Example

#include <Arduino.h>
#include <blues-minimal-i2c.h>
// I2C functions for Blues NoteCard
RAK_BLUES rak_blues;

 void setup()
 {
    if (rak_blues.start_req((char *)"note.add"))
    {
        char node_id[24];
        sprintf(node_id, "%02x%02x%02x%02x%02x%02x%02x%02x",
            g_lorawan_settings.node_device_eui[0], g_lorawan_settings.node_device_eui[1],
            g_lorawan_settings.node_device_eui[2], g_lorawan_settings.node_device_eui[3],
            g_lorawan_settings.node_device_eui[4], g_lorawan_settings.node_device_eui[5],
            g_lorawan_settings.node_device_eui[6], g_lorawan_settings.node_device_eui[7]);
        rak_blues.add_nested_string_entry((char *)"body", (char *)"sens1", (char *)"dev_eui", node_id);

        if (!rak_blues.send_req())
        {
            return false;
        }
        return true;
    }
 }

void loop()
{
}

void add_2lv_nested_int32_entry(char type,char nested,char * nested2,int32_t value)

Add 2 level nested integer entry to request

Parameters

Example

#include <Arduino.h>
#include <blues-minimal-i2c.h>
// I2C functions for Blues NoteCard
RAK_BLUES rak_blues;

 void setup()
 {
    if (rak_blues.start_req((char *)"note.add"))
    {
        rak_blues.add_nested_int32_entry((char *)"body", (char *)"sens1", (char *)"number", -65534);

        if (!rak_blues.send_req())
        {
            return false;
        }
        return true;
    }
 }

void loop()
{
}

void add_2lv_nested_uint32_entry(char type,char nested,char * nested2,uint32_t value)

Add nested unsigned integer entry to request.

Parameters

Example

#include <Arduino.h>
#include <blues-minimal-i2c.h>
// I2C functions for Blues NoteCard
RAK_BLUES rak_blues;

 void setup()
 {
    if (rak_blues.start_req((char *)"note.add"))
    {
        rak_blues.add_nested_uint32_entry((char *)"body", (char *)"sens1", (char *)"number", 65534);

        if (!rak_blues.send_req())
        {
            return false;
        }
        return true;
    }
 }

void loop()
{
}

void add_2lv_nested_string_entry(char type,char nested,char * nested2,bool value)

Add 2 level nested bool entry to request

Parameters

Example

#include <Arduino.h>
#include <blues-minimal-i2c.h>
// I2C functions for Blues NoteCard
RAK_BLUES rak_blues;

 void setup()
 {
    if (rak_blues.start_req((char *)"note.add"))
    {
        rak_blues.add_nested_bool_entry((char *)"body", (char *)"sens1", (char *)"valid", false);

        if (!rak_blues.send_req())
        {
            return false;
        }
        return true;
    }
 }

void loop()
{
}

bool get_2lv_nested_string_entry(char type,char nested,char nested2,char value,uint16_t value_size)

Get 2nd level nested string entry (char array) from the response

Parameters

Returns

true if entry was found

Returns

false if entry was not found

Example

#include <Arduino.h>
#include <blues-minimal-i2c.h>
// I2C functions for Blues NoteCard
RAK_BLUES rak_blues;

char str_value[128];

void setup()
{
    if (rak_blues.start_req((char *)"card.location"))
    {
        if (!rak_blues.send_req())
        {
            return false;
        }
        if (rak_blues.has_nested_entry((char *)"status",(char *)"sens_1"))
        {
            rak_blues.get_2lv_nested_string_entry((char *)"status",(char *)"sens_1",(char *)"error", str_value, 128);
        }
        return true;
    }
}

  void loop()
  {
  }

bool get_2lv_nested_int32_entry(char type,char nested,char * nested2,int32_t & value)

Get 2nd level nested signed 32bit integer entry from the response

Parameters

Returns

true if entry was found

Returns

false if entry was not found

Example

#include <Arduino.h>
#include <blues-minimal-i2c.h>
// I2C functions for Blues NoteCard
RAK_BLUES rak_blues;

int32_t value;

void setup()
{
    if (rak_blues.start_req((char *)"card.location"))
    {
        if (!rak_blues.send_req())
        {
            return false;
        }
        if (rak_blues.has_nested_entry((char *)"status",(char *)"sens_1"))
        {
            rak_blues.get_nested_int32_entry((char *)"status",(char *)"sens_1",(char *)"value", value);
        }
        return true;
    }
}

  void loop()
  {
  }

bool get_2lv_nested_uint32_entry(char type,char nested,char * nested2,uint32_t & value)

Get 2nd level nested unsigned 32bit integer entry from the response

Parameters

Returns

true if entry was found

Returns

false if entry was not found

Example

#include <Arduino.h>
#include <blues-minimal-i2c.h>
// I2C functions for Blues NoteCard
RAK_BLUES rak_blues;

 uint32_t value;

 void setup()
 {
    if (rak_blues.start_req((char *)"card.location"))
    {
        if (!rak_blues.send_req())
        {
            return false;
        }
        if (rak_blues.has_nested_entry((char *)"status",(char *)"sens_1"))
        {
            rak_blues.get_2lv_nested_uint32_entry((char *)"status", (char *)"sens1", (char *)"value", value);
        }
        return true;
    }
 }

void loop()
{
}

bool get_2lv_nested_bool_entry(char type,char nested,char * nested2,bool & value)

Get nested bool entry from the response.

Parameters

Returns

true if entry was found

Returns

false if entry was not found

Example

#include <Arduino.h>
#include <blues-minimal-i2c.h>
// I2C functions for Blues NoteCard
RAK_BLUES rak_blues;

bool value;

void setup()
{
    if (rak_blues.start_req((char *)"card.location"))
    {
        if (!rak_blues.send_req())
        {
            return false;
        }
        if (rak_blues.has_nested_entry((char *)"status",(char *)"sens_1"))
        {
            rak_blues.get_2lv_nested_bool_entry((char *)"status",(char *)"sens_1"),(char *)"value"), value);
        }
        return true;
    }
}

void loop()
{
}

void add_2lv_nested_float_entry(char type,char nested,char * nested2,float value)

Add nested float entry to request.

Parameters

Example

#include <Arduino.h>
#include <blues-minimal-i2c.h>
// I2C functions for Blues NoteCard
RAK_BLUES rak_blues;

 void setup()
 {
    if (rak_blues.start_req((char *)"note.add"))
    {
        rak_blues.add_nested_float_entry((char *)"body", (char *)"sens1", (char *)"temperature", 32.8);

        if (!rak_blues.send_req())
        {
            return false;
        }
        return true;
    }
 }

void loop()
{
}

Parse response JSON object


bool has_entry(char * type)

Check if the response has a specific entry.

Parameters

Returns

true if entry was found

Returns

false if entry was not found

Example

#include <Arduino.h>
#include <blues-minimal-i2c.h>
// I2C functions for Blues NoteCard
RAK_BLUES rak_blues;

 char str_value[128];

 void setup()
 {
    if (rak_blues.start_req((char *)"card.location"))
    {
        if (!rak_blues.send_req())
        {
            return false;
        }
        if (rak_blues.has_entry((char *)"status"))
        {
            rak_blues.get_string_entry((char *)"status", str_value, 128);
        }
        return true;
    }
 }

void loop()
{
}

bool has_nested_entry(char type,char nested)

Check if the response has a specific nested entry.

Parameters

Returns

true if entry was found

Returns

false if entry was not found

Example

#include <Arduino.h>
#include <blues-minimal-i2c.h>
// I2C functions for Blues NoteCard
RAK_BLUES rak_blues;

 char str_value[128];

 void setup()
 {
    if (rak_blues.start_req((char *)"card.location"))
    {
        if (!rak_blues.send_req())
        {
            return false;
        }
        if (rak_blues.has_nested_entry((char *)"status"), (char *)"error"))
        {
            rak_blues.get_nested_string_entry((char *)"status", (char *)"error"), str_value, 128);
        }
        return true;
    }
 }

void loop()
{
}

bool get_string_entry(char type,char value,uint16_t value_size)

Get string entry (char array) from the response.

Parameters

Returns

true if entry was found

Returns

false if entry was not found

Example

#include <Arduino.h>
#include <blues-minimal-i2c.h>
// I2C functions for Blues NoteCard
RAK_BLUES rak_blues;

 char str_value[128];

 void setup()
 {
    if (rak_blues.start_req((char *)"card.location"))
    {
        if (!rak_blues.send_req())
        {
            return false;
        }
        if (rak_blues.has_entry((char *)"status"))
        {
            rak_blues.get_string_entry((char *)"status", str_value, 128);
        }
        return true;
    }
 }

void loop()
{
}

bool get_string_entry_from_array(char type,char value,uint16_t value_size)

Get string entry (char array) from response when in an array.

Parameters

Returns

true if entry was found

Returns

false if entry was not found

Example

#include <Arduino.h>
#include <[blues-minimal-i2c.h](#blues-minimal-i2c_8h)>
// I2C functions for Blues NoteCard
RAK_BLUES rak_blues;

 char str_value[128];

 // {"files":["motion"],"set":true}

 void setup()
 {
    if (rak_blues.start_req((char *)"card.attn"))
    {
        if (!rak_blues.send_req())
        {
            return false;
        }
        if (rak_blues.has_entry((char *)"files"))
        {
            rak_blues.get_string_entry((char *)"files", str_value, 128);
        }
        return true;
    }
 }

void loop()
{
}

bool get_bool_entry(char * type,bool & value)

Get bool entry from the response.

Parameters

Returns

true if entry was found

Returns

false if entry was not found

Example

#include <Arduino.h>
#include <blues-minimal-i2c.h>
// I2C functions for Blues NoteCard
RAK_BLUES rak_blues;

 bool result;

 void setup()
 {
    if (rak_blues.start_req((char *)"card.location"))
    {
        if (!rak_blues.send_req())
        {
            return false;
        }
        if (rak_blues.has_entry((char *)"status"))
        {
            rak_blues.get_bool_entry((char *)"status", result);
        }
        return true;
    }
 }

void loop()
{
}

bool get_int32_entry(char * type,int32_t & value)

Get signed 32bit integer entry from the response.

Parameters

Returns

true if entry was found

Returns

false if entry was not found

Example

#include <Arduino.h>
#include <blues-minimal-i2c.h>
// I2C functions for Blues NoteCard
RAK_BLUES rak_blues;

 int32_t value;

 void setup()
 {
    if (rak_blues.start_req((char *)"card.location"))
    {
        if (!rak_blues.send_req())
        {
            return false;
        }
        if (rak_blues.has_entry((char *)"status"))
        {
            rak_blues.get_int32_entry((char *)"status", value);
        }
        return true;
    }
 }

void loop()
{
}

bool get_uint32_entry(char * type,uint32_t & value)

Get unsigned 32bit integer entry from the response.

Parameters

Returns

true if entry was found

Returns

false if entry was not found

Example

#include <Arduino.h>
#include <blues-minimal-i2c.h>
// I2C functions for Blues NoteCard
RAK_BLUES rak_blues;

 uint32_t value;

 void setup()
 {
    if (rak_blues.start_req((char *)"card.location"))
    {
        if (!rak_blues.send_req())
        {
            return false;
        }
        if (rak_blues.has_entry((char *)"status"))
        {
            rak_blues.get_uint32_entry((char *)"status", value);
        }
        return true;
    }
 }

void loop()
{
}

bool get_float_entry(char * type,float & value)

Get float entry from the response.

Parameters

Returns

true if entry was found

Returns

false if entry was not found

Example

#include <Arduino.h>
#include <blues-minimal-i2c.h>
// I2C functions for Blues NoteCard
RAK_BLUES rak_blues;

 float blues_latitude;

 void setup()
 {
    if (rak_blues.start_req((char *)"card.location"))
    {
        if (!rak_blues.send_req())
        {
            return false;
        }
        if (rak_blues.has_entry((char *)"lat"))
        {
            rak_blues.get_float_entry((char *)"lat", blues_latitude);
        }
        return true;
    }
 }

void loop()
{
}

bool get_nested_string_entry(char type,char nested,char * value,uint16_t value_size)

Get nested string entry (char array) from the response.

Parameters

Returns

true if entry was found

Returns

false if entry was not found

Example

#include <Arduino.h>
#include <blues-minimal-i2c.h>
// I2C functions for Blues NoteCard
RAK_BLUES rak_blues;

 char str_value[128];

 void setup()
 {
    if (rak_blues.start_req((char *)"card.location"))
    {
        if (!rak_blues.send_req())
        {
            return false;
        }
        if (rak_blues.has_nested_entry((char *)"status"),(char *)"error"))
        {
            rak_blues.get_nested_string_entry((char *)"status"),(char *)"error"), str_value, 128);
        }
        return true;
    }
 }

void loop()
{
}

bool get_nested_int32_entry(char type,char nested,int32_t & value)

Get nested signed 32bit integer entry from the response.

Parameters

Returns

true if entry was found

Returns

false if entry was not found

Example

#include <Arduino.h>
#include <blues-minimal-i2c.h>
// I2C functions for Blues NoteCard
RAK_BLUES rak_blues;

 int32_t value;

 void setup()
 {
    if (rak_blues.start_req((char *)"card.location"))
    {
        if (!rak_blues.send_req())
        {
            return false;
        }
        if (rak_blues.has_nested_entry((char *)"status"),(char *)"value"))
        {
            rak_blues.get_nested_int32_entry((char *)"status"),(char *)"value"), value);
        }
        return true;
    }
 }

void loop()
{
}

bool get_nested_uint32_entry(char type,char nested,uint32_t & value)

Get nested unsigned 32bit integer entry from the response.

Parameters

Returns

true if entry was found

Returns

false if entry was not found

Example

#include <Arduino.h>
#include <blues-minimal-i2c.h>
// I2C functions for Blues NoteCard
RAK_BLUES rak_blues;

 uint32_t value;

 void setup()
 {
    if (rak_blues.start_req((char *)"card.location"))
    {
        if (!rak_blues.send_req())
        {
            return false;
        }
        if (rak_blues.has_nested_entry((char *)"status"),(char *)"value"))
        {
            rak_blues.get_nested_uint32_entry((char *)"status"),(char *)"value"), value);
        }
        return true;
    }
 }

void loop()
{
}

bool get_nested_bool_entry(char type,char nested,bool & value)

Get nested bool entry from the response.

Parameters

Returns

true if entry was found

Returns

false if entry was not found

Example

#include <Arduino.h>
#include <blues-minimal-i2c.h>
// I2C functions for Blues NoteCard
RAK_BLUES rak_blues;

 bool value;

 void setup()
 {
    if (rak_blues.start_req((char *)"card.location"))
    {
        if (!rak_blues.send_req())
        {
            return false;
        }
        if (rak_blues.has_nested_entry((char *)"status"),(char *)"value"))
        {
            rak_blues.get_nested_bool_entry((char *)"status"),(char *)"value"), value);
        }
        return true;
    }
 }

void loop()
{
}

int myJB64Encode(char encoded,const char string,int len)

Encode a char buffer to Base64.

Parameters

Returns

int length of encoded string

Example

#include <Arduino.h>
#include <blues-minimal-i2c.h>
// I2C functions for Blues NoteCard
RAK_BLUES rak_blues;

 char data[] = {0x00, 0x01, 0x02, 0x03};
 int data_len = 4;
 char payload_b86[255];

 void setup()
 {

    if (rak_blues.start_req((char *)"note.add"))
    {
        rak_blues.add_string_entry((char *)"file", (char *)"data.qo");
        rak_blues.add_bool_entry((char *)"sync", true);
        char node_id[24];
        sprintf(node_id, "%02x%02x%02x%02x%02x%02x%02x%02x",
            g_lorawan_settings.node_device_eui[0], g_lorawan_settings.node_device_eui[1],
            g_lorawan_settings.node_device_eui[2], g_lorawan_settings.node_device_eui[3],
            g_lorawan_settings.node_device_eui[4], g_lorawan_settings.node_device_eui[5],
            g_lorawan_settings.node_device_eui[6], g_lorawan_settings.node_device_eui[7]);
        rak_blues.add_nested_string_entry((char *)"body", (char *)"dev_eui", node_id);

        rak_blues.myJB64Encode(payload_b86, (const char *)data, data_len);

        rak_blues.add_string_entry((char *)"payload", payload_b86);

        if (!rak_blues.send_req())
        {
            return false;
        }
        return true;
    }
    return false;
 }

void loop()
{
}