Using an ESP8266 (HUZZAH) with a DS3231 RTC. The temperature displays in the serial monitor but I’m unable to figure out how to get it to Cayenne. Tried every combination I could think of. Truly, I don’t have any idea of what I’m doing. Any pointers?
Thanks,
John
ERROR:
In function ‘void loop()’:
RTC_cayenne_min:93: error: cannot convert ‘RtcTemperature’ to ‘float’ in initialization
float currentTemp = (temp);
^
exit status 1
cannot convert ‘RtcTemperature’ to ‘float’ in initialization
Relevant code:
RtcTemperature temp = Rtc.GetTemperature();
Serial.print(temp.AsFloat());
Serial.println(“C”);
Serial.println();
// My stuff:
float currentTemp = (temp);
//float currentTemp = (96); // Test: this creates temperature widget with 96 in it.
Cayenne.celsiusWrite(1, currentTemp);
Full Code:
// This example shows how to connect to Cayenne using an ESP8266 and send/receive sample data.
// Make sure you install the ESP8266 Board Package via the Arduino IDE Board Manager and select the correct ESP8266 board before compiling.
//#define CAYENNE_DEBUG
#define CAYENNE_PRINT Serial
#include <CayenneMQTTESP8266.h>
#include <Wire.h> // must be included here so that Arduino library object file references work
#include <RtcDS3231.h>
RtcDS3231 Rtc(Wire);
Usual Login Stuff:
unsigned long lastMillis = 0;
void setup()
{
Serial.begin(9600);
Cayenne.begin(username, password, clientID, ssid, wifiPassword);
Serial.print("compiled: ");
Serial.print(__DATE__);
Serial.println(__TIME__);
RtcDateTime compiled = RtcDateTime(__DATE__, __TIME__);
printDateTime(compiled);
Serial.println();
if (!Rtc.IsDateTimeValid())
{
// Common Cuases:
// 1) first time you ran and the device wasn't running yet
// 2) the battery on the device is low or even missing
Serial.println("RTC lost confidence in the DateTime!");
// following line sets the RTC to the date & time this sketch was compiled
// it will also reset the valid flag internally unless the Rtc device is
// having an issue
Rtc.SetDateTime(compiled);Rtc.Begin();
}
if (!Rtc.GetIsRunning())
{
Serial.println("RTC was not actively running, starting now");
Rtc.SetIsRunning(true);
}
RtcDateTime now = Rtc.GetDateTime();
if (now < compiled)
{
Serial.println("RTC is older than compile time! (Updating DateTime)");
Rtc.SetDateTime(compiled);
}
else if (now > compiled)
{
Serial.println("RTC is newer than compile time. (this is expected)");
}
else if (now == compiled)
{
Serial.println("RTC is the same as compile time! (not expected but all is fine)");
}
// never assume the Rtc was last configured by you, so
// just clear them to your needed state
Rtc.Enable32kHzPin(false);
Rtc.SetSquareWavePin(DS3231SquareWavePin_ModeNone);
}
void loop() {
delay(15000);
if (!Rtc.IsDateTimeValid())
{
// Common Cuases:
// 1) the battery on the device is low or even missing and the power line was disconnected
Serial.println(“RTC lost confidence in the DateTime!”);
}
RtcDateTime now = Rtc.GetDateTime();
printDateTime(now);
Serial.println();
RtcTemperature temp = Rtc.GetTemperature();
Serial.print(temp.AsFloat());
Serial.println("C");
Serial.println();
// My stuff:
float currentTemp = (temp);
// float currentTemp = (96); // Test: this creates temperature widget with 96 in it.
Cayenne.celsiusWrite(1, currentTemp);
}
#define countof(a) (sizeof(a) / sizeof(a[0]))
void printDateTime(const RtcDateTime& dt)
{
char datestring[20];
snprintf_P(datestring,
countof(datestring),
PSTR("%02u/%02u/%04u %02u:%02u:%02u"),
dt.Month(),
dt.Day(),
dt.Year(),
dt.Hour(),
dt.Minute(),
dt.Second() );
Serial.print(datestring);
}