add MQTT and OTA update support #1

Open
burned42 wants to merge 6 commits from add_mqtt into main
2 changed files with 11 additions and 5 deletions
Showing only changes of commit 165540c120 - Show all commits

View File

@ -19,6 +19,7 @@ static SocketServer socketServer;
#define AIO_SERVERPORT credentials::mqtt_port
#define AIO_USERNAME credentials::mqtt_username.c_str()
#define AIO_KEY credentials::mqtt_password.c_str()
fmueller marked this conversation as resolved Outdated

Please add a blank line above.

Please add a blank line above.

done 👍

done 👍
WiFiClient client;
Adafruit_MQTT_Client mqtt(&client, AIO_SERVER, AIO_SERVERPORT, AIO_USERNAME, AIO_KEY);
Adafruit_MQTT_Subscribe mqtt_subscribe_topic = Adafruit_MQTT_Subscribe(&mqtt, "homeassistant/marquee_sign/text");
@ -90,7 +91,8 @@ void MQTT_connect() {
}
uint8_t retries = 6;
Review

I'd highly appreciate if you'd avoid the use of inline comments.

I'd highly appreciate if you'd avoid the use of inline comments.
Review

I think I copied the whole function from some code in an example of one of the libraries. Feel free to adjust to your prefered code style.

I think I copied the whole function from some code in an example of one of the libraries. Feel free to adjust to your prefered code style.
Review

Will do. I'll also test the USB flashing locally.

Will do. I'll also test the USB flashing locally.
while ((ret = mqtt.connect()) != 0) { // connect will return 0 for connected
// connect will return 0 for connected
while ((ret = mqtt.connect()) != 0) {
mqtt.disconnect();
// wait 10s till next try
fmueller marked this conversation as resolved Outdated

A chance to flash it while it's in the back-off? I'd appreciate a comment explaining this line.

A chance to flash it while it's in the back-off? I'd appreciate a comment explaining this line.

see above, I copied this from an example from one of the used libraries

see above, I copied this from an example from one of the used libraries

View File

@ -287,7 +287,8 @@ String convertToCP437(const String& input) {
if ((ch & 0xF0) == 0xE0) {
if (i + 2 < len) {
uint32_t utf8_char = ((uint8_t)input[i] << 16) | ((uint8_t)input[i + 1] << 8) | (uint8_t)input[i + 2];
i += 2; // skip 2 additional bytes
// skip 2 additional bytes
i += 2;
if (cp437_map.find(utf8_char) != cp437_map.end()) {
output += static_cast<char>(cp437_map[utf8_char]);
continue;
@ -298,7 +299,8 @@ String convertToCP437(const String& input) {
else if ((ch & 0xE0) == 0xC0) {
if (i + 1 < len) {
uint16_t utf8_char = ((uint8_t)input[i] << 8) | (uint8_t)input[i + 1];
i++; // skip second byte
// skip second byte
i++;
if (cp437_map.find(utf8_char) != cp437_map.end()) {
output += static_cast<char>(cp437_map[utf8_char]);
continue;
@ -306,11 +308,13 @@ String convertToCP437(const String& input) {
}
}
// single UTF-16 character (or plain ANSI character)
else if ((uint8_t)ch < 0x80) { // keep ASCII as is
else if ((uint8_t)ch < 0x80) {
// keep ASCII as is
output += ch;
}
else {
uint16_t utf16_char = (uint8_t)ch; // UTF-16 range
uint16_t utf16_char = (uint8_t)ch;
// check if character is in UTF-16 range, fallback to ?
if (cp437_map.find(utf16_char) != cp437_map.end()) {
output += static_cast<char>(cp437_map[utf16_char]);
} else {