add MQTT and OTA update support #1

Open
burned42 wants to merge 6 commits from add_mqtt into main
First-time contributor
No description provided.
burned42 added 1 commit 2024-09-10 20:39:00 +02:00
burned42 added 1 commit 2024-09-10 21:04:32 +02:00
fmueller reviewed 2024-09-10 21:14:48 +02:00
@ -13,10 +13,11 @@ platform = espressif8266
framework = arduino
monitor_speed = 115200
upload_speed = 500000
upload_protocol = espota
Owner

I presume with this change, flashing initially with USB is no longer an option? I.e., this needs to be commented? If so, I'd appreciate a short comment. It's been a really long time since I've used ArduinoOTA.

I presume with this change, flashing initially with USB is no longer an option? I.e., this needs to be commented? If so, I'd appreciate a short comment. It's been a really long time since I've used ArduinoOTA.
Author
First-time contributor

I honestly have no idea. I was happy when I got this working with the platform io thingy.

I honestly have no idea. I was happy when I got this working with the platform io thingy.
platformio.ini Outdated
@ -14,2 +14,4 @@
monitor_speed = 115200
upload_speed = 500000
upload_protocol = espota
upload_port = led-marquee-sign.fablab.local
Owner

Would it be sufficient just to target the mDNS hostname that by default should be led-marquee-sign.local?

Would it be sufficient just to target the mDNS hostname that by default should be `led-marquee-sign.local`?
Author
First-time contributor

IIRC that didn't work when we tried that.

IIRC that didn't work when we tried that.
Author
First-time contributor

Works when using just led-marquee-sign :)

Works when using just `led-marquee-sign` :)
Owner

That is some odd behavior, but then again, if it works... mDNS is pretty standard with these IoT devices nowadays. For example, WLED also advertises a (user-configurable) hostname. Perhaps PlatformIO applies some magic here.

That is some odd behavior, but then again, if it works... mDNS is pretty standard with these IoT devices nowadays. For example, [WLED](https://kno.wled.ge/) also advertises a (user-configurable) hostname. Perhaps PlatformIO applies some magic here.
src/main.cpp Outdated
@ -13,0 +19,4 @@
#define AIO_SERVERPORT credentials::mqtt_port
#define AIO_USERNAME credentials::mqtt_username.c_str()
#define AIO_KEY credentials::mqtt_password.c_str()
WiFiClient client;
Owner

Please add a blank line above.

Please add a blank line above.
Author
First-time contributor

done 👍

done 👍
fmueller marked this conversation as resolved
@ -56,0 +90,4 @@
}
uint8_t retries = 6;
while ((ret = mqtt.connect()) != 0) { // connect will return 0 for connected
Owner

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.
Author
First-time contributor

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.
Owner

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

Will do. I'll also test the USB flashing locally.
src/main.cpp Outdated
@ -56,0 +95,4 @@
// wait 10s till next try
for (int i = 0; i < 10000; i += 5) {
ArduinoOTA.handle();
Owner

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.
Author
First-time contributor

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
fmueller marked this conversation as resolved
@ -56,0 +101,4 @@
retries--;
if (retries == 0) {
ESP.restart();
Owner

Why not restart right away? I mean, sure, it's not quite necessary to do so, but it wouldn't hurt a lot either. Is there some rate limit?

Why not restart right away? I mean, sure, it's not quite necessary to do so, but it wouldn't hurt a lot either. Is there some rate limit?
Author
First-time contributor

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
fmueller marked this conversation as resolved
Owner

Looks pretty solid to me. This is such a niche application anyway...

Looks pretty solid to me. This is such a niche application anyway...
burned42 added 3 commits 2024-10-02 17:59:49 +02:00
Author
First-time contributor

While working on integrating the led sign into homeassistant (using MQTT) and potentially maybe also into our chat, we noticed that setting up https://git.fablab-altmuehlfranken.de/fmueller/led-marquee-sign-client as a separate service seems like a bit overkill and thought it would be nice to integrate it into this codebase.

We had a really hard time getting this to work. With the help of chatgpt I was able to get to this working version which should cover most characters on a german keyboard, except ° and § for which I didn't find a suitable mapping in your existing mapping and the mapping I found in codepage 437 didn't work, so 🤷

While working on integrating the led sign into homeassistant (using MQTT) and potentially maybe also into our chat, we noticed that setting up https://git.fablab-altmuehlfranken.de/fmueller/led-marquee-sign-client as a separate service seems like a bit overkill and thought it would be nice to integrate it into this codebase. We had a really hard time getting this to work. With the help of chatgpt I was able to get to this working version which should cover most characters on a german keyboard, except ° and § for which I didn't find a suitable mapping in your existing mapping and the mapping I found in codepage 437 didn't work, so 🤷
Owner

The mapping listed in both the Python and C++ code was deduced from the vendor's software which I blackbox reverse engineered with some USB serial converters. It was a tedious, time consuming process, but it's the best data we have. (The software even contained a "simulator" to show which dots would be lit.)

Why use a Windows codepage, though? UTF is the universal standard nowadays.

I'll review the new code ASAP.

The mapping listed in both the Python and C++ code was deduced from the vendor's software which I blackbox reverse engineered with some USB serial converters. It was a tedious, time consuming process, but it's the best data we have. (The software even contained a "simulator" to show which dots would be lit.) Why use a Windows codepage, though? UTF is the universal standard nowadays. I'll review the new code ASAP.
Author
First-time contributor

The mapping listed in both the Python and C++ code was deduced from the vendor's software which I blackbox reverse engineered with some USB serial converters. It was a tedious, time consuming process, but it's the best data we have. (The software even contained a "simulator" to show which dots would be lit.)

Why use a Windows codepage, though? UTF is the universal standard nowadays.

If the led sign would support UTF-8, we wouldn't have to worry about translation shenanigans at all, I guess :D

As written above, this is what chatgpt came up with. I basically told it some example input and output and asked to write the according code for the arduino platform (+3-4 rounds of telling it to fix bugs).

The python code will still work and you can still submit the output of that to the raw http endpoint like before. I didn't change anything on that end.

> The mapping listed in both the Python and C++ code was deduced from the vendor's software which I blackbox reverse engineered with some USB serial converters. It was a tedious, time consuming process, but it's the best data we have. (The software even contained a "simulator" to show which dots would be lit.) > > Why use a Windows codepage, though? UTF is the universal standard nowadays. If the led sign would support UTF-8, we wouldn't have to worry about translation shenanigans at all, I guess :D As written above, this is what chatgpt came up with. I basically told it some example input and output and asked to write the according code for the arduino platform (+3-4 rounds of telling it to fix bugs). The python code will still work and you can still submit the output of that to the raw http endpoint like before. I didn't change anything on that end.
Owner

So you are saying the LED sign's own encoding is close to CP437? I.e., if I send text to the sign that is in CP437 already, it would display most of it?

What I'm confused about is what is the real input format of convertToCP437? Is it UTF-8? Is it UTF-16? Or is it a mixture?

So you are saying the LED sign's own encoding is close to CP437? I.e., if I send text to the sign that is in CP437 already, it would display most of it? What I'm confused about is what is the real input format of `convertToCP437`? Is it UTF-8? Is it UTF-16? Or is it a mixture?
Author
First-time contributor

So you are saying the LED sign's own encoding is close to CP437?

That's what chatgpt guessed and when searching for some of the characters missing in the existing mapping table you added and trying the encoding for CP437, that somewhat seemed to hold true, yes. At least this way I found µ :)

What I'm confused about is what is the real input format of convertToCP437? Is it UTF-8? Is it UTF-16? Or is it a mixture?

I guess it's whatever the string contains you send to the sign, so usually I'd assume UTF-8.

> So you are saying the LED sign's own encoding is close to CP437? That's what chatgpt guessed and when searching for some of the characters missing in the existing mapping table you added and trying the encoding for CP437, that somewhat seemed to hold true, yes. At least this way I found `µ` :) > What I'm confused about is what is the real input format of convertToCP437? Is it UTF-8? Is it UTF-16? Or is it a mixture? I guess it's whatever the string contains you send to the sign, so usually I'd assume UTF-8.
Owner

That would be my assumption, too. At least for Python 3, we can be sure of it. And almost all browsers and terminals use UTF-8, too.

That would be my assumption, too. At least for Python 3, we can be sure of it. And almost all browsers and terminals use UTF-8, too.
burned42 added 1 commit 2024-10-22 19:29:14 +02:00
This pull request can be merged automatically.
You are not authorized to merge this pull request.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin add_mqtt:add_mqtt
git checkout add_mqtt
Sign in to join this conversation.
No reviewers
No Label
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: fmueller/esp8266-led-marquee-sign-controller#1
No description provided.