awsiot  2.1.0.0
awsiot.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2020 MikroElektronika d.o.o.
3 ** Contact: https://www.mikroe.com/contact
4 **
5 ** Permission is hereby granted, free of charge, to any person obtaining a copy
6 ** of this software and associated documentation files (the "Software"), to deal
7 ** in the Software without restriction, including without limitation the rights
8 ** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 ** copies of the Software, and to permit persons to whom the Software is
10 ** furnished to do so, subject to the following conditions:
11 ** The above copyright notice and this permission notice shall be
12 ** included in all copies or substantial portions of the Software.
13 **
14 ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16 ** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 ** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19 ** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 ** USE OR OTHER DEALINGS IN THE SOFTWARE.
21 ****************************************************************************/
22 
28 #ifndef AWSIOT_H
29 #define AWSIOT_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
35 #include "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 #include "drv_uart.h"
48 
69 #define AWSIOT_CMD_AT "AT"
70 #define AWSIOT_CMD_CONNECT "AT+CONNECT"
71 #define AWSIOT_CMD_CONNECT_CHECK "AT+CONNECT?"
72 #define AWSIOT_CMD_DISCONNECT "AT+DISCONNECT"
73 #define AWSIOT_CMD_SLEEP "AT+SLEEP"
74 #define AWSIOT_CMD_CONFMODE "AT+CONFMODE"
75 #define AWSIOT_CMD_RESET "AT+RESET"
76 #define AWSIOT_CMD_FACTORY_RESET "AT+FACTORY_RESET"
77 #define AWSIOT_CMD_SEND "AT+SEND"
78 #define AWSIOT_CMD_GET "AT+GET"
79 #define AWSIOT_CMD_SUBSCRIBE "AT+SUBSCRIBE"
80 #define AWSIOT_CMD_UNSUBSCRIBE "AT+UNSUBSCRIBE"
81 #define AWSIOT_CMD_CONF "AT+CONF"
82 #define AWSIOT_CMD_CONF_CHECK "AT+CONF?"
83 #define AWSIOT_CMD_EVENT "AT+EVENT?"
84 #define AWSIOT_CMD_TIME "AT+TIME"
85 #define AWSIOT_CMD_WHERE "AT+WHERE"
86 #define AWSIOT_CMD_SEPARATOR " "
87 #define AWSIOT_CMD_SIGN_EQUAL "="
88 
93 #define AWSIOT_CONF_KEY_ABOUT "About"
94 #define AWSIOT_CONF_KEY_VERSION "Version"
95 #define AWSIOT_CONF_KEY_TECH_SPEC "TechSpec"
96 #define AWSIOT_CONF_KEY_THING_NAME "ThingName"
97 #define AWSIOT_CONF_KEY_CERTIFICATE "Certificate"
98 #define AWSIOT_CONF_KEY_CUSTOM_NAME "CustomName"
99 #define AWSIOT_CONF_KEY_ENDPOINT "Endpoint"
100 #define AWSIOT_CONF_KEY_ROOT_CA "RootCA"
101 #define AWSIOT_CONF_KEY_DEFENDER "Defender"
102 #define AWSIOT_CONF_KEY_HOTA_CERTIFICATE "HOTAcertificate"
103 #define AWSIOT_CONF_KEY_OTA_CERTIFICATE "OTAcertificate"
104 #define AWSIOT_CONF_KEY_SSID "SSID"
105 #define AWSIOT_CONF_KEY_PASSPHRASE "Passphrase"
106 #define AWSIOT_CONF_KEY_APN "APN"
107 #define AWSIOT_CONF_KEY_QOS "QOS"
108 #define AWSIOT_CONF_KEY_TOPIC "Topic"
109 
114 #define AWSIOT_RSP_OK "OK"
115 #define AWSIOT_RSP_ERR "ERR"
116 
122 #define AWSIOT_TX_DRV_BUFFER_SIZE 300
123 #define AWSIOT_RX_DRV_BUFFER_SIZE 1000
124  // awsiot_cmd
126 
141 #define AWSIOT_MAP_MIKROBUS( cfg, mikrobus ) \
142  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
143  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
144  cfg.boot = MIKROBUS( mikrobus, MIKROBUS_AN ); \
145  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
146  cfg.event = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
147  cfg.wake = MIKROBUS( mikrobus, MIKROBUS_INT );
148  // awsiot_map // awsiot
151 
156 typedef struct
157 {
158  // Output pins
159  digital_out_t boot;
160  digital_out_t rst;
162  // Input pins
163  digital_in_t event;
164  digital_in_t wake;
166  // Modules
167  uart_t uart;
169  // Buffers
170  uint8_t uart_rx_buffer[ AWSIOT_RX_DRV_BUFFER_SIZE ];
171  uint8_t uart_tx_buffer[ AWSIOT_TX_DRV_BUFFER_SIZE ];
173 } awsiot_t;
174 
179 typedef struct
180 {
181  // Communication gpio pins
182  pin_name_t rx_pin;
183  pin_name_t tx_pin;
185  // Additional gpio pins
186  pin_name_t boot;
187  pin_name_t rst;
188  pin_name_t event;
189  pin_name_t wake;
191  // Static variable
192  uint32_t baud_rate;
194  uart_data_bits_t data_bit;
195  uart_parity_t parity_bit;
196  uart_stop_bits_t stop_bit;
198 } awsiot_cfg_t;
199 
204 typedef enum
205 {
211 
213 
230 
244 err_t awsiot_init ( awsiot_t *ctx, awsiot_cfg_t *cfg );
245 
258 err_t awsiot_generic_write ( awsiot_t *ctx, uint8_t *data_in, uint16_t len );
259 
272 err_t awsiot_generic_read ( awsiot_t *ctx, uint8_t *data_out, uint16_t len );
273 
285 void awsiot_send_cmd ( awsiot_t *ctx, uint8_t *cmd );
286 
296 
306 
316 
326 void awsiot_set_boot_pin ( awsiot_t *ctx, uint8_t state );
327 
337 
346 uint8_t awsiot_get_wake_pin ( awsiot_t *ctx );
347 
348 #ifdef __cplusplus
349 }
350 #endif
351 #endif // AWSIOT_H
352  // awsiot
354 
355 // ------------------------------------------------------------------------ END
awsiot_cfg_t::uart_blocking
bool uart_blocking
Definition: awsiot.h:193
awsiot_cfg_t::boot
pin_name_t boot
Definition: awsiot.h:186
AWSIOT_TX_DRV_BUFFER_SIZE
#define AWSIOT_TX_DRV_BUFFER_SIZE
AWS IoT driver buffer size.
Definition: awsiot.h:122
awsiot_t::wake
digital_in_t wake
Definition: awsiot.h:164
awsiot_generic_write
err_t awsiot_generic_write(awsiot_t *ctx, uint8_t *data_in, uint16_t len)
AWS IoT data writing function.
awsiot_get_wake_pin
uint8_t awsiot_get_wake_pin(awsiot_t *ctx)
AWS IoT get wake pin function.
awsiot_cfg_setup
void awsiot_cfg_setup(awsiot_cfg_t *cfg)
AWS IoT configuration object setup function.
awsiot_cfg_t::tx_pin
pin_name_t tx_pin
Definition: awsiot.h:183
awsiot_generic_read
err_t awsiot_generic_read(awsiot_t *ctx, uint8_t *data_out, uint16_t len)
AWS IoT data reading function.
awsiot_cfg_t::event
pin_name_t event
Definition: awsiot.h:188
awsiot_init
err_t awsiot_init(awsiot_t *ctx, awsiot_cfg_t *cfg)
AWS IoT initialization function.
AWSIOT_ERROR_UNKNOWN
@ AWSIOT_ERROR_UNKNOWN
Definition: awsiot.h:210
awsiot_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: awsiot.h:194
AWSIOT_ERROR_CMD
@ AWSIOT_ERROR_CMD
Definition: awsiot.h:209
awsiot_return_value_t
awsiot_return_value_t
AWS IoT Click return value data.
Definition: awsiot.h:205
AWSIOT_ERROR_TIMEOUT
@ AWSIOT_ERROR_TIMEOUT
Definition: awsiot.h:208
awsiot_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: awsiot.h:196
awsiot_t::event
digital_in_t event
Definition: awsiot.h:163
awsiot_t::boot
digital_out_t boot
Definition: awsiot.h:159
awsiot_t::uart
uart_t uart
Definition: awsiot.h:167
awsiot_cfg_t::wake
pin_name_t wake
Definition: awsiot.h:189
AWSIOT_RX_DRV_BUFFER_SIZE
#define AWSIOT_RX_DRV_BUFFER_SIZE
Definition: awsiot.h:123
awsiot_reset_device
void awsiot_reset_device(awsiot_t *ctx)
AWS IoT reset device function.
awsiot_t
AWS IoT Click context object.
Definition: awsiot.h:157
awsiot_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: awsiot.h:195
awsiot_set_boot_pin
void awsiot_set_boot_pin(awsiot_t *ctx, uint8_t state)
AWS IoT set boot pin function.
AWSIOT_ERROR
@ AWSIOT_ERROR
Definition: awsiot.h:207
awsiot_cfg_t::rst
pin_name_t rst
Definition: awsiot.h:187
awsiot_cfg_t
AWS IoT Click configuration object.
Definition: awsiot.h:180
awsiot_send_cmd
void awsiot_send_cmd(awsiot_t *ctx, uint8_t *cmd)
AWS IoT send cmd function.
awsiot_cfg_t::baud_rate
uint32_t baud_rate
Definition: awsiot.h:192
awsiot_cfg_t::rx_pin
pin_name_t rx_pin
Definition: awsiot.h:182
awsiot_get_event_pin
uint8_t awsiot_get_event_pin(awsiot_t *ctx)
AWS IoT get event pin function.
AWSIOT_OK
@ AWSIOT_OK
Definition: awsiot.h:206
awsiot_t::rst
digital_out_t rst
Definition: awsiot.h:160
awsiot_disable_device
void awsiot_disable_device(awsiot_t *ctx)
AWS IoT disable device function.
awsiot_enable_device
void awsiot_enable_device(awsiot_t *ctx)
AWS IoT enable device function.