Ferraris_MQTT_Energy_Counter_Meter_TCRT5000 icon indicating copy to clipboard operation
Ferraris_MQTT_Energy_Counter_Meter_TCRT5000 copied to clipboard

Refactor for more flexibility

Open ss89 opened this issue 2 years ago • 3 comments

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?

ss89 avatar Oct 16 '22 15:10 ss89

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 ?

Eisbaeeer avatar Oct 17 '22 06:10 Eisbaeeer

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 🙈

ss89 avatar Oct 17 '22 16:10 ss89

I started with refactoring, progress can be followed here: https://github.com/EtlamGit/Ferraris_MQTT_Energy_Counter_Meter_TCRT5000/tree/refactoring-2023

  1. move code into multiple files
  2. en-capsule a single Ferraris meter into own class
  3. -> enable easy change of number of Ferraris meters

Selection will be at compile time as IOT Framework does not allow dynamic web pages.

EtlamGit avatar Jan 22 '23 09:01 EtlamGit