diff --git a/esp32-timed-switch.ino b/esp32-timed-switch.ino
index 6fa3798..b3895a9 100644
--- a/esp32-timed-switch.ino
+++ b/esp32-timed-switch.ino
@@ -13,7 +13,7 @@
// --------------------------------------------
-const char* html_app="
ESP32 timed SwitchScheduler
";
+const char* html_app="ESP32 timed SwitchScheduler
";
// PREFERENCES
diff --git a/html/index.html b/html/index.html
index fa7641b..fcf4e0d 100644
--- a/html/index.html
+++ b/html/index.html
@@ -3,7 +3,7 @@
ESP32 timed Switch
-
+
Scheduler
@@ -28,7 +28,7 @@ class Schedule {
// Load from binary data
var view = new DataView(buffer);
for (var i = 0; i < 24; i++) {
- this.schedule[i] = view.getUint16(i * 2);
+ this.schedule[i] = view.getUint16(i * 2, true);
}
};
@@ -101,10 +101,11 @@ class Schedule {
// Convert to binary data
var buffer = new ArrayBuffer(24 * 2);
var view = new DataView(buffer);
- for (var i = 0; i < this.schedule.length; i++) {
- view.setUint16(i * 2, this.schedule[i]);
+ for (var i = 0; i < 24; i++) {
+ view.setUint8( i*2 , (this.schedule[i] & 65280) >> 8, true);
+ view.setUint8( i*2 + 1, this.schedule[i] & 255 , true);
}
- return view;
+ return buffer;
};
}
diff --git a/html/minify.sh b/html/minify.sh
index e499062..0b6eb67 100755
--- a/html/minify.sh
+++ b/html/minify.sh
@@ -2,10 +2,12 @@
APP_PATH=$(cd $(dirname $0) && pwd)
TMP_FILE=$(mktemp)
-FINAL_FILE=minify.html
+FINAL_FILE="${APP_PATH}/minify.html"
cp "$APP_PATH/index.html" "$TMP_FILE"
sed -ri "s/^\s+//" "$TMP_FILE"
sed -ri "s=^//.*$==" "$TMP_FILE"
sed -ri 's="=\\"=g' "$TMP_FILE"
tr -d '\n' < "$TMP_FILE" > "$FINAL_FILE"
-cat "$FINAL_FILE"
\ No newline at end of file
+sed -Ei 's= {2,}= =g' "$FINAL_FILE"
+cat "$FINAL_FILE"
+rm "$TMP_FILE"
diff --git a/html/mockup.py b/html/mockup.py
index 0d4f487..ef18aa4 100755
--- a/html/mockup.py
+++ b/html/mockup.py
@@ -29,7 +29,7 @@ def serve_file_in_dir(path):
# Generate a random 12-bit integer (0 to 4095)
def random_12_bit_int():
- return random.randint(0, 0b111111111111)
+ return random.randint(0, 0b111111111111)
# Convert a binary stream to 24 integers
@@ -37,7 +37,7 @@ def binary_stream_to_ints(binary_data):
integers = []
# Every 32-bit integer is represented by 2 bytes
for i in range(0, len(binary_data), 2):
- integers.append(int.from_bytes(binary_data[i:i + 2], byteorder='big') & 0b111111111111) # Extract 32-bit value
+ integers.append(int.from_bytes(binary_data[i:i + 2]) & 0b111111111111) # Extract 32-bit value
return integers
@@ -53,7 +53,7 @@ def get_schedule(plug_id):
# Ensure integer is in 12-bit range
integer &= 0b111111111111
# Convert to bytes and append
- yield integer.to_bytes(2, byteorder='big') # 2 bytes per integer
+ yield integer.to_bytes(2) # 2 bytes per integer
# Return as a binary stream
return Response(ints_to_binary_stream(schedule), status=200, content_type='application/octet-stream')