Note: when you get a value using api like
get
,hget
, etc. please keep in mind to free memory each time using thefree
api.To prevent memory leak, code like this must be avoided:
//Do not use Arancino.set("test", Arancino.get("mem"));Use the following instead:
//Use this char* mem = Arancino.get("mem"); Arancino.set("test", mem); Arancino.free(mem);is possible in some application static memory reserved for ArancinoPacket is not enough. To change the value of the memory assignment edit the follow line in ArancinoDefinition.h:
//MsgPack #define CMD_DOC_SIZE 512 //size for the message sent from the MCU #define RSP_DOC_SIZE 256 // size for message received on the MCU
Currently the memory values is sized to work with FreeRTOS enabled, if FreeRTOS is disabled is possible to increase these values.
Stores the metadata to use later during the START
command in begin
API.
data
: struct of typeArancinoMetadata
. Represents the firmware name, version and local timezone offset.
#include <Arancino.h>
ArancinoMetadata amdata = {
.fwname = "Arancino Firmware",
.fwversion = "1.0.0",
.tzoffset = "+1000"
};
void setup() {
// deprecated: do not use the .metadata function directly. Use the mandatory metadata argument in the begin function instead.
// This will be removed in the next major relase
//Arancino.metadata(meta);
//
Arancino.begin(amdata);
}
void loop() {
// Do something
}
Sets an ArancinoIface to be used by the Arancino Protocol as communication medium.
iface
: class of typeArancinoIface
. Represent the medium that will be used by the protocol in order to communicate with an Arancino Module.
#include <Arancino.h>
//Interface for Arancino protocol
SerialIface iface;
void setup() {
//Please remember to provide a serial port when not using an Arancino board
//iface.setSerialPort(Serial);
iface.setSerialPort();
Arancino.attachInterface(iface);
Arancino.begin(amdata);
}
void begin(ArancinoMetadata amdata, bool useid = false, int timeout = TIMEOUT ) | DEPRECATED from Version 1.4.0
Starts the communication with the Arancino Module. When communication starts, the begin
transmits the Arancino Library version for compatibility evaluatation.
From version 1.4.0
the ArancinoMetadata
argument became mandatory, becouse the data contained in it is part of the initial trasmission.
From version
- ArancinoConfig: is class composed only by attributes (see the following paragraph:
Arancino Config
): DECIMAL_DIGITS
SERIAL_TIMEOUT
PORT_ID_PREFIX_KEY
The convenience of using class ArancinoConfig is to be able to increase the number of parameters without necessarily having to change the prototypes. The use of the following arguments in thebegin
function is deprecated and will be removed in the next major release.timeout
useid
Set key to hold the string value. If key already holds a value, it is overwritten, regardless of its type.
key
: the key namevalue
: the value for the specified key. can be char*, int o floatisPersistent
optional boolean value to specify if value must be stored persistently or not. Default isfalse
.
ArancinoPacket reply: ArancinoPacket containing:
isError
: API call outcome (true
orfalse
);responseCode
: the response code value.responseType
:VOID
;response
:NULL
;
Get the value of key. If the key does not exist, the special value NULL
is returned.
key
: the name of the key from which the value is retrieved
char* reply:
- string that contains the value of selected key.
- NULL if the key doesn't exist. or ArancinoPacket reply: ArancinoPacket containing:
isError
: API call outcome (true
orfalse
);responseCode
: the response code value.responseType
:STRING
;response.string
:char*
pointer that can contain the value of selected key orNULL
if the key doesn't exist.
Executes the MSET command. Every key in the keys
parameter is set to the corresponding value in the values
parameter.
keys
: keys to set;values
: corresponding values of the keys;len
: number of keys to set, namely the length ofkeys
array.
ArancinoPacket reply: ArancinoPacket containing:
isError
: API call outcome (true
orfalse
);responseCode
: the response code value.responseType
:VOID
;response
:NULL
;
Note: 3
Retrieves multiple keys from redis.
keys
: array containing keys to retrieve;len
: number of keys to retrieve.
get
function can return both char**
and ArancinoPacket
depending on the template used.
In this case an array of char*
in returned. Every element contains the value stored in the corresponding key in the keys
parameter. If a key doesn't exist the corresponding element in the returned array is NULL
.
ArancinoPacket reply: ArancinoPacket containing:
isError
: API call outcome (true
orfalse
);responseCode
: the response code value.responseType
:STRING_ARRAY
;response.stringarray
:char**
pointer that points to the start of the returned array of strings.
Removes the specified key. A key is ignored if it does not exist.
key
: the name of the key to delete.
int reply: The number of keys that were removed. or ArancinoPacket reply: ArancinoPacket containing:
isError
: API call outcome (true
orfalse
);responseCode
: the response code value.responseType
:INT
;response.integer
: The number of keys that were removed.
Note: 1
Returns all the keys matching the pattern. Supported glob-style patterns:
- h?llo matches hello, hallo and hxllo
- h*llo matches hllo and heeeello
- h[ae]llo matches hello and hallo, but not hillo
- h[^e]llo matches hallo, hbllo, ... but not hello
- h[a-b]llo matches hallo and hbllo Use \ to escape special characters if you want to match them verbatim.
pattern
: the pattern used to find matching keys.
char** reply: list of keys matching pattern. or ArancinoPacket reply: ArancinoPacket containing:
isError
: API call outcome (true
orfalse
);responseCode
: the response code value.responseType
:STRING_ARRAY
;response.stringArray
:char**
pointer to the string array of keys matching pattern.
Sets field in the hash stored at key with the specified value. If key does not exist, a new key holding a hash is created. If field already exists in the hash, it is overwritten.
key
: the name of the key used to create the hash.field
: the name of the field to store in the hash.value
: the value to store in the hash with the specified field.
ArancinoPacket reply: ArancinoPacket containing:
isError
: API call outcome (true
orfalse
);responseCode
: the response code value.responseType
:VOID
;response
:NULL
;
Note: 2
Returns the value associated with field in the hash stored at key.
key
: the name of the key which hold the hash.field
: the name of the field from which the value is retrieved
char* reply:
- the value if a value is stored in field at key.
- NULL if there isn't a value stored. or ArancinoPacket reply: ArancinoPacket containing:
isError
: API call outcome (true
orfalse
);responseCode
: the response code value.responseType
:STRING
;response.string
:char*
pointer that can contain the value if a value is stored in field at key orNULL
if there isn't a value stored.
Returns all fields and values of the hash stored at key. In the returned value, every field name is followed by its value.
key
: the name of the key which holds the hash.
char** reply: string array of field and value matching key. or ArancinoPacket reply: ArancinoPacket containing:
isError
: API call outcome (true
orfalse
);responseCode
: the response code value.responseType
:STRING_ARRAY
;response.stringArray
:char**
pointer that can contain the string array of field and value matching key
Returns all field names in the hash stored at key.
key
: the name of the key which holds the hash.
char** reply: string array of fields matching key. or
ArancinoPacket reply: ArancinoPacket containing:
isError
: API call outcome (true
orfalse
);responseCode
: the response code value.responseType
:STRING_ARRAY
;response.stringArray
:char**
pointer to the string array of fields matching key.
Returns all values in the hash stored at key.
key
: the name of the key which holds the hash.
char** reply: string array of values matching key. or ArancinoPacket reply: ArancinoPacket containing:
isError
: API call outcome (true
orfalse
);responseCode
: the response code value.responseType
:STRING_ARRAY
;response.stringArray
:char**
pointer to the string array of values matching key.
Removes the specified field from the hash stored at key. If field is specified and it does not exist within this hash, this command returns 0. If the key does not exist, it is treated as an empty hash and this command returns 0.
key
: the name of the key stored in the hash.field
: the name of the field stored in the hash at key to delete.
int reply:
- 1 if the field is removed from hash.
- 0 if the field or the key does not exist in the hash. or ArancinoPacket reply: ArancinoPacket containing:
isError
: API call outcome (true
orfalse
);responseCode
: the response code value.responseType
:INT
;response.integer
: 1 if the field is removed from hash or 0 if the field or the key does not exist in the hash.
Note: 1
Delete all the keys.
ArancinoPacket reply: ArancinoPacket containing:
isError
: API call outcome (true
orfalse
);responseCode
: the response code value.responseType
:VOID
;response
:NULL
.
Posts a message to the given channel.
channel
: the name of the channel where the message will be sent.message
: message to send.
ArancinoPacket reply: ArancinoPacket containing:
isError
: API call outcome (true
orfalse
);responseCode
: the response code value.responseType
:INT
;response.integer
: the number of clients that received the message.
Append (or create and append) a new sample to the series specified by key.
key
: key to store.value
: the value for the specified key.timestamp
: the expicit timestamp for the specified key.
char* reply: the insertion timestamp. or ArancinoPacket reply: ArancinoPacket containing:
isError
: API call outcome (true
orfalse
);responseCode
: the response code value.responseType
:STRING
;response.string
:char*
pointer that contain the insertion timestamp to the series.
Append new samples to a list of series.
keys
: the list of keys to store.values
: corresponding values of the keys;len
: number of keys to set, namely the length of keys array.timestamp
: the expicit timestamp for the specified set of keys.
- char** reply: list of insertion timestamps.
- Returns nothing (
Void
) if timestamp prototype is used. (it uses ExecuteCommandFast so it don't require a response from Arancino Daemon). or ArancinoPacket reply: ArancinoPacket containing: isError
: API call outcome (true
orfalse
);responseCode
: the response code value.responseType
:STRING_ARRAY
;response.stringArray
:char**
pointer that points to the start of the returned array of insertion timestamps to the series.
key
: the key to store.tags
: the list of the tags to store.values
: corresponding values of the tags;len
: number of tags to set, namely the length of keys array.
ArancinoPacket reply: ArancinoPacket containing:
isError
: API call outcome (true
orfalse
);responseCode
: the response code value.responseType
:VOID
;response
:NULL
;
Enables the use of debug messages inside the Arancino Library as well as the use of print
functions. If a valid Stream is provided, it will be used to prompt debug messages. As an alternative, it can be chosen to prompt debug messages via set
command using the reserved key ___MONITOR___
if true
is provided as argument. If nothing (or false
) is provided instead, the library will try to initialize the default debug serial port (valid only for Arancino Boards).
#include <Arancino.h>
void setup() {
Arancino.begin();
Arancino.enableDebugMessages(SerialUSB);
//Arancino.enableDebugMessages(true);
//Arancino.enableDebugMessages();
}
void loop() {
Arancino.print(0,"Hello from Arancino");
delay(5000); //wait 5 seconds
}
Prints a debug message. Refer to enableDebugMessages
to see how to configure them.
#include <Arancino.h>
void setup() {
Arancino.begin();
Arancino.enableDebugMessages();
}
void loop() {
Arancino.print("Hello from Arancino");
delay(5000); //wait 5 seconds
}
Like print
but with a trailing new line char.
Return the array string count.
array
: pointer to string array.
int reply: string count.
#include <Arancino.h>
void setup() {
Arancino.enableDebugSerial();
Arancino.begin();
Arancino.set("exgetarraysize_pressure",1023);
Arancino.set("exgetarraysize_humidity",67.5);
Arancino.set("exgetarraysize_temperature",24.4);
}
void loop() {
char** key = Arancino.keys();
int count = Arancino.getArraySize(key);
Arancino.print("Key count: ");
Arancino.println(count);
Arancino.free(key);
}
frees the memory used by a char*
string, char**
array string, or by an ArancinoPacket.
string
: pointer to string.stringArray
: pointer to string array.packet
: ArancinoPacket variable.
#include <Arancino.h>
void setup() {
Arancino.begin();
Arancino.set("exfree_foo", "bar");
Arancino.set("exfree_qwe", "asd");
Arancino.set("exfree_pressure",1023);
Arancino.set("exfree_humidity",67.5);
Arancino.set("exfree_temperature",24.4);
}
void loop() {
char* str = Arancino.get("exfree_foo");
char** key = Arancino.keys();
ArancinoPacket myPacket = Arancino.getPacket("exfree_ qwe");
/* user code... */
Arancino.free(str);
Arancino.free(key);
Arancino.free(myPacket);
}
Note: when the free API is used for freeing an ArancinoPacket, the response type (string or string array ) is auto detected.
Check if the string is valid and correct for the utf-8 standard.
string
: pointer to string.
#include <Arancino.h>
void setup() {
Arancino.begin();
}
void loop() {
char* str = "Test";
if(isValidUTF8(str))
Arancino.set("key3", str);
}
- When using
get
-type functions (such asget
,hget
,mget
,hkeys
,hvals
,hgetall
, ...) the Arancino Module first searches the key in the volatile redis db. If it is not found there, the persistent redis db is used. - When using
set
andhset
functions the key has to be unique between both volatile and persistent db. Example: if we want to set a volatile variable namedkey1
, the Arancino Module first checks ifkey1
exists in the persistent db. - When using
mset
function the previous check is not executed. Later, when usingget
function the default redis db is first used (volatile). - When using arrays returned by Arancino Library functions it is important to free them after usage to prevent memory leaks. Example:
char* temp = Arancino.get("test");
Arancino.set("key2", temp);
Arancino.free(temp);
It is not recommended to do as follows:
Arancino.set("key2", Arancino.get("test"));
- When using
set
-type functions, make sure that the value is correctly formatted with utf-8 standard. Is recommended to use the internal functionisValidUTF8
before theset
to avoid decoding errors on Arancino Module. Example:
char* value="test";
if(isValidUTF8(value))
Arancino.set("key3", value);
Return timestamp in UNIX millis format.
char* timestamp: current timestamp.
#include <Arancino.h>
void setup() {
Arancino.begin();
}
void loop() {
char* ts = Arancino.getTimestamp();
Arancino.set("ts", ts);
delay(2000);
}
Return Arancino Module version.
char* modVersion: current Module version.
#include <Arancino.h>
void setup() {
Arancino.begin();
}
void loop() {
char* modVers = Arancino.getModuleVersion();
Arancino.set("mod_version", modVers);
Arancino.free(modVers);
delay(2000);
}
Return current Arancino Module log level.
char* modVersion: current Module log level.
#include <Arancino.h>
void setup() {
Arancino.begin();
}
void loop() {
char* logLvl = Arancino.getModuleLogLevel();
Arancino.set("Log_level", logLvl);
Arancino.free(logLvl);
delay(2000);
}