-
-
Notifications
You must be signed in to change notification settings - Fork 42
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
How to read 1byte data? #118
Comments
0C is 12 in decimal. Could that be the correct temperature? How you print it in your Serial monitor is in your code. If you share the code, I can assist. |
Yes, it is correct. 12 degrees. My code is almost the same as your example
The second question: is this a normal output? A lot of
|
So the response is correct. It comes down to matching the response to the right output formatting. You could distinguish by datapoint name or by datapoint address: void onResponse(const VitoWiFi::PacketVS2& response, const VitoWiFi::Datapoint& request) {
// raw data can be accessed through the 'response' argument
Serial.print("Raw data received:");
const uint8_t* data = response.data();
for (uint8_t i = 0; i < response.dataLength(); ++i) {
Serial.printf(" %02x", data[i]);
}
Serial.print("\n");
// Now we have different methods of printing the value.
Serial.printf("%s: ", request.name());
if (request.address() == 0x2306) { // you might want to include all relevant addresses here?
Serial.printf("%u\n", response.data()[0]);
return;
}
if (request.converter() == VitoWiFi::div10) {
float value = request.decode(response);
Serial.printf("%.1f\n", value);
return;
}
if (request.converter() == VitoWiFi::noconv) {
float value = request.decode(response);
// alternatively, we can just cast response.data()[0] to bool
//Serial.printf("%s\n", value);
Serial.printf("%f\n", value);
return;
}
} |
@bertmelis, thanks alot. I will try this soon. |
Alternatively, you define the datapoints outside the array. Then you create an array of pointers to the datapoints. VitoWiFi::Datapoint T0("T0", 0x5525, 2, VitoWiFi::div10);
VitoWiFi::Datapoint T1("T1", 0x0810, 2, VitoWiFi::div10);
VitoWiFi::Datapoint T2_A1M1("T2 A1M1", 0x2306, 1, VitoWiFi::noconv);
VitoWiFi::Datapoint* datapoints[] = {
T0, T1, T2
}; Then you have to dereference the pointer when reading/writing the datapoint: vitoWiFi.read(datapoints[datapointIndex])
// becomes
vitoWiFi.read(*datapoints[datapointIndex]) In the callback you can check using pointer/address equality. if (&request == &T0 ||
&request == &T1) {
// div10 conversion, display float
} else if (&request == & T2_A1M1) {
// noconv, display int
}
|
@bertmelis thank you for support, I was able to read 1byte data. Do I need to change something in following code to write data?
|
Consult the table in the README: https://github.com/bertmelis/VitoWiFi?tab=readme-ov-file#conversion-types A 1-byte noconv datapoint can be written to by using an So in your code snippet, |
Installation specifics
Symptom
Thank you for your project!
I'm making first steps with VitoWiFi v3 based on project's examples.
I was able to read 2byte temperature - VitoWiFi::Datapoint("T1", 0x0810, 2, VitoWiFi::div10)
Output was
Raw data received: a2 01
T1: 41.8
But I wasn't able to read 1byte temperature. I tryed different conversion types, but without success.
VitoWiFi::Datapoint("T2", 0x2306, 1, VitoWiFi::div10)
Output was
Raw data received: 0c
T2: 1.2
VitoWiFi::Datapoint("T2", 0x2306, 1, VitoWiFi::noconv)
Output was
Raw data received: 0c
T2: ON
Can you please edvise how to read and write 1byte data?
The text was updated successfully, but these errors were encountered: