-
Notifications
You must be signed in to change notification settings - Fork 4
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
Multiple PZEM example - Single Variable Compile Error #7
Comments
Hi @Petros144, what kind of compile error do you get? As for getting integer values you can do like this
mind that integer values are given in the way that PZEM sends it, i.e. voltage is in decivolts, not volts, current is in mA. |
I will update example with more detailed code like the one above. |
Thank you for the fast reply! this will help me a lot! I will test this tomorrow. so to get my values of interesst I have to change the getMetrics(id); (id ist not the adress, but the custom ID for one of my PZEMs), correct? So for every Phase I need to implement : const auto metrics =(const pz004::metrics)meters->getMetrics(41) ; // Phase 1 u1 = metrics->voltage; const auto metrics =(const pz004::metrics)meters->getMetrics(42) ; // Phase 2 u2 = metrics->voltage; const auto metrics =(const pz004::metrics)meters->getMetrics(42) ; // Phase 3 u3 = metrics->voltage; |
that is possible but would be incorrect. What callback does it just says "Hey, pzem with this 'id' just updated with fresh data". Also you do not really need to have separate variables void mycallback(uint8_t id, const RX_msg* m){
const auto *metrics =(const pz004::metrics*)meters->getMetrics(id);
Serial.printf("PZEM ID: %u, name: %s, voltage:%u, current:%u, etc...\n", id, meters->getDescr(id), metrics->voltage, metrics->current);
someSendToMQTTFunction("topic\voltage", metrics->voltage);
someSendToMQTTFunction("topic\current", metrics->current);
} but just in case if you do really want to keep your own copy of the data, you'd better use pzem struct for this. // somewhere in main.cpp
pz004::metrics phase1data;
pz004::metrics phase2data;
pz004::metrics phase3data;
void mycallback(uint8_t id, const RX_msg* m){
// copy data to your strucs
if (id == YOUR_PHASE1_ID){
phase1data = meters->getMetrics(id)
return;
}
if (id == YOUR_PHASE2_ID){
phase2data = meters->getMetrics(id)
return;
}
if (id == YOUR_PHASE3_ID){
phase3data = meters->getMetrics(id)
return;
}
}
// in some other function you can get to your copy of the data
void some_other_function(){
// print your data
Serial.printf("Phase 1 device name: %s, voltage:%u, current:%u, etc...\n", meters->getDescr(id), phase1data->voltage, phase1data->current);
Serial.printf("Phase 2 device name: %s, voltage:%u, current:%u, etc...\n", meters->getDescr(id), phase2data->voltage, phase2data->current);
Serial.printf("Phase 3 device name: %s, voltage:%u, current:%u, etc...\n", meters->getDescr(id), phase3data->voltage, phase3data->current);
}
|
Hi @vortigont, thanks for the nice Lib!
Im not a specialist in Programming, so I need to aks some silly questions.
I Use 3x PZEM and they work great with your example code.
pz004::rx_msg_prettyp(m); Gives me the Whole list of Values of the Boards wich is great!
What I need to do is only get Voltages / Currents / Power etc. and write them in custom variables.
I tried this from the main.cpp to get the current from one Sensor:
void mycallback(uint8_t id, const RX_msg* m){
But it wont compile and gives me errors.
I also dont need floats, so raw Integer values would be enough for me.
how do I access the single values within the callback (Raw values & Floats)?
Thanks in advance!
The text was updated successfully, but these errors were encountered: