51 lines
1.5 KiB
C
51 lines
1.5 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 *message;
|
|
uint16_t length;
|
|
mqtt_message_type type;
|
|
} mqtt_message_t;
|
|
|
|
typedef struct {
|
|
uint8_t ip[4];
|
|
uint32_t port;
|
|
uint32_t localPort;
|
|
uint8_t *client_id;
|
|
uint8_t *topic_name;
|
|
uint8_t qos_level;
|
|
uint8_t *username;
|
|
uint8_t *password;
|
|
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, mqtt_message_t *message);
|
|
LOCAL uint8_t ICACHE_FLASH_ATTR mqtt_connect(mqtt_session_t *session);
|