A simple MQTT library for the ESP8266
Find a file
AMRowsell b10ef4c8c1 Changed license to Mozilla Public License v2.0
All previous commits are licensed under the MIT License.
Commits from this point on are licensed under the Mozille Public License v2.0 as included.
2018-08-18 06:11:39 +00:00
.gitignore Started the rewrite of the library on this new branch. See full log. 2018-08-16 14:26:31 -04:00
LICENSE Changed license to Mozilla Public License v2.0 2018-08-18 06:11:39 +00:00
Makefile Initial commit 2018-08-13 23:34:17 -04:00
mqtt.c Started to write PUBLISH. Merging with Master next. 2018-08-18 01:53:12 -04:00
mqtt.h Rewritten code works! See full log. 2018-08-16 19:11:47 -04:00
README.md Fixed the markdown in README 2018-08-16 19:01:14 +00:00
user_config.h Initial commit 2018-08-13 23:34:17 -04:00

MQTT Library for ESP8266 SDK

written by Alexander Rowsell (MrAureliusR)
Released under the terms of the MIT License -- see LICENSE for more detail.

Summary

While working on a series of tutorials for Hackaday, I realized MQTT would be the perfect solution for one of the projects I was presenting. However, I didn't want to use a pre-existing MQTT library - that would be boring, and I wouldn't be able to teach the readers as much. Instead, I started to write one from scratch.

At this point, it's a bit messy. It still needs a lot of work. This documentation will help me keep everything organized and easy-to-use.

API Structures

  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;```

This is the main structure that contains all the information about the connection to the server. The IP address, port, client\_id, topic\_name, username, and password are all specified here by the end user. localPort is set by the API, and qos\_level should be set to 0. *activeConnection will point to the espconn struct that represents the TCP connection to the server. The end-user shouldn't need to touch anything in this struct.

## API Functions

### `mqtt_connect(mqtt_session_t *session, uint8_t *username, uint8_t *password)`  
This function establishes a TCP connection with the server specified in session->ip, on session->port. Most MQTT brokers listen on port 1883 for unencrypted packets, and on 8883 for TLS connections. This API currently only supports unencrypted packets on 1883. However, the port still needs to be specified, in case you use a non standard port.