
void createDeviceName()
{
  byte mac[6];
  WiFi.macAddress(mac);
  sprintf(confDevWiFi.deviceName, "%s-%02X%02X", FIRMWARE_SHORTNAME, (uint8_t)mac[4], (uint8_t)mac[5]);
}

void restart()
{
  delay(50);
  //ESP.restart();
  // Adding Safer Restart method
  ESP.wdtDisable();
  ESP.reset();
  delay(2000);
}

void restart_delayed(uint8_t _delaySec) {
  system_restartAtMillis = millis() + (_delaySec * 1000);
}

void log_sysdata()
{
  snprintf(logBuf, LOG_BUFFER_SIZE, "SYS:  uptime=%s, heapFree=%u, heapFragm=%u%%, heapMaxBlock=%u", getUptimeStr(true), ESP.getFreeHeap(), ESP.getHeapFragmentation(), ESP.getMaxFreeBlockSize());
  //sprintf_P(logBuf, "SYS: uptime=%lu, freeHeap=%u, heapFragm=%u%%", millis(), ESP.getFreeHeap(), ESP.getHeapFragmentation());
  sendLog(logBuf, LOGLEVEL_INFO);
}

void printIpcfg() {
  byte mac[6];
  WiFi.macAddress(mac);
  snprintf(logBuf, LOG_BUFFER_SIZE, "%s: SSID='%s', IP='%s', GW='%s', DNS='%s', MAC='%02X:%02X:%02X:%02X:%02X:%02X'", PGMStr_WiFi, WiFi.SSID().c_str(), WiFi.localIP().toString().c_str(), WiFi.gatewayIP().toString().c_str(), WiFi.dnsIP().toString().c_str(), (uint8_t)mac[0], (uint8_t)mac[1], (uint8_t)mac[2], (uint8_t)mac[3], (uint8_t)mac[4], (uint8_t)mac[5]);
  sendLog(logBuf, LOGLEVEL_INFO);
}

int strEndsWith(char *_str, char *_sfx) {
  _str = strrchr(_str, '.');
  if( _str != NULL )
    return( strcmp(_str, _sfx) );
  return( -1 );
}


