Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(reorganize): reorganize project files #323

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ OpenSprinkler
wtopts.txt
*.dat
*.sh
testmode.h
include/testmode.h
build-1284/*
.vscode
.pio
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion OpenSprinkler.service
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion examples/mainArduino/mainArduino.ino
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "OpenSprinkler.h"
#include "../../include/OpenSprinkler.h"

void do_setup();
void do_loop();
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions EMailSender.h → include/EMailSender.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@
#include "EMailSenderKey.h"

#if ARDUINO >= 100
#include "Arduino.h"
#include <Arduino.h>
#else
#include "WProgram.h"
#include <WProgram.h>
#endif

#if(NETWORK_ESP8266_242 == DEFAULT_EMAIL_NETWORK_TYPE_ESP8266)
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions I2CRTC.h → include/I2CRTC.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -36,4 +36,4 @@ class I2CRTC
extern I2CRTC RTC;

#endif

File renamed without changes.
4 changes: 2 additions & 2 deletions OpenSprinkler.h → include/OpenSprinkler.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion gpio.h → include/gpio.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

#if defined(ESP8266)

#include "Arduino.h"
#include <Arduino.h>

// PCA9555 register defines
#define NXP_INPUT_REG 0
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion mainArduino.ino
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "OpenSprinkler.h"
#include "include/OpenSprinkler.h"

void do_setup();
void do_loop();
Expand Down
8 changes: 4 additions & 4 deletions build.sh → scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ 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
echo "Compiling osbo firmware..."

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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion updater.sh → scripts/updater.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#! /bin/bash

git pull
./build.sh -s ospi
./scripts/build.sh -s ospi
systemctl restart OpenSprinkler.service
24 changes: 12 additions & 12 deletions EMailSender.cpp → src/EMailSender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
* THE SOFTWARE.
*/

#include "EMailSender.h"
#include "../include/EMailSender.h"
#include <stdio.h>
#if defined(ESP32)
#include <mbedtls/base64.h>
Expand Down Expand Up @@ -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<space>'

Expand All @@ -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.
Expand All @@ -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);
Expand All @@ -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"));
Expand Down
26 changes: 13 additions & 13 deletions I2CRTC.cpp → src/I2CRTC.cpp
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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 <Wire.h>

static uint8_t _addrs[] = {DS1307_ADDR, MCP7940_ADDR, PCF8563_ADDR};
Expand Down Expand Up @@ -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
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -108,39 +108,39 @@ 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));
Wire.write(dec2bcd(tm.Hour)); // sets 24 hour format
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));
Wire.write(dec2bcd(tm.Hour)); // sets 24 hour format
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));
Wire.write(dec2bcd(tm.Hour)); // sets 24 hour format
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;
}
Expand Down
2 changes: 1 addition & 1 deletion LiquidCrystal.cpp → src/LiquidCrystal.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#if defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega1284__)

#include "LiquidCrystal.h"
#include "../include/LiquidCrystal.h"
#include <inttypes.h>
#include <Arduino.h>
#include <Wire.h>
Expand Down
28 changes: 14 additions & 14 deletions OpenSprinkler.cpp → src/OpenSprinkler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
* <http://www.gnu.org/licenses/>.
*/

#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;
Expand Down Expand Up @@ -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()<timeout) {
Expand Down Expand Up @@ -714,13 +714,13 @@ void OpenSprinkler::reboot_dev(uint8_t cause) {

#else // RPI/BBB/LINUX network init functions

#include "etherport.h"
#include "../include/etherport.h"
#include <sys/reboot.h>
#include <stdlib.h>
#include <sys/ioctl.h>
#include <net/if.h>
#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() {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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"));
Expand Down
Loading