diff --git a/.github/workflows/build-ci.yml b/.github/workflows/build-ci.yml index ed125ebef..a4730b286 100644 --- a/.github/workflows/build-ci.yml +++ b/.github/workflows/build-ci.yml @@ -61,7 +61,7 @@ jobs: submodules: recursive - name: Build Script - run: sudo ./build.sh -s demo + run: sudo ./scripts/build.sh -s demo build-docker: name: Build Docker diff --git a/.gitignore b/.gitignore index 8348c923b..fddc0bae1 100644 --- a/.gitignore +++ b/.gitignore @@ -3,7 +3,7 @@ OpenSprinkler wtopts.txt *.dat *.sh -testmode.h +include/testmode.h build-1284/* .vscode .pio diff --git a/Makefile b/Makefile index 6c48ca424..5f36d8854 100644 --- a/Makefile +++ b/Makefile @@ -6,8 +6,8 @@ LD=$(CXX) LIBS=pthread mosquitto ssl crypto LDFLAGS=$(addprefix -l,$(LIBS)) BINARY=OpenSprinkler -SOURCES=main.cpp OpenSprinkler.cpp program.cpp opensprinkler_server.cpp utils.cpp weather.cpp gpio.cpp mqtt.cpp smtp.c $(wildcard external/TinyWebsockets/tiny_websockets_lib/src/*.cpp) $(wildcard external/OpenThings-Framework-Firmware-Library/*.cpp) -HEADERS=$(wildcard *.h) $(wildcard *.hpp) +SOURCES=$(wildcard src/*.cpp) $(wildcard src/*.c) $(wildcard external/TinyWebsockets/tiny_websockets_lib/src/*.cpp) $(wildcard external/OpenThings-Framework-Firmware-Library/*.cpp) +HEADERS=$(wildcard include/*.h) $(wildcard include/*.hpp) OBJECTS=$(addsuffix .o,$(basename $(SOURCES))) .PHONY: all diff --git a/OpenSprinkler.service b/OpenSprinkler.service index 82519cda1..4c2f0a6e4 100644 --- a/OpenSprinkler.service +++ b/OpenSprinkler.service @@ -9,7 +9,7 @@ Restart=always RestartSec=1 User=root WorkingDirectory=__OpenSprinkler_Path__ -ExecStart=/bin/bash -c ./startOpenSprinkler.sh +ExecStart=/bin/bash -c ./scripts/startOpenSprinkler.sh StandardError=journal StandardOutput=journal StandardInput=null diff --git a/examples/mainArduino/mainArduino.ino b/examples/mainArduino/mainArduino.ino index 702f3683c..9d3976cd6 100644 --- a/examples/mainArduino/mainArduino.ino +++ b/examples/mainArduino/mainArduino.ino @@ -1,4 +1,4 @@ -#include "OpenSprinkler.h" +#include "../../include/OpenSprinkler.h" void do_setup(); void do_loop(); diff --git a/ArduinoJson.hpp b/include/ArduinoJson.hpp similarity index 100% rename from ArduinoJson.hpp rename to include/ArduinoJson.hpp diff --git a/EMailSender.h b/include/EMailSender.h similarity index 99% rename from EMailSender.h rename to include/EMailSender.h index 36c42f580..e436993a4 100644 --- a/EMailSender.h +++ b/include/EMailSender.h @@ -38,9 +38,9 @@ #include "EMailSenderKey.h" #if ARDUINO >= 100 -#include "Arduino.h" +#include #else -#include "WProgram.h" +#include #endif #if(NETWORK_ESP8266_242 == DEFAULT_EMAIL_NETWORK_TYPE_ESP8266) diff --git a/EMailSenderKey.h b/include/EMailSenderKey.h similarity index 100% rename from EMailSenderKey.h rename to include/EMailSenderKey.h diff --git a/I2CRTC.h b/include/I2CRTC.h similarity index 94% rename from I2CRTC.h rename to include/I2CRTC.h index ca575feab..b66a70bb1 100644 --- a/I2CRTC.h +++ b/include/I2CRTC.h @@ -26,7 +26,7 @@ class I2CRTC static void write(tmElements_t &tm); static bool detect(); static bool exists(); - + private: static uint8_t dec2bcd(uint8_t num); static uint8_t bcd2dec(uint8_t num); @@ -36,4 +36,4 @@ class I2CRTC extern I2CRTC RTC; #endif - + diff --git a/LiquidCrystal.h b/include/LiquidCrystal.h similarity index 100% rename from LiquidCrystal.h rename to include/LiquidCrystal.h diff --git a/OpenSprinkler.h b/include/OpenSprinkler.h similarity index 99% rename from OpenSprinkler.h rename to include/OpenSprinkler.h index 050937bc8..386e59c81 100644 --- a/OpenSprinkler.h +++ b/include/OpenSprinkler.h @@ -301,7 +301,7 @@ class OpenSprinkler { static void switch_remotestation(RemoteOTCStationData *data, bool turnon, uint16_t dur=0); // switch remote OTC station static void switch_gpiostation(GPIOStationData *data, bool turnon); // switch gpio station static void switch_httpstation(HTTPStationData *data, bool turnon, bool usessl=false); // switch http station - + // -- options and data storeage static void nvdata_load(); static void nvdata_save(); @@ -341,7 +341,7 @@ class OpenSprinkler { static int8_t send_http_request(uint32_t ip4, uint16_t port, char* p, void(*callback)(char*)=NULL, bool usessl=false, uint16_t timeout=5000); static int8_t send_http_request(const char* server, uint16_t port, char* p, void(*callback)(char*)=NULL, bool usessl=false, uint16_t timeout=5000); static int8_t send_http_request(char* server_with_port, char* p, void(*callback)(char*)=NULL, bool usessl=false, uint16_t timeout=5000); - + #if defined(USE_OTF) static OTCConfig otc; #endif diff --git a/SSD1306Display.h b/include/SSD1306Display.h similarity index 100% rename from SSD1306Display.h rename to include/SSD1306Display.h diff --git a/TimeLib.h b/include/TimeLib.h similarity index 100% rename from TimeLib.h rename to include/TimeLib.h diff --git a/defines.h b/include/defines.h similarity index 100% rename from defines.h rename to include/defines.h diff --git a/espconnect.h b/include/espconnect.h similarity index 100% rename from espconnect.h rename to include/espconnect.h diff --git a/font.h b/include/font.h similarity index 100% rename from font.h rename to include/font.h diff --git a/gpio.h b/include/gpio.h similarity index 99% rename from gpio.h rename to include/gpio.h index 843c7f59a..b7c8ac7e6 100644 --- a/gpio.h +++ b/include/gpio.h @@ -28,7 +28,7 @@ #if defined(ESP8266) -#include "Arduino.h" +#include // PCA9555 register defines #define NXP_INPUT_REG 0 diff --git a/htmls.h b/include/htmls.h similarity index 100% rename from htmls.h rename to include/htmls.h diff --git a/images.h b/include/images.h similarity index 100% rename from images.h rename to include/images.h diff --git a/main.h b/include/main.h similarity index 100% rename from main.h rename to include/main.h diff --git a/mqtt.h b/include/mqtt.h similarity index 100% rename from mqtt.h rename to include/mqtt.h diff --git a/opensprinkler_server.h b/include/opensprinkler_server.h similarity index 100% rename from opensprinkler_server.h rename to include/opensprinkler_server.h diff --git a/program.h b/include/program.h similarity index 100% rename from program.h rename to include/program.h diff --git a/smtp.h b/include/smtp.h similarity index 100% rename from smtp.h rename to include/smtp.h diff --git a/types.h b/include/types.h similarity index 100% rename from types.h rename to include/types.h diff --git a/utils.h b/include/utils.h similarity index 100% rename from utils.h rename to include/utils.h diff --git a/weather.h b/include/weather.h similarity index 100% rename from weather.h rename to include/weather.h diff --git a/mainArduino.ino b/mainArduino.ino index 702f3683c..6944e25ec 100644 --- a/mainArduino.ino +++ b/mainArduino.ino @@ -1,4 +1,4 @@ -#include "OpenSprinkler.h" +#include "include/OpenSprinkler.h" void do_setup(); void do_loop(); diff --git a/build.sh b/scripts/build.sh similarity index 80% rename from build.sh rename to scripts/build.sh index ff1da16ca..b2d13161c 100755 --- a/build.sh +++ b/scripts/build.sh @@ -34,7 +34,7 @@ if [ "$1" == "demo" ]; then ws=$(ls external/TinyWebsockets/tiny_websockets_lib/src/*.cpp) otf=$(ls external/OpenThings-Framework-Firmware-Library/*.cpp) - g++ -o OpenSprinkler -DDEMO -DSMTP_OPENSSL $DEBUG -std=c++14 -include string.h main.cpp OpenSprinkler.cpp program.cpp opensprinkler_server.cpp utils.cpp weather.cpp gpio.cpp mqtt.cpp smtp.c -Iexternal/TinyWebsockets/tiny_websockets_lib/include $ws -Iexternal/OpenThings-Framework-Firmware-Library/ $otf -lpthread -lmosquitto -lssl -lcrypto + g++ -o OpenSprinkler -DDEMO -DSMTP_OPENSSL $DEBUG -std=c++14 -include string.h src/*.cpp src/smtp.c -Iinclude -Iexternal/TinyWebsockets/tiny_websockets_lib/include -Iexternal/OpenThings-Framework-Firmware-Library/ -lpthread -lmosquitto -lssl -lcrypto elif [ "$1" == "osbo" ]; then echo "Installing required libraries..." apt-get install -y libmosquitto-dev libssl-dev @@ -42,7 +42,7 @@ elif [ "$1" == "osbo" ]; then ws=$(ls external/TinyWebsockets/tiny_websockets_lib/src/*.cpp) otf=$(ls external/OpenThings-Framework-Firmware-Library/*.cpp) - g++ -o OpenSprinkler -DOSBO -DSMTP_OPENSSL $DEBUG -std=c++14 -include string.h main.cpp OpenSprinkler.cpp program.cpp opensprinkler_server.cpp utils.cpp weather.cpp gpio.cpp mqtt.cpp smtp.c -Iexternal/TinyWebsockets/tiny_websockets_lib/include $ws -Iexternal/OpenThings-Framework-Firmware-Library/ $otf -lpthread -lmosquitto -lssl -lcrypto + g++ -o OpenSprinkler -DOSBO -DSMTP_OPENSSL $DEBUG -std=c++14 -include string.h src/*.cpp src/smtp.c -Iinclude -Iexternal/TinyWebsockets/tiny_websockets_lib/include -Iexternal/OpenThings-Framework-Firmware-Library/ -lpthread -lmosquitto -lssl -lcrypto else echo "Installing required libraries..." apt-get update @@ -76,7 +76,7 @@ if [ -f /etc/init.d/OpenSprinkler.sh ]; then rm /etc/init.d/OpenSprinkler.sh fi -if [ ! "$SILENT" = true ] && [ -f OpenSprinkler.service ] && [ -f startOpenSprinkler.sh ] && [ ! -f /etc/systemd/system/OpenSprinkler.service ]; then +if [ ! "$SILENT" = true ] && [ -f OpenSprinkler.service ] && [ -f scripts/startOpenSprinkler.sh ] && [ ! -f /etc/systemd/system/OpenSprinkler.service ]; then read -p "Do you want to start OpenSprinkler on startup? " -n 1 -r echo @@ -96,7 +96,7 @@ if [ ! "$SILENT" = true ] && [ -f OpenSprinkler.service ] && [ -f startOpenSprin sed -e 's,\_\_OpenSprinkler\_Path\_\_,'"$DIR"',g' OpenSprinkler.service > /etc/systemd/system/OpenSprinkler.service # Make file executable - chmod +x startOpenSprinkler.sh + chmod +x scripts/startOpenSprinkler.sh # Reload systemd systemctl daemon-reload diff --git a/startOpenSprinkler.sh b/scripts/startOpenSprinkler.sh similarity index 100% rename from startOpenSprinkler.sh rename to scripts/startOpenSprinkler.sh diff --git a/updater.sh b/scripts/updater.sh similarity index 70% rename from updater.sh rename to scripts/updater.sh index eda30f0a4..7e46bee18 100755 --- a/updater.sh +++ b/scripts/updater.sh @@ -1,5 +1,5 @@ #! /bin/bash git pull -./build.sh -s ospi +./scripts/build.sh -s ospi systemctl restart OpenSprinkler.service diff --git a/EMailSender.cpp b/src/EMailSender.cpp similarity index 99% rename from EMailSender.cpp rename to src/EMailSender.cpp index 22b87894a..ce6cba01f 100644 --- a/EMailSender.cpp +++ b/src/EMailSender.cpp @@ -32,7 +32,7 @@ * THE SOFTWARE. */ -#include "EMailSender.h" +#include "../include/EMailSender.h" #include #if defined(ESP32) #include @@ -639,9 +639,9 @@ EMailSender::Response EMailSender::send(const char* to[], byte sizeOfTo, byte s // response = awaitSMTPResponse(client,"334","No digest error"); if (!response.status) { - client.flush(); - client.stop(); - return response; + client.flush(); + client.stop(); + return response; }; _serverResponce = _serverResponce.substring(4); // '334' @@ -654,12 +654,12 @@ EMailSender::Response EMailSender::send(const char* to[], byte sizeOfTo, byte s int e = mbedtls_base64_decode(digest, sizeof(digest), &len, b64, b64l); if (e || len < 3 || len >= 256) { - response.code = F("999"); - response.desc = F("Invalid digest"); - response.status = false; - client.flush(); - client.stop(); - return response; + response.code = F("999"); + response.desc = F("Invalid digest"); + response.status = false; + client.flush(); + client.stop(); + return response; }; // calculate HMAC with the password as the key of this digest. @@ -670,7 +670,7 @@ EMailSender::Response EMailSender::send(const char* to[], byte sizeOfTo, byte s mbedtls_md_init(&ctx); mbedtls_md_setup(&ctx, mbedtls_md_info_from_type(md_type), 1); - mbedtls_md_hmac_starts(&ctx, + mbedtls_md_hmac_starts(&ctx, (const unsigned char *)this->email_password, strlen(this->email_password)); mbedtls_md_hmac_update(&ctx, digest, len); mbedtls_md_hmac_finish(&ctx, md5); @@ -691,7 +691,7 @@ EMailSender::Response EMailSender::send(const char* to[], byte sizeOfTo, byte s // now exepct the normal login confirmation to continue. } -#endif +#endif else{ EMAIL_DEBUG_PRINTLN(F("AUTH LOGIN:")); client.println(F("AUTH LOGIN")); diff --git a/I2CRTC.cpp b/src/I2CRTC.cpp similarity index 89% rename from I2CRTC.cpp rename to src/I2CRTC.cpp index 6832a5580..bb74d6eb5 100644 --- a/I2CRTC.cpp +++ b/src/I2CRTC.cpp @@ -1,6 +1,6 @@ /* * I2CRTC.cpp - library for I2C RTC - + Copyright (c) Michael Margolis 2009 This library is intended to be uses with Arduino Time.h library functions @@ -17,17 +17,17 @@ You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - + 30 Dec 2009 - Initial release 5 Sep 2011 updated for Arduino 1.0 - + 23 Dec 2013 -- modified by Ray Wang (Rayshobby LLC) to add support for MCP7940 */ #if defined(ARDUINO) -#include "I2CRTC.h" +#include "../include/I2CRTC.h" #include static uint8_t _addrs[] = {DS1307_ADDR, MCP7940_ADDR, PCF8563_ADDR}; @@ -69,7 +69,7 @@ void I2CRTC::set(time_os_t t) { tmElements_t tm; breakTime(t, tm); - write(tm); + write(tm); } // Aquire data from the RTC chip in BCD format @@ -78,7 +78,7 @@ void I2CRTC::read( tmElements_t &tm) if(!addr) return; Wire.beginTransmission(addr); - if(addr == PCF8563_ADDR) { + if(addr == PCF8563_ADDR) { Wire.write((uint8_t)0x02); Wire.endTransmission(); Wire.requestFrom(addr, (uint8_t)7); @@ -90,7 +90,7 @@ void I2CRTC::read( tmElements_t &tm) tm.Month = bcd2dec(Wire.read() & 0x1f); // fix bug for MCP7940 tm.Year = (bcd2dec(Wire.read())); } else { - Wire.write((uint8_t)0x00); + Wire.write((uint8_t)0x00); Wire.endTransmission(); Wire.requestFrom(addr, (uint8_t)7); tm.Second = bcd2dec(Wire.read() & 0x7f); @@ -108,7 +108,7 @@ void I2CRTC::write(tmElements_t &tm) if(!addr) return; switch(addr) { case DS1307_ADDR: - Wire.beginTransmission(addr); + Wire.beginTransmission(addr); Wire.write((uint8_t)0x00); // reset register pointer Wire.write(dec2bcd(tm.Second) & 0x7f); // ray: start clock by setting CH bit low Wire.write(dec2bcd(tm.Minute)); @@ -116,11 +116,11 @@ void I2CRTC::write(tmElements_t &tm) Wire.write(dec2bcd(tm.Wday)); Wire.write(dec2bcd(tm.Day)); Wire.write(dec2bcd(tm.Month)); - Wire.write(dec2bcd(tmYearToY2k(tm.Year))); + Wire.write(dec2bcd(tmYearToY2k(tm.Year))); Wire.endTransmission(); break; case MCP7940_ADDR: - Wire.beginTransmission(addr); + Wire.beginTransmission(addr); Wire.write((uint8_t)0x00); // reset register pointer Wire.write(dec2bcd(tm.Second) | 0x80); // ray: start clock by setting ST bit high Wire.write(dec2bcd(tm.Minute)); @@ -128,11 +128,11 @@ void I2CRTC::write(tmElements_t &tm) Wire.write(dec2bcd(tm.Wday) | 0x08); // ray: turn on battery backup by setting VBATEN bit high Wire.write(dec2bcd(tm.Day)); Wire.write(dec2bcd(tm.Month)); - Wire.write(dec2bcd(tmYearToY2k(tm.Year))); + Wire.write(dec2bcd(tmYearToY2k(tm.Year))); Wire.endTransmission(); break; case PCF8563_ADDR: - Wire.beginTransmission(addr); + Wire.beginTransmission(addr); Wire.write((uint8_t)0x02); // reset register pointer Wire.write(dec2bcd(tm.Second) & 0x7f); Wire.write(dec2bcd(tm.Minute)); @@ -140,7 +140,7 @@ void I2CRTC::write(tmElements_t &tm) Wire.write(dec2bcd(tm.Day)); Wire.write(dec2bcd(tm.Wday)); Wire.write(dec2bcd(tm.Month)); - Wire.write(dec2bcd(tm.Year)); + Wire.write(dec2bcd(tm.Year)); Wire.endTransmission(); break; } diff --git a/LiquidCrystal.cpp b/src/LiquidCrystal.cpp similarity index 99% rename from LiquidCrystal.cpp rename to src/LiquidCrystal.cpp index 88050bd35..79fc1fdae 100644 --- a/LiquidCrystal.cpp +++ b/src/LiquidCrystal.cpp @@ -1,6 +1,6 @@ #if defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega1284__) -#include "LiquidCrystal.h" +#include "../include/LiquidCrystal.h" #include #include #include diff --git a/OpenSprinkler.cpp b/src/OpenSprinkler.cpp similarity index 99% rename from OpenSprinkler.cpp rename to src/OpenSprinkler.cpp index cdf25ec95..9b1621f85 100644 --- a/OpenSprinkler.cpp +++ b/src/OpenSprinkler.cpp @@ -21,12 +21,12 @@ * . */ -#include "OpenSprinkler.h" -#include "opensprinkler_server.h" -#include "gpio.h" -#include "testmode.h" -#include "program.h" -#include "ArduinoJson.hpp" +#include "../include/OpenSprinkler.h" +#include "../include/opensprinkler_server.h" +#include "../include/gpio.h" +#include "../include/testmode.h" +#include "../include/program.h" +#include "../include/ArduinoJson.hpp" /** Declare static data members */ OSMqtt OpenSprinkler::mqtt; @@ -629,7 +629,7 @@ unsigned char OpenSprinkler::start_ether() { if(!eth.begin((uint8_t*)tmp_buffer)) return 0; lcd_print_line_clear_pgm(PSTR("Start wired link"), 1); lcd_print_line_clear_pgm(eth.isW5500 ? PSTR(" [w5500] ") : PSTR(" [enc28j60] "), 2); - + ulong timeout = millis()+60000; // 60 seconds time out unsigned char timecount = 1; while (!eth.connected() && millis() #include #include #include -#include "utils.h" -#include "opensprinkler_server.h" +#include "../include/utils.h" +#include "../include/opensprinkler_server.h" /** Initialize network with the given mac address and http port */ unsigned char OpenSprinkler::start_network() { @@ -791,7 +791,7 @@ void OpenSprinkler::reboot_dev(uint8_t cause) { /** Launch update script */ void OpenSprinkler::update_dev() { char cmd[500]; - snprintf(cmd, 500, "cd %s && ./updater.sh", get_data_dir()); + snprintf(cmd, 500, "cd %s && ../scripts/updater.sh", get_data_dir()); system(cmd); } #endif // end network init functions @@ -1958,7 +1958,7 @@ int8_t OpenSprinkler::send_http_request(const char* server, uint16_t port, char* bool mfln = _c->probeMaxFragmentLength(server, port, 512); DEBUG_PRINTF("MFLN supported: %s\n", mfln ? "yes" : "no"); if (mfln) { - _c->setBufferSizes(512, 512); + _c->setBufferSizes(512, 512); } else { _c->setBufferSizes(2048, 2048); } @@ -1992,7 +1992,7 @@ int8_t OpenSprinkler::send_http_request(const char* server, uint16_t port, char* } #else EthernetClient *client = NULL; - + if (usessl) { client = new EthernetClientSsl(); } else { @@ -3016,7 +3016,7 @@ void OpenSprinkler::lcd_set_brightness(unsigned char value) { #endif // end of LCD and button functions #if defined(ESP8266) -#include "images.h" +#include "../include/images.h" void OpenSprinkler::flash_screen() { lcd.setCursor(0, -1); lcd.print(F(" OpenSprinkler")); diff --git a/TimeLib.cpp b/src/TimeLib.cpp similarity index 99% rename from TimeLib.cpp rename to src/TimeLib.cpp index b985a0242..063232156 100644 --- a/TimeLib.cpp +++ b/src/TimeLib.cpp @@ -33,8 +33,8 @@ #include #endif -#include "TimeLib.h" -#include "types.h" +#include "../include/TimeLib.h" +#include "../include/types.h" static tmElements_t tm; // a cache of time elements static time_os_t cacheTime; // the time the cache was updated diff --git a/defines.cpp b/src/defines.cpp similarity index 93% rename from defines.cpp rename to src/defines.cpp index a7a1d66db..f991e0b74 100644 --- a/defines.cpp +++ b/src/defines.cpp @@ -1,6 +1,6 @@ #if defined(ESP8266) -#include "defines.h" +#include "../include/defines.h" unsigned char PIN_BUTTON_1 = 255; unsigned char PIN_BUTTON_2 = 255; diff --git a/espconnect.cpp b/src/espconnect.cpp similarity index 98% rename from espconnect.cpp rename to src/espconnect.cpp index c52b874b2..0fb318412 100644 --- a/espconnect.cpp +++ b/src/espconnect.cpp @@ -19,7 +19,7 @@ */ #if defined(ESP8266) -#include "espconnect.h" +#include "../include/espconnect.h" String scan_network() { WiFi.mode(WIFI_STA); diff --git a/gpio.cpp b/src/gpio.cpp similarity index 98% rename from gpio.cpp rename to src/gpio.cpp index 8e7731219..f96bf92b1 100644 --- a/gpio.cpp +++ b/src/gpio.cpp @@ -21,14 +21,14 @@ * . */ -#include "gpio.h" +#include "../include/gpio.h" #if defined(ARDUINO) #if defined(ESP8266) #include -#include "defines.h" +#include "../include/defines.h" unsigned char IOEXP::detectType(uint8_t address) { Wire.beginTransmission(address); @@ -140,7 +140,7 @@ void PCF8574::i2c_write(uint8_t reg, uint16_t v) { Wire.endTransmission(); } -#include "OpenSprinkler.h" +#include "../include/OpenSprinkler.h" extern OpenSprinkler os; @@ -403,7 +403,7 @@ static void *interruptHandler (void *arg) { return NULL ; } -#include "utils.h" +#include "../include/utils.h" /** Attach an interrupt function to pin */ void attachInterrupt(int pin, const char* mode, void (*isr)(void)) { if((pin<0)||(pin>GPIO_MAX)) { @@ -466,7 +466,7 @@ void attachInterrupt(int pin, const char* mode, void (*isr)(void)) { #include #include -#include "utils.h" +#include "../include/utils.h" #define BUFFER_MAX 64 #define GPIO_MAX 64 @@ -507,8 +507,8 @@ int assert_gpiod_chip() { index += 1; } - cpu_buf += index + 1; - + cpu_buf += index + 1; + if (!strcmp("brcm,bcm2712", cpu_buf)) { // Pi 5 chip_name = "pinctrl-rp1"; @@ -524,7 +524,7 @@ int assert_gpiod_chip() { } } - + if (chip_name) { gpiod_chip_iter *iter = gpiod_chip_iter_new(); diff --git a/main.cpp b/src/main.cpp similarity index 99% rename from main.cpp rename to src/main.cpp index 311664623..d76e15174 100644 --- a/main.cpp +++ b/src/main.cpp @@ -23,19 +23,19 @@ #include -#include "types.h" -#include "OpenSprinkler.h" -#include "program.h" -#include "weather.h" -#include "opensprinkler_server.h" -#include "mqtt.h" -#include "main.h" +#include "../include/types.h" +#include "../include/OpenSprinkler.h" +#include "../include/program.h" +#include "../include/weather.h" +#include "../include/opensprinkler_server.h" +#include "../include/mqtt.h" +#include "../include/main.h" #if defined(ARDUINO) #include #endif -#include "ArduinoJson.hpp" +#include "../include/ArduinoJson.hpp" #if defined(ARDUINO) #if defined(ESP8266) @@ -896,11 +896,11 @@ void do_loop() } } } - + if(os.get_station_bit(mas_id - 1) == 0 && masbit == 1){ // notify master on event push_message(NOTIFY_STATION_ON, mas_id - 1, 0); } - + os.set_station_bit(mas_id - 1, masbit); } } @@ -1381,7 +1381,7 @@ void push_message(int type, uint32_t lval, float fval, const char* sval) { // check if ifttt key exists and also if the enable bit is set os.sopt_load(SOPT_IFTTT_KEY, tmp_buffer); bool ifttt_enabled = ((os.iopts[IOPT_NOTIF_ENABLE]&type)!=0) && (strlen(tmp_buffer)!=0); - + #define DEFAULT_EMAIL_PORT 465 // parse email variables @@ -1448,7 +1448,7 @@ void push_message(int type, uint32_t lval, float fval, const char* sval) { topic[PUSH_TOPIC_LEN]=0; strcat(postval+strlen(postval), topic); strcat_P(postval, PSTR("], ")); - if(email_enabled) { + if(email_enabled) { strcat(topic, " "); email_message.subject = topic; // prefix the email subject with device name } diff --git a/mqtt.cpp b/src/mqtt.cpp similarity index 98% rename from mqtt.cpp rename to src/mqtt.cpp index fa17b670c..3e27ab919 100644 --- a/mqtt.cpp +++ b/src/mqtt.cpp @@ -41,19 +41,19 @@ struct mosquitto *mqtt_client = NULL; #endif -#include "OpenSprinkler.h" -#include "opensprinkler_server.h" -#include "main.h" -#include "program.h" -#include "types.h" -#include "mqtt.h" -#include "ArduinoJson.hpp" +#include "../include/OpenSprinkler.h" +#include "../include/opensprinkler_server.h" +#include "../include/main.h" +#include "../include/program.h" +#include "../include/types.h" +#include "../include/mqtt.h" +#include "../include/ArduinoJson.hpp" // Debug routines to help identify any blocking of the event loop for an extended period #if defined(ENABLE_DEBUG) #if defined(ARDUINO) - #include "TimeLib.h" + #include "../include/TimeLib.h" #define DEBUG_TIMESTAMP(msg, ...) {time_os_t t = os.now_tz(); Serial.printf("%02d-%02d-%02d %02d:%02d:%02d - ", year(t), month(t), day(t), hour(t), minute(t), second(t));} #else #include @@ -98,7 +98,7 @@ char OSMqtt::_pub_topic[MQTT_MAX_TOPIC_LEN + 1] = {0}; // topic for publishing d char OSMqtt::_sub_topic[MQTT_MAX_TOPIC_LEN + 1] = {0}; // topic for subscribing bool OSMqtt::_done_subscribed = false; //Flag indicating if command topic has been subscribed to -//******************************** HELPER FUNCTIONS ********************************// +//******************************** HELPER FUNCTIONS ********************************// extern uint16_t parse_listdata(char **p); extern unsigned char findKeyVal (const char *str,char *strbuf, uint16_t maxlen,const char *key,bool key_in_pgm=false,uint8_t *keyfound=NULL); @@ -202,7 +202,7 @@ void manualRun(char *message){ }else{ q = pd.enqueue(); } - + if(q){ q->st = 0; q->dur = timer; @@ -361,7 +361,7 @@ void OSMqtt::begin(void) { if(subt_val) strncpy(_sub_topic, subt_val, MQTT_MAX_TOPIC_LEN); } - // properly end all strings to make sure + // properly end all strings to make sure _host[MQTT_MAX_HOST_LEN] = 0; _username[MQTT_MAX_USERNAME_LEN] = 0; _password[MQTT_MAX_PASSWORD_LEN] = 0; @@ -600,7 +600,7 @@ static void _mqtt_connection_cb(struct mosquitto *mqtt_client, void *obj, int re DEBUG_LOGF("MQTT Connnection Callback: %s (%d)\r\n", mosquitto_strerror(reason), reason); ::_connected = true; - + String avail_topic(OSMqtt::get_pub_topic()); avail_topic += "/"; avail_topic += MQTT_AVAILABILITY_TOPIC; diff --git a/opensprinkler_server.cpp b/src/opensprinkler_server.cpp similarity index 99% rename from opensprinkler_server.cpp rename to src/opensprinkler_server.cpp index f2acfc5a4..fe7b68e42 100644 --- a/opensprinkler_server.cpp +++ b/src/opensprinkler_server.cpp @@ -21,13 +21,13 @@ * . */ -#include "types.h" -#include "OpenSprinkler.h" -#include "program.h" -#include "opensprinkler_server.h" -#include "weather.h" -#include "mqtt.h" -#include "main.h" +#include "../include/types.h" +#include "../include/OpenSprinkler.h" +#include "../include/program.h" +#include "../include/opensprinkler_server.h" +#include "../include/weather.h" +#include "../include/mqtt.h" +#include "../include/main.h" // External variables defined in main ion file #if defined(USE_OTF) @@ -48,19 +48,19 @@ #if defined(ESP8266) #include #include - #include "espconnect.h" + #include "../include/espconnect.h" extern ESP8266WebServer *update_server; extern ENC28J60lwIP enc28j60; extern Wiznet5500lwIP w5500; extern lwipEth eth; #else - #include "SdFat.h" + #include "../include/SdFat.h" extern SdFat sd; #endif #else #include #include - #include "etherport.h" + #include "../include/etherport.h" #endif extern char ether_buffer[]; @@ -903,7 +903,7 @@ void server_change_program(OTF_PARAMS_DEF) { *(char*)(&prog) = parse_listdata(&pv); prog.days[0]= parse_listdata(&pv); prog.days[1]= parse_listdata(&pv); - + if (prog.type == PROGRAM_TYPE_INTERVAL) { if (prog.days[1] == 0) handle_return(HTML_DATA_OUTOFBOUND) else if (prog.days[1] >= 1) { @@ -1571,7 +1571,7 @@ void server_change_password(OTF_PARAMS_DEF) { #endif if (findKeyVal(FKV_SOURCE, tmp_buffer, TMP_BUFFER_SIZE, PSTR("npw"), true)) { const int pwBufferSize = TMP_BUFFER_SIZE/2; - char *tbuf2 = tmp_buffer + pwBufferSize; // use the second half of tmp_buffer + char *tbuf2 = tmp_buffer + pwBufferSize; // use the second half of tmp_buffer if (findKeyVal(FKV_SOURCE, tbuf2, pwBufferSize, PSTR("cpw"), true) && strncmp(tmp_buffer, tbuf2, pwBufferSize) == 0) { urlDecode(tmp_buffer); os.sopt_save(SOPT_PASSWORD, tmp_buffer); diff --git a/program.cpp b/src/program.cpp similarity index 99% rename from program.cpp rename to src/program.cpp index 88dfdfce3..0b764006c 100644 --- a/program.cpp +++ b/src/program.cpp @@ -22,8 +22,8 @@ */ #include -#include "program.h" -#include "main.h" +#include "../include/program.h" +#include "../include/main.h" #if !defined(SECS_PER_DAY) #define SECS_PER_MIN (60UL) diff --git a/smtp.c b/src/smtp.c similarity index 99% rename from smtp.c rename to src/smtp.c index bb077e85d..d01f84fde 100644 --- a/smtp.c +++ b/src/smtp.c @@ -62,7 +62,7 @@ */ #define SMTP_INTERNAL_DEFINE -#include "smtp.h" +#include "../include/smtp.h" /* * The SMTP_TEST converts some library routines into special test seams which diff --git a/utils.cpp b/src/utils.cpp similarity index 98% rename from utils.cpp rename to src/utils.cpp index b9209ec1e..2b95fa27b 100644 --- a/utils.cpp +++ b/src/utils.cpp @@ -21,9 +21,9 @@ * */ -#include "utils.h" -#include "types.h" -#include "OpenSprinkler.h" +#include "../include/utils.h" +#include "../include/types.h" +#include "../include/OpenSprinkler.h" extern OpenSprinkler os; #if defined(ARDUINO) // Arduino @@ -33,7 +33,7 @@ extern OpenSprinkler os; #include #else #include - #include "SdFat.h" + #include "../include/SdFat.h" extern SdFat sd; #endif diff --git a/weather.cpp b/src/weather.cpp similarity index 96% rename from weather.cpp rename to src/weather.cpp index d8289fa84..115c43e1f 100644 --- a/weather.cpp +++ b/src/weather.cpp @@ -22,12 +22,12 @@ */ #include -#include "OpenSprinkler.h" -#include "utils.h" -#include "opensprinkler_server.h" -#include "weather.h" -#include "main.h" -#include "types.h" +#include "../include/OpenSprinkler.h" +#include "../include/utils.h" +#include "../include/opensprinkler_server.h" +#include "../include/weather.h" +#include "../include/main.h" +#include "../include/types.h" extern OpenSprinkler os; // OpenSprinkler object extern char tmp_buffer[]; diff --git a/testmode.h b/testmode.h deleted file mode 100644 index e69de29bb..000000000