fix typos in examples

Fix typos

Signed-off-by: HowJMay <vulxj0j8j8@gmail.com>
This commit is contained in:
HowJMay 2020-05-26 15:19:51 +08:00 committed by Roger Light
parent 0946dc3a8d
commit 40a23981d3
2 changed files with 6 additions and 6 deletions

View File

@ -2,5 +2,5 @@ This is a simple example of the C++ library mosquittopp.
It is a client that subscribes to the topic temperature/celsius which should
have temperature data in text form being published to it. It reads this data as
a Celsius temperature, converts to Farenheit and republishes on
temperature/farenheit.
a Celsius temperature, converts to Fahrenheit and republishes on
temperature/fahrenheit.

View File

@ -28,7 +28,7 @@ void mqtt_tempconv::on_connect(int rc)
void mqtt_tempconv::on_message(const struct mosquitto_message *message)
{
double temp_celsius, temp_farenheit;
double temp_celsius, temp_fahrenheit;
char buf[51];
if(!strcmp(message->topic, "temperature/celsius")){
@ -36,9 +36,9 @@ void mqtt_tempconv::on_message(const struct mosquitto_message *message)
/* Copy N-1 bytes to ensure always 0 terminated. */
memcpy(buf, message->payload, 50*sizeof(char));
temp_celsius = atof(buf);
temp_farenheit = temp_celsius*9.0/5.0 + 32.0;
snprintf(buf, 50, "%f", temp_farenheit);
publish(NULL, "temperature/farenheit", strlen(buf), buf);
temp_fahrenheit = temp_celsius*9.0/5.0 + 32.0;
snprintf(buf, 50, "%f", temp_fahrenheit);
publish(NULL, "temperature/fahrenheit", strlen(buf), buf);
}
}