Here I'm with a suggestion on how the code could be improved or functionality can be added to your code. I thought of using a single MQTT publish topic and publish all the data in json format to that. Instead of using 3 topics. That way configuring can be a bit more easy. I have already something set up. The idea is using global variables, instead of passing everything data related as a parameter to the specific functions. You would need to define those variables tho. So, for example.
/******************************** MQTT TOPIC(s) change these to your liking *******************************/
#define mqtt_topic "/peopleCounter/" // one publisher topic
/******************************** VARIABLES FOR 'CARRYING' THE DATA *******************************/
String Passage_Event;
uint16_t Distance;
int LocalPeopleCount;
The general publish function can something like this.
The data first gets formatted into a json before it gets published to the MQTT server.
Then after an entry (peoplecounter.ino line 295) you can add these lines to publish the data.
if ((PathTrack[1] == 1) && (PathTrack[2] == 3) && (PathTrack[3] == 2)) {
// this is an entry
Passage_Event = "entry";
LocalPeopleCount++;
publishData();
}
You can use the same method for for the exit event and distance measuring.
And an example of the JSON data can consequently look like this.
Maybe I'm completely wrong and does this change only make things more difficult. Also it depends on how the users use the code of course. Anyway, it's just a suggestion. If it would help I can also share my 'version' of your code, where I did some stuff differently. (Using a cheap aliexpress time of flight sensor which has a different I2C address.)
Hi Andrea,
Here I'm with a suggestion on how the code could be improved or functionality can be added to your code. I thought of using a single MQTT publish topic and publish all the data in json format to that. Instead of using 3 topics. That way configuring can be a bit more easy. I have already something set up. The idea is using global variables, instead of passing everything data related as a parameter to the specific functions. You would need to define those variables tho. So, for example.
The general publish function can something like this.
The data first gets formatted into a json before it gets published to the MQTT server. Then after an entry (peoplecounter.ino line 295) you can add these lines to publish the data.
You can use the same method for for the exit event and distance measuring.
And an example of the JSON data can consequently look like this.
Maybe I'm completely wrong and does this change only make things more difficult. Also it depends on how the users use the code of course. Anyway, it's just a suggestion. If it would help I can also share my 'version' of your code, where I did some stuff differently. (Using a cheap aliexpress time of flight sensor which has a different I2C address.)