mqtt/strtoarr.py
A.M. Rowsell 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

32 lines
1.2 KiB
Python
Executable file

#!/usr/bin/env python3
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
##
# @file
# @brief File to create string arrays
#
# This file is included to assist the developer using the API in creating the arrays for the username, password, topic name, and client ID strings. It prints both the array itself as well as a variable with the length of the string. These can then be passed to os_memcpy() to copy the information into the mqtt_session_t.
###############################################
# First argument is the value to be encoded, #
# second argument is the name of the variable #
# to be used. #
###############################################
import sys
import os
inString = str(sys.argv[1]);
print("static const char {0}[{1}] = {{ ".format(sys.argv[2], len(inString)), end='')
for letter in inString[:-1]:
p = ord(letter)
print("{0:#x}, ".format(p), end='')
p = ord(inString[-1])
print("{0:#x} ".format(int(p)), end='')
print("};")
print("static const uint8_t {0}_len = {1};".format(sys.argv[2], len(inString)))