aws-iot-expresslink-library-arduino
|
#include <ExpressLink.h>
Classes | |
struct | Event |
struct | OTAState |
Public Types | |
enum | EventCode : int16_t { UNKNOWN = -2 , NONE = -1 , FIRST_EVENT_CODE = 1 , MSG = 1 , STARTUP = 2 , CONLOST = 3 , OVERRUN = 4 , OTA = 5 , CONNECT = 6 , CONFMODE = 7 , SUBACK = 8 , SUBNACK = 9 , SHADOW_INIT = 20 , SHADOW_INIT_FAILED = 21 , SHADOW_DOC = 22 , SHADOW_UPDATE = 23 , SHADOW_DELTA = 24 , SHADOW_DELETE = 25 , SHADOW_SUBACK = 26 , SHADOW_SUBNACK = 27 , LAST_EVENT_CODE } |
see https://docs.aws.amazon.com/iot-expresslink/latest/programmersguide/elpg-event-handling.html#elpg-event-handling-commands More... | |
enum | OTACode : int16_t { NoOTAInProgress = 0 , UpdateProposed = 1 , HostUpdateProposed = 2 , OTAInProgress = 3 , NewExpressLinkImageReady = 4 , NewHostImageReady = 5 } |
see https://docs.aws.amazon.com/iot-expresslink/latest/programmersguide/elpg-ota-updates.html#elpg-ota-commands More... | |
Public Member Functions | |
ExpressLink (void) | |
bool | begin (Stream &s, int event=-1, int wake=-1, int reset=-1, bool debug=false) |
Initializes an ExpressLink interface. More... | |
bool | cmd (String command) |
Execute AT command and reads all response lines. Escaping and unescaping is handled automatically. Check class attribute response (if true returned) and error (if false returned). More... | |
bool | selfTest () |
equivalent to sending AT and checking for OK response line More... | |
bool | connect (bool async=false) |
equivalent to: AT+CONNECT or AT+CONNECT! More... | |
bool | isConnected () |
equivalent to: AT+CONNECT? and parsing the response for CONNECTED/DISCONNECTED More... | |
bool | isOnboarded () |
equivalent to: AT+CONNECT? and parsing the response for STAGING/CUSTOMER More... | |
bool | disconnect () |
equivalent to: AT+DISCONNECT More... | |
bool | reset () |
soft-reboot of the module, equivalent to: AT+RESET More... | |
bool | factoryReset () |
wipe all data and config, equivalent to: AT+FACTORY_RESET More... | |
bool | sleep (uint32_t duration, uint8_t sleep_mode=0) |
Event | getEvent (bool checkPin=true) |
Gets the next pending Event, if available. More... | |
bool | subscribe (uint8_t topic_index, String topic_name) |
Subscribe to Topic#. More... | |
bool | unsubscribe (uint8_t topic_index) |
Unsubscribe from Topic#. More... | |
bool | get (uint8_t topic_index=-1) |
Request next message pending on the indicated topic. More... | |
bool | send (uint8_t topic_index, String message) |
Same as ExpressLink::publish - use it instead. More... | |
bool | publish (uint8_t topic_index, String message) |
Publish msg on a topic selected from topic list. More... | |
OTAState | otaGetState () |
Fetches the current state of the OTA process. More... | |
bool | otaAccept () |
Allow the OTA operation to proceed. More... | |
bool | otaRead (uint32_t count) |
Requests the next # bytes from the OTA buffer. More... | |
bool | otaSeek (uint32_t address=-1) |
Moves the read pointer to an absolute address. More... | |
bool | otaApply () |
Authorize the ExpressLink module to apply the new image. More... | |
bool | otaClose () |
The host OTA operation is completed. More... | |
bool | otaFlush () |
The contents of the OTA buffer are emptied. More... | |
bool | shadowInit (uint8_t index=-1) |
Initialize communication with the Device Shadow service. More... | |
bool | shadowDoc (uint8_t index=-1) |
Request a Device Shadow document. More... | |
bool | shadowGetDoc (uint8_t index=-1) |
Retrieve a device shadow document. More... | |
bool | shadowUpdate (String new_state, uint8_t index=-1) |
Request a device shadow document update. More... | |
bool | shadowGetUpdate (uint8_t index=-1) |
Retrieve a device shadow update response. More... | |
bool | shadowSubscribe (uint8_t index=-1) |
Subscribe to a device shadow document. More... | |
bool | shadowUnsubscribe (uint8_t index=-1) |
Unsubscribe from a device shadow document. More... | |
bool | shadowGetDelta (uint8_t index=-1) |
Retrieve a Shadow Delta message. More... | |
bool | shadowDelete (uint8_t index=-1) |
Request the deletion of a Shadow document. More... | |
bool | shadowGetDelete (uint8_t index=-1) |
Request a Shadow delete response. More... | |
void | passthrough (Stream *destination) |
Enters Serial/UART passthrough mode. All serial communication is bridged between the ExpressLink UART and the passed destination . This function never returns. You can use it for debugging or over-the-wire firmware upgrades. More... | |
String | readLine (uint32_t count=1) |
Public Attributes | |
ExpressLinkConfig | config |
String | response |
String | error |
uint32_t | additionalLines |
Static Public Attributes | |
static const uint32_t | BAUDRATE = 115200 |
The default UART configuration shall be 115200, 8, N, 1 (baud rate: 115200; data bits: 8; parity: none; stop bits: 1). There is no hardware or software flow control for UART communications. See https://docs.aws.amazon.com/iot-expresslink/latest/programmersguide/elpg-commands.html#elpg-commands-introduction. More... | |
static const uint32_t | TIMEOUT = 120000 |
The maximum runtime for every command must be listed in the datasheet. No command can take more than 120 seconds to complete (the maximum time for a TCP connection timeout). See https://docs.aws.amazon.com/iot-expresslink/latest/programmersguide/elpg-commands.html#elpg-response-timeout. More... | |
Protected Member Functions | |
void | escape (String &value) |
Escapes string in-place so it can be written to ExpressLink UART. More... | |
void | unescape (String &value) |
Unescapes string in-place after reading it from ExpressLink UART. More... | |
Friends | |
class | ExpressLinkConfig |
enum ExpressLink::EventCode : int16_t |
enum ExpressLink::OTACode : int16_t |
ExpressLink::ExpressLink | ( | void | ) |
bool ExpressLink::begin | ( | Stream & | u, |
int | event = -1 , |
||
int | wake = -1 , |
||
int | reset = -1 , |
||
bool | d = false |
||
) |
Initializes an ExpressLink interface.
u | serial uart for AT commands (initialize separately with RX/TX pins) |
event | GPIO pin where ExpressLink EVENT pin is connected, set to -1 if not connected (default) |
wake | GPIO pin where ExpressLink WAKE pin is connected, set to -1 if not connected (default) |
reset | GPIO pin where ExpressLink RESET pin is connected, set to -1 if not connected (default) |
debug | uses the default Serial stream to print AT commands and responses. Only enable if Serial is connected to a different UART than the ExpressLink UART. |
bool ExpressLink::cmd | ( | String | command | ) |
Execute AT command and reads all response lines. Escaping and unescaping is handled automatically. Check class attribute response
(if true returned) and error
(if false returned).
command | e.g., AT+CONNECT or SUBSCRIBE1 (with or without the AT+ prefix) |
bool ExpressLink::connect | ( | bool | async = false | ) |
equivalent to: AT+CONNECT or AT+CONNECT!
async | true to use non-blocking CONNECT! |
bool ExpressLink::disconnect | ( | ) |
equivalent to: AT+DISCONNECT
|
protected |
Escapes string in-place so it can be written to ExpressLink UART.
value | string (will be modified) |
bool ExpressLink::factoryReset | ( | ) |
wipe all data and config, equivalent to: AT+FACTORY_RESET
bool ExpressLink::get | ( | uint8_t | topic_index = -1 | ) |
Request next message pending on the indicated topic.
Equivalent to AT+GET{topic_index}
.
topic_index | use -1 (default) for GET , or value for GETx |
ExpressLink::Event ExpressLink::getEvent | ( | bool | checkPin = true | ) |
Gets the next pending Event, if available.
checkPin | true (default) if the EVENT pin should be read; false if the AT+EVENT? command should be used |
code
==NONE if no event is pending bool ExpressLink::isConnected | ( | ) |
equivalent to: AT+CONNECT? and parsing the response for CONNECTED/DISCONNECTED
bool ExpressLink::isOnboarded | ( | ) |
equivalent to: AT+CONNECT? and parsing the response for STAGING/CUSTOMER
bool ExpressLink::otaAccept | ( | ) |
Allow the OTA operation to proceed.
Equivalent to AT+OTA ACCEPT<EOL>
.
bool ExpressLink::otaApply | ( | ) |
Authorize the ExpressLink module to apply the new image.
Equivalent to AT+OTA APPLY<EOL>
.
bool ExpressLink::otaClose | ( | ) |
The host OTA operation is completed.
Equivalent to AT+OTA CLOSE<EOL>
.
bool ExpressLink::otaFlush | ( | ) |
The contents of the OTA buffer are emptied.
Equivalent to AT+OTA FLUSH<EOL>
.
ExpressLink::OTAState ExpressLink::otaGetState | ( | ) |
Fetches the current state of the OTA process.
Equivalent to AT+OTA?
.
bool ExpressLink::otaRead | ( | uint32_t | count | ) |
Requests the next # bytes from the OTA buffer.
Equivalent to AT+OTA READ {count}<EOL>
.
Retreive payload from ExpressLink::response
count | decimal value of number of bytes to read |
bool ExpressLink::otaSeek | ( | uint32_t | address = -1 | ) |
Moves the read pointer to an absolute address.
Equivalent to AT+OTA SEEK<EOL>
or AT+OTA SEEK {address}<EOL>
.
address | decimal value for read pointer to seek to, or -1 to seek to beginning |
void ExpressLink::passthrough | ( | Stream * | destination | ) |
Enters Serial/UART passthrough mode. All serial communication is bridged between the ExpressLink UART and the passed destination
. This function never returns. You can use it for debugging or over-the-wire firmware upgrades.
bool ExpressLink::publish | ( | uint8_t | topic_index, |
String | message | ||
) |
Publish msg on a topic selected from topic list.
Equivalent to AT+SEND{topic_index} {message}
.
topic_index | the topic index to publish to |
message | raw message to publish, typically JSON-encoded |
String ExpressLink::readLine | ( | uint32_t | count = 1 | ) |
bool ExpressLink::reset | ( | ) |
soft-reboot of the module, equivalent to: AT+RESET
bool ExpressLink::selfTest | ( | ) |
equivalent to sending AT and checking for OK response line
bool ExpressLink::send | ( | uint8_t | topic_index, |
String | message | ||
) |
Same as ExpressLink::publish - use it instead.
topic_index | |
message |
bool ExpressLink::shadowDelete | ( | uint8_t | index = -1 | ) |
Request the deletion of a Shadow document.
Equivalent to AT+SHADOW{index} DELETE<EOL>
.
index | shadow index. Use -1 (default), to select the unnamed shadow. |
bool ExpressLink::shadowDoc | ( | uint8_t | index = -1 | ) |
Request a Device Shadow document.
Equivalent to AT+SHADOW{index} DOC<EOL>
.
index | shadow index. Use -1 (default), to select the unnamed shadow. |
bool ExpressLink::shadowGetDelete | ( | uint8_t | index = -1 | ) |
Request a Shadow delete response.
Equivalent to AT+SHADOW{index} GET DELETE<EOL>
.
index | shadow index. Use -1 (default), to select the unnamed shadow. |
bool ExpressLink::shadowGetDelta | ( | uint8_t | index = -1 | ) |
Retrieve a Shadow Delta message.
Equivalent to AT+SHADOW{index} GET DELTA<EOL>
.
index | shadow index. Use -1 (default), to select the unnamed shadow. |
bool ExpressLink::shadowGetDoc | ( | uint8_t | index = -1 | ) |
Retrieve a device shadow document.
Equivalent to AT+SHADOW{index} GET DOC<EOL>
.
index | shadow index. Use -1 (default), to select the unnamed shadow. |
bool ExpressLink::shadowGetUpdate | ( | uint8_t | index = -1 | ) |
Retrieve a device shadow update response.
Equivalent to AT+SHADOW{index} GET UPDATE<EOL>
.
index | shadow index. Use -1 (default), to select the unnamed shadow. |
bool ExpressLink::shadowInit | ( | uint8_t | index = -1 | ) |
Initialize communication with the Device Shadow service.
Equivalent to AT+SHADOW{index} INIT<EOL>
.
index | shadow index. Use -1 (default), to select the unnamed shadow. |
bool ExpressLink::shadowSubscribe | ( | uint8_t | index = -1 | ) |
Subscribe to a device shadow document.
Equivalent to AT+SHADOW{index} SUBSCRIBE<EOL>
.
index | shadow index. Use -1 (default), to select the unnamed shadow. |
bool ExpressLink::shadowUnsubscribe | ( | uint8_t | index = -1 | ) |
Unsubscribe from a device shadow document.
Equivalent to AT+SHADOW{index} UNSUBSCRIBE<EOL>
.
index | shadow index. Use -1 (default), to select the unnamed shadow. |
bool ExpressLink::shadowUpdate | ( | String | new_state, |
uint8_t | index = -1 |
||
) |
Request a device shadow document update.
Equivalent to AT+SHADOW{index} UPDATE {new_state}<EOL>
.
index | shadow index. Use -1 (default), to select the unnamed shadow. |
bool ExpressLink::sleep | ( | uint32_t | duration, |
uint8_t | sleep_mode = 0 |
||
) |
bool ExpressLink::subscribe | ( | uint8_t | topic_index, |
String | topic_name | ||
) |
Subscribe to Topic#.
Equivalent to AT+CONF Topic{topic_index}={topic_name}
followed by AT+SUBSCRIBE{topic_index}
.
topic_index | index to subscribe to |
topic_name | name of topic (empty to skip setting topic in configuration dictionary) |
|
protected |
Unescapes string in-place after reading it from ExpressLink UART.
value | string (will be modified) |
bool ExpressLink::unsubscribe | ( | uint8_t | topic_index | ) |
Unsubscribe from Topic#.
Equivalent to AT+UNSUBSCRIBE{topic_index}
.
topic_index | index to unsubscribe from |
|
friend |
uint32_t ExpressLink::additionalLines |
|
static |
The default UART configuration shall be 115200, 8, N, 1 (baud rate: 115200; data bits: 8; parity: none; stop bits: 1). There is no hardware or software flow control for UART communications. See https://docs.aws.amazon.com/iot-expresslink/latest/programmersguide/elpg-commands.html#elpg-commands-introduction.
ExpressLinkConfig ExpressLink::config |
String ExpressLink::error |
String ExpressLink::response |
|
static |
The maximum runtime for every command must be listed in the datasheet. No command can take more than 120 seconds to complete (the maximum time for a TCP connection timeout). See https://docs.aws.amazon.com/iot-expresslink/latest/programmersguide/elpg-commands.html#elpg-response-timeout.