ESP32 / ESP8266 & BME280 / SHT2x sensor with InfluxDB support
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

DebugLog.cpp 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 "DebugLog.h"
  15. DebugLog debug;
  16. #if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
  17. void wifi_send_websocket(String s);
  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. #if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
  34. s = "log:" + s;
  35. wifi_send_websocket(s);
  36. #endif
  37. }
  38. void DebugLog::write(char c) {
  39. print(String(c));
  40. }
  41. void DebugLog::print(String s) {
  42. #if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
  43. addToBuffer(s);
  44. #endif
  45. sendToTargets(s);
  46. }
  47. void DebugLog::print(int n) {
  48. print(String(n));
  49. }
  50. void DebugLog::println(void) {
  51. print(String(F("\r\n")));
  52. }
  53. void DebugLog::println(String s) {
  54. s += String(F("\r\n"));
  55. print(s);
  56. }
  57. void DebugLog::println(int n) {
  58. println(String(n));
  59. }