0

I have a DHT11 sensor connected to a Yún shield, and I am reading data from the sensor using DHT library:

indoorHumidity = dhtBedRom.readHumidity();
// Read temperature as Celsius
indorTempinC = dhtBedRom.readTemperature();
// Read temperature as Fahrenheit
indorTempinF = dhtBedRom.readTemperature(true);
// Compute heat index, Must send in temp in Fahrenheit!
hi = dhtBedRom.computeHeatIndex(indorTempinF, indoorHumidity);
hIinCel = (hi + 40) / 1.8 - 40;
dP = (dewPointFast(indorTempinC, indoorHumidity));
dPF = ((dP * 9) / 5) + 32;

and then I am trying to put the data dew point and temperature, humidity and heat index to BridgeClient key so I can read it in a python program that renders HTML and displays using Python's bottle wsgi framework.

These lines produce errors:

Bridge.put(DEWPNTkey, dP);
Bridge.put(HEADINDXkey, hIinCel);

saying:

no matching function for call to 'SerialBridgeClass::put(String&, float&)'
gre_gor
  • 6,669
  • 9
  • 47
  • 52
Ciasto piekarz
  • 7,853
  • 18
  • 101
  • 197
  • See http://stackoverflow.com/questions/1123201/convert-double-to-string-c . Mixed up the initial question. So the previous link was useless. – MABVT Mar 08 '17 at 07:02

1 Answers1

0

The Bridge.put() method requires a char or a string as its second parameter. So we can use the String constructor to do that.

void setup()
{
  Serial.begin(115200); // To test this make sure your serial monitor's baud matches this, or change this to match your serial monitor's baud rate.

  double floatVal = 1234.2; // The value we want to convert

  // Using String()
  String arduinoString =  String(floatVal, 4); // 4 is the decimal precision

  Serial.print("String(): ");
  Serial.println(arduinoString);

  // You would use arduinoString now in your Bridge.put() method.
  // E.g. Bridge.put("Some Key", arduinoString)
  // 
  // In your case arduinoString would have been dP or hIinCel.

  // In case you need it as a char* at some point
  char strVal[arduinoString.length() + 1]; // +1 for the null terminator.
  arduinoString.toCharArray(strVal, arduinoString.length() + 1);

  Serial.print("String() to char*: ");
  Serial.println(strVal);
}

void loop()
{

}

And we get:

String(): 1234.2000
String() to char*: 1234.2000

Go here to read about the null terminator.

Morgoth
  • 4,935
  • 8
  • 40
  • 66
  • you mean to say I just need to `#include stdli.h"` and use the string module – Ciasto piekarz Mar 08 '17 at 11:19
  • If you haven't removed the Arduino bootloader, then you don't need to include `stdlib.h`. `String()` is already available on the Yún. – Morgoth Mar 08 '17 at 11:40
  • @Morgoth it might be worth mentioning that in case the user needs `const char*` on-the-fly, one can use `strvar.c_str()` instead of creating a `char[]` and what-not – Patrick Trentin Mar 08 '17 at 11:51