mqtt/mqtt.h
A.M. Rowsell bcbcde455a
Rewritten code works! See full log.
After much consternation, finally got the code generalized. For
some reason the ESP8266 absolutely cannot pass pointers between
functions. I'm not sure if this is because it's a timer function?
Either way, we have to memcpy the values, which makes things a
bit messier, but not too bad.

Now to start work on Publish...
2018-08-16 19:11:47 -04:00

61 lines
1.8 KiB
C

#include "user_interface.h"
#include "ets_sys.h"
#include "osapi.h"
#include "espconn.h"
#include "os_type.h"
typedef enum mqtt_message_enum
{
MQTT_MSG_TYPE_CONNECT = 1,
MQTT_MSG_TYPE_CONNACK = 2,
MQTT_MSG_TYPE_PUBLISH = 3,
MQTT_MSG_TYPE_PUBACK = 4,
MQTT_MSG_TYPE_PUBREC = 5,
MQTT_MSG_TYPE_PUBREL = 6,
MQTT_MSG_TYPE_PUBCOMP = 7,
MQTT_MSG_TYPE_SUBSCRIBE = 8,
MQTT_MSG_TYPE_SUBACK = 9,
MQTT_MSG_TYPE_UNSUBSCRIBE = 10,
MQTT_MSG_TYPE_UNSUBACK = 11,
MQTT_MSG_TYPE_PINGREQ = 12,
MQTT_MSG_TYPE_PINGRESP = 13,
MQTT_MSG_TYPE_DISCONNECT = 14
} mqtt_message_type;
typedef struct {
uint8_t *fixedHeader;
uint32_t fixedHeader_len;
uint8_t *varHeader;
uint32_t varHeader_len;
uint8_t *payload;
uint32_t payload_len;
uint32_t length;
mqtt_message_type msgType;
} mqtt_packet_t;
typedef struct {
uint8_t ip[4];
uint32_t port;
uint32_t localPort;
uint8_t *client_id;
uint32_t client_id_len;
uint8_t *topic_name;
uint32_t topic_name_len;
uint8_t qos_level;
uint8_t *username;
uint32_t username_len;
uint8_t *password;
uint32_t password_len;
char valid_connection;
struct espconn *activeConnection;
} mqtt_session_t;
LOCAL uint8_t ICACHE_FLASH_ATTR tcpConnect(void *arg);
LOCAL void ICACHE_FLASH_ATTR disconnected_callback(void *arg);
LOCAL void ICACHE_FLASH_ATTR reconnected_callback(void *arg, sint8 err);
LOCAL void ICACHE_FLASH_ATTR connected_callback(void *arg);
LOCAL void ICACHE_FLASH_ATTR data_recv_callback(void *arg, char *pdata, unsigned short len);
LOCAL void ICACHE_FLASH_ATTR data_sent_callback(void *arg);
LOCAL uint8_t ICACHE_FLASH_ATTR mqtt_send(mqtt_session_t *session, uint8_t *data, uint32_t len, mqtt_message_type msgType);
LOCAL uint8_t ICACHE_FLASH_ATTR mqtt_connect(mqtt_session_t *session, uint8_t *username, uint8_t *password);