ESP32 / ESP8266 & BME280 / SHT2x sensor with InfluxDB support
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

DebugLog.cpp 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * DebugLog.cpp
  3. *
  4. * ESP8266 / ESP32 Environmental Sensor
  5. *
  6. * ----------------------------------------------------------------------------
  7. * "THE BEER-WARE LICENSE" (Revision 42):
  8. * <xythobuz@xythobuz.de> wrote this file. As long as you retain this notice
  9. * you can do whatever you want with this stuff. If we meet some day, and you
  10. * think this stuff is worth it, you can buy me a beer in return. Thomas Buck
  11. * ----------------------------------------------------------------------------
  12. */
  13. #include <Arduino.h>
  14. #include "servers.h"
  15. #include "DebugLog.h"
  16. DebugLog debug;
  17. #ifdef ENABLE_DEBUGLOG
  18. String DebugLog::getBuffer(void) {
  19. String r;
  20. for (unsigned int i = 0; i < buffer.size(); i++) {
  21. r += buffer[i];
  22. }
  23. return r;
  24. }
  25. void DebugLog::addToBuffer(String s) {
  26. for (unsigned int i = 0; i < s.length(); i++) {
  27. buffer.push(s[i]);
  28. }
  29. }
  30. #endif
  31. void DebugLog::sendToTargets(String s) {
  32. Serial.print(s);
  33. s = "log:" + s;
  34. wifi_send_websocket(s);
  35. }
  36. void DebugLog::write(char c) {
  37. print(String(c));
  38. }
  39. void DebugLog::print(String s) {
  40. #ifdef ENABLE_DEBUGLOG
  41. addToBuffer(s);
  42. #endif // ENABLE_DEBUGLOG
  43. sendToTargets(s);
  44. }
  45. void DebugLog::print(int n) {
  46. print(String(n));
  47. }
  48. void DebugLog::println(void) {
  49. print(String(F("\r\n")));
  50. }
  51. void DebugLog::println(String s) {
  52. s += String(F("\r\n"));
  53. print(s);
  54. }
  55. void DebugLog::println(int n) {
  56. println(String(n));
  57. }