Commit graph

14 commits

Author SHA1 Message Date
48702bf328
First version that compiles with new file layout.
Had to make many changes to get it to compile across many files,
including removing the LOCAL specifier from almost all functions.
Edited the Makefile to compile all three files and link them.
Haven't tested on hardware yet, that's the next step.

Lots of small changes to avoid warnings, now that I have turned
-Wall on. This makes the code a bit "better".

Signed-off-by: A.M. Rowsell <amrowsell@frozenelectronics.ca>
2019-01-20 21:13:04 -05:00
1cd8191682
New branch for my new AIO key.
Will have to remember to sanitize before committing to master.

Signed-off-by: A.M. Rowsell <amrowsell@frozenelectronics.ca>
2019-01-19 15:25:44 -05:00
70cf55efdf
Splitting library into own file. Adding onewire.
The mqtt.c file was getting pretty big, so the example code
is now in main.c. Also, we need a onewire library, so I've
started to write on in onewire.c. We will need to make some
changes to the Makefile as well, but I will need to consult
a couple of resources for that.

Signed-off-by: A.M. Rowsell <amrowsell@frozenelectronics.ca>
2019-01-18 23:38:31 -05:00
c8bff5cace
Removed a few lines before release of the tutorial publicly.
Not a huge deal, and they are still in the git history, but
I wanted to make it clear that the SSID and passkey need to
be replaced with the user's own SSID and passkey for their
WIFI. They'd probably be unable to connect to mine!

Signed-off-by: A.M. Rowsell <amrowsell@frozenelectronics.ca>
2019-01-02 18:55:21 -05:00
0692b1776c
Updated doxyfile. Small changes to mqtt.c 2018-12-20 13:37:05 -05:00
cfb041a679
Added Doxyfile. See full log.
Since this is my first "quasi-professional" project that I actually
want others to use, I wanted there to be decent quality documentation
for all the functions and structs that the end user would need to use.
I had tried Doxygen before but never had much luck, mostly because
I didn't bother to put in the effort to read the documentation closely.
So this time around I did, and the output so far looks quite good
and has a lot of detail about the functions, and the two typedef
structs that are key to everything working.

Added code to check if wifi is connected before allowing the TCP
connection to be attempted. Similar code for mqtt_connect, checking
if we have a valid TCP connection to the server. Waiting for
wifi uses a new global timer. These changes affected the indentation
of huge chunks of the code, as they got wrapped in ifs.

We now take advantage of the void *reverse pointer in the espconn
struct to point to the mqtt_session_t that is active. This is a nice
touch that Espressif added, so you can access arbitrary data from
within callbacks. This will allow us to (soon) have user callbacks
to deal with MQTT messages.

Also added license notices to all the source code files.
2018-08-29 02:36:11 -04:00
dee07e5fe7
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>
2018-08-19 02:19:25 -04:00
29306a5699
Implemented basic receive functionality. See full log.
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.
2018-08-18 14:58:03 -04:00
247b772e3e
Completed PUBLISH, PINGREQ and DISCONNECT. See full log.
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)
2018-08-18 06:01:11 -04:00
68755929e6
Started to write PUBLISH. Merging with Master next. 2018-08-18 01:53:12 -04:00
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
cbc182fed4
Started the rewrite of the library on this new branch. See full log.
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.
2018-08-16 14:26:31 -04:00
65d0810b5e
Managed to get our first MQTT connection started!
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.
2018-08-15 00:07:42 -04:00
557188bb38 Initial commit 2018-08-13 23:34:17 -04:00