Chat freely about anything...

User avatar
By ssaguiar
#56581 I have been working in a sketch, using atom ide, with a tft lcd (128X160), a rtc and a nodemcu esp8266.
It works fine, but crahses at random. It can work for several hours and crash, or work only minutes and crash.

The crash error is:

Code: Select allException (0):
epc1=0x40205850 epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000000 depc=0x00000000

ctx: sys
sp: 3ffffc50 end: 3fffffb0 offset: 01a0

>>>stack>>>
3ffffdf0:  00000000 4010078f 00000000 3ffed1d0
3ffffe00:  00000001 00000000 3fffc248 4000050c
3ffffe10:  40004371 00000030 00000016 ffffffff
3ffffe20:  60000200 00000008 00022700 80000000
3ffffe30:  20000000 3fff1008 80000000 203fc220
3ffffe40:  00000000 3fffc6fc 00000001 3fff100c
3ffffe50:  000000d4 003fc220 60000600 00000030

3ffffe60:  00000124 4010307d 00040000 40101e8a
3ffffe70:  401021af 00080000 00000003 ffffff80
3ffffe80:  00000000 0072561c 00000000 4000050c
3ffffe90:  00000000 00000000 0000001f 401048f9
3ffffea0:  4000050c 0055b9e4 402227df 3fff051c
3ffffeb0:  40000f68 00000030 00000011 ffffffff
3ffffec0:  40000f58 00000000 00000020 00000000
3ffffed0:  00000000 40201ff4 00000000 bfffffff
3ffffee0:  ffffffff 3fffc6fc 3ffed3d4 3fffdab0
3ffffef0:  00000000 3fffdcb0 3ffed4d0 00000030
3fffff00:  00000000 400042db 3ffe91d1 60000600
3fffff10:  40004b31 3fff0dec 000002f4 003fc000
3fffff20:  40104e5e 3ffed4c0 3ffed320 40107494
3fffff30:  4020a1d9 3ffed320 3ffed4c0 0114287d
3fffff40:  3fff0dec 00001000 4020a676 00000008
3fffff50:  4010486a 3ffed3d4 4020a723 3ffed3d4
3fffff60:  3ffed4c0 00560dfb 3ffed4c0 60000600
3fffff70:  4020d401 3ffed3d4 3ffed4c0 0113ddac
3fffff80:  4020d446 3fffdab0 00000000 3fffdcb0
3fffff90:  3ffed4e8 3fffdad0 3ffeea78 40201b8b
3fffffa0:  40000f49 0001190a 3fffdab0 40000f49
<<<stack<<<
PlatformIO: BuildFile 0Project 0No Issuessrc\Esp8266_ap.ino298:14
CRLFUTF-8C++


and the sketch is:
Code: Select all
/************************************************************************
****                ESP8266 - NodeMCU System Test                    ****
****                                                                 ****
****               Rs-232 parameters : 115200,8,n,1                  ****
****                                                                 ****
************************************************************************/
/*
ESP8266 - NodeMCU Pinout:
TOUT --- ADC0 -----|      |----- D0 -- GPIO16 -- USER -- WAKE
         Reserved -|      |----- D1 -- GPIO5 -- SCL
         Reserved -|      |----- D2 -- GPIO4 -- SDA
SDD3 --- GPIO10 ---|      |----- D3 -- GPIO0 -- FLASH
SDD2 --- GPIO9 ----|      |----- D4 -- GPIO2 -- TXD1
SDD1 --- MOSI -----|      |----- 3.3V
SDCMD -- CS -------|      |----- GND
SDD0 --- MISO -----|      |----- D5 -- GPIO14 ---------- HSCLK
SDCCLK - SCLK -----|      |----- D6 -- GPIO12 ---------- HMISO
         GND ------|      |----- D7 -- GPIO13 - RXD2 --- HMOSI
         3.3V -----|      |----- D8 -- GPIO15 - TXD2 --- HCS
         EN -------|      |----- GPIO3 -- RXD0
         RST ------|      |----- GPIO1 -- TXD0
         GND ------|      |----- GND
         VIN ------|      |----- 3.3V
*/

extern "C"
{
   #include "user_interface.h"
   //uint16 readvdd33(void);
}

ADC_MODE(ADC_VCC);

#include                     "Arduino.h"
#include                     <ESP8266WiFi.h>
#include                     <WiFiUdp.h>
#include                     <Adafruit_GFX.h>    // Core graphics library
#include                     <Adafruit_QDTech.h> // Hardware-specific library
#include                     <SPI.h>
#include                     <Wire.h>
#include                     <SimpleDHT.h>
#include                     <Time.h>
#include                     "c_types.h"

const   char   *ssid[] =
{
      "ssid1",
      "ssid2",
      "ssid3",
      "ssid4",
      "ssid5"
};

const   char   *password[] =
{
   "pass1",
   "pass2",
   "pass3",
   "pass4",
   "pass5"
};

unsigned int   ssidlistsize         = 5;
unsigned int   ssidconnectto         = 0;
unsigned int   contimeout            = 10;
unsigned int   connecttimeout         = 0;

bool   STATE_CYCLE_INITIAL         = false;
bool   STATE_CYCLE_GETTIME         = false;
bool   STATE_CYCLE_TOGGLELED      = false;
bool   STATE_CYCLE_SCANWIFI      = false;
bool   STATE_CYCLE_GETANALOG      = false;
bool   STATE_CYCLE_GETH11         = false;

bool         gettime            = false;
bool         changeLed         = false;
bool         scanwifi         = false;
bool         toggle            = false;

#define TIMETOGETTIME            600      // Get time every 10 minutes
#define TIMETOTOGGLELED            1      // Toggle led every 1/10 second
#define TIMETOSCANWIFI            100      // Scan wifi every 10 seconds
#define TIMETOGETANALOGREAD         200      // Get analog channel value every 20 seconds
#define   TIMETOGETHT11READ         300      // Get temperature and humidity every 30 seconds

#define SECS_PER_HOUR            3600

// Init pins
#define         sclk             D5
#define         mosi             D7
#define         cs               D0
#define         dc               D8
#define         rst              D6
#define         LED_PIN            D3
#define         LED_SCAN         D4
#define         DHTpin            D9

#define         ANALOG_PIN         A0 // The only analog pin on the Thing

#define         Binary            0
#define         Hex               1
#define         DS1307_I2C_ADDRESS  0x68    // Endereço do RTC

const int      timeZone         = -3;     // Brazil

unsigned int   counttogettime      = 0;
unsigned int   counttotoggleled   = 0;
unsigned int   counttoscanwifi      = 0;
unsigned int   counttogetanalog   = 0;
unsigned int   counttogetht11      = 0;
unsigned int   machinestate      = STATE_CYCLE_INITIAL;

unsigned int   out;

String         channel            = "";
String         spaces            = "              ";
String         presenttime         = "";

unsigned int   localPort         = 2390;      // local port to listen for UDP packets
unsigned int   ssidlist;

byte         ledStatus         = LOW;
byte         temperature;
byte         humidity;

byte         Second;     // Store second value
byte         Minute;     // Store minute value
byte         Hour;       // Store hour value
byte         dayOfWeek;  // Store day value
byte         dayOfMonth; // Store date value
byte         Month;      // Store month value
byte         Year;       // Store year value


char            *weekdayname[] =
{
   "Domingo",
   "Segunda-Feira",
   "Terca-Feira",
   "Quarta-Feira",
   "Quinta-Feira",
   "Sexta-Feira",
   "Sabado"
};

char         *MonthName[] =
{
   "Janeiro",
   "Fevereiro",
   "Marco",
   "Abril",
   "Maio",
   "Junho",
   "Julho",
   "Agosto",
   "Setembro",
   "Outubro",
   "Novembro",
   "Dezembro"
};

struct datetime_t           // Estrutura para operações com data/hora
{
    byte        Seconds;    // Store seconds value
    byte        Minute;     // Store minute value
    byte        Hour;       // Store hour value
    byte        Date;       // Store day value
    byte        WeekDay;    // Store week day
    byte        Month;      // Store month value
    byte        Year;       // Store year value
} datetime;

IPAddress timeServerIP; // time.nist.gov NTP server address
const char* ntpServerName = "gps.ntp.br";

const int NTP_PACKET_SIZE = 48; // NTP time stamp is in the first 48 bytes of the message
byte packetBuffer[ NTP_PACKET_SIZE]; //buffer to hold incoming and outgoing packets

// A UDP instance to let us send and receive packets over UDP
WiFiUDP               udp;
WiFiServer            server(80);
Adafruit_QDTech   tft    = Adafruit_QDTech(cs, dc, rst);  // Invoke custom library
SimpleDHT11 dht11      = SimpleDHT11();

time_t         prevDisplay = 0;   // when the digital clock was displayed
time_t         networkTime;      // Variable to hold NTP time to be set in Arduino/RTC

void            getDateDs1307(  byte *second, byte *minute, byte *hour, byte *dayOfWeek,
                                byte *dayOfMonth, byte *month, byte *year);

void            setDateDs1307(  byte second, byte minute, byte hour, byte dayOfWeek,
                                byte dayOfMonth, byte month, byte year);

uint8_t         decToBcd(int val);
uint8_t         bcdToDec(uint8_t val);

ETSTimer      *ptimer;

void timer0_ISR (void)
{
   noInterrupts();

   counttogettime++;
   counttogetanalog++;
   counttoscanwifi++;
   counttotoggleled++;
   counttogetht11++;

   timer0_write(ESP.getCycleCount() + 8000000L); // 80MHz == 0.1sec

   interrupts();
}

void setup()
{
   initsystem();
}

void loop()
{
   tft.setCursor(50, 20);
   tft.setTextSize(2); //set text size for seconds
   tft.setTextColor(QDTech_BLUE, QDTech_BLACK); // set color for seconds
   tft.print(millis() / 1000);
   tft.setTextSize(1); //set text size for all data coming from DHT11

   if (counttogettime >= TIMETOGETTIME)
   {
      counttogettime = 0;
      updateNtpTime();
   }

   if (counttogetanalog >= TIMETOGETANALOGREAD)
   {
      counttogetanalog = 0;
      getanalogstate();
   }

   if (counttoscanwifi >= TIMETOSCANWIFI)
   {
      counttoscanwifi = 0;
      scanWifiNetwork();
   }

   if (counttotoggleled >= TIMETOTOGGLELED)
   {
      counttotoggleled = 0;

      if (toggle == true)
      {
         digitalWrite(LED_PIN, HIGH);
         toggle = false;
      }
      else
      {
         digitalWrite(LED_PIN, LOW);
         toggle = true;
      }

      //tft.fillRect (0, 0, 80, 16, QDTech_BLUE);
      tft.setTextColor(QDTech_WHITE, QDTech_BLUE); // set color for seconds
      tft.setCursor (78, 5);
      tft.print(__TIME__);
   }

   if (counttogetht11 >= TIMETOGETHT11READ)
   {
      counttogetht11 = 0;
      //getdht11data();
   }
}

void getdht11data()
{
   /*
   if (dht11.read(DHTpin, &temperature, &humidity, NULL))
   {
      Serial.print("Failed.");
   }
   else
   {
      Serial.print("temperature: ");
      Serial.print(temperature);
      Serial.println(" C");
      Serial.print("Humidity: ");
      Serial.print(humidity);
      Serial.println("%");
   }
   */
}

void getanalogstate()
{
   //out = (unsigned int) analogRead(ANALOG_PIN);
   float vdd = ESP.getVcc() / 1000.0;
   Serial.print("Power supply: ");
   Serial.print(vdd);
   Serial.println(" Volts");
}

void scanWifiNetwork()
{
   digitalWrite(LED_SCAN, HIGH);
   int n = WiFi.scanNetworks();

   if (n == 0)
   {
      tft.setTextColor(QDTech_WHITE, QDTech_BLUE); // set color for seconds
      tft.setCursor (2, 5);
      tft.print("no networks");
   }
   else
   {
      tft.setTextColor(QDTech_WHITE, QDTech_BLUE); // set color for seconds
      tft.setCursor (2, 5);
      tft.print(n);
      tft.print(" networks");
      tft.fillRect (0, 18, 128, 122, QDTech_BLACK);
      tft.setTextColor(QDTech_GREEN, QDTech_BLACK);
      tft.setCursor (0, 42);

      if (n > 10) n = 10;
      for (int i = 0; i < n; ++i)
      {
         channel =  WiFi.SSID(i);

         if (channel.length() > 15)
         {
            channel = channel.substring(0, 14);
         }

         if (channel.length() < 15)
         {
            channel = channel + spaces.substring(0, 14 - channel.length());
         }

         tft.setTextColor(QDTech_GREEN, QDTech_BLACK);
         tft.print(channel);
         tft.print(" ");
         tft.setTextColor(QDTech_YELLOW, QDTech_BLACK);
         tft.print(WiFi.RSSI(i));
         tft.setTextColor(QDTech_BLUE, QDTech_BLACK);
         tft.println((WiFi.encryptionType(i) == ENC_TYPE_NONE)?"  ":" *");

         delay(10);
      }
   }

   DisplayTime();
   digitalWrite(LED_SCAN, LOW);
}

void updateNtpTime()
{
   Serial.println("Getting time from server...");
   networkTime = getNtpTime();

   if (networkTime > 0)
   {
      dayOfWeek      = weekday(networkTime);
      dayOfMonth      = day(networkTime);
      Month         = month(networkTime);
      Year         = year(networkTime) - 2000;
      Hour         = hour(networkTime);
      Minute         = minute(networkTime);
      Second         = second(networkTime);

      Serial.print(dayOfMonth);              // The day for the given time t
      Serial.print("/");
      Serial.print(Month);                  // The month for the given time t
      Serial.print("/");
      Serial.print(Year);
      Serial.print(" - ");
      Serial.print(Hour);                   // Returns the hour for the given
      Serial.print(":");
      Serial.print(Minute);                 // Returns the minute for the given
      Serial.print(":");
      Serial.print(Second);                 // Returns the second for the given
      Serial.print(" -> weekday: ");
      Serial.println(dayOfWeek);             // Day of the week for the given

      Serial.println(networkTime);

      setDateDs1307(  decToBcd(Second),               // 0-59
                       decToBcd(Minute),               // 0-59
                       decToBcd(Hour),                  // 1-23
                       weekday(dayOfWeek),               // 1-7
                       decToBcd(dayOfMonth),            // 1-28/29/30/31
                       decToBcd(Month),               // 1-12
                       decToBcd(Year));               // 0-99

      Serial.print("Result of NTP: ");
       Serial.print(weekdayname[dayOfWeek-1]);
       Serial.print(", ");
       Serial.print(dayOfMonth);
       Serial.print(" de ");
       Serial.print(MonthName[Month-1]);
       Serial.print(" de 20");
       Serial.print(Year);
       Serial.print(" - ");
       Serial.print(Hour);
       Serial.print(":");
       Serial.println(Minute);

   }
}

time_t getNtpTime()
{
   //digitalWrite(LED_NTP, HIGH);

   Serial.println("getNtpTime");

   //get a random server from the pool
   WiFi.hostByName(ntpServerName, timeServerIP);

   sendNTPpacket(timeServerIP); // send an NTP packet to a time server
   // wait to see if a reply is available
   delay(1000);

   int cb = udp.parsePacket();
   if (!cb)
   {
      Serial.println("no packet yet");
      return 0;
   }
   else
   {
      // We've received a packet, read the data from it
      udp.read(packetBuffer, NTP_PACKET_SIZE); // read the packet into the buffer

      unsigned long secsSince1900;
      // convert four bytes starting at location 40 to a long integer
      secsSince1900 =  (unsigned long)packetBuffer[40] << 24;
      secsSince1900 |= (unsigned long)packetBuffer[41] << 16;
      secsSince1900 |= (unsigned long)packetBuffer[42] << 8;
      secsSince1900 |= (unsigned long)packetBuffer[43];

      //digitalWrite(LED_NTP, LOW);

      return secsSince1900 - 2208988800UL + timeZone * SECS_PER_HOUR;
   }
}

// send an NTP request to the time server at the given address
unsigned long sendNTPpacket(IPAddress& address)
{
   // set all bytes in the buffer to 0
   memset(packetBuffer, 0, NTP_PACKET_SIZE);

   // Initialize values needed to form NTP request
   // (see URL above for details on the packets)
   packetBuffer[0] = 0b11100011;   // LI, Version, Mode
   packetBuffer[1] = 0;     // Stratum, or type of clock
   packetBuffer[2] = 6;     // Polling Interval
   packetBuffer[3] = 0xEC;  // Peer Clock Precision
   // 8 bytes of zero for Root Delay & Root Dispersion
   packetBuffer[12]  = 49;
   packetBuffer[13]  = 0x4E;
   packetBuffer[14]  = 49;
   packetBuffer[15]  = 52;

   // all NTP fields have been given values, now
   // you can send a packet requesting a timestamp:
   udp.beginPacket(address, 123); //NTP requests are to port 123
   udp.write(packetBuffer, NTP_PACKET_SIZE);
   udp.endPacket();
}

void initsystem()
{
   // Init serial for serial monitor, so we can see debug text in the Serial Monitor Window
   Serial.begin(115200);
   while (!Serial) ; // wait for serial
   delay(2000);

   counttogettime         = 0;
   counttotoggleled      = 0;
   counttoscanwifi         = 0;

   gettime               = false;
   changeLed            = false;
   scanwifi            = false;

   //pinMode(5, INPUT_PULLUP);
   //attachInterrupt(digitalPinToInterrupt(5), notifyOnButtonPress, CHANGE);


   Serial.println("Starting wifi...");

   // Put WiFi into Station mode
   WiFi.mode(WIFI_STA);
   ssidconnectto = 0;
   pinMode(LED_PIN, OUTPUT);
   pinMode(LED_SCAN, OUTPUT);
   //pinMode(LED_NTP, OUTPUT);
   pinMode(ANALOG_PIN, INPUT);
   digitalWrite(LED_PIN, LOW);
   digitalWrite(LED_SCAN, HIGH);

   tft.init();

   uint16_t time = millis();
   tft.setRotation(0);   // 0 - Portrait, 1 - Lanscape
   tft.fillScreen(QDTech_BLACK);
   tft.setTextWrap(true);
   delay(500);

   // large block of text
   tft.fillScreen (QDTech_BLACK);
   tft.fillRect (0, 0, 128, 16, QDTech_BLUE);
   tft.fillRect (0, 142, 128, 36, QDTech_BLUE);

   tft.drawLine(0, 16, 128, 16, QDTech_WHITE);
   tft.drawLine(0, 141, 128, 141, QDTech_WHITE);

   //noInterrupts();

   tft.setTextSize(1); //set text size for seconds
   tft.setTextColor(QDTech_BLUE, QDTech_BLACK); // set color for seconds

   while (WiFi.status() != WL_CONNECTED)
   {
      digitalWrite(LED_SCAN, HIGH);
      connecttimeout = 0;
      tft.fillRect (0, 18, 128, 122, QDTech_BLACK);
      tft.setCursor (0, 30);
      tft.println("Trying to connect to:");
      tft.println(ssid[ssidconnectto]);

      WiFi.begin(ssid[ssidconnectto], password[ssidconnectto]);

      // Wait for connection
      while ((WiFi.status() != WL_CONNECTED) && (connecttimeout++ <= contimeout))
      {
         tft.print(".");
         delay(1000);
      }

      contimeout   = 10;

      if(++ssidconnectto == ssidlistsize)
      {
         ssidconnectto = 0;
      }

      digitalWrite(LED_SCAN, LOW);
      delay(3000);
   }

   //interrupts();

   tft.fillRect (0, 18, 128, 122, QDTech_BLACK);

   Wire.begin();                           // join i2c bus (address optional for master)

   Wire.beginTransmission(DS1307_I2C_ADDRESS);
   Wire.write((uint8_t)0x00);                      // Register 0x00 holds the oscillator start/stop bit
   Wire.endTransmission();
   Wire.requestFrom(DS1307_I2C_ADDRESS, 1);
   int second = Wire.read() & 0x7f;       // save actual seconds and AND sec with bit 7 (sart/stop bit) = clock started
   Wire.beginTransmission(DS1307_I2C_ADDRESS);
   Wire.write((uint8_t)0x00);
   Wire.write((uint8_t)second);                    // write seconds back and start the clock
   Wire.endTransmission();

   digitalWrite(LED_PIN,HIGH);
   ledStatus = HIGH;

   // Start the server
   server.begin();

   tft.fillRect (0, 142, 128, 36, QDTech_BLUE);
   tft.setTextColor(QDTech_WHITE, QDTech_BLUE);
   tft.setCursor (2, 148);
   tft.setTextSize(1);
   tft.print("MY IP:");
   tft.println (WiFi.localIP());
   tft.setTextSize(1);

   udp.begin(localPort);

   noInterrupts();
   timer0_isr_init();
   timer0_attachInterrupt(timer0_ISR);
   timer0_write(ESP.getCycleCount() + 8000000L); // 80MHz == 0.1sec
   interrupts();

   //setSyncProvider(RTC.get);
   //setSyncProvider(&getNtpTime);
   //setSyncInterval(TIMETOGETTIME); // Seconds between resync. If not set, the dafault is 5 minutes.
}


/****************************************************************************
* DESCRIPTION: Sets the date and time to the ds1307
* RETURN:      none
* ALGORITHM:   none
* NOTES:       none
*****************************************************************************/

void setDateDs1307(byte second,        // 0-59
                   byte minute,        // 0-59
                   byte hour,          // 1-23
                   byte dayOfWeek,     // 1-7
                   byte dayOfMonth,    // 1-28/29/30/31
                   byte month,         // 1-12
                   byte year)          // 0-99
{
   Wire.beginTransmission(DS1307_I2C_ADDRESS);
   Wire.write(0);

   Wire.write(second);
   Wire.write(minute);
   Wire.write(hour);
   Wire.write(dayOfWeek);
   Wire.write(dayOfMonth);
   Wire.write(month);
   Wire.write(year);
   Wire.endTransmission();
}

/****************************************************************************
* DESCRIPTION: Gets the date and time from the ds1307
* RETURN:      none
* ALGORITHM:   none
* NOTES:       none
*****************************************************************************/

void getDateDs1307( byte *second,
                    byte *minute,
                    byte *hour,
                    byte *dayOfWeek,
                    byte *dayOfMonth,
                    byte *month,
                    byte *year)
{
  // Reset the register pointer
  Wire.beginTransmission(DS1307_I2C_ADDRESS);
  Wire.write(0);
  Wire.endTransmission();

  Wire.requestFrom(DS1307_I2C_ADDRESS, 7);

  // A few of these need masks because certain bits are control bits
  *second     = (Wire.read());
  *minute     = (Wire.read());
  *hour       = (Wire.read());  // Need to change this if 12 hour am/pm
  *dayOfWeek  = (Wire.read());
  *dayOfMonth = (Wire.read());
  *month      = (Wire.read());
  *year       = (Wire.read());
}

/****************************************************************************
* DESCRIPTION: Read and display date/time from RTC
* RETURN:      none
* ALGORITHM:   none
* NOTES:       none
*****************************************************************************/
void DisplayTime()
{
    getDateDs1307(  &datetime.Seconds, &datetime.Minute, &datetime.Hour, &datetime.WeekDay, &datetime.Date, &datetime.Month, &datetime.Year);

/*
   Serial.println("DisplayTime() ");

   Serial.print("datetime.Seconds = ");
   if (datetime.Seconds < 10) Serial.print("0");
   Serial.println(datetime.Seconds);
   Serial.print("datetime.Minute = ");
   if (datetime.Minute < 10) Serial.print("0");
   Serial.println(datetime.Minute);
   Serial.print("datetime.Hour = ");
   if (datetime.Hour < 10) Serial.print("0");
   Serial.println(datetime.Hour);
   Serial.print("datetime.WeekDay = ");
   Serial.println(datetime.WeekDay);
   if (datetime.Date < 10) Serial.print("0");
   Serial.print("datetime.Date = ");
   Serial.println(datetime.Date);
   if (datetime.Month < 10) Serial.print("0");
   Serial.print("datetime.Month = ");
   Serial.println(datetime.Month);
   Serial.print("datetime.Year = 20");
   Serial.println(datetime.Year);
*/

   Serial.println("-----------------------------------------");

   Serial.println("DisplayTime() 1:");
   Serial.print(weekdayname[dayOfWeek-1]);
   Serial.print(", ");
   Serial.print(dayOfMonth);
   Serial.print(" de ");
   Serial.print(MonthName[Month-1]);
   Serial.print(" de 20");
   Serial.print(Year);
   Serial.print(" - ");
   Serial.print(Hour);
   Serial.print(":");
   Serial.println(Minute);

   Serial.println("-----------------------------------------");

   Serial.println("DisplayTime() 2:");

   time_t s_tm = tmConvert_t(datetime.Year, datetime.Month, datetime.Date, datetime.Hour, datetime.Minute, datetime.Seconds);

    Serial.print(weekdayname[datetime.WeekDay - 1]);
    Serial.print(", ");

    if (datetime.Date < 10) Serial.print("0");
    Serial.print(datetime.Date, HEX);
    Serial.print(" de ");

    Serial.print(MonthName[datetime.Month - 1]);//(datetime.Month, DEC)+1]);
    Serial.print(" de 20");

    if (datetime.Year < 10)
    Serial.print("0");
    Serial.print(datetime.Year, HEX);
    Serial.print(" ");

    if (datetime.Hour < 10) Serial.print("0");
    Serial.print(datetime.Hour, HEX);
    Serial.print(":");

    if (datetime.Minute < 10) Serial.print("0");
    Serial.print(datetime.Minute, HEX);
    Serial.print(":");

    if (datetime.Seconds < 10) Serial.print("0");
    Serial.println(datetime.Seconds, HEX);

   Serial.println("-----------------------------------------");

}

uint8_t decToBcd( int val )
{
    return (uint8_t) ((val / 10 * 16) + (val % 10));
}

uint8_t bcdToDec( uint8_t val )
{
    return (uint8_t) ((val / 16 * 10) + (val % 16));
}



// Visto em http://forum.arduino.cc/index.php?topic=61529.0
time_t tmConvert_t(int YYYY, byte MM, byte DD, byte hh, byte mm, byte ss)
{
  tmElements_t tmSet;
  tmSet.Year = YYYY - 1970;
  tmSet.Month = MM;
  tmSet.Day = DD;
  tmSet.Hour = hh;
  tmSet.Minute = mm;
  tmSet.Second = ss;
  return makeTime(tmSet);         //convert to time_t
}


I wish to know if somebody can help to find what is the error.

Thanks a lot for any help.
User avatar
By ssaguiar
#56633 The function prototype is commented.
I use, for the power supply read:

Code: Select allvoid getanalogstate()
{
   //out = (unsigned int) analogRead(ANALOG_PIN);
   float vdd = ESP.getVcc() / 1000.0;
   Serial.print("Power supply: ");
   Serial.print(vdd);
   Serial.println(" Volts");
}