sysFunctions.ino 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. void createDeviceName()
  2. {
  3. byte mac[6];
  4. WiFi.macAddress(mac);
  5. sprintf(confDevWiFi.deviceName, "%s-%02X%02X", FIRMWARE_SHORTNAME, (uint8_t)mac[4], (uint8_t)mac[5]);
  6. }
  7. void restart()
  8. {
  9. delay(50);
  10. //ESP.restart();
  11. // Adding Safer Restart method
  12. ESP.wdtDisable();
  13. ESP.reset();
  14. delay(2000);
  15. }
  16. void restart_delayed(uint8_t _delaySec) {
  17. system_restartAtMillis = millis() + (_delaySec * 1000);
  18. }
  19. void log_sysdata()
  20. {
  21. snprintf(logBuf, LOG_BUFFER_SIZE, "SYS: uptime=%s, heapFree=%u, heapFragm=%u%%, heapMaxBlock=%u", getUptimeStr(true), ESP.getFreeHeap(), ESP.getHeapFragmentation(), ESP.getMaxFreeBlockSize());
  22. //sprintf_P(logBuf, "SYS: uptime=%lu, freeHeap=%u, heapFragm=%u%%", millis(), ESP.getFreeHeap(), ESP.getHeapFragmentation());
  23. sendLog(logBuf, LOGLEVEL_INFO);
  24. }
  25. void printIpcfg() {
  26. byte mac[6];
  27. WiFi.macAddress(mac);
  28. 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]);
  29. sendLog(logBuf, LOGLEVEL_INFO);
  30. }
  31. int strEndsWith(char *_str, char *_sfx) {
  32. _str = strrchr(_str, '.');
  33. if( _str != NULL )
  34. return( strcmp(_str, _sfx) );
  35. return( -1 );
  36. }