Skip to content

Commit

Permalink
v1.2.16
Browse files Browse the repository at this point in the history
- deprecated seconds fields in crontab expressions
- automating firmware build and publish process
- added generic esp32 smart switch relay x2 config
  • Loading branch information
genemars committed Jun 6, 2024
1 parent 2a1f70e commit 3b11f3e
Show file tree
Hide file tree
Showing 9 changed files with 88 additions and 37 deletions.
11 changes: 11 additions & 0 deletions .github/post-build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
outputFolder="./artifacts";
if [ ! -d $outputFolder ]; then mkdir $outputFolder; fi;
pio project config | grep "env:" | while read -r line; do
firmware="${line:4}";
if [ -d "./.pio/build/${firmware}" ]; then
cd ./.pio/build/
zip "../../artifacts/${firmware}-${VERSION_NUMBER}.zip" "$firmware/firmware.bin" "$firmware/bootloader.bin" "$firmware/partitions.bin"
cd ../..
fi
done;
ls -latr artifacts/
18 changes: 17 additions & 1 deletion .github/workflows/platformio.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,23 @@ jobs:
- uses: actions/setup-python@v4
with:
python-version: '3.9'

- name: Set env
run: |
echo "export RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
echo "export VERSION_NUMBER=$(echo ${GITHUB_REF#refs/*/} | cut -d"v" -f 2)" >> $GITHUB_ENV
- name: Install PlatformIO Core
run: pip install --upgrade platformio

- name: Build PlatformIO Project
run: pio run
run: |
pio run
sh ./github/post-build.sh
- name: Release
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
files: |
./artifacts/*.zip
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ https://homegenie.it/mini
- Easy Wi-Fi configuration using Bluetooth (ESP32) or WPS (ESP8266)
- Does not require an Internet connection to be configured or to work properly
- Time synchronization using internal RTC (ESP32), mobile app time or NTP
- Integrated actions scheduler supporting *cron expressions* with seconds field
- Integrated actions scheduler supporting *extended cron expressions*
- Device discovery through SNMP/UPnP advertising with customizable name
- Multi-channel I/O: HTTP, WebSocket, SSE, MQTT
- Status LED
Expand Down Expand Up @@ -159,7 +159,7 @@ You can use the following command to list all possible configurations to build t
pio project config
```

See also [HomeGenie Mini Documentation](https://homegenie.it/mini/1.2/) for further information
See also [HomeGenie Mini Documentation](https://homegenie.it/mini/) for further information
about included examples.


Expand Down
14 changes: 10 additions & 4 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ lib_deps =

[env:default]
platform = [email protected]
build_flags = ${env.build_flags}


[env:d1-mini]
Expand All @@ -49,7 +50,12 @@ lib_ignore =

[env:d1-mini-esp32]
platform = [email protected]
build_flags = ${env.build_flags} -D MINI_ESP32 -D CONFIG_ServiceButtonPin=16 -D CONFIG_StatusLedPin=26 -D CONFIG_GPIO_OUT={18,19,23,5} -D CONFIG_GPIO_IN={}
build_flags = ${env.build_flags} -D MINI_ESP32 -D CONFIG_ServiceButtonPin=16 -D CONFIG_StatusLedPin=26 -D CONFIG_GPIO_OUT={18,19,23,5}


[env:switch-relay-x2-esp32]
platform = [email protected]
build_flags = ${env.build_flags} -D DISABLE_UI -D CONFIG_ServiceButtonPin=0 -D CONFIG_StatusLedPin=23 -D CONFIG_GPIO_OUT="{16,17}"


[env:sonoff]
Expand All @@ -68,7 +74,7 @@ lib_deps = ${env.lib_deps}

[env:smart-sensor-d1-mini-esp32]
platform = [email protected]
build_flags = ${env.build_flags} -I examples -I src -D MINI_ESP32 -D DISABLE_UI -D CONFIG_ServiceButtonPin=16 -D CONFIG_StatusLedPin=26 -D CONFIG_GPIO_OUT={18,19,23,5} -D CONFIG_GPIO_IN={}
build_flags = ${env.build_flags} -I examples -I src -D MINI_ESP32 -D DISABLE_UI -D CONFIG_ServiceButtonPin=16 -D CONFIG_StatusLedPin=26 -D CONFIG_GPIO_OUT={18,19,23,5}
build_src_filter = +<src> -<src/main.cpp> +<examples/smart-sensor>
lib_deps = ${env.lib_deps}
[email protected]
Expand Down Expand Up @@ -125,7 +131,7 @@ lib_ignore =
[env:x10-transceiver-d1-mini]
platform = [email protected]
board = d1_mini
build_flags = ${env.build_flags} -D DISABLE_UI -D DISABLE_AUTOMATION
build_flags = ${env.build_flags} -D DISABLE_UI
build_src_filter = +<src> -<src/main.cpp> +<examples/x10-transceiver>
lib_ignore =
ESP32Time
Expand All @@ -142,7 +148,7 @@ lib_deps = ${env.lib_deps}
[env:rf-transceiver-d1-mini]
platform = [email protected]
board = d1_mini
build_flags = ${env.build_flags} -D DISABLE_UI -D DISABLE_AUTOMATION
build_flags = ${env.build_flags} -D DISABLE_UI
build_src_filter = +<src> -<src/main.cpp> +<examples/rf-transceiver>
lib_deps = ${env.lib_deps}
[email protected]
Expand Down
46 changes: 29 additions & 17 deletions src/automation/ExtendedCron.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,34 @@ namespace Automation {
return nullptr;
}

bool ExtendedCron::IsScheduling(time_t date, String& cronExpression, int recursionCount)
bool ExtendedCron::IsScheduling(time_t date, String& cronExpression)
{
return getScheduling(date, date, cronExpression, recursionCount).size() > 0;
struct tm timeStart;
localtime_r(&date, &timeStart);
timeStart.tm_sec = timeStart.tm_min = timeStart.tm_hour = 0;
struct tm timeEnd;
localtime_r(&date, &timeEnd);
timeEnd.tm_sec = 59;
timeEnd.tm_min = 59;
timeEnd.tm_hour = 23;
auto start = mktime(&timeStart);
auto end = mktime(&timeEnd);
auto list = getScheduling(start, end, cronExpression);
int low = 0;
int high = list.size() - 1;
time_t x = normalizeStartTime(date);
while (low <= high) {
int mid = low + (high - low) / 2;
if (list[mid] == x) {
return true;
}
if (list[mid] < x) {
low = mid + 1;
} else {
high = mid - 1;
}
}
return false;
}

time_t ExtendedCron::normalizeStartTime(time_t timestamp) {
Expand All @@ -52,10 +77,8 @@ namespace Automation {
LinkedList<time_t> ExtendedCron::getScheduling(time_t dateStart, time_t dateEnd, String& cronExpression, int recursionCount)
{
// align input time
if (!hasSecondsField(cronExpression.c_str())) {
dateStart = normalizeStartTime(dateStart);
dateEnd = normalizeEndTime(dateEnd);
}
dateStart = normalizeStartTime(dateStart);
dateEnd = normalizeEndTime(dateEnd);

// '[' and ']' are just aesthetic alias for '(' and ')'
cronExpression.replace("[", "(");
Expand Down Expand Up @@ -221,17 +244,6 @@ namespace Automation {
return copy;
}

int ExtendedCron::hasSecondsField(const char* str) {
char del = ' ';
size_t count = 0;
if (!str) return -1;
while ((str = strchr(str, del)) != nullptr) {
count++;
do str++; while (del == *str);
}
return (int)count + 1 > 5;
}

void ExtendedCron::getNextOccurrences(LinkedList<time_t>& occurrences, time_t dateStart, time_t dateEnd, const String& cronExpression)
{

Expand Down
2 changes: 1 addition & 1 deletion src/automation/ExtendedCron.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ namespace Automation {

class ExtendedCron {
public:
static bool IsScheduling(time_t date, String& cronExpression, int recursionCount = 0);
static bool IsScheduling(time_t date, String& cronExpression);

static time_t normalizeStartTime(time_t timestamp);
static time_t normalizeEndTime(time_t timestamp);
Expand Down
4 changes: 4 additions & 0 deletions src/automation/Scheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
namespace Automation {
LinkedList<Schedule*> Scheduler::scheduleList;
SchedulerListener* Scheduler::listener = nullptr;
int Scheduler::lastCheckMinute = -1;

void Scheduler::addSchedule(Schedule* schedule) {
int existingIndex = -1;
Expand Down Expand Up @@ -76,6 +77,9 @@ namespace Automation {

void Scheduler::loop() {
auto now = time(0);
tm* t = localtime(&now);
if (t->tm_min == lastCheckMinute || millis() < 10000) return;
lastCheckMinute = t->tm_min;
//for(;;) {
// int lastRun = millis() % 1000;
for (int i = 0; i < scheduleList.size(); i++) {
Expand Down
22 changes: 10 additions & 12 deletions src/automation/Scheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,16 @@ namespace Automation {
using namespace Data;

namespace ScheduleField {
static const char name[] PROGMEM = "Name";
static const char description[] PROGMEM = "Description";
static const char data[] PROGMEM = "Data";
static const char cronExpression[] PROGMEM = "CronExpression";
static const char script[] PROGMEM = "Script";
static const char boundDevices[] PROGMEM = "BoundDevices";
static const char boundModules[] PROGMEM = "BoundModules";
static const char name[] = "Name";
static const char description[] = "Description";
static const char data[] = "Data";
static const char cronExpression[] = "CronExpression";
static const char script[] = "Script";
static const char boundDevices[] = "BoundDevices";
static const char boundModules[] = "BoundModules";
};
namespace ScheduleData {
static const char fileName[] PROGMEM = "/schedules.json";
static const char fileName[] = "/schedules.json";
}

class Schedule {
Expand All @@ -77,10 +77,7 @@ namespace Automation {
return ExtendedCron::IsScheduling(ts, cronExpression);
}
bool wasScheduled(time_t ts) {
if (!ExtendedCron::hasSecondsField(cronExpression.c_str())) {
return ExtendedCron::normalizeStartTime(lastOccurrence) == ExtendedCron::normalizeStartTime(ts);
}
return lastOccurrence == ts;
return ExtendedCron::normalizeStartTime(lastOccurrence) == ExtendedCron::normalizeStartTime(ts);
}
void setScheduled(time_t ts) {
lastOccurrence = ts;
Expand Down Expand Up @@ -126,6 +123,7 @@ namespace Automation {
private:
static LinkedList<Schedule*> scheduleList;
static SchedulerListener* listener;
static int lastCheckMinute;
};

}
Expand Down
4 changes: 4 additions & 0 deletions src/service/api/HomeGenieHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ namespace Service { namespace API {
" \"script\": \"$$.boundModules.off();\\n\"\n"
" },\n"
" {\n"
" \"id\": \"command_toggle\",\n"
" \"script\": \"$$.boundModules.toggle();\\n\"\n"
" },\n"
" {\n"
" \"id\": \"command_set_level\",\n"
" \"script\": \"$$.boundModules.level = $level$;\\n\",\n"
" \"config\": {\n"
Expand Down

0 comments on commit 3b11f3e

Please sign in to comment.