|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- #include <Arduino.h>
-
- #ifdef WITH_DEBUGGING_ON
- #include <GDBStub.h> // debugging support via GDBStub over UART
- #endif
-
- #include "PCA9685.h"
- extern "C" {
- #include "user_interface.h"
- }
- // OTA & WEB
- #include "httpserver.h"
- #include "ota.h"
- #include "wifi_credentials.h"
- #include <EEPROM.h>
-
- // BOARD
- #define ESP12_LED 2
- // #define NODEMCU_LED 16
-
- // PWM
- #include "treppe.h"
- os_timer_t timer1;
- uint8_t timer_flag = 0;
- Treppe stairs(16);
-
- // WIFI
- const char* ssid = STASSID;
- const char* password = STAPSK;
-
- // port 80, root directory of server '/'
- HTTPServer httpServer(80, "/", &stairs);
-
- uint32_t _t=0;
- #define SP_US(_str,_a) Serial.print(_str); Serial.print(" took: "); Serial.print(_a); Serial.println("us")
- #define TIMEIF_US(_f, _l, _str) _t=micros(); _f; _t=micros()-_t; if(_t > (_l)) { SP_US(_str, _t); }
-
- struct { // Struct for wifi-data, 40 Bytes each SSID and PW
- char SSID[40] = "";
- char PW[40] = "";
- } wifi_data;
-
-
- void timerCallback(void *pArg)
- {
- *(static_cast<int *>(pArg)) += 1;
- stairs.task();
- }
-
- // ===============================================
- uint8_t inter = 0;
- ICACHE_RAM_ATTR void int_test(){
- inter = 1;
- }
-
- void setup() {
- #ifdef WITH_DEBUGGING_ON
- Serial.begin(460800);
- gdbstub_init();
- #else
- Serial.begin(76800);
- #endif
- Serial.println("Booting ....");
- pinMode(ESP12_LED, OUTPUT);
-
- EEPROM.begin(512); // init virtual "EEPROM" with size 512 Bytes
-
- //strncpy(wifi_data.SSID, "donotconnect", 40);
- //strncpy(wifi_data.PW, "unsafe lol", 40);
-
- EEPROM.get(0, wifi_data);
- //EEPROM.commit();
-
- Wire.begin(); // Wire must be started first
- Wire.setClock(1000000); // Supported baud rates are 100kHz, 400kHz, and 1000kHz
- stairs.setup();
- Serial.println("PCA9685 connected !");
- //attachInterrupt(digitalPinToInterrupt(2), int_test, RISING);
- //attachInterrupt(digitalPinToInterrupt(12), int_test, RISING);
-
- WiFi.mode(WIFI_STA);
- WiFi.begin(ssid, password);
-
- while (WiFi.waitForConnectResult() != WL_CONNECTED) {
- Serial.println("Connection Failed! Rebooting...");
- delay(5000);
- ESP.restart();
- }
-
- Serial.println("");
- Serial.print("Connected to ");
- Serial.println(ssid);
- Serial.print("IP address: ");
- Serial.println(WiFi.localIP());
-
- ota_setup();
-
- httpServer.start();
- httpServer.start_apps();
- Serial.println("HTTP server started !");
-
- os_timer_setfn(&timer1, timerCallback, &timer_flag);
- os_timer_arm(&timer1, 20, true);
-
- Serial.println("SSID: " + String(wifi_data.SSID) + " PW: " + String(wifi_data.PW));
- }
-
- uint32_t c = 0;
-
- void loop() {
- if(inter != 0u){
- Serial.printf("interrupt\n");
- inter = 0;
- }
- if(c++%1000000 == 0) { { {
- httpServer.logt("[%d] starting :)\n", c);
- }
- }
- }
-
- TIMEIF_US(ArduinoOTA.handle(), 10000, "OTA");
- TIMEIF_US(httpServer.handleClient(), 10000, "HTTP");
- }
|