12 static int32_t _mqtt_status = 0;
16 #ifndef MA_HAS_NATTIVE_MQTT_SUPPORT
17 #define MA_HAS_NATTIVE_MQTT_SUPPORT 1
20 #if MA_USE_EXTERNAL_WIFI_STATUS
21 extern volatile int _net_sta;
39 encoder.
write(_mqtt_topic_config);
41 transport.
send(
reinterpret_cast<const char*
>(encoder.
data()), encoder.
size());
47 if (argv.size() < 5) {
54 _mqtt_topic_config.
pub_qos = std::atoi(argv[3].c_str());
55 _mqtt_topic_config.
sub_qos = std::atoi(argv[4].c_str());
68 encoder.
write(_mqtt_topic_config);
70 transport.
send(
reinterpret_cast<const char*
>(encoder.
data()), encoder.
size());
77 #if MA_USE_EXTERNAL_WIFI_STATUS
78 _mqtt_status = (((uint8_t)_net_sta & 0xf) - 1) & 0b0110;
80 encoder.
write(
"status", _mqtt_status);
82 transport.
send(
reinterpret_cast<const char*
>(encoder.
data()), encoder.
size());
85 #if !MA_HAS_NATTIVE_MQTT_SUPPORT
86 void setMqttSta(
const std::vector<std::string>& argv,
Transport& transport,
Encoder& encoder) {
89 if (argv.size() < 2) {
94 _mqtt_status = std::atoi(argv[1].c_str());
98 encoder.
write(
"status", _mqtt_status);
100 transport.
send(
reinterpret_cast<const char*
>(encoder.
data()), encoder.
size());
107 if (argv.size() < 7) {
108 MA_LOGD(
MA_TAG,
"Invalid number of arguments %d", argv.size());
114 _mqtt_server_config.
port = std::atoi(argv[3].c_str());
116 std::string client_id = argv[1];
117 if (client_id.empty()) {
118 using namespace std::string_literals;
119 client_id = std::string(PRODUCT_NAME_PREFIX) +
"_"s + std::string(PRODUCT_NAME_SUFFIX) +
"_"s +
126 _mqtt_server_config.
use_ssl = std::atoi(argv[6].c_str());
140 using namespace std::string_literals;
142 topic_prefix += _mqtt_server_config.
client_id;
143 auto tx = topic_prefix +
"/tx"s;
144 auto rx = topic_prefix +
"/rx"s;
156 encoder.
write(_mqtt_server_config);
158 transport.
send(
reinterpret_cast<const char*
>(encoder.
data()), encoder.
size());
175 #if MA_USE_EXTERNAL_WIFI_STATUS
176 _mqtt_status = (((uint8_t)_net_sta & 0xf) - 1) & 0b11;
178 if (std::strlen(_mqtt_server_config.
host) < 1) {
181 encoder.
write(_mqtt_server_config, (
int*)&_mqtt_status);
183 transport.
send(
reinterpret_cast<const char*
>(encoder.
data()), encoder.
size());
189 std::string ca_string;
192 if (argv.size() < 2) {
198 ca_hash = std::hash<std::string>{}(ca_string);
204 encoder.
write(
"hash", (uint64_t)ca_hash);
206 transport.
send(
reinterpret_cast<const char*
>(encoder.
data()), encoder.
size());
214 std::string ca_string;
216 int b64ca_len = ca_string.size() * 4 / 3 + 4;
217 b64ca.resize(b64ca_len + 1);
220 reinterpret_cast<char*
>(b64ca.data()),
222 b64ca[b64ca_len] =
'\0';
226 encoder.
write(
"ca", b64ca);
228 transport.
send(
reinterpret_cast<const char*
>(encoder.
data()), encoder.
size());
Definition: ma_codec_base.h:14
virtual ma_err_t end()=0
Encoder type for end.
virtual const void * data() const =0
Encoder type for get data.
virtual ma_err_t begin()=0
Encoder type for begin.
virtual ma_err_t write(const std::string &key, int8_t value)=0
Encoder type for write int8_t value.
virtual const size_t size() const =0
Encoder type for get size.
Definition: ma_transport.h:12
virtual size_t send(const char *data, size_t length) noexcept=0
#define MA_MQTT_MAX_PASSWORD_LENGTH
Definition: ma_config_internal.h:68
#define MA_MQTT_MAX_BROKER_LENGTH
Definition: ma_config_internal.h:52
#define MA_MQTT_MAX_CLIENT_ID_LENGTH
Definition: ma_config_internal.h:56
#define MA_MQTT_MAX_USERNAME_LENGTH
Definition: ma_config_internal.h:64
#define MA_MQTT_MAX_TOPIC_LENGTH
Definition: ma_config_internal.h:60
#define MA_LOGD(TAG,...)
Definition: ma_debug.h:79
#define MA_TAG
Definition: ma_debug.h:9
#define MA_STORAGE_KEY_MQTT_PWD
Definition: ma_definations.h:35
#define MA_STORAGE_KEY_MQTT_PUB_TOPIC
Definition: ma_definations.h:36
#define MA_STORAGE_KEY_MQTT_SSL_CA
Definition: ma_definations.h:41
#define MA_STORAGE_KEY_MQTT_PORT
Definition: ma_definations.h:32
#define MA_STORAGE_KEY_MQTT_SUB_TOPIC
Definition: ma_definations.h:38
#define MA_STORAGE_KEY_MQTT_CLIENTID
Definition: ma_definations.h:33
#define MA_STORAGE_KEY_MQTT_SSL
Definition: ma_definations.h:40
#define MA_STORAGE_KEY_MQTT_USER
Definition: ma_definations.h:34
#define MA_STORAGE_KEY_MQTT_HOST
Definition: ma_definations.h:31
#define MA_STORAGE_KEY_MQTT_PUB_QOS
Definition: ma_definations.h:37
#define MA_STORAGE_KEY_MQTT_SUB_QOS
Definition: ma_definations.h:39
@ MA_MSG_TYPE_RESP
Definition: ma_types.h:252
ma_err_t
Definition: ma_types.h:21
@ MA_OK
Definition: ma_types.h:23
@ MA_EINVAL
Definition: ma_types.h:28
#define MA_AT_API_VERSION
Definition: ma_version.h:8
Definition: algorithm.hpp:11
void configureMqttPubsub(const std::vector< std::string > &argv, Transport &transport, Encoder &encoder)
Definition: mqtt.hpp:44
void getMqttSta(const std::vector< std::string > &argv, Transport &transport, Encoder &encoder)
Definition: mqtt.hpp:73
void getMqttCA(const std::vector< std::string > &argv, Transport &transport, Encoder &encoder)
Definition: mqtt.hpp:209
void configureMqttServer(const std::vector< std::string > &argv, Transport &transport, Encoder &encoder)
Definition: mqtt.hpp:104
void getMqttPubsub(const std::vector< std::string > &argv, Transport &transport, Encoder &encoder)
Definition: mqtt.hpp:26
void configureMqttCA(const std::vector< std::string > &argv, Transport &transport, Encoder &encoder)
Definition: mqtt.hpp:186
void getMqttConfig(const std::vector< std::string > &argv, Transport &transport, Encoder &encoder)
Definition: mqtt.hpp:161
ma_err_t base64_encode(const unsigned char *in, int in_len, char *out, int *out_len)
Definition: ma_base64.cpp:41
std::string base64_decode(const std::string &in)
Definition: ma_base64.cpp:20
#define static_resource
Definition: resource.hpp:64
Definition: ma_types.h:314
char username[128]
Definition: ma_types.h:318
int16_t port
Definition: ma_types.h:316
int8_t use_ssl
Definition: ma_types.h:320
char client_id[128]
Definition: ma_types.h:317
char password[256]
Definition: ma_types.h:319
char host[128]
Definition: ma_types.h:315
Definition: ma_types.h:323
char sub_topic[128]
Definition: ma_types.h:325
char pub_topic[128]
Definition: ma_types.h:324
int8_t sub_qos
Definition: ma_types.h:327
int8_t pub_qos
Definition: ma_types.h:326