Closed josef2600 closed 1 year ago
i forgot what was the number of issue, but with old code, it wouldn't compile it because of the preferences.putString(PREFERENCES_AUTOMATION, getAutomationsJson());
. then i changed it to my new code and it compiled.
put this in code char my_stringbuffer_[500];
PreferenceHandler.cpp
else if (strcmp(preference, PREFERENCES_AUTOMATION) == 0) { // Note: saving a string instead of bytes. // The struct for AutomationFlash does not seem to work properly with the putBytes. // Need further investigation preferences.putString(PREFERENCES_AUTOMATION, getAutomationsJson());
i changed it (and more!) to this:
getAutomationsJson(); preferences.putBytes(PREFERENCES_AUTOMATION, &my_stringbuffer_, sizeof(my_stringbuffer_)); . . . String PreferenceHandler::getAutomationsJson() { DynamicJsonDocument doc(AUTOMATIONS_JSON_CAPACITY); for (AutomationFlash& a : automations) { if (a.id) { doc.add(serialized(automationToJson(a))); } } // String output; my_stringbuffer_.remove(0); serializeJson(doc, my_stringbuffer_); return my_stringbuffer_; }
for now the only thing i fund is 2 links: https://www.esp32.com/viewtopic.php?t=29383 https://github.com/espressif/esp-idf/issues/9631 so far no solution. i have to check where is it coming from.
i think i found a clue what is what. this project is excellent and works with very little changes, mainly because the library's have been updated and changed some codes. but, the main problem comes from this rep:
https://github.com/me-no-dev/ESPAsyncWebServer
and:
https://github.com/me-no-dev/AsyncTCP
since these are very very old and extremely boggy codes, everything goes bad. and because i don't work with (or like) C++, and it is extremely hard (and for me and many not possible) to convert it to C, the fix is unlikely. everything is bad! from leaking to just bad codes and misscoding, the ram conflicting to just trow out the SPIFFS and many more. it works some times, because usually everyone is using a module with PSRAM. but when i have removed it and changed it to only work with one ram and it is low amount, the leaks and mismanaging the registers, makes the CPU to trow bad Exceptions.
i have tested it with and without using the RTOS too. i ran it without the RTOS and i ran it for 500 times before crash, but the timing is the same. meaning, fast or slow, with or without RTOS in main code (this rap codes with fixes i have said before), in all that, the process works for 1 minute (around it) and crashes. the timing is the same, not how many time this code runs, but how many times the ESPAsyncWebServer
is running.
and the last fix i have to mention is this:
https://github.com/philbowles/ESPAsyncWebServer/issues/3
Change these three lines in WebAuthentication.cpp:
mbedtls_md5_starts(&_ctx);
mbedtls_md5_update(&_ctx, data, len);
mbedtls_md5_finish(&_ctx, _buf);
To:
mbedtls_md5_starts_ret(&_ctx);
mbedtls_md5_update_ret(&_ctx, data, len);
mbedtls_md5_finish_ret(&_ctx, _buf);
i don't know what to do except change everything and began from the beginnings. reason is, i don't work with C++ and the code from C++ cannot be converted to C. there are few instructions in C++ that don't Implements in C. in any case, i have found this repo too. maybe it will help somebody. it didn't help me since it doesn't include all the functions needed. he tried to fix many problems, but didn't do it all. https://github.com/philbowles/h4plugins anyway, if i could help in my specialty, please do ask. i will work on this until i am sure i cant do anything more. goodluck to everyone. best regards, Josef.
Hello @josef2600 Unfortunately you are right, the intent of ESPecial was to learn basics. It was never made for production. I encounter the crashes you described. And found out that it was indeed coming from these libraries. Very difficult to debug. If you have a look to other branches of ESPecial repo, you'll find an attempt of using H4 (the library you are suggesting). I think this is the right way to go, but this would require a full rewrite of ESPecial. I don't have time at the moment for this.
I'll start soon a new esp32 project, and I will for sure follow your advice about C/C++ and I'll go the H4 road as it will give the right tooling without spending too much time on learning.
thank you @RomeHein , i have been working on automation projects for 18 years. i have a patented invention on one. but until 2 years ago, i was always working with PIC (microchip) for them. my last project was around 18 month ago. it was beautiful and wonderful. the only problem was, i used a PIC32MZ2048EFH144 for it. and the price for that thing was 25$ alone! it had a huge PCB and a lot of expensive other parts. including an extra 32MB DDR2 ram on it. in total, the price got to around 90$ just for one board. and the programming for that was enormous! in general, for everyone using, it was too expensive. so i was looking and searching. at least i checked 500 projects from cheap micro to using a PC! and among all of them, the best one that i loved, was yours. your idea was excellent and with a cheap module. the reason i chose the ESP32-C3 is simple. it wasn't the price, but the specs. i chose ESP32-C3FN4
because it can handle temp up to 105 °C. the next best is S3 with internal 2MB internal psram, but only goes up to 85°C. both have 4MB internal flash. i designed my own antenna for them and it is excellent. this is my work:
https://drive.google.com/file/d/1q3-kTbD4nNodlmIjtXle3ac3R4p9MVp4/view?usp=sharing
https://drive.google.com/file/d/1rjRe8KgQiB1MUPzGF67mWDhQ5aRISkvK/view?usp=sharing
ok, back to program. i found that the async lib has a big problem (among 50 more!). as i said, it uses the RTOS, the big big problem with this kind of working is when you use it, you cant know when 2 or more functions are going to clash. for example in this particular work, it is crashing because events.send
are going simultaneously to output. and it is bad! if i was the programmer, the solution would have been simple, but i am not! neither are you. so, i am working on it to go to H4 lib. but it doesn't include all of the parts your project needs. lets see if i can go farther or not!
the thing i am trying to say is, thank you, but if you can, continue your work.
the other thing i am confused about in your code is this:
in file esp32.ino
there are 2 void with the same name, why? am i missing something?
void runAutomation(int id)
and void runAutomation(AutomationFlash& automation)
thank you. best regards, Josef.
void runAutomation(int id) and void runAutomation(AutomationFlash& automation)
This is known as function overloading, which is a feature of the C++ language that allows you to define multiple functions with the same name but different parameter types or numbers. But I guess you are horrified by this type of things 😅 In general, I would say it is good practice to use descriptive function names to avoid confusion when overloading functions, especially if they have similar functionality. So yeah, maybe change the name, but be aware to change the functions accordingly in the code 😉
At the moment I only have classic esp32, but also esp32-s2 for low power projects. I bought these only for the price which is super low, and the form factor super small. I'll go the C3 or S3 road once the price will be lower.
By the way, I have changed the telegram channel to be open for discussion: https://t.me/especial32 You can join there and we can discuss all this ;)
oh man, great! and yes! i was going crazy how is it working!
but i have a fantastic news for you! i will try telegram again, hope works! only there i am going to send you the full work. right now i am so tired i can do anything and as i have already pissed you off(!) i wont send the files here. well, i don't know how!
any way, that fff H4 man! that repo and libs work! i cant believe it! with those libs and few fixes that i already said and 1 more fix, it can run perfectly fine. the last fix is to convert serverhandler->events.send
to a static void
and no hangs, and no leaks any more.
static bool boolmy_events_sendd=0;
static void my_events_sendd(const char *message, const char *event)
{
while (boolmy_events_sendd) vTaskDelay(1); boolmy_events_sendd = 1;
serverhandler->events.send(message, event, millis());
boolmy_events_sendd=0;
}
e.g
my_events_sendd(myeventMessage, "pin");
i have tested it with 2 user and for over 1 hour. just last thing you have to know is this, all this sh%&y chips have problem with USB! again! just dont use them or it will leak so much that memory will blow up! and it freeze too. dont use USB for final work. this is the link:
https://github.com/espressif/arduino-esp32/issues/6089
and thank you. hope we can work more or be friends. i like your mind. it is a rare thing! i assure you! just it takes time to get use to me!
and please, for microcontrollers, any micro, the C++ is a no no no no no!
Guru Meditation Error: Core 0 panic'ed (Load access fault). Exception was unhandled.
now, it runs, works, and suddenly, panics! i setup 3 analog input pins and read them. if the an2 is over 0, it send a massage in serial port (i am using USB inside the chip as serial port). after awhile, it panics, then hangs, then reboot itself.for now i am working on changing strings on air to a global register. again, please when programming for microcontrollers, never use C++ as it is the worst language for it. read a datasheet, any micro from last 25 years that still exist. if they support any high language, it is always C and never C++. there are many reasons for it. eg: what is the difference between array and string? in C, nothing! and that is logic answer. BUT A "C" string:
char *myString = "This is my string";
is an array of characters. It is no different to an "array".
However, a "C++ String Object" is vastly different.
String myString = "This is my string";
That is an entire object with methods and properties which, while it makes programming easier, is not advised when working with microcontrollers. The memory usage when you're not doing much with it is only slightly more than a "C" string. However, a lot of the methods involve the allocation and deallocation (freeing) of memory, which leads to memory fragmentation.
"C" strings take a bit more working with, but the benefits from a memory management point of view are worth the time taken to learn about working with them.