aws-iot-expresslink-library-arduino
ExpressLink.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "Arduino.h"
4 #include "Stream.h"
5 
6 class ExpressLink;
7 
9 {
10 public:
12 
13  bool get(String key);
14  bool set(String key, String value);
15 
16  String getAbout();
17  String getVersion();
18  String getTechSpec();
19  String getThingName();
20  String getCertificate();
21 
22  String getCustomName();
23  bool setCustomName(const String &value);
24 
25  String getEndpoint();
26  bool setEndpoint(const String &value);
27 
28  String getRootCA();
29  bool setRootCA(const String &value);
30 
31  String getShadowToken();
32  bool setShadowToken(const String &value);
33 
34  uint32_t getDefenderPeriod();
35  bool setDefenderPeriod(const uint32_t value);
36 
37  String getHOTAcertificate();
38  bool setHOTAcertificate(const String &value);
39 
40  String getOTAcertificate();
41  bool setOTAcertificate(const String &value);
42 
43  String getSSID();
44  bool setSSID(const String &value);
45 
46  bool setPassphrase(const String &value);
47 
48  String getAPN();
49  bool setAPN(const String &value);
50 
51  String getTopic(uint8_t index);
52  bool setTopic(uint8_t index, String topic);
53 
54  String getShadow(uint8_t index);
55  bool setShadow(uint8_t index, String topic);
56 
57 private:
58  ExpressLink &expresslink;
59 };
60 
62 {
63  friend class ExpressLinkConfig;
64 
65 public:
67  enum EventCode : int16_t
68  {
69  UNKNOWN = -2,
70  NONE = -1,
72  MSG = 1,
73  STARTUP = 2,
74  CONLOST = 3,
75  OVERRUN = 4,
76  OTA = 5,
77  CONNECT = 6,
78  CONFMODE = 7,
79  SUBACK = 8,
80  SUBNACK = 9,
81  // 10..19 RESERVED
82  SHADOW_INIT = 20,
84  SHADOW_DOC = 22,
86  SHADOW_DELTA = 24,
91  // <= 999 reserved
92  // >= 1000 available for custom implementation
93  };
94 
96  enum OTACode : int16_t
97  {
104  };
105 
106  struct Event
107  {
110  };
111 
112  struct OTAState
113  {
115  String detail;
116  };
117 
118  ExpressLink(void);
119  bool begin(Stream &s, int event = -1, int wake = -1, int reset = -1, bool debug = false);
120 
121  bool cmd(String command);
122 
123  bool selfTest();
124 
125  bool connect(bool async = false);
126  bool isConnected();
127  bool isOnboarded();
128  bool disconnect();
129 
130  bool reset();
131  bool factoryReset();
132  bool sleep(uint32_t duration, uint8_t sleep_mode = 0);
133 
134  Event getEvent(bool checkPin = true);
135 
136  bool subscribe(uint8_t topic_index, String topic_name);
137  bool unsubscribe(uint8_t topic_index);
138  bool get(uint8_t topic_index = -1); // -1 = GET, 0...X = GETX
139  bool send(uint8_t topic_index, String message);
140  bool publish(uint8_t topic_index, String message);
141 
143  bool otaAccept();
144  bool otaRead(uint32_t count);
145  bool otaSeek(uint32_t address = -1);
146  bool otaApply();
147  bool otaClose();
148  bool otaFlush();
149 
150  bool shadowInit(uint8_t index = -1);
151  bool shadowDoc(uint8_t index = -1);
152  bool shadowGetDoc(uint8_t index = -1);
153  bool shadowUpdate(String new_state, uint8_t index = -1);
154  bool shadowGetUpdate(uint8_t index = -1);
155  bool shadowSubscribe(uint8_t index = -1);
156  bool shadowUnsubscribe(uint8_t index = -1);
157  bool shadowGetDelta(uint8_t index = -1);
158  bool shadowDelete(uint8_t index = -1);
159  bool shadowGetDelete(uint8_t index = -1);
160 
161  void passthrough(Stream* destination);
162 
164 
165  String readLine(uint32_t count = 1);
166  String response;
167  String error;
168  uint32_t additionalLines;
169 
174  static const uint32_t BAUDRATE = 115200;
175 
179  static const uint32_t TIMEOUT = 120000; // milliseconds
180 
181 protected:
182  void escape(String &value);
183  void unescape(String &value);
184 
185 private:
186  bool debug;
187  Stream *uart;
188  int resetPin = -1;
189  int eventPin = -1;
190  int wakePin = -1;
191 };
Definition: ExpressLink.h:9
bool setCustomName(const String &value)
equivalent to: AT+CONF CustomName={value}
Definition: ExpressLink.cpp:71
bool setShadow(uint8_t index, String topic)
bool get(String key)
String getCustomName()
equivalent to: AT+CONF? CustomName
Definition: ExpressLink.cpp:62
bool setSSID(const String &value)
equivalent to: AT+CONF SSID={value}
Definition: ExpressLink.cpp:154
bool setAPN(const String &value)
String getAbout()
equivalent to: AT+CONF? About
Definition: ExpressLink.cpp:21
bool setOTAcertificate(const String &value)
bool setShadowToken(const String &value)
String getHOTAcertificate()
equivalent to: AT+CONF? HOTAcertificate pem
Definition: ExpressLink.cpp:127
String getCertificate()
equivalent to: AT+CONF? Certificate pem
Definition: ExpressLink.cpp:53
bool setTopic(uint8_t index, String topic)
Definition: ExpressLink.cpp:14
String getShadow(uint8_t index)
String getRootCA()
equivalent to: AT+CONF? Endpoint pem
Definition: ExpressLink.cpp:94
String getVersion()
equivalent to: AT+CONF? Version
Definition: ExpressLink.cpp:29
bool setHOTAcertificate(const String &value)
bool set(String key, String value)
bool setRootCA(const String &value)
equivalent to: AT+CONF RootCA={value}
Definition: ExpressLink.cpp:104
String getThingName()
equivalent to: AT+CONF? ThingName
Definition: ExpressLink.cpp:45
String getTopic(uint8_t index)
Definition: ExpressLink.cpp:8
bool setPassphrase(const String &value)
equivalent to: AT+CONF Passphrase={value}
Definition: ExpressLink.cpp:162
uint32_t getDefenderPeriod()
equivalent to: AT+CONF? DefenderPeriod
Definition: ExpressLink.cpp:119
String getAPN()
equivalent to: AT+CONF? APN
Definition: ExpressLink.cpp:169
bool setEndpoint(const String &value)
equivalent to: AT+CONF Endpoin={value}
Definition: ExpressLink.cpp:87
bool setDefenderPeriod(const uint32_t value)
ExpressLinkConfig(ExpressLink &el)
Definition: ExpressLink.cpp:3
String getSSID()
equivalent to: AT+CONF? SSID
Definition: ExpressLink.cpp:145
String getTechSpec()
equivalent to: AT+CONF? TechSpec
Definition: ExpressLink.cpp:37
String getShadowToken()
equivalent to: AT+CONF? ShadowToken
Definition: ExpressLink.cpp:111
String getEndpoint()
equivalent to: AT+CONF? Endpoint
Definition: ExpressLink.cpp:78
String getOTAcertificate()
equivalent to: AT+CONF? OTAcertificate pem
Definition: ExpressLink.cpp:136