Ferraris_MQTT_Energy_Counter_Meter_TCRT5000
Ferraris_MQTT_Energy_Counter_Meter_TCRT5000 copied to clipboard
Refactor for more flexibility
Currently for each new meter we want to add, we do need to add a lot of code.
This should be more flexible in my opinion, as in the easiest case i should only have to raise the number of meters and recompile my firmware (maybe not even that?). Depending on the setup of the pins, we'd have to predefine all possible meter to pin configurations.
If we ignore the most flexible way, then i could think of some pre-compiler stuff and we'd be good.
Maybe there is an even smarter way, that doesn't even need pre-compiler magic?
The framework allow flexible pin definitions. Perhaps we can define the pin definitions by dropdown selection. The project starts with one meter. The additional meters where requested by users. Actually there was no user with more the 4 requested. I don´t know if there is a user with >4 ?
I've seen the history of the project (at least from the iobroker forum entries) and i saw that someone requested 7 meters (which i think should be possible?) here: https://forum.iobroker.net/topic/35404/ferraris-z%C3%A4hler-mit-tcrt5000-und-esp8266/17?_=1666024770196&lang=de If i see the wiring correctly, then i only need to connect all modules to the same ground and have the digital pin go to an individual pin on the board. For the wemos d1 mini that'd be 9 digital pins => 9 potential meters i could read. Am i wrong?
I guess a dropdown allows the configuration to be as flexible for the user as possible, i don't know if there is any input validation on the web stuff though. Yet another construction site that i haven't digged into too much 🙈
I started with refactoring, progress can be followed here: https://github.com/EtlamGit/Ferraris_MQTT_Energy_Counter_Meter_TCRT5000/tree/refactoring-2023
- move code into multiple files
- en-capsule a single Ferraris meter into own class
- -> enable easy change of number of Ferraris meters
Selection will be at compile time as IOT Framework does not allow dynamic web pages.