ESP8266 Treppenlichtsteuerung mit OTA zum Firmware Upload
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.

main.cpp 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. #include <Arduino.h>
  2. #ifdef WITH_DEBUGGING_ON
  3. #include <GDBStub.h> // debugging support via GDBStub over UART
  4. #endif
  5. #include "PCA9685.h"
  6. extern "C" {
  7. #include "user_interface.h"
  8. }
  9. // OTA & WEB
  10. #include "httpserver.h"
  11. #include "ota.h"
  12. #include "wifi_credentials.h"
  13. // BOARD
  14. #define ESP12_LED 2
  15. // #define NODEMCU_LED 16
  16. // PWM
  17. #include "treppe.h"
  18. os_timer_t timer1;
  19. uint8_t timer_flag = 0;
  20. Treppe stairs(16);
  21. // WIFI
  22. const char* ssid = STASSID;
  23. const char* password = STAPSK;
  24. // port 80, root directory of server '/'
  25. HTTPServer httpServer(80, "/", &stairs);
  26. uint32_t _t=0;
  27. #define SP_US(_str,_a) Serial.print(_str); Serial.print(" took: "); Serial.print(_a); Serial.println("us")
  28. #define TIMEIF_US(_f, _l, _str) _t=micros(); _f; _t=micros()-_t; if(_t > (_l)) { SP_US(_str, _t); }
  29. void timerCallback(void *pArg)
  30. {
  31. *(static_cast<int *>(pArg)) += 1;
  32. stairs.task();
  33. }
  34. // ===============================================
  35. uint8_t inter = 0;
  36. ICACHE_RAM_ATTR void int_test(){
  37. inter = 1;
  38. }
  39. void setup() {
  40. #ifdef WITH_DEBUGGING_ON
  41. Serial.begin(460800);
  42. gdbstub_init();
  43. #else
  44. Serial.begin(76800);
  45. #endif
  46. Serial.println("Booting ....");
  47. pinMode(ESP12_LED, OUTPUT);
  48. Wire.begin(); // Wire must be started first
  49. Wire.setClock(1000000); // Supported baud rates are 100kHz, 400kHz, and 1000kHz
  50. stairs.setup();
  51. Serial.println("PCA9685 connected !");
  52. //attachInterrupt(digitalPinToInterrupt(2), int_test, RISING);
  53. //attachInterrupt(digitalPinToInterrupt(12), int_test, RISING);
  54. WiFi.mode(WIFI_STA);
  55. WiFi.begin(ssid, password);
  56. while (WiFi.waitForConnectResult() != WL_CONNECTED) {
  57. Serial.println("Connection Failed! Rebooting...");
  58. delay(5000);
  59. ESP.restart();
  60. }
  61. Serial.println("");
  62. Serial.print("Connected to ");
  63. Serial.println(ssid);
  64. Serial.print("IP address: ");
  65. Serial.println(WiFi.localIP());
  66. ota_setup();
  67. httpServer.start();
  68. httpServer.start_apps();
  69. Serial.println("HTTP server started !");
  70. os_timer_setfn(&timer1, timerCallback, &timer_flag);
  71. os_timer_arm(&timer1, 20, true);
  72. }
  73. uint32_t c = 0;
  74. void loop() {
  75. if(inter != 0u){
  76. Serial.printf("interrupt\n");
  77. inter = 0;
  78. }
  79. if(c++%1000000 == 0) { { {
  80. httpServer.logt("[%d] starting :)\n", c);
  81. }
  82. }
  83. }
  84. TIMEIF_US(ArduinoOTA.handle(), 10000, "OTA");
  85. TIMEIF_US(httpServer.handleClient(), 10000, "HTTP");
  86. }