@ -16,144 +16,84 @@ 
			
		
	
		
		
			
				
					
 
			
		
	
		
		
			
				
					
 
			
		
	
		
		
			
				
					//-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
  
			
		
	
		
		
			
				
					
					ahoywifi : : ahoywifi ( settings_t  * config )  { ahoywifi : : ahoywifi ( )  {  
			
				
				
			
		
	
		
		
			
				
					
					    mConfig   =  config ;     mCnt        =  0 ;  
			
				
				
			
		
	
		
		
			
				
					
					
    mConnected  =  false ;  
			
				
				
			
		
	
		
		
			
				
					
					    mDns  =  new  DNSServer ( ) ;     mInitNtp    =  true ;  
			
				
				
			
		
	
		
		
			
				
					    mUdp  =  new  WiFiUDP ( ) ;  
			
		
	
		
		
			
				
					
 
			
		
	
		
		
			
				
					    mWifiStationTimeout  =  10 ;  
			
		
	
		
		
			
				
					    wifiWasEstablished   =  false ;  
			
		
	
		
		
			
				
					    mNextTryTs           =  0 ;  
			
		
	
		
		
			
				
					    mApLastTick          =  0 ;  
			
		
	
		
		
			
				
					    mApActive            =  false ;  
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					} }  
			
		
	
		
		
			
				
					
 
			
		
	
		
		
			
				
					
 
			
		
	
		
		
			
				
					//-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
  
			
		
	
		
		
			
				
					
					void  ahoywifi : : setup ( uint32_t  timeout ,  bool  settingValid )  { void  ahoywifi : : setup ( settings_t  * config ,  uint32_t  * utcTimestamp )  {  
			
				
				
			
		
	
		
		
			
				
					
					    //wifiConnectHandler = WiFi.onStationModeGotIP(std::bind(&ahoywifi::onConnect, this, std::placeholders::_1));
     char  ipSta [ 16 ] ;  
			
				
				
			
		
	
		
		
			
				
					
					    //wifiDisconnectHandler = WiFi.onStationModeDisconnected(std::bind(&ahoywifi::onDisconnect, this, std::placeholders::_1));
     mConfig  =  config ;  
			
				
				
			
		
	
		
		
			
				
					
					
     mUtcTimestamp  =  utcTimestamp ;   
			
				
				
			
		
	
		
		
			
				
					
					    # ifdef FB_WIFI_OVERRIDDEN  
  
			
				
				
			
		
	
		
		
			
				
					
					        mStationWifiIsDef  =  false ;      # if !defined(FB_WIFI_OVERRIDDEN)  
			
				
				
			
		
	
		
		
			
				
					
					    # else         if ( strncmp ( mConfig - > sys . stationSsid ,  FB_WIFI_SSID ,  14 )  ! =  0 )   
			
				
				
			
		
	
		
		
			
				
					
					        mStationWifiIsDef  =  ( strncmp ( mConfig - > sys . stationSsid ,  FB_WIFI_SSID ,  14 )  = =  0 ) ;             setupAp (  ) ;  
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					    # endif     # endif  
			
		
	
		
		
			
				
					
					    mWifiStationTimeout  =  timeout ;     # if !defined(AP_ONLY)  
			
				
				
			
		
	
		
		
			
				
					
					    # ifndef AP_ONLY         setupStation ( ) ;  
			
				
				
			
		
	
		
		
			
				
					
					        if ( false  = =  mApActive )         ah : : ip2Char ( mConfig - > sys . ip . ip ,  ipSta ) ;  
			
				
				
			
		
	
		
		
			
				
					            mApActive  =  ( mStationWifiIsDef )  ?  true  :  setupStation ( mWifiStationTimeout ) ;  
			
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					    # endif     # endif  
			
		
	
		
		
			
				
					
					    if ( ! settingValid )  { 
 
			
				
				
			
		
	
		
		
			
				
					
					        DPRINTLN ( DBG_WARN ,  F ( " your settings are not valid! check [IP]/setup " ) ) ;     wifiConnectHandler  =  WiFi . onStationModeGotIP ( std : : bind ( & ahoywifi : : onConnect ,  this ,  std : : placeholders : : _1 ) ) ;  
			
				
				
			
		
	
		
		
			
				
					
					        mApActive  =  true ;     wifiDisconnectHandler  =  WiFi . onStationModeDisconnected ( std : : bind ( & ahoywifi : : onDisconnect ,  this ,  std : : placeholders : : _1 ) ) ;  
			
				
				
			
		
	
		
		
			
				
					        mApLastTick  =  millis ( ) ;  
			
		
	
		
		
			
				
					        mNextTryTs  =  ( millis ( )  +  ( WIFI_AP_ACTIVE_TIME  *  1000 ) ) ;  
			
		
	
		
		
			
				
					        setupAp ( WIFI_AP_SSID ,  WIFI_AP_PWD ) ;  
			
		
	
		
		
			
				
					    }  
			
		
	
		
		
			
				
					    else  {  
			
		
	
		
		
			
				
					        DPRINTLN ( DBG_INFO ,  F ( " \n \n ---------------------------------------- " ) ) ;  
			
		
	
		
		
			
				
					        DPRINTLN ( DBG_INFO ,  F ( " Welcome to AHOY! " ) ) ;  
			
		
	
		
		
			
				
					        DPRINT ( DBG_INFO ,  F ( " \n point your browser to http:// " ) ) ;  
			
		
	
		
		
			
				
					        if ( mApActive )  
			
		
	
		
		
			
				
					            DBGPRINTLN ( F ( " 192.168.4.1 " ) ) ;  
			
		
	
		
		
			
				
					        else  
			
		
	
		
		
			
				
					            DBGPRINTLN ( WiFi . localIP ( ) . toString ( ) ) ;  
			
		
	
		
		
			
				
					        DPRINTLN ( DBG_INFO ,  F ( " to configure your device " ) ) ;  
			
		
	
		
		
			
				
					        DPRINTLN ( DBG_INFO ,  F ( " ---------------------------------------- \n " ) ) ;  
			
		
	
		
		
			
				
					    }  
			
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					} }  
			
		
	
		
		
			
				
					
 
			
		
	
		
		
			
				
					
 
			
		
	
		
		
			
				
					//-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
  
			
		
	
		
		
			
				
					
					bool  ahoywifi : : loop ( void )  { void  ahoywifi : : loop ( )  {  
			
				
				
			
		
	
		
		
			
				
					
					    if ( mApActive )  {     # if !defined(AP_ONLY)  
			
				
				
			
		
	
		
		
			
				
					
					        mDns - > processNextRequest ( ) ;     if ( ! mConnected )  {  
			
				
				
			
		
	
		
		
			
				
					
					# ifndef AP_ONLY         delay ( 100 ) ;  
			
				
				
			
		
	
		
		
			
				
					
					        if ( ah : : checkTicker ( & mNextTryTs ,  ( WIFI_AP_ACTIVE_TIME  *  1000 ) ) )  {         mCnt + + ;  
			
				
				
			
		
	
		
		
			
				
					
					            mApActive  =  ( mStationWifiIsDef )  ?  true  :  setupStation ( mWifiStationTimeout ) ;         if ( ( mCnt  %  50 )  = =  0 )  
			
				
				
			
		
	
		
		
			
				
					
					            if ( mApActive )  {             WiFi . disconnect ( ) ;  
			
				
				
			
		
	
		
		
			
				
					
					                if ( strlen ( WIFI_AP_PWD )  <  8 )         else  if ( ( mCnt  %  60 )  = =  0 )  {  
			
				
				
			
		
	
		
		
			
				
					
					                    DPRINTLN ( DBG_ERROR ,  F ( " password must be at least 8 characters long " ) ) ;             WiFi . reconnect ( ) ;  
			
				
				
			
		
	
		
		
			
				
					
					                mApLastTick  =  millis ( ) ;             mCnt  =  0 ;  
			
				
				
			
		
	
		
		
			
				
					                mNextTryTs  =  ( millis ( )  +  ( WIFI_AP_ACTIVE_TIME  *  1000 ) ) ;  
			
		
	
		
		
			
				
					                setupAp ( WIFI_AP_SSID ,  WIFI_AP_PWD ) ;  
			
		
	
		
		
			
				
					            }  
			
		
	
		
		
			
				
					        }  
			
		
	
		
		
			
				
					        else  {  
			
		
	
		
		
			
				
					            if ( millis ( )  -  mApLastTick  >  10000 )  {  
			
		
	
		
		
			
				
					                mApLastTick  =  millis ( ) ;  
			
		
	
		
		
			
				
					                uint8_t  cnt  =  WiFi . softAPgetStationNum ( ) ;  
			
		
	
		
		
			
				
					                if ( cnt  >  0 )  {  
			
		
	
		
		
			
				
					                    DPRINTLN ( DBG_INFO ,  String ( cnt )  +  F ( "  client connected (no timeout) " ) ) ;  
			
		
	
		
		
			
				
					                    mNextTryTs  =  ( millis ( )  +  ( WIFI_AP_ACTIVE_TIME  *  1000 ) ) ;  
			
		
	
		
		
			
				
					                }  
			
		
	
		
		
			
				
					                else  {  
			
		
	
		
		
			
				
					                    DBGPRINT ( F ( " AP will be closed in  " ) ) ;  
			
		
	
		
		
			
				
					                    DBGPRINT ( String ( ( mNextTryTs  -  mApLastTick )  /  1000 ) ) ;  
			
		
	
		
		
			
				
					                    DBGPRINTLN ( F ( "  seconds " ) ) ;  
			
		
	
		
		
			
				
					                }  
			
		
	
		
		
			
				
					            }  
			
		
	
		
		
			
				
					        }  
			
		
	
		
		
			
				
					# endif  
			
		
	
		
		
			
				
					    }  
			
		
	
		
		
			
				
					
 
			
		
	
		
		
			
				
					    if ( ( WiFi . status ( )  ! =  WL_CONNECTED )  & &  wifiWasEstablished )  {  
			
		
	
		
		
			
				
					        if ( ! mApActive )  {  
			
		
	
		
		
			
				
					            DPRINTLN ( DBG_INFO ,  " [WiFi]: Connection Lost " ) ;  
			
		
	
		
		
			
				
					            mApActive  =  ( mStationWifiIsDef )  ?  true  :  setupStation ( mWifiStationTimeout ) ;  
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					        }         }  
			
		
	
		
		
			
				
					    }  else  if ( mInitNtp )  {  
			
		
	
		
		
			
				
					        getNtpTime ( ) ;  
			
		
	
		
		
			
				
					        mInitNtp  =  false ;  
			
		
	
		
		
			
				
					    }     }  
			
		
	
		
		
			
				
					    mCnt  =  0 ;  
			
		
	
		
		
			
				
					    # endif  
			
		
	
		
		
			
				
					
 
			
		
	
		
		
			
				
					    return  mApActive ;  
			
		
	
		
		
			
				
					} }  
			
		
	
		
		
			
				
					
 
			
		
	
		
		
			
				
					
 
			
		
	
		
		
			
				
					//-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
  
			
		
	
		
		
			
				
					
					void  ahoywifi : : setupAp ( const  char  * ssid ,  const  char  * pw d)  { void  ahoywifi : : setupAp ( void )  {  
			
				
				
			
		
	
		
		
			
				
					
					    DPRINTLN ( DBG_VERBOSE ,  F ( " app ::setupAp" ) ) ;     DPRINTLN ( DBG_VERBOSE ,  F ( " wifi::setupAp " ) ) ;  
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					    IPAddress  apIp ( 192 ,  168 ,  4 ,  1 ) ;     IPAddress  apIp ( 192 ,  168 ,  4 ,  1 ) ;  
			
		
	
		
		
			
				
					
 
			
		
	
		
		
			
				
					
					    DBGPRINTLN ( F ( " \n --------- \n Ahoy Info: " ) ) ;     DBGPRINTLN ( F ( " \n --------- \n AhoyDTU Info: " ) ) ;  
			
				
				
			
		
	
		
		
	
		
		
			
				
					    DBGPRINT ( F ( " Version:  " ) ) ;     DBGPRINT ( F ( " Version:  " ) ) ;  
			
		
	
		
		
			
				
					    DBGPRINTLN ( String ( VERSION_MAJOR )  +  F ( " . " )  +  String ( VERSION_MINOR )  +  F ( " . " )  +  String ( VERSION_PATCH ) ) ;     DBGPRINTLN ( String ( VERSION_MAJOR )  +  F ( " . " )  +  String ( VERSION_MINOR )  +  F ( " . " )  +  String ( VERSION_PATCH ) ) ;  
			
		
	
		
		
			
				
					    DBGPRINT ( F ( " Github Hash:  " ) ) ;     DBGPRINT ( F ( " Github Hash:  " ) ) ;  
			
		
	
		
		
			
				
					    DBGPRINTLN ( String ( AUTO_GIT_HASH ) ) ;     DBGPRINTLN ( String ( AUTO_GIT_HASH ) ) ;  
			
		
	
		
		
			
				
					
 
			
		
	
		
		
			
				
					    DBGPRINT ( F ( " \n --------- \n AP MODE \n SSID:  " ) ) ;     DBGPRINT ( F ( " \n --------- \n AP MODE \n SSID:  " ) ) ;  
			
		
	
		
		
			
				
					
					    DBGPRINTLN ( ssid ) ;     DBGPRINTLN ( WIFI_AP_SSID ) ;  
			
				
				
			
		
	
		
		
	
		
		
			
				
					    DBGPRINT ( F ( " PWD:  " ) ) ;     DBGPRINT ( F ( " PWD:  " ) ) ;  
			
		
	
		
		
			
				
					
					    DBGPRINTLN ( pwd ) ;     DBGPRINTLN ( WIFI_AP_PWD ) ;  
			
				
				
			
		
	
		
		
			
				
					
					    DBGPRINT ( F ( " \n Active for:  " ) ) ;     DBGPRINTLN ( " IP Address: http:// "  +  apIp . toString ( ) ) ;  
			
				
				
			
		
	
		
		
			
				
					
					    DBGPRINT ( String ( WIFI_AP_ACTIVE_TIME ) ) ;     DBGPRINTLN ( F ( " --------- \n " ) ) ;  
			
				
				
			
		
	
		
		
			
				
					    DBGPRINTLN ( F ( "  seconds " ) ) ;  
			
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
 
			
		
	
		
		
			
				
					
					    DBGPRINTLN ( " \n Ip Address:  "  +  apIp [ 0 ]  +  apIp [ 1 ]  +  apIp [ 2 ]  +  apIp [ 3 ] ) ;     WiFi . mode ( WIFI_AP_STA ) ;  
			
				
				
			
		
	
		
		
			
				
					    DBGPRINTLN ( F ( " \n --------- \n " ) ) ;  
			
		
	
		
		
			
				
					
 
			
		
	
		
		
			
				
					    WiFi . mode ( WIFI_AP ) ;  
			
		
	
		
		
	
		
		
			
				
					    WiFi . softAPConfig ( apIp ,  apIp ,  IPAddress ( 255 ,  255 ,  255 ,  0 ) ) ;     WiFi . softAPConfig ( apIp ,  apIp ,  IPAddress ( 255 ,  255 ,  255 ,  0 ) ) ;  
			
		
	
		
		
			
				
					
					    WiFi . softAP ( ssid ,  pwd ) ;     WiFi . softAP ( WIFI_AP_SSID ,  WIFI_AP_PWD ) ;  
			
				
				
			
		
	
		
		
	
		
		
			
				
					
 
			
		
	
		
		
			
				
					
					    mDns - > start ( 53 ,  " * " ,  apIp ) ;     mDns . start ( 53 ,  " * " ,  apIp ) ;  
			
				
				
			
		
	
		
		
	
		
		
			
				
					} }  
			
		
	
		
		
			
				
					
 
			
		
	
		
		
			
				
					
 
			
		
	
		
		
			
				
					//-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
  
			
		
	
		
		
			
				
					
					bool  ahoywifi : : setupStation ( uint32_t  timeout )  { void  ahoywifi : : setupStation ( void )  {  
			
				
				
			
		
	
		
		
			
				
					
					    DPRINTLN ( DBG_VERBOSE ,  F ( " app::setupStation " ) ) ;     DPRINTLN ( DBG_VERBOSE ,  F ( " wifi::setupStation " ) ) ;  
			
				
				
			
		
	
		
		
			
				
					    int32_t  cnt ;  
			
		
	
		
		
			
				
					    bool  startAp  =  false ;  
			
		
	
		
		
			
				
					
 
			
		
	
		
		
			
				
					    if ( timeout  > =  3 )  
			
		
	
		
		
			
				
					        cnt  =  ( timeout  -  3 )  /  2  *  10 ;  
			
		
	
		
		
			
				
					    else  {  
			
		
	
		
		
			
				
					        timeout  =  1 ;  
			
		
	
		
		
			
				
					        cnt  =  1 ;  
			
		
	
		
		
			
				
					    }  
			
		
	
		
		
			
				
					
 
			
		
	
		
		
			
				
					    WiFi . mode ( WIFI_STA ) ;  
			
		
	
		
		
	
		
		
	
		
		
			
				
					    if ( mConfig - > sys . ip . ip [ 0 ]  ! =  0 )  {     if ( mConfig - > sys . ip . ip [ 0 ]  ! =  0 )  {  
			
		
	
		
		
			
				
					        IPAddress  ip ( mConfig - > sys . ip . ip ) ;         IPAddress  ip ( mConfig - > sys . ip . ip ) ;  
			
		
	
		
		
			
				
					        IPAddress  mask ( mConfig - > sys . ip . mask ) ;         IPAddress  mask ( mConfig - > sys . ip . mask ) ;  
			
		
	
	
		
		
			
				
					
						
						
						
							
								 
						
					 
					@ -167,45 +107,14 @@ bool ahoywifi::setupStation(uint32_t timeout) { 
			
		
	
		
		
			
				
					    if ( String ( mConfig - > sys . deviceName )  ! =  " " )     if ( String ( mConfig - > sys . deviceName )  ! =  " " )  
			
		
	
		
		
			
				
					        WiFi . hostname ( mConfig - > sys . deviceName ) ;         WiFi . hostname ( mConfig - > sys . deviceName ) ;  
			
		
	
		
		
			
				
					
 
			
		
	
		
		
			
				
					    delay ( 2000 ) ;  
			
		
	
		
		
			
				
					    DBGPRINT ( F ( " connect to network ' " ) ) ;     DBGPRINT ( F ( " connect to network ' " ) ) ;  
			
		
	
		
		
			
				
					    DBGPRINT ( mConfig - > sys . stationSsid ) ;     DBGPRINT ( mConfig - > sys . stationSsid ) ;  
			
		
	
		
		
			
				
					    DBGPRINTLN ( F ( " ' ... " ) ) ;     DBGPRINTLN ( F ( " ' ... " ) ) ;  
			
		
	
		
		
			
				
					    while  ( WiFi . status ( )  ! =  WL_CONNECTED )  {  
			
		
	
		
		
			
				
					        delay ( 100 ) ;  
			
		
	
		
		
			
				
					        if ( cnt  %  40  = =  0 )  
			
		
	
		
		
			
				
					            DBGPRINTLN ( " . " ) ;  
			
		
	
		
		
			
				
					        else  
			
		
	
		
		
			
				
					            DBGPRINT ( " . " ) ;  
			
		
	
		
		
			
				
					
 
			
		
	
		
		
			
				
					        if ( timeout  >  0 )  {  // limit == 0 -> no limit
  
			
		
	
		
		
			
				
					            if ( - - cnt  < =  0 )  {  
			
		
	
		
		
			
				
					                if ( WiFi . status ( )  ! =  WL_CONNECTED )  {  
			
		
	
		
		
			
				
					                    startAp  =  true ;  
			
		
	
		
		
			
				
					                    WiFi . disconnect ( ) ;  
			
		
	
		
		
			
				
					                }  
			
		
	
		
		
			
				
					                delay ( 100 ) ;  
			
		
	
		
		
			
				
					                break ;  
			
		
	
		
		
			
				
					            }  
			
		
	
		
		
			
				
					        }  
			
		
	
		
		
			
				
					    }  
			
		
	
		
		
			
				
					    Serial . println ( " . " ) ;  
			
		
	
		
		
			
				
					
 
			
		
	
		
		
			
				
					    if ( false  = =  startAp )  
			
		
	
		
		
			
				
					        wifiWasEstablished  =  true ;  
			
		
	
		
		
			
				
					
 
			
		
	
		
		
			
				
					    delay ( 1000 ) ;  
			
		
	
		
		
			
				
					    return  startAp ;  
			
		
	
		
		
			
				
					} }  
			
		
	
		
		
			
				
					
 
			
		
	
		
		
			
				
					
 
			
		
	
		
		
			
				
					//-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
  
			
		
	
		
		
			
				
					
					bool  ahoywifi : : getApActive ( void )  { void  ahoywifi : : getNtpTime ( void )  {  
			
				
				
			
		
	
		
		
			
				
					    return  mApActive ;  
			
		
	
		
		
			
				
					}  
			
		
	
		
		
			
				
					
 
			
		
	
		
		
			
				
					//-----------------------------------------------------------------------------
  
			
		
	
		
		
			
				
					time_t  ahoywifi : : getNtpTime ( void )  {  
			
		
	
		
		
	
		
		
			
				
					    //DPRINTLN(DBG_VERBOSE, F("wifi::getNtpTime"));
     //DPRINTLN(DBG_VERBOSE, F("wifi::getNtpTime"));
  
			
		
	
		
		
			
				
					    time_t  date  =  0 ;     time_t  date  =  0 ;  
			
		
	
		
		
			
				
					    IPAddress  timeServer ;     IPAddress  timeServer ;  
			
		
	
	
		
		
			
				
					
						
						
						
							
								 
						
					 
					@ -213,16 +122,16 @@ time_t ahoywifi::getNtpTime(void) { 
			
		
	
		
		
			
				
					    uint8_t  retry  =  0 ;     uint8_t  retry  =  0 ;  
			
		
	
		
		
			
				
					
 
			
		
	
		
		
			
				
					    WiFi . hostByName ( mConfig - > ntp . addr ,  timeServer ) ;     WiFi . hostByName ( mConfig - > ntp . addr ,  timeServer ) ;  
			
		
	
		
		
			
				
					
					    mUdp - > begin ( mConfig - > ntp . port ) ;     mUdp . begin ( mConfig - > ntp . port ) ;  
			
				
				
			
		
	
		
		
	
		
		
			
				
					
 
			
		
	
		
		
			
				
					    sendNTPpacket ( timeServer ) ;     sendNTPpacket ( timeServer ) ;  
			
		
	
		
		
			
				
					
 
			
		
	
		
		
			
				
					    while ( retry + +  <  5 )  {     while ( retry + +  <  5 )  {  
			
		
	
		
		
			
				
					        int  wait  =  150 ;         int  wait  =  150 ;  
			
		
	
		
		
			
				
					        while ( - - wait )  {         while ( - - wait )  {  
			
		
	
		
		
			
				
					
					            if ( NTP_PACKET_SIZE  < =  mUdp - > parsePacket ( ) )  {             if ( NTP_PACKET_SIZE  < =  mUdp . parsePacket ( ) )  {  
			
				
				
			
		
	
		
		
	
		
		
			
				
					                uint64_t  secsSince1900 ;                 uint64_t  secsSince1900 ;  
			
		
	
		
		
			
				
					
					                mUdp - > read ( buf ,  NTP_PACKET_SIZE ) ;                 mUdp . read ( buf ,  NTP_PACKET_SIZE ) ;  
			
				
				
			
		
	
		
		
	
		
		
			
				
					                secsSince1900   =  ( buf [ 40 ]  < <  24 ) ;                 secsSince1900   =  ( buf [ 40 ]  < <  24 ) ;  
			
		
	
		
		
			
				
					                secsSince1900  | =  ( buf [ 41 ]  < <  16 ) ;                 secsSince1900  | =  ( buf [ 41 ]  < <  16 ) ;  
			
		
	
		
		
			
				
					                secsSince1900  | =  ( buf [ 42 ]  < <   8 ) ;                 secsSince1900  | =  ( buf [ 42 ]  < <   8 ) ;  
			
		
	
	
		
		
			
				
					
						
						
						
							
								 
						
					 
					@ -230,13 +139,14 @@ time_t ahoywifi::getNtpTime(void) { 
			
		
	
		
		
			
				
					
 
			
		
	
		
		
			
				
					                date  =  secsSince1900  -  2208988800UL ;  // UTC time
                 date  =  secsSince1900  -  2208988800UL ;  // UTC time
  
			
		
	
		
		
			
				
					                break ;                 break ;  
			
		
	
		
		
			
				
					
					            }             }  else  
			
				
				
			
		
	
		
		
			
				
					            else  
			
		
	
		
		
	
		
		
			
				
					                delay ( 10 ) ;                 delay ( 10 ) ;  
			
		
	
		
		
			
				
					        }         }  
			
		
	
		
		
			
				
					    }     }  
			
		
	
		
		
			
				
					
 
			
		
	
		
		
			
				
					
					    return  date ;     * mUtcTimestamp  =  date ;  
			
				
				
			
		
	
		
		
	
		
		
			
				
					
 
			
		
	
		
		
			
				
					    DPRINTLN ( DBG_INFO ,  F ( " [NTP]:  " )  +  ah : : getDateTimeStr ( * mUtcTimestamp )  +  F ( "  UTC " ) ) ;  
			
		
	
		
		
			
				
					} }  
			
		
	
		
		
			
				
					
 
			
		
	
		
		
			
				
					
 
			
		
	
	
		
		
			
				
					
						
							
								 
						
						
							
								 
						
						
					 
					@ -285,19 +195,42 @@ void ahoywifi::sendNTPpacket(IPAddress& address) { 
			
		
	
		
		
			
				
					    buf [ 14 ]  =  49 ;     buf [ 14 ]  =  49 ;  
			
		
	
		
		
			
				
					    buf [ 15 ]  =  52 ;     buf [ 15 ]  =  52 ;  
			
		
	
		
		
			
				
					
 
			
		
	
		
		
			
				
					
					    mUdp - > beginPacket ( address ,  123 ) ;  // NTP request, port 123
     mUdp . beginPacket ( address ,  123 ) ;  // NTP request, port 123
  
			
				
				
			
		
	
		
		
			
				
					
					    mUdp - > write ( buf ,  NTP_PACKET_SIZE ) ;     mUdp . write ( buf ,  NTP_PACKET_SIZE ) ;  
			
				
				
			
		
	
		
		
			
				
					
					    mUdp - > endPacket ( ) ;     mUdp . endPacket ( ) ;  
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					} }  
			
		
	
		
		
			
				
					
 
			
		
	
		
		
			
				
					
 
			
		
	
		
		
			
				
					//-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
  
			
		
	
		
		
			
				
					
					/*void ahoywifi::onConnect(const WiFiEventStationModeGotIP& event) {
 void  ahoywifi : : onConnect ( const  WiFiEventStationModeGotIP &  event )  {  
			
				
				
			
		
	
		
		
			
				
					
					    Serial . println ( " Connected to Wi-Fi. " ) ;     if ( ! mConnected )  {  
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					        mConnected  =  true ;  
			
		
	
		
		
			
				
					        DBGPRINTLN ( F ( " \n [WiFi] Connected " ) ) ;  
			
		
	
		
		
			
				
					        WiFi . mode ( WIFI_STA ) ;  
			
		
	
		
		
			
				
					        WiFi . begin ( ) ;  
			
		
	
		
		
			
				
					        DBGPRINTLN ( F ( " [WiFi] AP disabled " ) ) ;  
			
		
	
		
		
			
				
					        mDns . stop ( ) ;  
			
		
	
		
		
			
				
					
 
			
		
	
		
		
			
				
					        welcome ( WiFi . localIP ( ) . toString ( )  +  F ( "  (Station) " ) ) ;  
			
		
	
		
		
			
				
					    }  
			
		
	
		
		
			
				
					} }  
			
		
	
		
		
			
				
					
 
			
		
	
		
		
			
				
					
 
			
		
	
		
		
			
				
					//-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
  
			
		
	
		
		
			
				
					void  ahoywifi : : onDisconnect ( const  WiFiEventStationModeDisconnected &  event )  { void  ahoywifi : : onDisconnect ( const  WiFiEventStationModeDisconnected &  event )  {  
			
		
	
		
		
			
				
					
					    Serial . println ( " Disconnected from Wi-Fi. " ) ;     if ( mConnected )  {  
			
				
				
			
		
	
		
		
			
				
					
					} */         mConnected  =  false ;  
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					        DPRINTLN ( DBG_INFO ,  " [WiFi] Connection Lost " ) ;  
			
		
	
		
		
			
				
					    }  
			
		
	
		
		
			
				
					}  
			
		
	
		
		
			
				
					
 
			
		
	
		
		
			
				
					
 
			
		
	
		
		
			
				
					//-----------------------------------------------------------------------------
  
			
		
	
		
		
			
				
					void  ahoywifi : : welcome ( String  msg )  {  
			
		
	
		
		
			
				
					    DBGPRINTLN ( F ( " \n \n -------------------------------- " ) ) ;  
			
		
	
		
		
			
				
					    DBGPRINTLN ( F ( " Welcome to AHOY! " ) ) ;  
			
		
	
		
		
			
				
					    DBGPRINT ( F ( " \n point your browser to http:// " ) ) ;  
			
		
	
		
		
			
				
					    DBGPRINTLN ( msg ) ;  
			
		
	
		
		
			
				
					    DBGPRINTLN ( F ( " to configure your device " ) ) ;  
			
		
	
		
		
			
				
					    DBGPRINTLN ( F ( " -------------------------------- \n " ) ) ;  
			
		
	
		
		
			
				
					}