Subscribe feature now works. See huge commit log!

Quite a few updates. Subscription feature is now working,
which is great. This has been tested with mosquitto broker
as well as Adafruit IO, and it works perfectly with both.

I tried to compile this project as a library (see the changes
to Makefile) but when I used that .a file in another project
the linking process failed. More research needed, I've never
tried to do that before.

I compressed some of the case statements in mqtt_send as they
are so similar, it's a waste of code space to duplicate them.
Disconnect and ping are identical except for one byte, and
unsubscribe and subscribe differ in only a few lines.

The data receive callback now prints information on what kind
of packet/data was received; again, mostly useful during
debugging, but the framework is there to expand it to do
useful things like triggering other tasks/timers, etc.

There is now a keepalive ping timer which keeps both the MQTT
and thus the TCP connection alive. It currently pings every 5
seconds, though I might change that closer to the timeout
maximum (50 seconds).

Signed-off-by: A.M. Rowsell <amrowsell@frozenelectronics.ca>
This commit is contained in:
A.M. Rowsell 2018-08-19 02:19:25 -04:00
commit dee07e5fe7
Signed by: amr
GPG key ID: 0B6E2D8375CF79A9
3 changed files with 125 additions and 40 deletions

3
mqtt.h
View file

@ -57,5 +57,6 @@ 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 void ICACHE_FLASH_ATTR pingAlive(void *arg);
LOCAL uint8_t ICACHE_FLASH_ATTR *encodeLength(uint32_t trueLength);
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);