Reading Data from Device in every 30 minutes

#11

– Everything looks fine if i set timer 10 seconds intresting…

⸮txyH⸮⸮⸮D:hų⸮[557] Connecting to DSL-6740U
[3559] Connected to WiFi
[3559] IP: 192.168.1.3
[3560] Connecting to mqtt.mydevices.com:1883
[3984] Connected
[4146] Publish: topic 4, channel 65534, value NodeMCU, subkey , key
[4147] Publish: topic 6, channel 65534, value Xtensa32, subkey , key
[4160] Publish: topic 7, channel 65534, value 80000000, subkey , key
[4234] Publish: topic 5, channel 65534, value 1.2.0, subkey , key
[4305] Publish: topic 8, channel 65534, value ESP8266, subkey , key
[6385] Publish: topic 1, channel 0, value 6385, subkey , key
[10401] Publish: topic 1, channel 1, value 29.576, subkey c, key temp
[15420] Connection ok
[20444] Publish: topic 1, channel 1, value 30.133, subkey c, key temp
[21452] Publish: topic 1, channel 0, value 21452, subkey , key
[25475] Connection ok
[30502] Publish: topic 1, channel 1, value 30.133, subkey c, key temp
[35536] Connection ok
[36540] Publish: topic 1, channel 0, value 36540, subkey , key
[40565] Publish: topic 1, channel 1, value 30.133, subkey c, key temp
[45592] Connection ok
[50620] Publish: topic 1, channel 1, value 30.133, subkey c, key temp
[51630] Publish: topic 1, channel 0, value 51629, subkey , key
[55656] Connection ok
[60681] Publish: topic 1, channel 1, value 30.226, subkey c, key temp
[65713] Connection ok
[66718] Publish: topic 1, channel 0, value 66718, subkey , key
[70745] Publish: topic 1, channel 1, value 30.226, subkey c, key temp
[75772] Connection ok
[80799] Publish: topic 1, channel 1, value 30.226, subkey c, key temp
[81808] Publish: topic 1, channel 0, value 81807, subkey , key
[85834] Connection ok
[90860] Publish: topic 1, channel 1, value 30.226, subkey c, key temp
[95887] Connection ok
[96894] Publish: topic 1, channel 0, value 96893, subkey , key
[100917] Publish: topic 1, channel 1, value 30.226, subkey c, key temp
[105950] Connection ok
[110979] Publish: topic 1, channel 1, value 30.133, subkey c, key temp
[111988] Publish: topic 1, channel 0, value 111988, subkey , key
[116012] Connection ok
[121037] Publish: topic 1, channel 1, value 30.133, subkey c, key temp
[126069] Connection ok
[127075] Publish: topic 1, channel 0, value 127075, subkey , key
[131103] Publish: topic 1, channel 1, value 29.761, subkey c, key temp
[136124] Connection ok
[141150] Publish: topic 1, channel 1, value 30.133, subkey c, key temp
[142158] Publish: topic 1, channel 0, value 142157, subkey , key
[146181] Connection ok
[151208] Publish: topic 1, channel 1, value 30.133, subkey c, key temp
[156232] Connection ok
[157238] Publish: topic 1, channel 0, value 157238, subkey , key
[161261] Publish: topic 1, channel 1, value 30.133, subkey c, key temp
[166292] Connection ok
[171317] Publish: topic 1, channel 1, value 30.226, subkey c, key temp
[172326] Publish: topic 1, channel 0, value 172325, subkey , key
[176353] Connection ok
[181379] Publish: topic 1, channel 1, value 29.761, subkey c, key temp
[186402] Connection ok
[187408] Publish: topic 1, channel 0, value 187408, subkey , key
[191437] Publish: topic 1, channel 1, value 30.226, subkey c, key temp
[196467] Connection ok
[201494] Publish: topic 1, channel 1, value 29.761, subkey c, key temp
[202503] Publish: topic 1, channel 0, value 202503, subkey , key
[206531] Connection ok

#12

This code works well too, Channel Five Counts like : 10- 20-30-40-50 how man seconds elplased until last Read… Is it possible to do it in minutes

millisLeft = millisLeft / 1000 * 60 ; something like that because in my Code i will read every 30 minutes or 1 hours.

ı know im asking very much questions but this topic is like millis() lesson for community.

Thanks a lot

#13

can you try same debug with 30 minutes and check the output? Also, check the data on the dashboard.

give this a try,do it on your own, this will help you learn. if it does not work then I will help.

1 Like
#14

Almost DONE!!
actually i decided to use countdown library, The code works well But it sends data to cayenne Every Second its not goot for the battery life and Server load. Instead of Live count down im Trying to Write Time when Tempareture have been read. Does cayenne have something like Write.Time function or should i use another library for know time and send data to Cayenne dashboard. Here is the working code now.

#include <Arduino.h>
#include <CountUpDownTimer.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



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 adc

const double A = 0.001129148;   // thermistor equation parameters
const double B = 0.000234125;
const double C = 0.0000000876741; 
// WiFi network info.
char ssid[] = "xxx;
char wifiPassword[] = "xxx";

// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = "xxxx";
char password[] = "xxx";
char clientID[] = "xxx";

unsigned long lastMillis = 0;

void setup() {
  Serial.begin(9600);
  Cayenne.begin(username, password, clientID, ssid, wifiPassword);
 
  //Countdown settings
   T.SetTimer(0,1,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();
  
}
void loop() {
  Cayenne.loop();
   T.Timer();
 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 kelvin

  temperature = temperature - 273.15;

  if (T.TimeHasChanged() ) // this prevents the time from being constantly shown.
  {
Cayenne.virtualWrite(2, T.ShowSeconds(), "counter", "null"); // !!! SENDS DATA EVERY SECOND
    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) {
//IF Time is over send data to Cayenne dashboard
   Cayenne.virtualWrite(1, temperature, TYPE_TEMPERATURE, UNIT_CELSIUS);
  // I NEED A CODE HERE WRITE TIME STAMP TO Channel 5.....??
    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);
 
}
#15

sending data fast will block your device Sending MQTT messages within rate limits

i am working on this using an RTC module and done with it. It will be out by next week. It is possible, give it a try with RTC module if you have.

1 Like
#16

I tried to use NPT time than realised i have “RTC DS1302” module. with 5 pins Cant find the suitable library or circuit about wiring on internet. working on in since hours.

P.S: Countdown library works perfect with Cayenne i would suggest to other developers about timing…

The RTC what i have i think its an old version coz its hard to find suitable library and circuit for nodemcu

#17

try this library https://playground.arduino.cc/Main/DS1302RTC. i have DS3231 which has a good support.

1 Like
#18

i tried RTC Virtuabotix Library Link here if you want to try

The output comes Seperated with RTC like “-RTC.hours - RTC.minutes -myRTC.seconds” Do i supposed to get each data for seperated Channel or do you have idea if there is a way to link them together and send with one channel.

Serial.print(“Current Date / Time: “);
Serial.print(myRTC.dayofmonth); //You can switch between day and month if you’re using American system
Serial.print(”/”);
Serial.print(myRTC.month);
Serial.print("/");
Serial.print(myRTC.year);
Serial.print(" “);
Serial.print(myRTC.hours);
Serial.print(”:");
Serial.print(myRTC.minutes);
Serial.print(":");
Serial.println(myRTC.seconds);

#19

this is what i am doing.

long time1 = hr * 10000 + min * 100 + sec;

then send this to

Cayenne.virtualWrite(2, time1, "counter", "null");
1 Like
#20

in this case you get just HR wich supposed to be hour and let counter calculates the rest? if yes it could be good for countdown but would not work good for timestamp (when the device last Read Data from Device) on dashboard in my opinion…

#21

You get the entire timestamp.

1 Like
#22

im having issues by implementing RTC module to arduino. Watchdog resets the module if i add RTC module to nodemcu, having following message on Serial monitor and cant find the solution

wdt reset
load 0x4010f000, len 1384, room 16
tail 8
chksum 0x2d
csum 0x2d
v614f7c32
~ld

EDIT: i was using pins 6-7-8 and it was causing reset ESP9266 changed pins to 2-3-4 but now cant get the true time from RTC it gives me output like Current Date / Time: 45/25/2165 45:85:85

Maybe because RTC needs 5v instead of 3.3v from Nodemcu ?

#23

can you give a try with this code https://playground.arduino.cc/Main/DS1302RTC

1 Like
#24

I tried this code many times but i could not let the code work neither with arduino nor with Nodemcu
Getting exceptions always with this library :frowning:

In file included from C:\Users\Harun\Documents\Arduino\libraries\DS1302RTC\examples\DS1302_Serial\DS1302_Serial.ino:17:0:

C:\Users\Harun\Documents\Arduino\libraries\DS1302RTC/DS1302RTC.h:97:26: error: 'tmElements_t' has not been declared

     static  uint8_t read(tmElements_t &tm);

                          ^

C:\Users\Harun\Documents\Arduino\libraries\DS1302RTC/DS1302RTC.h:98:27: error: 'tmElements_t' has not been declared

     static  uint8_t write(tmElements_t &tm);

                           ^

C:\Users\Harun\Documents\Arduino\libraries\DS1302RTC\examples\DS1302_Serial\DS1302_Serial.ino: In function 'void loop()':

DS1302_Serial:61: error: 'tmElements_t' was not declared in this scope

   tmElements_t tm;

   ^

DS1302_Serial:61: error: expected ';' before 'tm'

   tmElements_t tm;

                ^

DS1302_Serial:66: error: expected primary-expression before ')' token

   if (! RTC.read(tm)) {

                    ^

DS1302_Serial:68: error: expected primary-expression before '.' token

     print2digits(tm.Hour);

                    ^

DS1302_Serial:70: error: expected primary-expression before '.' token

     print2digits(tm.Minute);

                    ^

DS1302_Serial:72: error: expected primary-expression before '.' token

     print2digits(tm.Second);

                    ^

DS1302_Serial:74: error: expected primary-expression before '.' token

     Serial.print(tm.Day);

                    ^

DS1302_Serial:76: error: expected primary-expression before '.' token

     Serial.print(tm.Month);

                    ^

DS1302_Serial:78: error: expected primary-expression before '.' token

     Serial.print(tmYearToCalendar(tm.Year));

                                     ^

DS1302_Serial:78: error: 'tmYearToCalendar' was not declared in this scope

     Serial.print(tmYearToCalendar(tm.Year));

                                          ^

DS1302_Serial:80: error: expected primary-expression before '.' token

     Serial.print(tm.Wday);

                    ^

exit status 1
'tmElements_t' was not declared in this scope
#25

try connecting RTC vcc to vin pin of Nodemcu.

1 Like
#26

something weird with Nodemcu, it semes there are some pins device dont let you use, if you use it makes Wdt reset. For example i use pins 678 for RTC i get WDT reset. I use pins 123 RTC works but Blue light on ESP8266 runs continiueusly and the RTC gives wrong date- time Now testing all pins. going to be crazy…

#27

i give up Trying RTC and started NTP somebody from community shared a code for getting time from NTP but i can not configure it for Nodemcu ESP8266

#28

im closed with this code using time library.

#include <ESP8266WiFi.h>
#include <time.h>

const char* ssid = “xxx”;
const char* password = “xxx”;
int timezone = 3;
int dst = 0;

void setup() {
Serial.begin(115200);
Serial.setDebugOutput(true);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
Serial.println("\nConnecting to WiFi");
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(1000);
}
configTime(timezone * 3600, dst * 0, “pool.ntp.org”, “time.nist.gov”);
Serial.println("\nWaiting for time");
while (!time(nullptr)) {
Serial.print(".");
delay(1000);
}
Serial.println("");
}

void loop() {
time_t now = time(nullptr);
Serial.println(ctime(&now));
delay(1000);
}

but it gives output like

Sat Jun 16 23:27:57 2018

i just need to parse it like Hour - minute

on github page it tells how there are avalible functions for it but i could not find out how to use it

Here are the functions i need from readme.md

time_t t = now(); // store the current time in time variable t
hour(t); // returns the hour for the given time t
minute(t); // returns the minute for the given time t
second(t); // returns the second for the given time t
day(t); // the day for the given time t
weekday(t); // day of the week for the given time t
month(t); // the month for the given time t
year(t); // the year for the given time t

void loop() {
time_t now;
struct tm * timeinfo;
time(&now);
timeinfo = localtime(&now);
Serial.println(timeinfo->tm_hour);
delay(1000);
}

i could parse just hour with this code but i dont know if i can send "timeinfo->tm_hour "

like that

Cayenne.virtualWrite(2,timeinfo->tm_hour , “Time”, “HHMM.SS”);

like that

#29

It looks like you got it working, but I’m not sure. Should I mark your thread as helped?

#30

it does not work exactly how i want but its ok. you can mark as helped. thank you

1 Like