-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Serial] Redirect all Serial.print/println to a buffer #2089
Conversation
This is meant to be used later on to make the rules be executed directly again, not delayed execution by the scheduler. Would be nice if some already can test this part, to make sure I didn't break any plugins actually using the serial port. |
is it possible, that with this PR some logs on the serial port get lost? for instance I don't get any events andymore (eg.
before this PR:
|
just saw, that when I open the web-log viewer I see the events in the web log and also then in the serial log, as long as hte web-log window is open... |
It is possible some logs will not appear, but that will only happen if you're already almost out of memory. |
I do see a serial log, but only the |
What serial log level do you have active? In the sysinfo page you should also see what level is actually active and not just what is set. (web log level is made more dynamic, if no log is being read) |
serial and weblog are both on "info" and in he weblog windoow it tells me also it's on info. also I did not change before and after the update/recompile, so I would assume the serial log should look the same before and after... |
Can you have a look at this piece of the code: Lines 49 to 59 in 85be5b8
Maybe change this: int roomLeft = ESP.getFreeHeap() - 5000;
if (roomLeft > 0) { Into this: int freeHeap = ESP.getFreeHeap();
int roomLeft = freeHeap - 5000;
if (roomLeft > 0) { And then add some |
changed the function to:
now it seems to work again?! I get all log entries and it actually never runs into the |
You cannot add the free heap like this. |
oh, ok, didn't realize.... however it works again and if it would run into the else condition at least it would add a "/" and a newline... which it doesn't.. but I'll change the free heap addition...... tomorrw...... ;) |
@TD-er I'm not sure what's going on here, I reverted the changes (at least the first line) and added (for simplicity) just a '1' as you suggested in the else condition. after recompiling everything still worked on my 2 test nodes. then I removed the so I added the else condition again and now still one node show all events and the other one only uptime and clock (never running into the one more recompile and flash (same code) now I get all events again on both nodes!! I'm really confused now (compiler issues?)... sorry for this... |
one more thing: it seems that sending commands on the serial does also not work anymore. sending a command shows something like (no matter which command):
|
else if (error == OTA_RECEIVE_ERROR) Serial.println(F("Receive Failed")); | ||
else if (error == OTA_END_ERROR) Serial.println(F("End Failed")); | ||
serialPrint(F("\nOTA : Error (will reboot): ")); | ||
if (error == OTA_AUTH_ERROR) serialPrintln(F("Auth Failed")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not use braces here, it can prevent braces mismatch and therefore strange bugs.
Throughout the code I have seen this and it is not used consistent .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, there is not a consistent coding standard used.
For "oneliners" I tend to use the notation you see in your linked lines.
Whenever I am changing code which either has a longer statement in the if-scope, I replace it by adding {}
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi,
I would suggest to always use it. It makes it also more readable in my opinion.
@clumsy-stefan And I tested running commands yesterday via the serial and those I tested just work. How do you add the 1 to the buffer? as |
¡ user Arduino SDK on a Mac.... so It can't be plattformIO related I guess... but it could mean that the cross-compiler has issues... I did it as a
|
Hmm, so if I add a "clean" as step in the platformIO config, it would maybe help to regain stability? |
Hi @TD-er And is it always correct after an clean rebuild? Marc |
@Barracuda09 I agree it may be hiding the real issue, but reality is we cannot do much about it ourselves and the issues have been reported a long time ago. As I heard from the Tasmota people, they recently moved from PlatformIO to Arduino builds for the "automated builds" and now have (more?) reproducible builds. |
@TD-er consider to fill bug in platformio-core/esp8266 maybe this will reveal something what is wrong in build time |
@TD-er |
@uzi18 I am sure I have reported several times on a topic about this, but apparently not on platformio-core issues (or I cannot find it now) @Barracuda09 The build problems are probably related to several issues, but I can describe the symptoms:
All those issues may be gone by simply starting another build on the same project. This last issue may be related to the missing The WiFi issues tend to get worse by the day. It used to be that building the project twice would help the WiFi stability issues. By just building it once, it was at random if the built image would be able to connect to WiFi. That's the reason our build script is building it twice. Recently we have had a lot of watchdog issues and the introduction of the scheduler I made. I still don't know why running commands from outside the scheduler (what used to work just fine before I added the scheduler) is causing resets. On my own nodes it seems to be working just fine when I tried it, but on builds made by others it is crashing. So either we hit some kind of limit and are the resets just a matter of some stack overflow or something else which makes perfect sense. Like I said, Tasmota has recently stopped building the automated builds using PlatformIO and I am looking into how to make Arduino-based builds and still use the PlatformIO.ini configs to make sure if someone is building it in PIO, it will at least use the same settings. |
I am not familiar with how the settings are stored, but is it just storing the struct 'as is' and casting it back when it is red? I expect you did not update PIO, as to say recently, that you have these issues your self? If not that should rule out an problem in PIO at the moment. So an "problem" in the code could maybe cause PIO to generate wrong binaries? |
@TD-er good compilation of the issues currently around... .unfortunately I think that switching to Arduino SDK does not necessarily improve things. I use Arduiono SDK from the start when I did my own builds and, as seen today with this PR, it seems to have similar issues (eg. code running different when compiling multiple times).... however I'm happy to provide any help, support, testing, whatever, just let me know... |
@Barracuda09 Indeed the settings are stored "as is", meaning we simply dump the data starting at the address of the struct and continue for And the instability between builds is without update of platformIO inbetween. There simply aren't that many updates on PlatformIO ;) @clumsy-stefan Good to know Arduino environment (not just the SDK, but the way of building like Arduino IDE does) may not be the holy grail either. |
Ok so the storing of settings is indeed an tricky think. And indeed an potential problem when something or someone is changing the struct at any point. So the build problem is something that is feed into PIO that now makes it produce wrong builds. Maybe increase the warnings to see if it finds anything? |
We have had some checksum in the settings a while ago, but that caused also issues, since its implementation demanded the checksum to be located at the end of the file. |
Well at least an 'plain' struct should not get reorder, only padding is allowed. But indeed an more robust system would be an good idea. But that should be consistent between build as you did not change PIO, so that makes me believe that some code "complexity" (large files?) makes PIO now produce wrong builds. |
Indeed. And that's what is worrying me a lot. I've been programming long enough to know that any time I was thinking "it must be some compiler issue", in the end I was (almost) always wrong. But this time I am really out of options on what may cause these issues so I tend to believe the tools simply contain a bug. |
Yes, that is an bug in PIO no question about that. If it seems to be able to produce correct working builds. Now what triggers this bug at this point in PIO. Something in the code or libs or file sizes. |
That's a lot of green lines with timings of over 2 seconds. |
It is local network (192.168.1.x), so please try to set the Client Timeout to something like 200 or 300 msec. Edit: Also I got the feeling MQTT is a bit more lightweight to the ESP, compared to a HTTP connection. |
Will do Gijs. |
Welterusten :) |
What was the reboot reason for the last one? Exception or software/hardware watchdog? |
And that one is still using 1000 msec timeout in the controller? |
And the timings on that one? |
what happens if |
@clumsy-stefan Then no other call can be made. So GPIO events will be missed also, unless they have an interrupt attached to them. |
so, also background/core tasks (like handling WiFi) will be blocked then? |
The call to our own function could still be done, depending on what is causing the delay. |
Feedback: Both experience resets, reported as Manual Reboot, Hardware Watchdog. The resets do not occur at the same time. From what I can see the reset occurrences seem about the same with this PR. But I've only been running it for about a day, so it's too soon to know for sure.
|
seem like serial server is borken in later builds. tried ESPEasy_mega-20181129. no working serial data via netcat. (no blinking on port). (serial logging turned off) blinking leds for tx and rx on rs232 shield |
Is 20181004 the last one to work? |
Running ESP_Easy_mega-20181128_normal_ESP8266_4096.bin and checked 2# Wemos D1 units: |
There are so many causes for HW watchdog, and the serial port writing is now one of them we can check of the list (except for plugins actually writing to that port like Nextion plugin) Also @xztraz reported about the Serial2Net plugin. I really want to know the last version it was working. |
@TD-er Ser2net bug doesn't seem to have to do with this merge. its from earlier. weird @Domosapiens got it to work thou.. 20181129-normal - no lights 20181030-normal <- Here stuff seems to get broken 20181029-normal - ok
|
These were the differences: mega-20181029...mega-20181030 |
Could you also try the build image with core 2.4.1 in its name? ("normal_core_241_ESP8266_4096") |
ESP_Easy_mega-20181129_normal_core_241_ESP8266_4096 works. so the new core seem to introduce something. |
So at least you now have a work-around for this. |
Writing data to the serial port while it is not being read may cause all kinds of issues and maybe even Watchdog Resets.
All
Serial.print
andSerial.println
calls in our own code is now sent to a dynamic buffer.This buffer will try to only send data to the serial port when its buffer permits it.
After a while, unread data will be dropped.