Device goes offline-


#1

Hi there,
Im building Beer fermentation chamber Temperature control system With Nodemcu esp8266 12e module using ntc Termistor.

It supposed to work like, get temperature every 30mins and write timestamp when the data written.

So if the device does not send any data 30 minute long the device goes offline ist the first problem. To avoid it i try to send millis to a channel.

The webpage and App does not Records the last Temperature if the device does not send any data for 30 mins.


#2

Do you want to do anything during this 30 min or you can put the device to sleep and wake up after 30 min, send data and again go to sleep.


#3

i have a timer which counts 30 minutes and read the temperature in this case if the device sleeps it goes offline and the counter begins from 30 again. I use cayenne out default send millis to keep device alive othervise it goes offline after a while because cayenne dont get any data from Nodemcu.


#4

do you want to show the counter running on the dashboard? you just needs to send temp data every 30 minutes?


#5

my code have countdown timer, if time is up reads the temperature data and write time to channel 2.
Until next time up device sends no data it makes him Go offline. I think its kind of bug of Cayenne.

I solved the problem by sending Millis by Cayenne default.

Answer to your question: I want time stamp stays on the screen until next time stamp comes.


#6

you can try similar thing as this project Battery Powered ESP8266 Temperature/Humidity Monitor with DHT11 . it sleeps for 30 mins and when awake it reads temp and time stamp from RTC and sends to cayenne. then sleep again. this can solve two major problem. if you are running on battery it will not drain the battery power and when the device comes online it will send temp and timestamp thus solving your problem of offline and not receiving data.

yes this is a bug and i will report it to team.


#7

ON this picture you can see the bug better, if there is no channel 0. The device goes offline after a while because there are no data coming from Device.

secondly the counter shows 00000000 until cayenne gets any data device than shows the counter maybe any other recorded data can be seen

In this picture you can see that dashboard waits for any new data…

And here we are, i send millis to channel 0 so that the device stays alive and shows me the data.

i


#8

Can you share the code you are using?


#9
#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 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[] = "xxxxxx";

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

unsigned long lastMillis = 0;


void setup() {
  Serial.begin(9600);
  //Serial.setDebugOutput(true);
  Cayenne.begin(username, password, clientID, ssid, wifiPassword);
 
//Countdown settings
   T.SetTimer(0,30,00);  // 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, "europe.pool.ntp.org", "time.nist.gov");
 Serial.println("\nWaiting for time");
while (!time(nullptr)) {
  Serial.print(".");
  delay(1000);
 }
 Serial.println("NTP Time OK!");

}
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;

 long saat = timeinfo->tm_hour*10000 + timeinfo->tm_min*100 + timeinfo->tm_sec;
 
 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, 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, saat, "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);
 
}

#10

i was able to produce this issue with offline at my end and reported to the team. till then do you have any problem sending millis() to cayenne to keep it online? Also you were trying to send a counter to show how many counts are remaining. this can be used in place of sending millis(), so the counter keeps the dashboard online.


#11

im using the counter to write timestamp when the last data measured by Thermistor. sending millis to channel 0 keeps device alive and i can see the counter everytime when the device send millis to channel 0.

I could to it just by counting time with millis on counter but it reduces the battery power and overload the server.


#12

yes, i have understand your problem, it will take some time to solve it. till then send millis() to channel 0 to keep it online.

i did not get what you are trying to do.


#13

[/quote]
i did not get what you are trying to do.
[/quote]

if (T.TimeHasChanged() ) // this prevents the time from being constantly shown.
  {
//Cayenne.virtualWrite(2, timefloat, "counter", "null");

with this way i can send continiously data to counter and there will be no problem, but it will send data to cayenne a lot, it will overload and shorten the battery life of External Node mcu.

So anyway. I find my own solution i just wanted to report about bug

thanks


#14

what is the solution?


#15

i send millis() to channel 0 it makes the device alive and let me see the recorded data of temperature and time stamp when the channel 0 gets new millis


#16

hi @harunsivasli. I just made a prototype of your project and tested it out. it is based on @adam Battery Powered ESP8266 Temperature/Humidity Monitor with DHT11

Components: nodemcu, RTC DS3231, DTH11(you can replace this with the sensor you are using to read the temp).

code:

/*
  This example shows how to connect to Cayenne using an ESP8266 and send/receive sample data.

  The CayenneMQTT Library is required to run this sketch. If you have not already done so you can install it from the Arduino IDE Library Manager.

  Steps:
  1. If you have not already installed the ESP8266 Board Package install it using the instructions here: https://github.com/esp8266/Arduino#installing-with-boards-manager.
  2. Select your ESP8266 board from the Tools menu.
  3. Set the Cayenne authentication info to match the authentication info from the Dashboard.
  4. Set the network name and password.
  5. Compile and upload the sketch.
  6. A temporary widget will be automatically generated in the Cayenne Dashboard. To make the widget permanent click the plus sign on the widget.
*/

#define CAYENNE_DEBUG
#define CAYENNE_PRINT Serial
#include <CayenneMQTTESP8266.h>

// WiFi network info.
char ssid[] = "";
char wifiPassword[] = "";

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

#include <Wire.h>
#include "RTClib.h"

RTC_DS3231 rtc;
unsigned long lastMillis_rtc;

long x;
long y;
long z;

//DTH
#include "DHT.h"
#define DHTPIN 14
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
#define DTH_hum_Virtual_Channel 1
#define DTH_tempC_Virtual_Channel 3
#define DTH_tempF_Virtual_Channel 4
#define DTH_hic_Virtual_Channel 5
#define DTH_hif_Virtual_Channel 6
unsigned long lastMillis_dht = 0;

int SleepTime = 60000000;
bool CayenneSent = false;


void setup() {
  Serial.begin(9600);
  Cayenne.begin(username, password, clientID, ssid, wifiPassword);

  dht.begin();
  CayenneSent = false;
  if (! rtc.begin()) {
    Serial.println("Couldn't find RTC");
    while (1);
  }

  if (rtc.lostPower()) {
    Serial.println("RTC lost power, lets set the time!");
    // following line sets the RTC to the date & time this sketch was compiled
    rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
    // This line sets the RTC with an explicit date & time, for example to set
    // January 21, 2014 at 3am you would call:
    // rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
  }
}

void loop() {
  Cayenne.loop();
  if (millis() - lastMillis_rtc  > 10000) {
    lastMillis_rtc  = millis();
    DateTime now = rtc.now();
    x = now.hour();
    y = now.minute();
    z = now.second();
    long a = x * 10000 + y * 100 + z;
    Cayenne.virtualWrite(2, a, "counter", "null");

    //DTH
    // Reading temperature or humidity takes about 250 milliseconds!
    // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
    float h = dht.readHumidity();
    // Read temperature as Celsius (the default)
    float t = dht.readTemperature();
    // Read temperature as Fahrenheit (isFahrenheit = true)
    float f = dht.readTemperature(true);

    // Check if any reads failed and exit early (to try again).
    if (isnan(h) || isnan(t) || isnan(f)) {
      Serial.println("Failed to read from DHT sensor!");
      return;
    }

    // Compute heat index in Fahrenheit (the default)
    float hif = dht.computeHeatIndex(f, h);
    // Compute heat index in Celsius (isFahreheit = false)
    float hic = dht.computeHeatIndex(t, h, false);
    Cayenne.virtualWrite(DTH_hum_Virtual_Channel, h, "rel_hum", "p");
    Cayenne.virtualWrite(DTH_tempC_Virtual_Channel, t, "temp", "c");
    Cayenne.virtualWrite(DTH_tempF_Virtual_Channel, f, "temp", "f");
    Cayenne.virtualWrite(DTH_hif_Virtual_Channel, hif, "temp", "f");
    Cayenne.virtualWrite(DTH_hic_Virtual_Channel, hic, "temp", "c");
    CayenneSent = true;
  }
  if (CayenneSent) {
    Serial.println("Sent all values - sleeping");
    delay(100);
    ESP.deepSleep(SleepTime, WAKE_RF_DEFAULT);
    delay(100);
    }

}

currently, the sleep time is set to 10 minutes, you can change to 30 minutes.
this code reads the current time from DS3231 and temp from DTH11. It sends data to cayenne and sleeps for 10 minutes. After 10 min it wakes up and sends data and time to cayenne.

Now if you want to check the timestamp during which the temp is sent, you can click on the data option on your dashboard and get it.


#17

thank you i will give a try, i have DS1302 and had trouble with it, i will buy ds321 and try it.


#18

Actually don’t need one if you don’t want to show the timestamp on dashboard. In data tab you get the timestamp when sensor data is recievdd.


#19

@harunsivasli what is the status? is the above solution working for you?


#20

Dont have - DS3231 ordered and waiting for delivery. Until i got im using the previous code. it works ok thanks