0

Stops approximately once a week
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Stops approximately once a week

by tj1 on Sun Nov 04, 2018 10:56 am

Hello, Feed stops about once a week, requiring me to sign out and then sign in to get it working.
The blue dashes across the top turn red. Is this normal or is there something I can do ?
Thanks Much, T

tj1
 
Posts: 21
Joined: Sun Apr 08, 2012 1:15 pm

Re: Stops approximately once a week

by brubell on Tue Nov 06, 2018 10:15 am

Hi T,

The feed stops working, or are you logged out of the Adafruit IO Website? Do you have a computer/display monitoring a dashboard?

brubell
 
Posts: 336
Joined: Fri Jul 17, 2015 10:33 pm

Re: Stops approximately once a week

by tj1 on Tue Nov 06, 2018 5:31 pm

Hi brubell,
Thanks for responding.
I'm using Chrome on the desktop of a windows 10 machine, logged in all of the time.
However, the machine is set to go to sleep. Normally upon wake up, it's all there and
functioning properly. I do have a Huzzah esp 8266 on a timer that reconnects every
10-12 minutes sending data. It's more of an annoyance than a problem.
Thank you very much for any advice.
T

tj1
 
Posts: 21
Joined: Sun Apr 08, 2012 1:15 pm

Re: Stops approximately once a week

by tj1 on Sun Jan 27, 2019 3:29 pm

answered questions two months ago. no reply ?

tj1
 
Posts: 21
Joined: Sun Apr 08, 2012 1:15 pm

Re: Stops approximately once a week

by brubell on Mon Jan 28, 2019 11:04 am

tj1 wrote:answered questions two months ago. no reply ?

Can you post the code that's running on the ESP8266?

brubell
 
Posts: 336
Joined: Fri Jul 17, 2015 10:33 pm

Re: Stops approximately once a week

by tj1 on Mon Jan 28, 2019 3:50 pm

Thanks for getting back. I think this is it, (had 5 or 6 efforts to get it working initially,) (forgot to delete
ones that didn't work.) I'm not good with coding
Thank You Very Much for your time.
Tim

Code: Select all | TOGGLE FULL SIZE
[code]


/***************************************************
  Adafruit ESP8266 Sensor Module
 
  Must use ESP8266 Arduino from:
    https://github.com/esp8266/Arduino
  Works great with Adafruit's Huzzah ESP board:
  ----> https://www.adafruit.com/product/2471
  Adafruit invests time and resources providing this open source code,
  please support Adafruit and open-source hardware by purchasing
  products from Adafruit!
  Written by Tony DiCola for Adafruit Industries.
  MIT license, all text above must be included in any redistribution
 ****************************************************/

// Libraries
#include "ESP8266WiFi.h"
#include "Adafruit_MQTT.h"
#include "Adafruit_MQTT_Client.h"
#include "DHT.h"

// DHT 22 sensor
#define DHTPIN_IN 5
#define DHTPIN_OUT 4
#define DHTTYPE_IN DHT22
#define DHTTYPE_OUT DHT22

// WiFi parameters
#define WLAN_SSID       "*********"
#define WLAN_PASS       "***************"

// Adafruit IO
#define AIO_SERVER      "io.adafruit.com"
#define AIO_SERVERPORT  1883
#define AIO_USERNAME    "tj1"
#define AIO_KEY         "76060e2caa594895982dae3c8e4db024"

// DHT sensor
DHT dht_IN(DHTPIN_IN, DHTTYPE_IN, 15);
DHT dht_OUT(DHTPIN_OUT, DHTTYPE_OUT, 22);
// Functions
void connect();

// Create an ESP8266 WiFiClient class to connect to the MQTT server.
WiFiClient client;

// Store the MQTT server, client ID, username, and password in flash memory.
const char MQTT_SERVER[] PROGMEM    = AIO_SERVER;

// Set a unique MQTT client ID using the AIO key + the date and time the sketch
// was compiled (so this should be unique across multiple devices for a user,
// alternatively you can manually set this to a GUID or other random value).
//
Adafruit_MQTT_Client mqtt(&client, AIO_SERVER, AIO_SERVERPORT, AIO_USERNAME, AIO_KEY);
// Setup the MQTT client class by passing in the WiFi client and MQTT server and login details.
//****************************** Feeds ***************************************/

// Setup feeds for temperature & humidity

Adafruit_MQTT_Publish temperature_IN = Adafruit_MQTT_Publish(&mqtt, AIO_USERNAME "/feeds/Temperature_IN");


Adafruit_MQTT_Publish humidity_IN = Adafruit_MQTT_Publish(&mqtt, AIO_USERNAME "/feeds/Humidity_IN");


Adafruit_MQTT_Publish temperature_OUT = Adafruit_MQTT_Publish(&mqtt, AIO_USERNAME "/feeds/Temperature_OUT");


Adafruit_MQTT_Publish humidity_OUT = Adafruit_MQTT_Publish(&mqtt, AIO_USERNAME "/feeds/Humidity_OUT");


/*************************** Sketch Code ************************************/

void setup() {

  // Init sensor
  dht_IN.begin();
  dht_OUT.begin();

  Serial.begin(115200);
  Serial.println(F("Adafruit IO Example"));

  // Connect to WiFi access point.
  Serial.println(); Serial.println();
  delay(10);
  Serial.print(F("Connecting to "));
  Serial.println(WLAN_SSID);

  WiFi.begin(WLAN_SSID, WLAN_PASS);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(F("."));
  }
  Serial.println();

  Serial.println(F("WiFi connected"));
  Serial.println(F("IP address: "));
  Serial.println(WiFi.localIP());

  // connect to adafruit io
  connect();

}

void loop() {

  // ping adafruit io a few times to make sure we remain connected
  if(! mqtt.ping(3)) {
    // reconnect to adafruit io
    if(! mqtt.connected())
      connect();
  }

  // Grab the current state of the sensor
  int humidity_IN_data = (int)dht_IN.readHumidity();
  int temperature_IN_data = (int)dht_IN.readTemperature ();
 
//  ///////////////////////////////////////////////
   // Grab the current state of the sensor
  int humidity_OUT_data = (int)dht_OUT.readHumidity();
  int temperature_OUT_data = (int)dht_OUT.readTemperature ();

// ////////////////////////////////////////////////

  // Publish data
  if (! temperature_IN.publish(temperature_IN_data * 1.8 +32))
    Serial.println(F("Failed to publish temperature IN"));
  else
    Serial.println(F("Temperature IN published!"));

  if (! humidity_IN.publish(humidity_IN_data))
    Serial.println(F("Failed to publish humidity"));
  else
    Serial.println(F("Humidity IN published!"));

    //delay (5000);
//    /////////////////////////////////////////////////////////
  // Publish data
  if (! temperature_OUT.publish(temperature_OUT_data * 1.8 +32))
    Serial.println(F("Failed to publish temperature OUT"));
  else
    Serial.println(F("Temperature OUT published!"));

  if (! humidity_OUT.publish(humidity_OUT_data))
    Serial.println(F("Failed to publish humidity OUT"));
   else
    Serial.println(F("Humidity OUT published!"));

// /////////////////////////////////////////////////////////////

   

  // Repeat every 1000 seconds (16.6 min.)
  delay(1000000);

}

// connect to adafruit io via MQTT
void connect() {

  Serial.print(F("Connecting to Adafruit IO... "));

  int8_t ret;

  while ((ret = mqtt.connect()) != 0) {

    switch (ret) {
      case 1: Serial.println(F("Wrong protocol")); break;
      case 2: Serial.println(F("ID rejected")); break;
      case 3: Serial.println(F("Server unavail")); break;
      case 4: Serial.println(F("Bad user/pass")); break;
      case 5: Serial.println(F("Not authed")); break;
      case 6: Serial.println(F("Failed to subscribe")); break;
      default: Serial.println(F("Connection failed")); break;
    }

    if(ret >= 0)
      mqtt.disconnect();

    Serial.println(F("Retrying connection..."));
    delay(5000);

  }

  Serial.println(F("Adafruit IO Connected!"));

}
[/code]

tj1
 
Posts: 21
Joined: Sun Apr 08, 2012 1:15 pm

Re: Stops approximately once a week

by brubell on Tue Jan 29, 2019 11:30 am

I feel this is the offending code which disconnects you from IO, at the bottom of the loop:
Code: Select all | TOGGLE FULL SIZE
 // Repeat every 1000 seconds (16.6 min.)
  delay(1000000);


The code at the top of the loop pings Adafruit.IO, this keeps it connected to the service:
Code: Select all | TOGGLE FULL SIZE
  // ping adafruit io a few times to make sure we remain connected
  if(! mqtt.ping(3)) {
    // reconnect to adafruit io
    if(! mqtt.connected())
      connect();
  }


Since you're delaying for 16 minutes, the esp might become disconnected as this code doesn't run, and therefore doesn't ping the service that it's connected.

You might find success with using the deepsleep example: (https://github.com/adafruit/Adafruit_IO ... psleep.ino). It'll put your ESP into a special type of operating mode for low power consumption (which you'll want if you're reading every 16 minutes). When it restarts, it'll reconnect to IO (instead of connecting once, and attempting to ping, even if disconnected)

brubell
 
Posts: 336
Joined: Fri Jul 17, 2015 10:33 pm

Re: Stops approximately once a week

by tj1 on Tue Jan 29, 2019 4:05 pm

Thank You VERY MUCH Brubell !
I'll give that a try.
Tim

tj1
 
Posts: 21
Joined: Sun Apr 08, 2012 1:15 pm

Please be positive and constructive with your questions and comments.