mistergreen / WAAC

Web-enabled Arduino Aquarium Controller
Other
9 stars 5 forks source link

Handle the events in separate class #19

Open Avilla83 opened 3 years ago

Avilla83 commented 3 years ago

Hi, I am moving all the logic that handles the events in a separate class common to all the classes that use this logic. This should simplify the devices logic and focus on the single functionality. I am doing this to try to have a better understanding of the status of the class (e.g. relay ON vs OFF) and avoid mistakes in the event logic handling.

This logic will be present soon in my fork, what do you think about it?

mistergreen commented 3 years ago

Give it a try. Don't forget that you can assign a dependency on a device. A dependency is looking at the another device's ON/OFF state, like a relay is dependent on a pH sensor.

The messiest part of the web logic part, those long if else statements. Wish I could clean that up somehow.

Avilla83 commented 3 years ago

Hi,

I have the scheduler on my fork (scheduler or master branches). The scheduler is a class called EventHandler and the devices using events are extending it.

I also worked a bit on PWM4 and AdafriutPWM8, AdafruitPWM8 now extends PWM4 and most of its logic is in common. This semplification allowed to have an easier serialization into json, so also PWM4 and AdafruitPWM8 can be stored in memory.

I plan to add storage for remaining classes (some inputs are not being stored), it should not be a big effort. The remaining storage problem is about the dependent devices, I need to figure out how to fix it, probably it is sufficient to change the deviceDelegate to insert devices with a given id. So currently no dependencies between devices is saved in memory.

I tested PWM4 and AdafruitPWM8 only looking at logs, I do not have real PWM controlled devices at the moment.

mistergreen commented 3 years ago

Oh, I thought you were going to make a Event system of dispatcher and observers. I see that separating the Events makes it easier to serialize.

Avilla83 commented 3 years ago

I started with a publish subscribe idea but then I realized I had to do a rationalization of the events logic before. Then the storage on SPIFF part became easier, so now on the configuration_storage branch I added serialization and deserialization to all the devices. This means that all the devices should be recreated at reboot. Now I think to complete the storage stuff by adding the general settings (right now only ip, ntp server and local zone are stored).

I am also thinking to test ESPAsyncWebServer that may give more speed to the html part, also using the two ESP32 cores may be an option.

Avilla83 commented 3 years ago

In my fork now all storage of settings should be done.

Here the changes in my master/configuration_storage (they should be aligned):

Next step I want to try is the ezTime library to allow setting of time zones instead of current time add/subtract. In addition ezTime can mange timed events (like setting alarms at defined time) and this may substitute the current event handling.

Avilla83 commented 3 years ago

Don't mind about my comment on the example JSON file, I uploaded one in the Json folder

mistergreen commented 3 years ago

What do you mean by "Access Point mode'? Do you mean when the ESP32 restarts and tries to recreate the objects from the JSON file?

Avilla83 commented 3 years ago

If the ESP32 does not have the JSON settings file starts as an access point so it does not try to connect to a WiFi network but instead it creates a WiFi network called ESP32-WAAC. At this point the user can connect to the ESP32-WAAC WiFi network, go to http://192.168.4.1 and access to the WACC settings. If the settings are saved then the WAAC tries to connect to the stored WiFi and IP settings.