Example sketches for the new Arduino IDE for ESP8266

Moderator: igrr

User avatar
By Slider2732
#55279 It's been a lot of fun Dans and I should also thank Mikejstb for the way he introduced the sprintf method..which was new learning !
Have been here a while, sort of as a lurker and have no idea how to edit posts. I realised pretty fast that pics and the code itself should have been in the original post, not many want to click on YouTube links (I don't 'monetize' the channel at all, no adverts etc).

Anyway, there is a Beta version of a clock now, instead of Thingspeak data.
It will run for about 45 seconds once connected to home WiFi and showing the time, but then both an ESP-01 and ESP-03 bomb out with an Exception (20) error :shock:
It's fine for a quick switch on, checking the time and switch off and will loop as usual when scanning AP's, but that's no solution !!!!
This may be a broader issue than your thread/wrong section for working through. i'd welcome any advice on fixing it.
i also noted something about a large Font ? and would like to put large numbers on the OLED for the time :)

Code is attached (replaces the original .ino. The OLED and Fonts files should also be in the same folder for use in the Arduino IDE).


Pic of Scanner-01 build:
Image
You do not have the required permissions to view the files attached to this post.
User avatar
By danbicks
#55328 Slider,

Had a quick look at your code buddy, I think your issue is with UDP time code.

I use Google for NTP time, and alleviate Json etc. See if the following helps you out.
It is a bit of a hash but works a treat, uses TCP client instead..

Good luck keep me posted on your progress.... Dans

Declare in global scope the following, you may need to add any flags prefixed FL_ as well data type bool

Code: Select all// added NTP strings
String NTP_Time_Str,TMnow,MyNtP;                                 // The current TimeStamp from Google....
int NTP_Hour,NTP_Min,NTP_Sec,newt,newt1,inChar,SCsa,MNsa,HRsa;   // Integer values from Gooogle time reply
int hr,mn,st,st1;                                         // Uptime Duration Counter......
String DsTable;                                           // Discarded parts if the Strings......
String theDate,theDate1,duration1,theDateTr;              // The current TimeStamp Date from Google....



Main Code Routines, I call Get_NTP() every 20 seconds and use return to control automation of sockets and lighting around my house..

Code: Select all/*
------------------------------------------------------------------------------------
                     NTP SUBROUTINES ALL LOCATED HERE
------------------------------------------------------------------------------------
*/

void Get_NTP()

{
  FL_NTP_Got = false;
  WiFiClient NTPclient;
  while (!!!NTPclient.connect("google.co.uk", 80))
  {

  }
 
  NTPclient.print("HEAD / HTTP/1.1\r\n\r\n");
  while(!!!NTPclient.available())
  {
     yield();
  }
 
  while(NTPclient.available())
  {
  NTPclient.readStringUntil('\n');
   theDate1 = NTPclient.readStringUntil('\r'); //Date: Tue, 10 Nov 2015 19:55:38 GMT
    if (theDate1.startsWith("Date:"))
       {
       NTP_Time_Str = theDate1;
       theDate = theDate1.substring(6,23);
       NTPclient.flush();
       NTPclient.stop();
       Serial.println(theDate1);
       FL_NTP_Got = true;
       return;                   
       }
       else
       {
       FL_NTP_Got = false;
       }
  }

  FL_NTP_Got = false;
  Serial.println("Not successful in Obtaining time date via NTP..");
}

/*
------------------------------------------------------------------------------------
                        PARSE NTP TO VARIABLES HERE
------------------------------------------------------------------------------------
*/

void ParseToVar()

{
 
  String Day;
   
  inChar = NTP_Time_Str.charAt(30);
  newt=inChar-48;             // Convert Numerical Char to int.....
  inChar = NTP_Time_Str.charAt(29);  // seconds
  newt1=inChar-48;
  NTP_Sec=(newt1*10)+newt;
 
  inChar = NTP_Time_Str.charAt(27);  // mins
  newt=inChar-48;
  inChar = NTP_Time_Str.charAt(26);
  newt1=inChar-48;
  NTP_Min=(newt1*10)+newt;
 
  inChar = NTP_Time_Str.charAt(24);  // hours
  newt=inChar-48;
  inChar = NTP_Time_Str.charAt(23);
  newt1=inChar-48;
  NTP_Hour=(newt1*10)+newt;

  if (config.daylight) // add hour if daylight saving enabled
     {
     NTP_Hour ++; // inc by one
     }
 
// get Day!
  Day = "";
  Day = NTP_Time_Str.charAt(6);
  Day += NTP_Time_Str.charAt(7);
  Day += NTP_Time_Str.charAt(8);


 // Serial.print("Hour: ");Serial.println(NTP_Hour);
 // Serial.print("Mins: ");Serial.println(NTP_Min);
 // Serial.print("Secs: ");Serial.println(NTP_Sec);

 // Serial.print("Day: ");Serial.println(Day); 

}



Use the following in the main loop, only parse if FL_NTP_Got is set.

Code: Select allGet_NTP(); // check FTP
                if (FL_NTP_Got)
                   {
                   ParseToVar(); // pass all to variables
                  // do your print or check time stuff here
                  }
User avatar
By Slider2732
#55335 Many thanks 8-)
There are likely a few ways that should work, but it makes sense to put code that you use yourself into a project that you started !
So, will have a crack at the changes.

I blame that 1900 time stamping thing...because, perhaps with some sort of middle aged stubbornness and naivety going on, I can't fathom why it hasn't at least been bumped to the year 2000 yet. Apparently there'll be a Y2K issue in a few years over it, so why the persistence with ultra huge seconds from 1900 and then adding 70 years etc ?????
I mean, really, for ESP8266's it should be 2014. We can't be talking ease of use and round numbers here, not with that huge seconds number and setting it to some mythical Unix start up moment :shock:
It's over, been and gone, kaput, walked away into history lol
No wonder stuff falls over !
"Sir, why do all these shipping containers have a large penguin on them ?"
"Oh well because Linus Torvalds once sneezed into a handkerchief that was made in Brazil, so we mark all the Brazilian freight like that"


Anyway *cough*
/rant

:D