Hi im trying to make A Beer fermentation chamber Temperature controller, Using Node mcu And thermistor. I try to make device Get the chambers temperature and Write Timestamp of the Time when the device got the Data. I got time from NTP server and got Hour-Minute-Second seperatally ( actually ican get data like 01.01.1970) But im having issues to send timestamp information to Virtual Channel
#include <Arduino.h>
#include <CountUpDownTimer.h>
#include <time.h>// 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>//Countdown Settings
CountUpDownTimer T(DOWN, HIGH); // DOWN / UP//Timestamp settings
int timezone = 3;
int dst = 0;const double VCC = 3.3; // NodeMCU on board 3.3v vcc
const double R2 = 10000; // 10k ohm series resistor
const double adc_resolution = 1023; // 10-bit adcconst double A = 0.001129148; // thermistor equation parameters
const double B = 0.000234125;
const double C = 0.0000000876741;
// WiFi network info.
char ssid = “xxxx”;
char wifiPassword = “xxx”;// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username = “xxx”;
char password = “xxxx”;
char clientID = “xxxx”;unsigned long lastMillis = 0;
void setup() {
Serial.begin(9600);
Cayenne.begin(username, password, clientID, ssid, wifiPassword);//Countdown settings
T.SetTimer(0,30,0); // H-M-S //start at 1 minute (USE FOR: DOWN ONLY)
// T.SetStopTime(0,0,30); // stop at 10 seconds (USE FOR: UP/DOWN)
T.StartTimer();configTime(timezone * 3600, dst * 0, “tr.pool.ntp.org”, “time.nist.gov”);
Serial.println(“\nWaiting for time”);
while (!time(nullptr)) {
Serial.print(“.”);
delay(1000);
}
Serial.println(“”);}
void loop() {
Cayenne.loop();
T.Timer();
//time stamp settings
time_t now;
struct tm * timeinfo;
time(&now);
timeinfo = localtime(&now);
//Serial.println(timeinfo->tm_hour);
//Serial.println(timeinfo->tm_min);
//Serial.println(timeinfo->tm_sec);
//Serial.println(timeinfo->tm_mday);
//Serial.println(timeinfo->tm_mon);
//Serial.println(timeinfo->tm_year);
float timefloat = timeinfo->tm_hour*100 + timeinfo->tm_min + timeinfo->tm_sec/100.0;double Vout, Rth, temperature, adc_value;
adc_value = analogRead(A0);
Vout = (adc_value * VCC) / adc_resolution;
Rth = (VCC * R2 / Vout) - R2;/* Steinhart-Hart Thermistor Equation:
- Temperature in Kelvin = 1 / (A + B[ln(R)] + C[ln(R)]^3)
- where A = 0.001129148, B = 0.000234125 and C = 8.76741*10^-8 */
temperature = (1 / (A + (B * log(Rth)) + (C * pow((log(Rth)),3)))); // Temperature in kelvintemperature = temperature - 273.15;
if (T.TimeHasChanged() ) // this prevents the time from being constantly shown.
{
//Cayenne.virtualWrite(2, timefloat, “counter”, “null”);Serial.print(T.ShowMinutes());
Serial.print(" - Timecheck:");
Serial.println(T.TimeCheck());// This DOES NOT format the time to 0:0x when seconds is less than 10. // if you need to format the time to standard format, use the sprintf() function.
if (T.TimeCheck() > 0) {
Cayenne.virtualWrite(1, temperature, TYPE_TEMPERATURE, UNIT_CELSIUS);
Cayenne.virtualWrite(2, timefloat, “counter”, “null”);
Serial.println(" - Sıcaklık Girildi ");
T.ResetTimer();
}
}// 1 minutes 60000
//10 minutes 600000
//30 minutes = 1800000
//60 minutes 3600000} // loop bitis
// Default function for sending sensor data at intervals to Cayenne.
// You can also use functions for specific channels, e.g CAYENNE_OUT(1) for sending channel 1 data.
CAYENNE_OUT_DEFAULT()
{// Write data to Cayenne here. This example just sends the current uptime in milliseconds on virtual channel 0.
Cayenne.virtualWrite(0, millis());
// Some examples of other functions you can use to send data.
//Cayenne.celsiusWrite(1, 22.0);
//Cayenne.luxWrite(2, 700);
//Cayenne.virtualWrite(3, 50, TYPE_PROXIMITY, UNIT_CENTIMETER);}
wit this code i could do like
time is 03.08 now and i want to send this data like 03:09:00 To cayenne
Thanks