Commit graph

16 commits

Author SHA1 Message Date
a84326db7f
Re-formatted code and made some small changes to behaviour.
At some point this repo might get updated to MQTT v5. I have to
carefully read the standard and see what has changed.
2024-05-06 08:02:52 -04:00
7c5dfae57b
Updated formatting with astyle -A14 -S
Signed-off-by: A.M. Rowsell <amrowsell@frozenelectronics.ca>
2019-03-04 12:58:17 -05:00
8acff6e880
Updated to v0.3.1
Renamed mqtt_send to mqttSend to better follow my usual naming
convention. Made a few other small changes, including disabling
the debug macro by default. Just uncomment to add it again.

This is the version that will be used with the first release
of Part 3 of the SDK tutorials on hackaday.io.

Signed-off-by: A.M. Rowsell <amrowsell@frozenelectronics.ca>
2019-02-27 02:28:00 -05:00
627df20e53
Squashed commit of the following:
commit a4632bb7ad
Author: A.M. Rowsell <amrowsell@frozenelectronics.ca>
Date:   Mon Jan 21 20:13:12 2019 -0500

    Sanitizing key and wifi

    Signed-off-by: A.M. Rowsell <amrowsell@frozenelectronics.ca>

commit 5e3be0f561
Author: A.M. Rowsell <amrowsell@frozenelectronics.ca>
Date:   Mon Jan 21 19:53:42 2019 -0500

    It's alive! New code all working.

    The OneWire library works. It's a bit hacked together, as neither
    the software timer or hardware timer APIs would have worked well,
    because they are implemented terribly by Espressif. The easiest
    way to get around this was to just use system_get_time() and work
    off of that for timing in one-wire comms.

    Split the publish function into two separate functions: one to
    publish floating point numbers, and one to publish integers. In
    a language like Lua or C++ you could have these as one function,
    but in C it's easier to just split them.

    The main.c has a new function called dataLog that deals with
    getting the DS18B20 data and then handing that off to pubfloat().

    I updated the timer names to be more descriptive.

    I grabbed some code to convert integers and floats to strings, as
    I can't be bothered to write that code myself for the millionth
    time.

    If something goes wrong and we are disconnected from our TCP
    connection, all timers are halted so we don't blindly keep
    trying to send packets over a non-existent link.

    Unfortunately the onewire library is hardcoded to use pin 5.
    That will be the next update.

    Signed-off-by: A.M. Rowsell <amrowsell@frozenelectronics.ca>

commit 48702bf328
Author: A.M. Rowsell <amrowsell@frozenelectronics.ca>
Date:   Sun Jan 20 21:13:04 2019 -0500

    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>

commit 1cd8191682
Author: A.M. Rowsell <amrowsell@frozenelectronics.ca>
Date:   Sat Jan 19 15:25:44 2019 -0500

    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>

Signed-off-by: A.M. Rowsell <amrowsell@frozenelectronics.ca>
2019-01-21 20:14:09 -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