AWS IoT Firmware
Firmware code for AWS IoT Devices
event_handler_util.hpp
Go to the documentation of this file.
1 
14 #ifndef _EVENT_HANDLER_UTIL_H
15 #define _EVENT_HANDLER_UTIL_H
16 
17 #include "mgos.h"
18 #include "mgos_mqtt.h"
19 
20 #include <stdarg.h>
21 #include <stdint.h>
22 
26 #define MAX_COMMAND_LEN 30
27 
31 #define MAX_NAMESPACE_LEN 30
32 
37 typedef enum {
38  HANDLER_NO_ERR = 0,
39  MQTT_ERR_UNKNOWN_COMMAND,
40  MQTT_ERR_GPIO,
41  JSON_NOT_ENOUGH_ARG,
42  MQTT_CONFIG_NOT_SET,
43  JSON_UNKNOWN_NAMESPACE,
44  JSON_VPRINTF_ERROR,
45  JSON_VSCANF_ERROR,
46  HANDLER_NULL
47 } HandlerError;
48 
52 typedef struct {
53  HandlerError errorCode;
54  const char* errorMessage;
55 } ErrDescript;
56 
57 HandlerError getCommandInfo(struct mg_str* message, char* commandName, char* nameSpace);
58 HandlerError getAwsPayload(const struct mg_str* message,
59  const char* awsPayloadFormat,
60  const uint8_t& totalArg,
61  ...);
62 
63 HandlerError write_pin(const uint8_t pinNum, const uint8_t pinState);
64 HandlerError read_pin(const uint8_t pinNum, uint8_t* pinState);
65 
67  struct mg_str* payload,
68  char* errorMessage);
69 
70 /* State Report Helper */
71 HandlerError printStateReportOpen(char* jsonOut);
73 HandlerError printStateReportEnd(char* jsonOut);
74 
75 #endif
76 
HandlerError write_pin(const uint8_t pinNum, const uint8_t pinState)
used for writing to a digital pin given its pin number and state
Definition: event_handler_util.cpp:80
HandlerError printStateReportEnd(char *jsonOut)
print the ending part of an aws iot state report
Definition: event_handler_util.cpp:184
HandlerError read_pin(const uint8_t pinNum, uint8_t *pinState)
used to reat the status of a digital pin
Definition: event_handler_util.cpp:94
HandlerError printStateReportOpen(char *jsonOut)
print the beginning of an aws smarthome state report
Definition: event_handler_util.cpp:162
HandlerError
enum defining errors that the system(including master handler and other child handler) may have ...
Definition: event_handler_util.hpp:37
used for storing the error code and its corresponding error message
Definition: event_handler_util.hpp:52
HandlerError getAwsPayload(const struct mg_str *message, const char *awsPayloadFormat, const uint8_t &totalArg,...)
Get the Aws Payload json key.
Definition: event_handler_util.cpp:138
HandlerError create_error_message(const HandlerError error, struct mg_str *payload, char *errorMessage)
create error message based on the error code given and stores it in the given buffer ...
Definition: event_handler_util.cpp:38
HandlerError printStateReportDelimiter(char *jsonOut)
print the delimiter between endpoints reports in aws iot state report
Definition: event_handler_util.cpp:173
HandlerError getCommandInfo(struct mg_str *message, char *commandName, char *nameSpace)
get command name as well as command namespace of messages sent from aws lambda
Definition: event_handler_util.cpp:108