![]() |
![]() |
![]() |
---|---|---|
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:
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.
The API calls are split into 3 categories:
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()
{
}
Create a request structure to be sent to the NoteCard.
request
name of request, e.g. card.wireless true if request could be created
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()
{
}
Send a completed request to the NoteCard.
response
if not NULL, the response of the Notecard will copied into this buffer
resp_len
max length of buffer for the Notecard response
true if request could be sent and the response does not have "err"
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()
{
}
Add C-String entry to request.
type
char * name
value
char * value
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()
{
}
Add boolean entry to request.
type
char * name
value
bool value
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()
{
}
Add integer entry to request.
type
char * name
value
integer value
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()
{
}
Add unsigned integer entry to request.
type
char * name
value
unsigned integer value
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()
{
}
Add float entry to request.
type
char * name
value
float value
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()
{
}
Add nested C-String entry to request.
type
char * name
nested
char * nested name
value
char * value
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()
{
}
Add nested integer entry to request.
type
char * name
nested
char * nested name
value
integer value
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()
{
}
Add nested unsigned integer entry to request.
type
char * name
nested
char * nested name
value
unsigned integer value
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()
{
}
Add nested bool entry to request.
type
char * name
nested
char * nested name
value
char * value
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()
{
}
Add nested float entry to request.
type
char * name
nested
char * nested name
value
float value
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()
{
}
Add 2 level nested C-String entry to request
type
char * name
nested
char * nested name
nested2
char * 2nd level nested name
value
char * value
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()
{
}
Add 2 level nested integer entry to request
type
char * name
nested
char * nested name
nested2
char * 2nd level nested name
value
integer value
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()
{
}
Add nested unsigned integer entry to request.
type
char * name
nested
char * nested name
nested2
char * 2nd level nested name
value
unsigned integer value
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()
{
}
Add 2 level nested bool entry to request
type
char * name
nested
char * nested name
nested2
char * 2nd level nested name
value
bool value
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()
{
}
Get 2nd level nested string entry (char array) from the response
type
entry name as char *
nested
nested level name as char *
nested2
nested 2nd level name as char *
value
(out) address of char array to write the string to
value_size
size of target char array
true if entry was found
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()
{
}
Get 2nd level nested signed 32bit integer entry from the response
type
entry name as char *
nested
nested level name as char *
nested2
nested 2nd level name as char *
value
(out) address of signed 32bit integer variable to write the value to
true if entry was found
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()
{
}
Get 2nd level nested unsigned 32bit integer entry from the response
type
entry name as char *
nested
nested level name as char *
nested2
nested 2nd level name as char *
value
(out) address of unsigned 32bit integer variable to write the value to
true if entry was found
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()
{
}
Get nested bool entry from the response.
type
entry name as char *
nested
nested level name as char *
nested2
nested 2nd level name as char *
value
(out) address of bool variable to write the value to
true if entry was found
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()
{
}
Add nested float entry to request.
type
char * name
nested
char * nested name
nested2
char * 2nd level nested name
value
float value
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()
{
}
Check if the response has a specific entry.
type
entry name as char * true if entry was found
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()
{
}
Check if the response has a specific nested entry.
type
entry name as char *
nested
nested level name as char *
true if entry was found
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()
{
}
Get string entry (char array) from the response.
type
entry name as char *
value
(out) address of char array to write the string to
value_size
size of target char array
true if entry was found
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()
{
}
Get string entry (char array) from response when in an array.
type
entry name as char *
value
(out) address of char array to write the string to
value_size
size of target char array
true if entry was found
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()
{
}
Get bool entry from the response.
type
entry name as char *
value
(out) address of bool variable to write the value to
true if entry was found
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()
{
}
Get signed 32bit integer entry from the response.
type
entry name as char *
value
(out) address of signed integer variable to write the value to
true if entry was found
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()
{
}
Get unsigned 32bit integer entry from the response.
type
entry name as char *
value
(out) address of unsigned integer variable to write the value to
true if entry was found
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()
{
}
Get float entry from the response.
type
entry name as char *
value
(out) address of float variable to write the value to
true if entry was found
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()
{
}
Get nested string entry (char array) from the response.
type
entry name as char *
nested
nested level name as char *
value
(out) address of char array to write the string to
value_size
size of target char array
true if entry was found
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()
{
}
Get nested signed 32bit integer entry from the response.
type
entry name as char *
nested
nested level name as char *
value
(out) address of signed 32bit integer variable to write the value to
true if entry was found
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()
{
}
Get nested unsigned 32bit integer entry from the response.
type
entry name as char *
nested
nested level name as char *
value
(out) address of unsigned 32bit integer variable to write the value to
true if entry was found
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()
{
}
Get nested bool entry from the response.
type
entry name as char *
nested
nested level name as char *
value
(out) address of bool variable to write the value to
true if entry was found
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()
{
}
Encode a char buffer to Base64.
encoded
(out) encoded string
string
char buffer for encoding
len
length of buffer
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()
{
}