Fixed the bug in PUBLISH. Tested with Adafruit IO and data
can be published successfully! This was the original goal of
this project -- being able to blindly fire values at Adafruit
and not having to worry about receiving data. However, I've
widened the scope of the project, and want to eventually do a
full MQTT implementation per the spec.
The basic receive functionality looks at what type of message
is receieved, and then prints out basic messages depending on
what the payload is. Mostly useful as a debugging tool, but
it can easily be expanded. This should probably be split out
into its own function at some point.
strtoarr.py: Because of the weird bug that makes passing string
pointers impossible with the ESP8266, strings have to be stored
as hex arrays and then passed as a pointer. This is a pain for
the user, so I've written a basic script which will take two
arguments: the string to be encoded, and the variable name
to be used. It then spits out C code which can be copied
and pasted into the user code. This saves a bunch of time, and
because it spits them out as static const, it also tells the
compiler to store them in flash (as far as I can tell).
As mentioned, it has now been tested with Adafruit IO. There
are a few more functions in the "user" area of the file. These
are only for debugging and will eventually be surrounded with
\#ifdef DEBUG so they won't be included in the compiled version.
Also, more ifdef preprocessor directives have been added so
that debug messages won't be printed to a user's output unless
they want them.
The next step is to implement SUBSCRIBE, and to compile the code
as mqtt.a - a linkable object file.
Publish still has a small bug, but it's unclear if the bug is in
my implementation, or the way Wireshark decodes the MQTT packets.
It seems to miscalculate the length of the data itself; it's not
subtracting the length of the topic name to get the length of the
message, or something along those lines. Further testing will be
needed.
PINGREQ and DISCONNECT are almost identical -- the packets simply
contain the command byte and a 0 for the remaining length. Both
of these have been tested and work perfectly.
Next steps:
Implement subscribe and unsubscribe
Implement events/tasks on receive
Remove testing code, or put in separate branch
Change makefile to create .a (library version that can be linked)
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...
Created a README, as yet incomplete. Added more files to the gitignore
to get rid of emacs temporary files. Currently making the mqtt_send command
independent of connecting, which is all it can do currently.
The code is now pretty messy, as I've just been hacking it
together so far. It's basically hardcoded, so the next steps
will be to parameterise everything. I also need to rethink
the data structures, and function names/structures.
I need to make this feel more like an API to be called by
a user. This will naturally help organize the functions.