Compare commits
1 Commits
main
...
homeassist
Author | SHA1 | Date |
---|---|---|
Siwat Sirichai | e59c00b46e |
|
@ -6,5 +6,3 @@
|
||||||
.vs/
|
.vs/
|
||||||
.vscode/
|
.vscode/
|
||||||
.vscode/settings.json
|
.vscode/settings.json
|
||||||
firmware/
|
|
||||||
release/
|
|
|
@ -73,6 +73,5 @@
|
||||||
"C_Cpp_Runner.useLeakSanitizer": false,
|
"C_Cpp_Runner.useLeakSanitizer": false,
|
||||||
"C_Cpp_Runner.showCompilationTime": false,
|
"C_Cpp_Runner.showCompilationTime": false,
|
||||||
"C_Cpp_Runner.useLinkTimeOptimization": false,
|
"C_Cpp_Runner.useLinkTimeOptimization": false,
|
||||||
"C_Cpp_Runner.msvcSecureNoWarnings": false,
|
"C_Cpp_Runner.msvcSecureNoWarnings": false
|
||||||
"cmake.sourceDirectory": "D:/Git/iot-firmware/.pio/libdeps/full/Adafruit BusIO"
|
|
||||||
}
|
}
|
|
@ -1,20 +0,0 @@
|
||||||
pipeline {
|
|
||||||
agent any
|
|
||||||
|
|
||||||
stages {
|
|
||||||
stage('Build') {
|
|
||||||
steps {
|
|
||||||
git branch: 'main', url: 'https://git.siwatsystem.com/ise-senior-iot/iot-firmware.git'
|
|
||||||
sh 'export PLATFORMIO_PATH=/root/.platformio/penv/bin/platformio'
|
|
||||||
sh '/usr/bin/python3 gen_release.py'
|
|
||||||
stash includes: 'release/**/*', name: 'release_binaries'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
stage('Publish') {
|
|
||||||
steps {
|
|
||||||
unstash 'release_binaries'
|
|
||||||
archiveArtifacts artifacts: 'release/**/*', fingerprint: true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
115
gen_release.py
115
gen_release.py
|
@ -1,115 +0,0 @@
|
||||||
import os
|
|
||||||
import shutil
|
|
||||||
import subprocess
|
|
||||||
import sys
|
|
||||||
import subprocess
|
|
||||||
import os
|
|
||||||
import shutil
|
|
||||||
import subprocess
|
|
||||||
import sys
|
|
||||||
import platform
|
|
||||||
import re
|
|
||||||
import configparser
|
|
||||||
from time import sleep as delay
|
|
||||||
|
|
||||||
|
|
||||||
# Get the current directory
|
|
||||||
current_dir = os.path.dirname(os.path.abspath(__file__))
|
|
||||||
|
|
||||||
# Define the path to the firmware folder
|
|
||||||
firmware_folder = os.path.join(current_dir, 'firmware')
|
|
||||||
|
|
||||||
# Create the firmware folder if it does not exist
|
|
||||||
if not os.path.exists(firmware_folder):
|
|
||||||
os.makedirs(firmware_folder)
|
|
||||||
|
|
||||||
# Define the path to the release folder
|
|
||||||
release_folder = os.path.join(current_dir, 'release')
|
|
||||||
|
|
||||||
# Get the platformio path from environment variable
|
|
||||||
platformio_path = os.environ.get('PLATFORMIO_PATH')
|
|
||||||
# If the environment variable is not set, use the default path
|
|
||||||
if platformio_path is None:
|
|
||||||
if platform.system() == 'Darwin':
|
|
||||||
platformio_path = os.path.expanduser('~/.platformio/penv/bin/platformio')
|
|
||||||
elif platform.system() == 'Windows':
|
|
||||||
platformio_path = os.path.expanduser('~/.platformio/penv/Scripts/platformio.exe')
|
|
||||||
elif platform.system() == 'Linux':
|
|
||||||
platformio_path = os.path.expanduser('~/.platformio/penv/bin/platformio')
|
|
||||||
|
|
||||||
if os.path.exists(release_folder):
|
|
||||||
# If the release folder exists, delete it
|
|
||||||
shutil.rmtree(release_folder)
|
|
||||||
os.makedirs(release_folder)
|
|
||||||
|
|
||||||
# Get the current Git branch name
|
|
||||||
git_branch = subprocess.check_output(['git', 'rev-parse', '--abbrev-ref', 'HEAD']).decode().strip()
|
|
||||||
commit_hash = subprocess.check_output(['git', 'rev-parse', 'HEAD']).decode().strip()[:10]
|
|
||||||
|
|
||||||
# If arguments are supplied, build the environments that match the arguments
|
|
||||||
if len(sys.argv) > 1:
|
|
||||||
environments = sys.argv[1:]
|
|
||||||
|
|
||||||
# If no argument are supplied, build all environments listed in platformio.ini
|
|
||||||
else:
|
|
||||||
environments = []
|
|
||||||
with open(os.path.join(current_dir, 'platformio.ini')) as f:
|
|
||||||
|
|
||||||
# Iterate over the lines in platformio.ini
|
|
||||||
for line in f.readlines():
|
|
||||||
|
|
||||||
# Check if the line contains the string "env:"
|
|
||||||
if '[env:' in line:
|
|
||||||
|
|
||||||
# Extract the environment using regular expressions
|
|
||||||
environment = re.search(r'\[env:(.*?)\]', line).group(1)
|
|
||||||
|
|
||||||
# Add the environment to the list of environments
|
|
||||||
environments.append(environment)
|
|
||||||
|
|
||||||
# Remove old platformio.ini file from firmware folder if it exists
|
|
||||||
if os.path.isfile(os.path.join(firmware_folder, 'platformio.ini')):
|
|
||||||
os.remove(os.path.join(firmware_folder, 'platformio.ini'))
|
|
||||||
|
|
||||||
# Copy the platformio.ini file to the firmware folder
|
|
||||||
shutil.copyfile(os.path.join(current_dir, 'platformio.ini'), os.path.join(firmware_folder, 'platformio.ini'))
|
|
||||||
|
|
||||||
# Check that the file is copied correctly
|
|
||||||
if not os.path.isfile(os.path.join(firmware_folder, 'platformio.ini')):
|
|
||||||
raise Exception('platformio.ini file not copied correctly')
|
|
||||||
|
|
||||||
# Read the platformio.ini file
|
|
||||||
config = configparser.ConfigParser()
|
|
||||||
config.read(os.path.join(firmware_folder, 'platformio.ini'))
|
|
||||||
|
|
||||||
# Add firmware version to build_flags in platformio.ini
|
|
||||||
for environment in environments:
|
|
||||||
if 'build_flags' not in config[f'env:{environment}']:
|
|
||||||
config[f'env:{environment}']['build_flags'] = f'-DFW_VERSION=\\"{git_branch}_{environment}_{commit_hash}\\"'
|
|
||||||
else:
|
|
||||||
config[f'env:{environment}']['build_flags'] = config[f'env:{environment}']['build_flags'] + f' -DFW_VERSION=\\"{git_branch}_{environment}_{commit_hash}\\"'
|
|
||||||
|
|
||||||
# Write the platformio.ini file
|
|
||||||
with open(os.path.join(firmware_folder, 'platformio.ini'), 'w') as configfile:
|
|
||||||
config.write(configfile)
|
|
||||||
|
|
||||||
# if argument is not supplied, build all environments listed in platformio.ini
|
|
||||||
if len(sys.argv) == 1:
|
|
||||||
subprocess.run([f'{platformio_path}', 'run','-c',f'{firmware_folder}/platformio.ini'], cwd=current_dir)
|
|
||||||
|
|
||||||
for environment in environments:
|
|
||||||
if(len(sys.argv) > 1):
|
|
||||||
subprocess.run([f'{platformio_path}', 'run', '-e', environment,'-c',f'{firmware_folder}/platformio.ini'], cwd=current_dir)
|
|
||||||
|
|
||||||
# Iterate over the subfolders in the firmware folder
|
|
||||||
for subfolder in os.listdir(firmware_folder):
|
|
||||||
subfolder_path = os.path.join(firmware_folder, subfolder)
|
|
||||||
|
|
||||||
# Check if the subfolder matches the environment argument
|
|
||||||
if subfolder == environment:
|
|
||||||
# Check if the subfolder contains a firmware.bin file
|
|
||||||
firmware_file = os.path.join(subfolder_path, 'firmware.bin')
|
|
||||||
if os.path.isfile(firmware_file):
|
|
||||||
# Move the firmware.bin file to the release folder with the Git branch name and commit hash appended
|
|
||||||
new_file_name = os.path.join(release_folder, f"{git_branch}_{subfolder}_{commit_hash}.bin")
|
|
||||||
shutil.move(firmware_file, new_file_name)
|
|
147
platformio.ini
147
platformio.ini
|
@ -8,15 +8,11 @@
|
||||||
; Please visit documentation for the other options and examples
|
; Please visit documentation for the other options and examples
|
||||||
; https://docs.platformio.org/page/projectconf.html
|
; https://docs.platformio.org/page/projectconf.html
|
||||||
|
|
||||||
[platformio]
|
[env:wt32-eth01]
|
||||||
build_dir = firmware
|
|
||||||
|
|
||||||
[env:full]
|
|
||||||
platform = espressif32
|
platform = espressif32
|
||||||
board = wt32-eth01
|
board = wt32-eth01
|
||||||
framework = arduino
|
framework = arduino
|
||||||
board_build.f_cpu = 240000000L
|
board_build.f_cpu = 240000000L
|
||||||
build_flags = -DENABLE_INTERNAL_LCD -DENABLE_IR_MODULE -DENABLE_CLIMATE_MODULE -DENABLE_ANALOG_MODULE -DENABLE_WEBUI
|
|
||||||
lib_deps = siwats/ESPMegaPROR3@^1.3.0
|
lib_deps = siwats/ESPMegaPROR3@^1.3.0
|
||||||
knolleary/PubSubClient@^2.8
|
knolleary/PubSubClient@^2.8
|
||||||
ivanseidel/ArduinoThread@^2.1.1
|
ivanseidel/ArduinoThread@^2.1.1
|
||||||
|
@ -28,144 +24,3 @@ lib_deps = siwats/ESPMegaPROR3@^1.3.0
|
||||||
robtillaart/FRAM_I2C@^0.6.1
|
robtillaart/FRAM_I2C@^0.6.1
|
||||||
esphome/ESPAsyncWebServer-esphome@^3.1.0
|
esphome/ESPAsyncWebServer-esphome@^3.1.0
|
||||||
monitor_speed = 115200
|
monitor_speed = 115200
|
||||||
|
|
||||||
[env:lcd_climate]
|
|
||||||
platform = espressif32
|
|
||||||
board = wt32-eth01
|
|
||||||
framework = arduino
|
|
||||||
board_build.f_cpu = 240000000L
|
|
||||||
build_flags = -DENABLE_INTERNAL_LCD -DENABLE_IR_MODULE -DENABLE_CLIMATE_MODULE
|
|
||||||
lib_deps = siwats/ESPMegaPROR3@^1.3.0
|
|
||||||
knolleary/PubSubClient@^2.8
|
|
||||||
ivanseidel/ArduinoThread@^2.1.1
|
|
||||||
arduino-libraries/Arduino_BuiltIn@^1.0.0
|
|
||||||
dersimn/PubSubClientTools@^0.6
|
|
||||||
z3t0/IRremote@^4.2.0
|
|
||||||
robtillaart/DHTNEW@^0.4.18
|
|
||||||
seithan/Easy Nextion Library@^1.0.6
|
|
||||||
robtillaart/FRAM_I2C@^0.6.1
|
|
||||||
esphome/ESPAsyncWebServer-esphome@^3.1.0
|
|
||||||
monitor_speed = 115200
|
|
||||||
|
|
||||||
[env:webui]
|
|
||||||
platform = espressif32
|
|
||||||
board = wt32-eth01
|
|
||||||
framework = arduino
|
|
||||||
board_build.f_cpu = 240000000L
|
|
||||||
build_flags = -DENABLE_WEBUI
|
|
||||||
lib_deps = siwats/ESPMegaPROR3@^1.3.0
|
|
||||||
knolleary/PubSubClient@^2.8
|
|
||||||
ivanseidel/ArduinoThread@^2.1.1
|
|
||||||
arduino-libraries/Arduino_BuiltIn@^1.0.0
|
|
||||||
dersimn/PubSubClientTools@^0.6
|
|
||||||
z3t0/IRremote@^4.2.0
|
|
||||||
robtillaart/DHTNEW@^0.4.18
|
|
||||||
seithan/Easy Nextion Library@^1.0.6
|
|
||||||
robtillaart/FRAM_I2C@^0.6.1
|
|
||||||
esphome/ESPAsyncWebServer-esphome@^3.1.0
|
|
||||||
|
|
||||||
[env:climate_webui]
|
|
||||||
platform = espressif32
|
|
||||||
board = wt32-eth01
|
|
||||||
framework = arduino
|
|
||||||
board_build.f_cpu = 240000000L
|
|
||||||
build_flags = -DENABLE_IR_MODULE -DENABLE_CLIMATE_MODULE -DENABLE_WEBUI
|
|
||||||
lib_deps = siwats/ESPMegaPROR3@^1.3.0
|
|
||||||
knolleary/PubSubClient@^2.8
|
|
||||||
ivanseidel/ArduinoThread@^2.1.1
|
|
||||||
arduino-libraries/Arduino_BuiltIn@^1.0.0
|
|
||||||
dersimn/PubSubClientTools@^0.6
|
|
||||||
z3t0/IRremote@^4.2.0
|
|
||||||
robtillaart/DHTNEW@^0.4.18
|
|
||||||
seithan/Easy Nextion Library@^1.0.6
|
|
||||||
robtillaart/FRAM_I2C@^0.6.1
|
|
||||||
esphome/ESPAsyncWebServer-esphome@^3.1.0
|
|
||||||
monitor_speed = 115200
|
|
||||||
|
|
||||||
[env:lcd_webui]
|
|
||||||
platform = espressif32
|
|
||||||
board = wt32-eth01
|
|
||||||
framework = arduino
|
|
||||||
board_build.f_cpu = 240000000L
|
|
||||||
build_flags = -DENABLE_INTERNAL_LCD -DENABLE_WEBUI
|
|
||||||
lib_deps = siwats/ESPMegaPROR3@^1.3.0
|
|
||||||
knolleary/PubSubClient@^2.8
|
|
||||||
ivanseidel/ArduinoThread@^2.1.1
|
|
||||||
arduino-libraries/Arduino_BuiltIn@^1.0.0
|
|
||||||
dersimn/PubSubClientTools@^0.6
|
|
||||||
z3t0/IRremote@^4.2.0
|
|
||||||
robtillaart/DHTNEW@^0.4.18
|
|
||||||
seithan/Easy Nextion Library@^1.0.6
|
|
||||||
robtillaart/FRAM_I2C@^0.6.1
|
|
||||||
esphome/ESPAsyncWebServer-esphome@^3.1.0
|
|
||||||
monitor_speed = 115200
|
|
||||||
|
|
||||||
[env:ir_climate_analog_webui]
|
|
||||||
platform = espressif32
|
|
||||||
board = wt32-eth01
|
|
||||||
framework = arduino
|
|
||||||
board_build.f_cpu = 240000000L
|
|
||||||
build_flags = -DENABLE_IR_MODULE -DENABLE_CLIMATE_MODULE -DENABLE_ANALOG_MODULE -DENABLE_WEBUI
|
|
||||||
lib_deps = siwats/ESPMegaPROR3@^1.3.0
|
|
||||||
knolleary/PubSubClient@^2.8
|
|
||||||
ivanseidel/ArduinoThread@^2.1.1
|
|
||||||
arduino-libraries/Arduino_BuiltIn@^1.0.0
|
|
||||||
dersimn/PubSubClientTools@^0.6
|
|
||||||
z3t0/IRremote@^4.2.0
|
|
||||||
robtillaart/DHTNEW@^0.4.18
|
|
||||||
seithan/Easy Nextion Library@^1.0.6
|
|
||||||
robtillaart/FRAM_I2C@^0.6.1
|
|
||||||
esphome/ESPAsyncWebServer-esphome@^3.1.0
|
|
||||||
monitor_speed = 115200
|
|
||||||
|
|
||||||
[env:lcd_analog]
|
|
||||||
platform = espressif32
|
|
||||||
board = wt32-eth01
|
|
||||||
framework = arduino
|
|
||||||
board_build.f_cpu = 240000000L
|
|
||||||
build_flags = -DENABLE_INTERNAL_LCD -DENABLE_ANALOG_MODULE
|
|
||||||
lib_deps = siwats/ESPMegaPROR3@^1.3.0
|
|
||||||
knolleary/PubSubClient@^2.8
|
|
||||||
ivanseidel/ArduinoThread@^2.1.1
|
|
||||||
arduino-libraries/Arduino_BuiltIn@^1.0.0
|
|
||||||
dersimn/PubSubClientTools@^0.6
|
|
||||||
z3t0/IRremote@^4.2.0
|
|
||||||
robtillaart/DHTNEW@^0.4.18
|
|
||||||
seithan/Easy Nextion Library@^1.0.6
|
|
||||||
robtillaart/FRAM_I2C@^0.6.1
|
|
||||||
esphome/ESPAsyncWebServer-esphome@^3.1.0
|
|
||||||
monitor_speed = 115200
|
|
||||||
|
|
||||||
[env:lcd]
|
|
||||||
platform = espressif32
|
|
||||||
board = wt32-eth01
|
|
||||||
framework = arduino
|
|
||||||
board_build.f_cpu = 240000000L
|
|
||||||
build_flags = -DENABLE_INTERNAL_LCD
|
|
||||||
lib_deps = siwats/ESPMegaPROR3@^1.3.0
|
|
||||||
knolleary/PubSubClient@^2.8
|
|
||||||
ivanseidel/ArduinoThread@^2.1.1
|
|
||||||
arduino-libraries/Arduino_BuiltIn@^1.0.0
|
|
||||||
dersimn/PubSubClientTools@^0.6
|
|
||||||
z3t0/IRremote@^4.2.0
|
|
||||||
robtillaart/DHTNEW@^0.4.18
|
|
||||||
seithan/Easy Nextion Library@^1.0.6
|
|
||||||
robtillaart/FRAM_I2C@^0.6.1
|
|
||||||
esphome/ESPAsyncWebServer-esphome@^3.1.0
|
|
||||||
monitor_speed = 115200
|
|
||||||
|
|
||||||
[env:minimal]
|
|
||||||
platform = espressif32
|
|
||||||
board = wt32-eth01
|
|
||||||
framework = arduino
|
|
||||||
board_build.f_cpu = 240000000L
|
|
||||||
lib_deps = siwats/ESPMegaPROR3@^1.3.0
|
|
||||||
knolleary/PubSubClient@^2.8
|
|
||||||
ivanseidel/ArduinoThread@^2.1.1
|
|
||||||
arduino-libraries/Arduino_BuiltIn@^1.0.0
|
|
||||||
dersimn/PubSubClientTools@^0.6
|
|
||||||
z3t0/IRremote@^4.2.0
|
|
||||||
robtillaart/DHTNEW@^0.4.18
|
|
||||||
seithan/Easy Nextion Library@^1.0.6
|
|
||||||
robtillaart/FRAM_I2C@^0.6.1
|
|
||||||
esphome/ESPAsyncWebServer-esphome@^3.1.0
|
|
|
@ -47,7 +47,6 @@ uint8_t utc_offset = 7;
|
||||||
float current_room_temp = 0;
|
float current_room_temp = 0;
|
||||||
float current_room_humid = 0;
|
float current_room_humid = 0;
|
||||||
#endif
|
#endif
|
||||||
bool pwm_report_enable = true;
|
|
||||||
|
|
||||||
// Inputs
|
// Inputs
|
||||||
#define VINT_COUNT 16
|
#define VINT_COUNT 16
|
||||||
|
@ -70,7 +69,6 @@ const float pwm_linear_scaling_c[PWM_COUNT] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
const int PWM_CYCLE_VALUES[PWM_CYCLE_VALUES_COUNT] = {50, 125, 255};
|
const int PWM_CYCLE_VALUES[PWM_CYCLE_VALUES_COUNT] = {50, 125, 255};
|
||||||
char PWM_SET_STATE_TOPIC[70];
|
char PWM_SET_STATE_TOPIC[70];
|
||||||
char PWM_SET_VALUE_TOPIC[70];
|
char PWM_SET_VALUE_TOPIC[70];
|
||||||
char PWM_REPORT_ENABLE_TOPIC[70];
|
|
||||||
|
|
||||||
#ifdef ENABLE_INTERNAL_LCD
|
#ifdef ENABLE_INTERNAL_LCD
|
||||||
// LCD
|
// LCD
|
||||||
|
@ -251,20 +249,18 @@ void loop()
|
||||||
*/
|
*/
|
||||||
void fram_retrieve_init()
|
void fram_retrieve_init()
|
||||||
{
|
{
|
||||||
#ifdef ENABLE_WEBUI
|
#ifdef ENABLE_WEBUI
|
||||||
ESPMega_FRAM.read(FRAM_ADDRESS_WEBUI_USERNAME, (uint8_t *)WEBUI_USERNAME, 32);
|
ESPMega_FRAM.read(FRAM_ADDRESS_WEBUI_USERNAME, (uint8_t *)WEBUI_USERNAME, 32);
|
||||||
ESPMega_FRAM.read(FRAM_ADDRESS_WEBUI_PASSWORD, (uint8_t *)WEBUI_PASSWORD, 32);
|
ESPMega_FRAM.read(FRAM_ADDRESS_WEBUI_PASSWORD, (uint8_t *)WEBUI_PASSWORD, 32);
|
||||||
if (strlen(WEBUI_USERNAME) == 0)
|
if(strlen(WEBUI_USERNAME)==0) {
|
||||||
{
|
strcpy(WEBUI_USERNAME,"admin");
|
||||||
strcpy(WEBUI_USERNAME, "admin");
|
|
||||||
ESPMega_FRAM.write(FRAM_ADDRESS_WEBUI_USERNAME, (uint8_t *)WEBUI_USERNAME, 32);
|
ESPMega_FRAM.write(FRAM_ADDRESS_WEBUI_USERNAME, (uint8_t *)WEBUI_USERNAME, 32);
|
||||||
}
|
}
|
||||||
if (strlen(WEBUI_PASSWORD) == 0)
|
if(strlen(WEBUI_PASSWORD)==0) {
|
||||||
{
|
strcpy(WEBUI_PASSWORD,"admin");
|
||||||
strcpy(WEBUI_PASSWORD, "admin");
|
|
||||||
ESPMega_FRAM.write(FRAM_ADDRESS_WEBUI_PASSWORD, (uint8_t *)WEBUI_PASSWORD, 32);
|
ESPMega_FRAM.write(FRAM_ADDRESS_WEBUI_PASSWORD, (uint8_t *)WEBUI_PASSWORD, 32);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
// FRAM Data Retrival
|
// FRAM Data Retrival
|
||||||
#ifdef ENABLE_CLIMATE_MODULE
|
#ifdef ENABLE_CLIMATE_MODULE
|
||||||
ac_mode = ESPMega_FRAM.read8(FRAM_ADDRESS_AC_MODE);
|
ac_mode = ESPMega_FRAM.read8(FRAM_ADDRESS_AC_MODE);
|
||||||
|
@ -324,8 +320,6 @@ void fram_retrieve_init()
|
||||||
strcat(PWM_SET_STATE_TOPIC, "/pwm/00/set/state");
|
strcat(PWM_SET_STATE_TOPIC, "/pwm/00/set/state");
|
||||||
memcpy(PWM_SET_VALUE_TOPIC, MQTT_BASE_TOPIC, 20);
|
memcpy(PWM_SET_VALUE_TOPIC, MQTT_BASE_TOPIC, 20);
|
||||||
strcat(PWM_SET_VALUE_TOPIC, "/pwm/00/set/value");
|
strcat(PWM_SET_VALUE_TOPIC, "/pwm/00/set/value");
|
||||||
memcpy(PWM_REPORT_ENABLE_TOPIC, MQTT_BASE_TOPIC, 20);
|
|
||||||
strcat(PWM_REPORT_ENABLE_TOPIC, "/pwm/report_enable");
|
|
||||||
#ifdef ENABLE_CLIMATE_MODULE
|
#ifdef ENABLE_CLIMATE_MODULE
|
||||||
memcpy(AC_SET_MODE_TOPIC, MQTT_BASE_TOPIC, 20);
|
memcpy(AC_SET_MODE_TOPIC, MQTT_BASE_TOPIC, 20);
|
||||||
strcat(AC_SET_MODE_TOPIC, "/ac/set/mode");
|
strcat(AC_SET_MODE_TOPIC, "/ac/set/mode");
|
||||||
|
@ -401,11 +395,6 @@ void ota_begin()
|
||||||
otabuffer+=ota_part2_1+"IP Address"+ota_part2_2+IP.toString()+ota_part2_3;
|
otabuffer+=ota_part2_1+"IP Address"+ota_part2_2+IP.toString()+ota_part2_3;
|
||||||
otabuffer+=ota_part2_1+"MAC Address"+ota_part2_2+ETH.macAddress()+ota_part2_3;
|
otabuffer+=ota_part2_1+"MAC Address"+ota_part2_2+ETH.macAddress()+ota_part2_3;
|
||||||
otabuffer+=ota_part2_1+"Device"+ota_part2_2+ESPMEGA_REV+ota_part2_3;
|
otabuffer+=ota_part2_1+"Device"+ota_part2_2+ESPMEGA_REV+ota_part2_3;
|
||||||
#ifdef FW_VERSION
|
|
||||||
otabuffer+=ota_part2_1+"Firmware"+ota_part2_2+FW_VERSION+ota_part2_3;
|
|
||||||
#else
|
|
||||||
otabuffer+=ota_part2_1+"Firmware"+ota_part2_2+"Out of Tree"+ota_part2_3;
|
|
||||||
#endif
|
|
||||||
otabuffer+=ota_part2_1+"BMS Server"+ota_part2_2+MQTT_SERVER.toString()+ota_part2_3;
|
otabuffer+=ota_part2_1+"BMS Server"+ota_part2_2+MQTT_SERVER.toString()+ota_part2_3;
|
||||||
otabuffer+=ota_part2_1+"BMS Endpoint"+ota_part2_2+String(MQTT_BASE_TOPIC)+ota_part2_3;
|
otabuffer+=ota_part2_1+"BMS Endpoint"+ota_part2_2+String(MQTT_BASE_TOPIC)+ota_part2_3;
|
||||||
otabuffer+=ota_part2_1+"Centrally Managed"+ota_part2_2;
|
otabuffer+=ota_part2_1+"Centrally Managed"+ota_part2_2;
|
||||||
|
@ -671,7 +660,6 @@ void mqtt_subscribe()
|
||||||
mqtt.subscribe(PWM_SET_STATE_TOPIC);
|
mqtt.subscribe(PWM_SET_STATE_TOPIC);
|
||||||
mqtt.subscribe(PWM_SET_VALUE_TOPIC);
|
mqtt.subscribe(PWM_SET_VALUE_TOPIC);
|
||||||
}
|
}
|
||||||
mqtt.subscribe(PWM_REPORT_ENABLE_TOPIC);
|
|
||||||
#ifdef ENABLE_CLIMATE_MODULE
|
#ifdef ENABLE_CLIMATE_MODULE
|
||||||
mqtt.subscribe(AC_SET_FAN_TOPIC);
|
mqtt.subscribe(AC_SET_FAN_TOPIC);
|
||||||
mqtt.subscribe(AC_SET_TEMPERATURE_TOPIC);
|
mqtt.subscribe(AC_SET_TEMPERATURE_TOPIC);
|
||||||
|
@ -704,7 +692,7 @@ void mqtt_subscribe()
|
||||||
* @param payload The payload of the received message.
|
* @param payload The payload of the received message.
|
||||||
* @param length The length of the payload.
|
* @param length The length of the payload.
|
||||||
*/
|
*/
|
||||||
IRAM_ATTR void mqtt_callback(char *topic, byte *payload, unsigned int length)
|
void mqtt_callback(char *topic, byte *payload, unsigned int length)
|
||||||
{
|
{
|
||||||
uint8_t topic_length = strlen(topic);
|
uint8_t topic_length = strlen(topic);
|
||||||
char topic_trim[50];
|
char topic_trim[50];
|
||||||
|
@ -720,10 +708,6 @@ IRAM_ATTR void mqtt_callback(char *topic, byte *payload, unsigned int length)
|
||||||
{
|
{
|
||||||
pwm_value_callback(topic_trim, topic_length, payload_nt, length);
|
pwm_value_callback(topic_trim, topic_length, payload_nt, length);
|
||||||
}
|
}
|
||||||
else if (!strcmp(topic_trim, "/pwm/report_enable"))
|
|
||||||
{
|
|
||||||
pwm_set_publish_callback(topic_trim, topic_length, payload_nt, length);
|
|
||||||
}
|
|
||||||
#ifdef ENABLE_ANALOG_MODULE
|
#ifdef ENABLE_ANALOG_MODULE
|
||||||
else if ((!strncmp(topic_trim, "/adc/", 5)) && !strncmp(topic_trim + 7, "/set/state", 10))
|
else if ((!strncmp(topic_trim, "/adc/", 5)) && !strncmp(topic_trim + 7, "/set/state", 10))
|
||||||
{
|
{
|
||||||
|
@ -741,14 +725,13 @@ IRAM_ATTR void mqtt_callback(char *topic, byte *payload, unsigned int length)
|
||||||
#ifdef ENABLE_IR_MODULE
|
#ifdef ENABLE_IR_MODULE
|
||||||
else if (!strcmp(topic_trim, "/ir/send"))
|
else if (!strcmp(topic_trim, "/ir/send"))
|
||||||
{
|
{
|
||||||
const char *delimiter = ",";
|
const char* delimiter = ",";
|
||||||
char *token = strtok(const_cast<char *>(payload_nt), delimiter);
|
char* token = strtok(const_cast<char*>(payload_nt), delimiter);
|
||||||
while (token != nullptr && ir_buffer_length < IR_RAW_BUFFER_LENGTH)
|
while (token != nullptr && ir_buffer_length < IR_RAW_BUFFER_LENGTH) {
|
||||||
{
|
|
||||||
ir_buffer[ir_buffer_length++] = atoi(token);
|
ir_buffer[ir_buffer_length++] = atoi(token);
|
||||||
token = strtok(nullptr, delimiter);
|
token = strtok(nullptr, delimiter);
|
||||||
}
|
}
|
||||||
IrSender.sendRaw(ir_buffer, ir_buffer_length, NEC_KHZ);
|
IrSender.sendRaw(ir_buffer,ir_buffer_length ,NEC_KHZ);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
else if (!strcmp(topic, STATE_REQUEST_TOPIC))
|
else if (!strcmp(topic, STATE_REQUEST_TOPIC))
|
||||||
|
@ -796,7 +779,7 @@ void thread_initialization()
|
||||||
* @param payload The message payload.
|
* @param payload The message payload.
|
||||||
* @param payload_length The length of the message payload.
|
* @param payload_length The length of the message payload.
|
||||||
*/
|
*/
|
||||||
IRAM_ATTR void pwm_state_callback(char *topic, uint8_t topic_length, char *payload, unsigned int payload_length)
|
void pwm_state_callback(char *topic, uint8_t topic_length, char *payload, unsigned int payload_length)
|
||||||
{
|
{
|
||||||
int a = topic[5] - '0';
|
int a = topic[5] - '0';
|
||||||
int b = topic[6] - '0';
|
int b = topic[6] - '0';
|
||||||
|
@ -822,7 +805,7 @@ IRAM_ATTR void pwm_state_callback(char *topic, uint8_t topic_length, char *paylo
|
||||||
* @param payload The message payload.
|
* @param payload The message payload.
|
||||||
* @param payload_length The length of the message payload.
|
* @param payload_length The length of the message payload.
|
||||||
*/
|
*/
|
||||||
IRAM_ATTR void pwm_value_callback(char *topic, uint8_t topic_length, char *payload, unsigned int payload_length)
|
void pwm_value_callback(char *topic, uint8_t topic_length, char *payload, unsigned int payload_length)
|
||||||
{
|
{
|
||||||
int a = topic[5] - '0';
|
int a = topic[5] - '0';
|
||||||
int b = topic[6] - '0';
|
int b = topic[6] - '0';
|
||||||
|
@ -881,7 +864,6 @@ void publish_pwm_states()
|
||||||
for (int i = 0; i < PWM_COUNT; i++)
|
for (int i = 0; i < PWM_COUNT; i++)
|
||||||
{
|
{
|
||||||
publish_pwm_state(i);
|
publish_pwm_state(i);
|
||||||
publish_pwm_value(i);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -892,11 +874,12 @@ void publish_pwm_states()
|
||||||
*/
|
*/
|
||||||
void publish_pwm_state(int id)
|
void publish_pwm_state(int id)
|
||||||
{
|
{
|
||||||
if (!pwm_report_enable)
|
|
||||||
return;
|
|
||||||
int state = pwm_states[id];
|
int state = pwm_states[id];
|
||||||
|
int value = pwm_values[id];
|
||||||
PWM_STATE_TOPIC[base_topic_length + 4] = ((id - id % 10) / 10) + '0';
|
PWM_STATE_TOPIC[base_topic_length + 4] = ((id - id % 10) / 10) + '0';
|
||||||
PWM_STATE_TOPIC[base_topic_length + 5] = (id % 10) + '0';
|
PWM_STATE_TOPIC[base_topic_length + 5] = (id % 10) + '0';
|
||||||
|
PWM_VALUE_TOPIC[base_topic_length + 4] = ((id - id % 10) / 10) + '0';
|
||||||
|
PWM_VALUE_TOPIC[base_topic_length + 5] = (id % 10) + '0';
|
||||||
if (state == 1)
|
if (state == 1)
|
||||||
{
|
{
|
||||||
mqtt.publish(PWM_STATE_TOPIC, "on");
|
mqtt.publish(PWM_STATE_TOPIC, "on");
|
||||||
|
@ -905,15 +888,6 @@ void publish_pwm_state(int id)
|
||||||
{
|
{
|
||||||
mqtt.publish(PWM_STATE_TOPIC, "off");
|
mqtt.publish(PWM_STATE_TOPIC, "off");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void publish_pwm_value(int id)
|
|
||||||
{
|
|
||||||
if (!pwm_report_enable)
|
|
||||||
return;
|
|
||||||
int value = pwm_values[id];
|
|
||||||
PWM_VALUE_TOPIC[base_topic_length + 4] = ((id - id % 10) / 10) + '0';
|
|
||||||
PWM_VALUE_TOPIC[base_topic_length + 5] = (id % 10) + '0';
|
|
||||||
char temp[6];
|
char temp[6];
|
||||||
itoa(value, temp, DEC);
|
itoa(value, temp, DEC);
|
||||||
mqtt.publish(PWM_VALUE_TOPIC, temp);
|
mqtt.publish(PWM_VALUE_TOPIC, temp);
|
||||||
|
@ -925,7 +899,7 @@ void publish_pwm_value(int id)
|
||||||
* @param id The ID of the PWM pin.
|
* @param id The ID of the PWM pin.
|
||||||
* @param state The new state of the PWM pin.
|
* @param state The new state of the PWM pin.
|
||||||
*/
|
*/
|
||||||
IRAM_ATTR void pwm_set_state(int id, int state)
|
void pwm_set_state(int id, int state)
|
||||||
{
|
{
|
||||||
if (state != pwm_states[id])
|
if (state != pwm_states[id])
|
||||||
{
|
{
|
||||||
|
@ -949,7 +923,7 @@ IRAM_ATTR void pwm_set_state(int id, int state)
|
||||||
* @param id The id of the PWM pin.
|
* @param id The id of the PWM pin.
|
||||||
* @param value The value to set the PWM pin to.
|
* @param value The value to set the PWM pin to.
|
||||||
*/
|
*/
|
||||||
IRAM_ATTR void pwm_set_value(int id, int value)
|
void pwm_set_value(int id, int value)
|
||||||
{
|
{
|
||||||
pwm_values[id] = value;
|
pwm_values[id] = value;
|
||||||
int pwm_state = pwm_states[id];
|
int pwm_state = pwm_states[id];
|
||||||
|
@ -960,7 +934,7 @@ IRAM_ATTR void pwm_set_value(int id, int value)
|
||||||
else if (lcd_current_page == 5 && id == lcd_pwmAdj_id)
|
else if (lcd_current_page == 5 && id == lcd_pwmAdj_id)
|
||||||
panel.writeNum("pwm_value.val", pwm_values[lcd_pwmAdj_id]);
|
panel.writeNum("pwm_value.val", pwm_values[lcd_pwmAdj_id]);
|
||||||
#endif
|
#endif
|
||||||
publish_pwm_value(id);
|
publish_pwm_state(id);
|
||||||
pwm_changed_user_callback(id);
|
pwm_changed_user_callback(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1076,11 +1050,6 @@ void publish_input_state(int id, int state)
|
||||||
mqtt.publish(INPUTS_TOPIC, state ? "1" : "0");
|
mqtt.publish(INPUTS_TOPIC, state ? "1" : "0");
|
||||||
}
|
}
|
||||||
|
|
||||||
void pwm_set_publish_callback(char *topic, uint8_t topic_length, char *payload, unsigned int payload_length)
|
|
||||||
{
|
|
||||||
pwm_report_enable = !strcmp(payload, "on");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Callback function to request the current state of the device.
|
* @brief Callback function to request the current state of the device.
|
||||||
*
|
*
|
||||||
|
@ -1091,7 +1060,6 @@ void state_request_callback()
|
||||||
{
|
{
|
||||||
publish_input_states();
|
publish_input_states();
|
||||||
publish_pwm_states();
|
publish_pwm_states();
|
||||||
pwm_report_enable = true;
|
|
||||||
#ifdef ENABLE_CLIMATE_MODULE
|
#ifdef ENABLE_CLIMATE_MODULE
|
||||||
publish_ac_state();
|
publish_ac_state();
|
||||||
publish_env_state();
|
publish_env_state();
|
||||||
|
@ -1268,8 +1236,6 @@ void ac_set_state(int mode, int temperature, int fan_speed)
|
||||||
*/
|
*/
|
||||||
void publish_env_state()
|
void publish_env_state()
|
||||||
{
|
{
|
||||||
if(!pwm_report_enable)
|
|
||||||
return;
|
|
||||||
int errorCode = env_sensor.read();
|
int errorCode = env_sensor.read();
|
||||||
yield();
|
yield();
|
||||||
switch (errorCode)
|
switch (errorCode)
|
||||||
|
@ -1871,7 +1837,6 @@ void set_mqtt_useauth(bool use_auth)
|
||||||
ESPMega_FRAM.write8(FRAM_ADDRESS_MQTT_USEAUTH, MQTT_USE_AUTH);
|
ESPMega_FRAM.write8(FRAM_ADDRESS_MQTT_USEAUTH, MQTT_USE_AUTH);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef ENABLE_WEBUI
|
|
||||||
void set_webui_username(String username)
|
void set_webui_username(String username)
|
||||||
{
|
{
|
||||||
username.toCharArray(WEBUI_USERNAME, 32);
|
username.toCharArray(WEBUI_USERNAME, 32);
|
||||||
|
@ -1883,7 +1848,6 @@ void set_webui_password(String password)
|
||||||
password.toCharArray(WEBUI_PASSWORD, 32);
|
password.toCharArray(WEBUI_PASSWORD, 32);
|
||||||
ESPMega_FRAM.write(FRAM_ADDRESS_WEBUI_PASSWORD, (uint8_t *)WEBUI_PASSWORD, 32);
|
ESPMega_FRAM.write(FRAM_ADDRESS_WEBUI_PASSWORD, (uint8_t *)WEBUI_PASSWORD, 32);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Resets the device to factory default settings.
|
* @brief Resets the device to factory default settings.
|
||||||
|
@ -1920,10 +1884,8 @@ void factory_reset()
|
||||||
set_ip("192.168.0.10");
|
set_ip("192.168.0.10");
|
||||||
set_gw("192.168.0.1");
|
set_gw("192.168.0.1");
|
||||||
set_netmask("255.255.255.0");
|
set_netmask("255.255.255.0");
|
||||||
#ifdef ENABLE_WEBUI
|
|
||||||
set_webui_username("admin");
|
set_webui_username("admin");
|
||||||
set_webui_password("admin");
|
set_webui_password("admin");
|
||||||
#endif
|
|
||||||
|
|
||||||
// Reboot
|
// Reboot
|
||||||
#ifdef ENABLE_INTERNAL_LCD
|
#ifdef ENABLE_INTERNAL_LCD
|
||||||
|
@ -2296,10 +2258,8 @@ bool dac_get_state(int id)
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void virtual_interrupt_preload()
|
void virtual_interrupt_preload() {
|
||||||
{
|
for (int i = 0; i < 16; i++) {
|
||||||
for (int i = 0; i < 16; i++)
|
|
||||||
{
|
|
||||||
virtual_interupt_state[i] = ESPMega_digitalRead(virtual_interrupt_pins[i]);
|
virtual_interupt_state[i] = ESPMega_digitalRead(virtual_interrupt_pins[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -43,7 +43,7 @@
|
||||||
#endif
|
#endif
|
||||||
#include "espmega_iot_timer.hpp"
|
#include "espmega_iot_timer.hpp"
|
||||||
|
|
||||||
IRAM_ATTR void mqtt_callback(char* topic, byte* payload, unsigned int length);
|
void mqtt_callback(char* topic, byte* payload, unsigned int length);
|
||||||
void virtual_interrupt_loop();
|
void virtual_interrupt_loop();
|
||||||
void virtual_interrupt_callback(int pin, int state);
|
void virtual_interrupt_callback(int pin, int state);
|
||||||
void virtual_interrupt_preload();
|
void virtual_interrupt_preload();
|
||||||
|
@ -51,8 +51,8 @@ void network_begin();
|
||||||
void mqtt_connect();
|
void mqtt_connect();
|
||||||
void mqtt_subscribe();
|
void mqtt_subscribe();
|
||||||
void thread_initialization();
|
void thread_initialization();
|
||||||
IRAM_ATTR void pwm_state_callback(char* topic, uint8_t topic_length, char* payload, unsigned int payload_length);
|
void pwm_state_callback(char* topic, uint8_t topic_length, char* payload, unsigned int payload_length);
|
||||||
IRAM_ATTR void pwm_value_callback(char* topic, uint8_t topic_length, char* payload, unsigned int payload_length);
|
void pwm_value_callback(char* topic, uint8_t topic_length, char* payload, unsigned int payload_length);
|
||||||
void state_request_callback();
|
void state_request_callback();
|
||||||
void io_begin();
|
void io_begin();
|
||||||
void ir_loop();
|
void ir_loop();
|
||||||
|
@ -61,9 +61,8 @@ void ota_begin();
|
||||||
|
|
||||||
void publish_pwm_states();
|
void publish_pwm_states();
|
||||||
void publish_pwm_state(int id);
|
void publish_pwm_state(int id);
|
||||||
void publish_pwm_value(int id);
|
void pwm_set_state(int id, int state);
|
||||||
IRAM_ATTR void pwm_set_state(int id, int state);
|
void pwm_set_value(int id, int value);
|
||||||
IRAM_ATTR void pwm_set_value(int id, int value);
|
|
||||||
void pwm_toggle(int id);
|
void pwm_toggle(int id);
|
||||||
void pwm_toggle(int id1, int id2);
|
void pwm_toggle(int id1, int id2);
|
||||||
void pwm_cycle_value(int id);
|
void pwm_cycle_value(int id);
|
||||||
|
@ -159,5 +158,3 @@ uint16_t adc_get_value(int id);
|
||||||
bool adc_get_state(int id);
|
bool adc_get_state(int id);
|
||||||
uint16_t dac_get_value(int id);
|
uint16_t dac_get_value(int id);
|
||||||
bool dac_get_state(int id);
|
bool dac_get_state(int id);
|
||||||
|
|
||||||
void pwm_set_publish_callback(char *topic, uint8_t topic_length, char *payload, unsigned int payload_length);
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
#include <espmega_iot_homeassistant.hpp>
|
||||||
|
void homeassistant_setup() {
|
||||||
|
|
||||||
|
}
|
||||||
|
void homeassistant_loop() {
|
||||||
|
|
||||||
|
}
|
||||||
|
void homeassistant_mqtt_callback(char* topic, uint8_t topic_length, char* payload, unsigned int payload_length) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
char* homeassistant_get_state(char* entity_id) {
|
||||||
|
|
||||||
|
}
|
||||||
|
void homeassistant_set_state(char* entity_id, char* state) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
char* homeassistant_get_attributes(char* entity_id, char* attribute_name) {
|
||||||
|
|
||||||
|
}
|
||||||
|
void homeassistant_set_attributes(char* entity_id, char* attribute_name, char* value) {
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,22 @@
|
||||||
|
#pragma once
|
||||||
|
#include <PubSubClient.h>
|
||||||
|
|
||||||
|
extern PubSubClient mqtt;
|
||||||
|
extern bool standalone;
|
||||||
|
extern char MQTT_BASE_TOPIC[];
|
||||||
|
|
||||||
|
void homeassistant_setup();
|
||||||
|
void homeassistant_loop();
|
||||||
|
|
||||||
|
void homeassistant_mqtt_callback(char* topic, uint8_t topic_length, char* payload, unsigned int payload_length);
|
||||||
|
|
||||||
|
char* homeassistant_get_state(char* entity_id);
|
||||||
|
void homeassistant_set_state(char* entity_id, char* state);
|
||||||
|
|
||||||
|
char* homeassistant_get_attributes(char* entity_id, char* attribute_name);
|
||||||
|
void homeassistant_set_attributes(char* entity_id, char* attribute_name, char* value);
|
||||||
|
|
||||||
|
struct homeassistant_entity {
|
||||||
|
char* entity_id;
|
||||||
|
char* mqtt_topic;
|
||||||
|
};
|
|
@ -16,16 +16,15 @@
|
||||||
#define VIRTUAL_INTERRUPT_PRELOAD // Preload Virtual Interrupts buffer
|
#define VIRTUAL_INTERRUPT_PRELOAD // Preload Virtual Interrupts buffer
|
||||||
|
|
||||||
// Enable Software Module(s)
|
// Enable Software Module(s)
|
||||||
// Deprecated. Use Build Flags instead.
|
#define ENABLE_INTERNAL_LCD
|
||||||
// #define ENABLE_INTERNAL_LCD
|
#define ENABLE_IR_MODULE
|
||||||
// #define ENABLE_IR_MODULE
|
#define ENABLE_CLIMATE_MODULE // Require IR Module
|
||||||
// #define ENABLE_CLIMATE_MODULE // Require IR Module
|
#define ENABLE_ANALOG_MODULE
|
||||||
// #define ENABLE_ANALOG_MODULE
|
#define ENABLE_WEBUI
|
||||||
// #define ENABLE_WEBUI
|
|
||||||
|
|
||||||
// IR Kit Configuration
|
// IR Kit Configuration
|
||||||
#define IR_RECIEVE_PIN 35
|
#define IR_RECIEVE_PIN 35
|
||||||
#define IR_SEND_PIN 5
|
#define IR_SEND_PIN 17
|
||||||
#define MARK_EXCESS_MICROS 20
|
#define MARK_EXCESS_MICROS 20
|
||||||
#define IR_RAW_BUFFER_LENGTH 750
|
#define IR_RAW_BUFFER_LENGTH 750
|
||||||
#define AC_MAX_TEMPERATURE 30
|
#define AC_MAX_TEMPERATURE 30
|
||||||
|
|
Loading…
Reference in New Issue