CAYENNE_OUT(VIRTUAL_PIN)
{
// Send the command to get temperatures.
sensors.requestTemperatures();
// This command writes the temperature in Celsius to the Virtual Pin.
Cayenne.virtualWrite(VIRTUAL_PIN, sensors.getTempCByIndex(0),TEMPERATURE, FAHRENHEIT);
// Cayenne.celsiusWrite(VIRTUAL_PIN, sensors.getTempC(OutsideTempAdd));
// To send the temperature in Fahrenheit use the corresponding code below.
//Cayenne.fahrenheitWrite(VIRTUAL_PIN, sensors.getTempFByIndex(0));
Serial.print("Temp: ");
Serial.println(sensors.getTempCByIndex(0));
Cayenne.virtualWrite(V10, 10);
}
In the dashboard i get
If i use celsiusWrite V1 shows 0
after changing to virtualWrite i get
On V1 i get 75.1 degree,
on V10 i get 50.0. It dosn’t matter what setting i use in dashboard.
The serial out shows 24 degrees celsius , as expected.
Could anyone explain how this is supposed to work, and what I am missing
CAYENNE_OUT(VIRTUAL_PIN)
{
// Send the command to get temperatures.
sensors.requestTemperatures();
// This command writes the temperature in Celsius to the Virtual Pin.
Cayenne.virtualWrite(VIRTUAL_PIN, sensors.getTempCByIndex(0),TEMPERATURE, FAHRENHEIT);
// Cayenne.celsiusWrite(VIRTUAL_PIN, sensors.getTempC(OutsideTempAdd));
// To send the temperature in Fahrenheit use the corresponding code below.
//Cayenne.fahrenheitWrite(VIRTUAL_PIN, sensors.getTempFByIndex(0));
Serial.print("Temp: ");
Serial.println(sensors.getTempCByIndex(0));
Cayenne.virtualWrite(V10, sensors.getTempCByIndex(0));
}
On your dashboard use channel 10 to display the value.
There was a bug from a while back that Celsius temps were getting converted to Fahrenheit even though you were sending the temp in Celsius. @rsiegel do you know if that was ever fixed?
Cayenne.celsiusWrite(VIRTUAL_PIN, sensors.getTempC(OutsideTempAdd)); doesn’t work
Cayenne.virtualWrite(V1, sensors.getTempCByIndex(0)); this work
2 it is essential that this is on top in the schets, other vise it gives wrong data, and debug doesn’t work #define CAYENNE_DEBUG // Uncomment to show debug messages #define CAYENNE_PRINT Serial
My code aree below, if someone else would like it.
It is also OTA compliant, so it can be uploaded over the air in arduino IDE
Do you know if it is possibly to have 2 or more readings in the same Chart view??
Thanks for you help.
Some feedback to Cayenne team:
I tried to use UECIDE (another IDE for ARV like Arduino), but it seems that cayenne’s library dosn’t follow the guidelines described here https://www.arduino.cc/en/Hacking/libraryTutorial
Mostly the Libs are not in seperate folders with same name, and the keywords.txt are missing.
thats pretty anoying, I hope it will be fixed in the future.
#include <ESP8266WiFi.h>
#include <ArduinoOTA.h>
#define CAYENNE_DEBUG // Uncomment to show debug messages
#define CAYENNE_PRINT Serial // Comment this out to disable prints and save space
#include <CayenneDefines.h>
#include <BlynkSimpleEsp8266.h>
#include <CayenneWiFiClient.h>
#include <OneWire.h>
#include <DallasTemperature.h>
// Digital pin the DS18B20 is connected to. Do not use digital pins 0 or 1 since those conflict with the use of Serial.
const int tmpPin = 13;
OneWire oneWire(tmpPin);
DallasTemperature sensors(&oneWire);
// Cayenne authentication token. This should be obtained from the Cayenne Dashboard.
char token[] = "xxxxxxx";
const char* ssid = "Ullernet";
const char* password = "xxxxxxx";
void setup() {
delay(5); //added by JMS
Serial.begin(115200);
Serial.println("Booting");
Cayenne.begin(token, ssid, password);
// showFlashInfo();
// Port defaults to 8266
// ArduinoOTA.setPort(8266);
// Hostname defaults to esp8266-[ChipID]
// ArduinoOTA.setHostname("myesp8266");
// No authentication by default
// ArduinoOTA.setPassword((const char *)"Shumatic");
ArduinoOTA.onStart([]() {
Serial.println("Start");
});
ArduinoOTA.onEnd([]() {
Serial.println("\nEnd");
});
ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
Serial.printf("Progress: %u%%\r", (progress / (total / 100)));
});
ArduinoOTA.onError([](ota_error_t error) {
Serial.printf("Error[%u]: ", error);
if (error == OTA_AUTH_ERROR) Serial.println("Auth Failed");
else if (error == OTA_BEGIN_ERROR) Serial.println("Begin Failed");
else if (error == OTA_CONNECT_ERROR) Serial.println("Connect Failed");
else if (error == OTA_RECEIVE_ERROR) Serial.println("Receive Failed");
else if (error == OTA_END_ERROR) Serial.println("End Failed");
});
ArduinoOTA.begin();
Serial.println("Ready");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
}
void loop() {
ArduinoOTA.handle();
Cayenne.run();
yield(); // Do (almost) nothing -- yield to allow ESP8266 background functions
}
CAYENNE_OUT(V1) { // temp reading
// Send the command to get temperatures.
sensors.requestTemperatures();
// This command writes the temperature in Celsius to the Virtual Pin.
Cayenne.virtualWrite(V1, sensors.getTempCByIndex(0));
// Cayenne.celsiusWrite(VIRTUAL_PIN, sensors.getTempC(OutsideTempAdd));
// To send the temperature in Fahrenheit use the corresponding code below.
//Cayenne.fahrenheitWrite(VIRTUAL_PIN, sensors.getTempFByIndex(0));
Serial.print("Temp: ");
Serial.println(sensors.getTempCByIndex(0));
}
CAYENNE_OUT(V5) { // uptime in second.
Cayenne.virtualWrite(V5, millis() / 1000);
Serial.println(millis() / 1000);
}
CAYENNE_OUT(V10) { // Just a fixed valut to see if it worked :-)
Cayenne.virtualWrite(V10, 10);
}