First steps and need some help. From serial monitor I get : “vw 1 temp,c=%.3f”
My code:
#define CAYENNE_DEBUG
#define CAYENNE_PRINT Serial
#include <ESP8266WiFi.h>
#include "CayenneDefines.h"
#include "BlynkSimpleEsp8266.h"
#include "CayenneWiFiClient.h"
#include <OneWire.h>
#include <DallasTemperature.h>
#define VIRTUAL_PIN V1
const int tmpPin = 0;
OneWire oneWire(tmpPin);
DallasTemperature sensors(&oneWire);
// WiFi network info.
char token[] = "token";
// Your network name and password.
char ssid[] = "ssid";
char wifiPassword[] = "pass";
void setup() {
Serial.begin(115200);
Cayenne.begin(token, ssid, wifiPassword);
sensors.begin();
}
void loop() {
Cayenne.run();
// do something
}
// This function is called when the Cayenne widget requests data for the Virtual Pin.
CAYENNE_OUT(VIRTUAL_PIN)
{
// Send the command to get temperatures.
sensors.requestTemperatures();
// This command writes the temperature in Celsius to the Virtual Pin.
Cayenne.celsiusWrite(VIRTUAL_PIN, sensors.getTempCByIndex(0));
// To send the temperature in Fahrenheit use the corresponding code below.
//Cayenne.fahrenheitWrite(VIRTUAL_PIN, sensors.getTempFByIndex(0));
}
CAYENNE_CONNECTED()
{
CAYENNE_LOG("Connection established");
}
I believe Celsius / Fahrenheit . write currently doesn’t work on arduino. You have to use virtual,write still, this is the code that’s working for me
CAYENNE_OUT(V1)
{
// 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));
// To send the temperature in Fahrenheit use the corresponding code below.
//Cayenne.fahrenheitWrite(VIRTUAL_PIN, sensors.getTempFByIndex(0));
}
For everyone to try (for copy/paste) Celsius values for two parallel DS18B20 (NodeMCU D3 (GPIO0)):
#define CAYENNE_DEBUG
#define CAYENNE_PRINT Serial
#include <ESP8266WiFi.h>
#include "CayenneDefines.h"
#include "BlynkSimpleEsp8266.h"
#include "CayenneWiFiClient.h"
#include <OneWire.h>
#include <DallasTemperature.h>
#define VIRTUAL_PIN1 V1
#define VIRTUAL_PIN2 V2
const int tmpPin = 0;
OneWire oneWire(tmpPin);
DallasTemperature sensors(&oneWire);
//const int tmpPin1 = 1;
//OneWire oneWire1(tmpPin1);
//DallasTemperature sensors1(&oneWire1);
// WiFi network info.
char token[] = "token";
// Your network name and password.
char ssid[] = "ssid";
char wifiPassword[] = "pass";
void setup() {
Serial.begin(115200);
Cayenne.begin(token, ssid, wifiPassword);
sensors.begin();
}
void loop() {
Cayenne.run();
// do something
}
// This function is called when the Cayenne widget requests data for the Virtual Pin.
CAYENNE_OUT(V1)
{
// 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));
// To send the temperature in Fahrenheit use the corresponding code below.
Cayenne.virtualWrite(VIRTUAL_PIN1, sensors.getTempFByIndex(0));
}
CAYENNE_OUT(V2)
{
// 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));
// To send the temperature in Fahrenheit use the corresponding code below.
Cayenne.virtualWrite(VIRTUAL_PIN2, sensors.getTempFByIndex(1));
}
CAYENNE_CONNECTED()
{
CAYENNE_LOG("Connection established");
}
To get correct values in Celsius, I had to get Fahrenheit value in NodeMCU and set Celsius in widget. To get correct Fahrenheit in widget, you should change F to C:
Cayenne.virtualWrite(VIRTUAL_PIN1, sensors.getTempFByIndex(0));
to: Cayenne.virtualWrite(VIRTUAL_PIN1, sensors.getTempCByIndex(0));
I used the codes above and I am getting the C info on my Cayenne dashboard as F. I am not sure what I am doing wrong, would appreciate any hep here.
My code:
#define CAYENNE_DEBUG
#define CAYENNE_PRINT Serial
#include <ESP8266WiFi.h>
#include "CayenneDefines.h"
#include "BlynkSimpleEsp8266.h"
#include "CayenneWiFiClient.h"
#include <OneWire.h>
#include <DallasTemperature.h>
#define VIRTUAL_PIN V1
const int tmpPin = 0;
OneWire oneWire(tmpPin);
DallasTemperature sensors(&oneWire);
// Cayenne authentication token. This should be obtained from the Cayenne Dashboard.
char token[] = "token";
// Your network name and password.
char ssid[] = "ssid";
char password[] = "pass";
void setup() {
Serial.begin(115200);
Cayenne.begin(token, ssid, password);
sensors.begin();
}
void loop() {
Cayenne.run();
// do something
}
// This function is called when the Cayenne widget requests data for the Virtual Pin.
CAYENNE_OUT(V1)
{
// 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));
// To send the temperature in Fahrenheit use the corresponding code below.
//Cayenne.fahrenheitWrite(VIRTUAL_PIN, sensors.getTempFByIndex(0));
}
CAYENNE_CONNECTED()
{
CAYENNE_LOG("Connection established");
}