• Skip to main content
  • Skip to primary sidebar

RNTLab.com

The Ultimate Shortcut to Learn Electronics and Programming with Open Source Hardware and Software

  • Courses
  • Forum
    • Forum
    • Ask Question
  • Shop
  • Account
  • Blog
  • Login

client.publish error

Q&A Forum › Category: ESP8266 › client.publish error
0 Vote Up Vote Down
Nadav Madar asked 9 years ago

Hi
I’m using DS18B20 temperature sensor.
My goal is to read the sensor data and publish it using client.publish command.
char temperature = sensors.getTempCByIndex(0);
client.publish(“home/storage/esp1/tsensor1”, temperature);
the compilation failed with error code: “Storage1:147: error: no matching function for call to ‘PubSubClient::publish(const char [27], float&)'”
Please help!

Question Tags: client.publish
1 Answers
0 Vote Up Vote Down
Nadav Madar answered 9 years ago

Solved thanks to Gertjan Assies. Looks like the getTempCBYIndex returns a float, while the PubSubClient wants something else (a string probably)
Use this command to convert float to string: dtostrf(tempC, 2, 2, temperatureCString);
where tempC is the value you get from the sensor, and temperatureCString a char[6] where the string value is stored, the numbers are the decimals before and after the comma, but not sure about the latter

Primary Sidebar

Login to Ask or Answer Questions

This Forum is private and it’s only available for members enrolled in our Courses.

Login »

Latest Course Updates

  • [New Edition] Build ESP32-CAM Projects eBook – 2nd Edition April 16, 2025
  • [eBook Updated] Learn ESP32 with Arduino IDE eBook – Version 3.2 April 16, 2025

You must be logged in to view this content.

Contact Support - Refunds - Privacy - Terms - MakerAdvisor.com - Member Login

Copyright © 2013-2025 · RandomNerdTutorials.com · All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.