-
Notifications
You must be signed in to change notification settings - Fork 23
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
Refactor of the Fsm to be more modular (component based) + various improvments #60
base: master
Are you sure you want to change the base?
Conversation
* changed ICACHE_RAM_ATTR to IRAM_ATTR to remove a warning * fix an issue with the previous submit * WIP * move all the entry/exit logic into the states * ready for the first test * rename BaseFsmState to FsmSTate * renamed a bunch of things * some more renaming * add debug config * First coffee with the new FSM! * removed a bunch of commented code * removed a couple of useless files * Renamed Fsm folder * more renaming * Rename FsmWithComponent into ModularFsm * Move the setup of the fsm into a dedicated class * improved a comment * First test with the command component * fixed an issue with a recursive loop * introduce a separation between pending an processed commands * Fixed the brew full cycle * Reduces the time spent in brewing states when caming from a command * plugged back input buttons * first iteration on the progam cup switch * forgot to initialize the pin * Connected the input button with the program switch in HA * moved pin initialization into their respective components * some work on the buzzer * backup before testing the new led probe * Poc of a LedObserver working only with interrupt * did some melody tweaking + added a led state sensor * Move the senseoLed to a dedicated folder + rewrote the interface * Switch back to the regular SenseoLed * Moved the pin setup into their components * removed obsolete code * bump homie version to a more recent CL * Move all the advertising stuff before the setup * test for addon auto detection * constant tweaking for the new pcb design * some more constants tweaking * Add led burst functionality * ledState property is now correctly initialized to LedUnknown * This should fix the issue of the LedObserver being stuck in LedUnknown state * Moved all the usage of the cupComponent into the FSM + new input button patern * remove commented code * code clean up * removed an useless if * CupComponent clean up * reformating + plug the reset button * some more formating * some more formating * some more formating * Did some renaming * Made the standard LedObserver "thread safe" --------- Co-authored-by: Pierre Gironde <[email protected]>
Sorry, I didn't meant to update this PR with my huge refacto, I wanted to create a new one instead. Since I don't now how to revert that, I'll update the description of this one. |
@ThomDietrich sorry to poke you here, did you get a chance to take a look at my PR? |
Hey! This is huge. Great effort on your side :) Of course I am interested in your improvements and fixes (EzBuzzer, the bugs you found, etc) but I certainly would want to understand everything. In the next couple of weeks I am going to hack a newer Senseo and will likewise have to change a few parts of the overall logic. While at it, I will take your fork for a testrun :) Even though cool and lucrative for many, I will not have the time nor the urgent need to look into your hacked buttons. Long story short: You should continue to maintain your branch! I will have a look at this PR in a couple of weeks, let's stay in touch :) |
Great, let me know if you need some help to wrap your head around it. But you'll see, it's not that more complicated, it certainly add a lot of files, but I don't think it add a lot of code and it might even make your life easier for your new Senseo. Or maybe I'm not objective because I'm used to that kind of component paterns :) |
And I thought my degree of objects and two cascaded fsm would already make someone "used to component patterns" happy :D Jup, will let you know as soon as I am at it ;) |
when i upload your fork and i enable home assistant discovery, the esp reboots. After that i get config.json error? If i leave autodicovery disabled the esp works just fine. Im a doing something wrong? thanx in advance |
Hi, mine is working like a charm for a few months now, and I just check that forgot any commit on my computer, so I don't see why it's not working for you :-/ Any log or message that could be useful before the reboot? Ha Autodiscovery require AsyncMQTTClient 0.9.0 to work, but if you didn't change anything, you should have it. You should look for "marvinroger/AsyncMqttClient @ ^0.9.0" in your platformio.ini file just in case it's missing. The only difference between autodiscovery enable or disable should be the call to publishHomeAssistandDiscoveryConfig(). You can try to comment things out to pinpoint the faulty line. I'm just realizing you must be using Thom PCB without the customizable button since I didn't share mine :-/ And I didn't test my fork without the add-on for quite a while now. I'll try to re read the code with that in mind to see if I can catch anything obvious. Also, are you using the cup detector and the buzzer? |
Hello Pierre, i uploaded your fork to test again, when i configer everything the esp reboots en connects to the wifi. When i watch my broker the senseo topic gets updated but not for all sensors. The status of the senseo $state keeps at INIT, it never get to ready. can you help me with this? |
Sorry, without any logs or any more informations, I have no clue on what could be going on your side :-/ |
Hello Pierre, this is my log when connected to the pc, i also added the overview of the mqtt broker. so as you can see it looks like mqtt is working because some topics get populated but still the log says Sending initial information and never gets past that message.
|
Are you confortable enough with C++ to add a few logs? If so, could you add a bunch of "Serial.println("some unique string to identify this log");" in SenseoWifi.cpp:
Which version of the PCB are using? Which "option" did you choose. Did you have a buzzer? A cup detector? A reset Button wired to D4? Did you used my version of the PCB with the customizable button add-on? Are you sync to latest on my forks? (and NOT on the old branch within it). |
Hello Pierre, thanx for your message, iam not very confortable with C++ so i shall see of i can add some logging. today i was looking around in your programming and i found some strange behavour. mqtt topics get populated until PendingCommands so i though let i comment out that rule. after a flash i got some sort of bootloop so i checked the programming again. after i comment out the next 3 lines the senseo boots and functions.
so i think there is the problem, PendingCommands and processedCommands are nowhere declaired so is it still in use? i shall check this weekend if i can add some Serial.printIn to the programming so we can see what kind of errors i got. Thanx in advance and have a nice weekend. |
Yes, I noticed that as well, that's why I asked some extra logs around those lines :) We'll see what the logs will tell us, but my bet would be that the program is stuck either inside advertise("pendingCommands") or advertise("processedCommands"). On a totally different idea, can you try to comment all those lines in setup() ?
When I don't detect the CustomizableButtonsAddon (like in your case), I configure D4 to be used as the resetButtonPin, since you don't have one it might introduce weird behavior. I honestly don't bet too much on that since we would most likely see the reboot in the logs, but it could worse a try. Another interesting test to do would be to try @ThomDietrich repo instead of my branch to see if the issue is only present on my fork or if it might be something with your PCB. Have a nice weekend too! |
Hi Pierre i did this but no logs are shown, can you tell me if i did it correct?
|
Yes, that look right, if it pass the compilation it should work. Did you put any other Serial.println, like at the beginning of the function or did you start just by those? |
@ThomDietrich , sorry for all the noise here, maybe it's better if we move the conversation into an issue directly on my forks. |
hello Pierre, let move it to your fork, can you create an issue? the option is not available at your fork |
I think I just activated the option, can you try? |
Hey!
So this is the result of my last weeks of work. It's kind of a huge refactor, so let me know if you accept that as a PR or if you'd rather have me stay in my fork. I'll try to describe here the most noticeable change.
SenseoWifi.cpp has been slim down and now mostly handle setup and Homie things like Mqtt handlers. Among the most noticeable things :
The folder SenseoFsm contain all the states logic which is basically the same as before.
You'll find in that folder a component folder. Each of them represents a different functionality of the Senseo, like the Buzzer or the CupDetector. You should recognize your code inside most of them. The nice thing is that most of them are totally optional. If you don't have a Buzzer, just don't add the BuzzerComponent when you create the Fsm :)
Regarding the LedObserver :
I change all the formatting to something more VScode compliant. At first I tried to comply with the previous formatting but then I realize that it was most likely because your project started with the Arduino Ide and that it didn't make much sense with a modern IDE. Hope it wasn't a mistake...
In terms of pure features, here is what you can expect (line in bold require the CustomizableButtonAddon) :
All that is quite fresh and would probably require a few weeks of testing to be sure everyting is smooth