Compare commits

..

4 Commits

Author SHA1 Message Date
Siwat Sirichai 790f176d51 Merge branch 'main' into smart-meeting 2023-11-07 20:43:45 +07:00
Siwat Sirichai 132aa86d89 Merge branch 'main' into smart-meeting 2023-11-07 19:38:29 +07:00
Siwat Sirichai bbb6278c51 port bug 2023-10-26 23:32:46 +07:00
Siwat Sirichai ac4213de4d smart meeting proto 2023-10-26 22:50:27 +07:00
20 changed files with 411 additions and 1947 deletions

4
.gitignore vendored
View File

@ -4,7 +4,3 @@
.vscode/launch.json .vscode/launch.json
.vscode/ipch .vscode/ipch
.vs/ .vs/
.vscode/
.vscode/settings.json
firmware/
release/

60
.vscode/settings.json vendored
View File

@ -16,63 +16,5 @@
"*.html": "cpp", "*.html": "cpp",
"*.tcc": "cpp", "*.tcc": "cpp",
"regex": "cpp" "regex": "cpp"
}, }
"C_Cpp_Runner.msvcBatchPath": "",
"C_Cpp_Runner.cCompilerPath": "gcc",
"C_Cpp_Runner.cppCompilerPath": "g++",
"C_Cpp_Runner.debuggerPath": "gdb",
"C_Cpp_Runner.cStandard": "",
"C_Cpp_Runner.cppStandard": "",
"C_Cpp_Runner.useMsvc": false,
"C_Cpp_Runner.warnings": [
"-Wall",
"-Wextra",
"-Wpedantic",
"-Wshadow",
"-Wformat=2",
"-Wcast-align",
"-Wconversion",
"-Wsign-conversion",
"-Wnull-dereference"
],
"C_Cpp_Runner.msvcWarnings": [
"/W4",
"/permissive-",
"/w14242",
"/w14287",
"/w14296",
"/w14311",
"/w14826",
"/w44062",
"/w44242",
"/w14905",
"/w14906",
"/w14263",
"/w44265",
"/w14928"
],
"C_Cpp_Runner.enableWarnings": true,
"C_Cpp_Runner.warningsAsError": false,
"C_Cpp_Runner.compilerArgs": [],
"C_Cpp_Runner.linkerArgs": [],
"C_Cpp_Runner.includePaths": [],
"C_Cpp_Runner.includeSearch": [
"*",
"**/*"
],
"C_Cpp_Runner.excludeSearch": [
"**/build",
"**/build/**",
"**/.*",
"**/.*/**",
"**/.vscode",
"**/.vscode/**"
],
"C_Cpp_Runner.useAddressSanitizer": false,
"C_Cpp_Runner.useUndefinedSanitizer": false,
"C_Cpp_Runner.useLeakSanitizer": false,
"C_Cpp_Runner.showCompilationTime": false,
"C_Cpp_Runner.useLinkTimeOptimization": false,
"C_Cpp_Runner.msvcSecureNoWarnings": false,
"cmake.sourceDirectory": "D:/Git/iot-firmware/.pio/libdeps/full/Adafruit BusIO"
} }

20
Jenkinsfile vendored
View File

@ -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
}
}
}
}

View File

@ -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)

View File

@ -8,15 +8,10 @@
; 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
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
@ -27,145 +22,6 @@ lib_deps = siwats/ESPMegaPROR3@^1.3.0
seithan/Easy Nextion Library@^1.0.6 seithan/Easy Nextion Library@^1.0.6
robtillaart/FRAM_I2C@^0.6.1 robtillaart/FRAM_I2C@^0.6.1
esphome/ESPAsyncWebServer-esphome@^3.1.0 esphome/ESPAsyncWebServer-esphome@^3.1.0
bblanchon/ArduinoJson@^6.21.3
monitor_speed = 115200 monitor_speed = 115200
monitor_port = COM26
[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

View File

@ -1,35 +0,0 @@
# IoT Core OS V3
This is an OS for the ESPMega PRO R3 Programable Logic Controller
## **Compatibility**
1. **CPU**
- ESPMega PRO R3.0a/b
- ESPMega PRO R3.1a
- ESPMega PRO R3.2a/b/c
2. **CPU Add-ons**
- ESPMega PRO Internal Display Module
- ESPMega PRO External Touch Display Module
3. **Add-on Cards**
- ESPMega I/O Analog Expansion Card
- ESPMega I/O IR Expansion Kit
- ESPMega I/O Card Hub
- ESPMega I/O UART Multiplexer [WIP]
- ESPMega I/O Digital Expansion Card [WIP]
## Features
- Internal Touch Display support for diagnostics and configuration
- WebUI for Configuration and OTA Update
- Allowing for reading and writing to registers from MQTT
- Provides abstraction layer to the MQTT protocol and internal components
## User Code and 3rd Party Extension
This OS allows the user to write custom program for the device to run in the OS<br/>
### *usercode.hpp* and *user_code.cpp*
### I/O Abstraction Layer
### MQTT Abstraction Layer
### RTC and Clock Abstraction Layer
### Persistent Storage Abstraction Layer
### Climate Abstraction Layer
### Energy Monitoring Abstraction Layer
### Timer Abstraction Layer
### LCD Abstraction Layer

File diff suppressed because it is too large Load Diff

View File

@ -1,12 +1,3 @@
/**
* @brief Header file for the ESPMega IoT Core library.
*
* This library provides functions for controlling various IoT modules such as climate, IR, and input/output.
* It also includes functions for MQTT communication, LCD display, and OTA updates.
*
* @note This library requires the ESPMegaPRO library to be installed.
*
*/
#pragma once #pragma once
#include <ESPMegaPRO.h> #include <ESPMegaPRO.h>
@ -18,6 +9,7 @@
#endif #endif
#include <ETH.h> #include <ETH.h>
#include <PubSubClient.h> #include <PubSubClient.h>
#include <PubSubClientTools.h>
#include <Thread.h> #include <Thread.h>
#include <StaticThreadController.h> #include <StaticThreadController.h>
#ifdef ENABLE_IR_MODULE #ifdef ENABLE_IR_MODULE
@ -33,7 +25,7 @@
#include <WebServer.h> #include <WebServer.h>
#include <Update.h> #include <Update.h>
#endif #endif
#include "espmega_iot_lcd.hpp" #include "lcd.hpp"
#ifdef ENABLE_CLIMATE_MODULE #ifdef ENABLE_CLIMATE_MODULE
#include "ir_codes.hpp" #include "ir_codes.hpp"
@ -43,17 +35,15 @@
#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 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 network_begin(); 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(String topic, String message);
IRAM_ATTR void pwm_value_callback(char* topic, uint8_t topic_length, char* payload, unsigned int payload_length); void pwm_value_callback(String topic, String message);
void state_request_callback(); void state_request_callback(String topic, String message);
void io_begin(); void io_begin();
void ir_loop(); void ir_loop();
@ -61,9 +51,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);
@ -77,7 +66,7 @@ void publish_env_state();
uint8_t ac_get_temperature(); uint8_t ac_get_temperature();
uint8_t ac_get_mode(); uint8_t ac_get_mode();
uint8_t ac_get_fan_speed(); uint8_t ac_get_fan_speed();
void ac_state_callback(char* topic, uint8_t topic_length, char* payload, unsigned int payload_length); void ac_state_callback(String topic, String message);
void ac_set_state(int mode, int temperature, int fan_speed); void ac_set_state(int mode, int temperature, int fan_speed);
void publish_input_states(); void publish_input_states();
@ -106,8 +95,8 @@ void trigger13();
void trigger14(); void trigger14();
void trigger15(); void trigger15();
void fram_retrieve_init(); void eeprom_retrieve_init();
void fram_pwm_update(); void eeprom_pwm_update();
void lcd_ac_refresh_fan(); void lcd_ac_refresh_fan();
void lcd_ac_refresh_mode(); void lcd_ac_refresh_mode();
@ -117,47 +106,20 @@ void set_netmask(String address);
void set_dns(String address); void set_dns(String address);
void set_gw(String address); void set_gw(String address);
void set_mqtt_server(String address); void set_mqtt_server(String address);
void fram_ip_update(uint16_t rom_address, uint8_t byte1, uint8_t byte2, uint8_t byte3, uint8_t byte4); void eeprom_ip_update(uint16_t rom_address, uint8_t byte1, uint8_t byte2, uint8_t byte3, uint8_t byte4);
IPAddress fram_ip_retrieve(uint16_t rom_address); IPAddress eeprom_ip_retrieve(uint16_t rom_address);
void set_hostname(String hostname); void set_hostname(String hostname);
void fram_hostname_retrieve(); void eeprom_hostname_retrieve();
void set_basetopic(String topic); void set_basetopic(String topic);
void fram_basetopic_retrieve(); void eeprom_basetopic_retrieve();
void mqtt_port_set(uint16_t port); void mqtt_port_set(uint16_t port);
void fram_mqtt_port_retrieve(); void eeprom_mqtt_port_retrieve();
void fram_mqtt_username_retrieve(); void eeprom_mqtt_username_retrieve();
void fram_mqtt_password_retrieve(); void eeprom_mqtt_password_retrieve();
void set_mqtt_username(String username); void set_mqtt_username(String username);
void set_mqtt_password(String password); void set_mqtt_password(String password);
void fram_mqtt_useauth_retrieve(); void eeprom_mqtt_useauth_retrieve();
void set_mqtt_useauth(bool use_auth); void set_mqtt_useauth(bool use_auth);
void factory_reset(); void factory_reset();
void check_boot_reset(); void check_boot_reset();
void enable_adc(int id);
void disable_adc(int id);
void adc_update(int id);
void adc_update_force(int id);
void adc_update_all();
void adc_loop();
void publish_adc_value(int id);
void publish_adc_values();
uint16_t get_adc_value(int id);
void adc_set_state_callback(char *topic, uint8_t topic_length, char *payload, unsigned int payload_length);
void dac_set_value(int id, int value);
void dac_set_state(int id, bool state);
void dac_set_value_callback(char *topic, uint8_t topic_length, char *payload, unsigned int payload_length);
void dac_set_state_callback(char *topic, uint8_t topic_length, char *payload, unsigned int payload_length);
void publish_dac_value(int id);
void publish_dac_state(int id);
void publish_dac_values();
void publish_dac_states();
void publish_adc_state(int id);
void publish_adc_states();
uint16_t adc_get_value(int id);
bool adc_get_state(int id);
uint16_t dac_get_value(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);

View File

@ -1,14 +1,5 @@
#include "espmega_iot_emon.hpp" #include "espmega_iot_emon.hpp"
/**
* @brief Constructor for ESPMega_CT class.
*
* @param analog_pin The analog pin to read the current sensor from.
* @param adc_to_watts A function pointer to a function that converts ADC value to watts.
* @param fram_address The address of the FRAM to store energy data.
*/
ESPMega_CT::ESPMega_CT(uint8_t analog_pin, float (*adc_to_watts)(uint16_t adc_value), uint32_t fram_address) ESPMega_CT::ESPMega_CT(uint8_t analog_pin, float (*adc_to_watts)(uint16_t adc_value), uint32_t fram_address)
{ {
this->analog_pin = analog_pin; this->analog_pin = analog_pin;
@ -16,11 +7,6 @@ ESPMega_CT::ESPMega_CT(uint8_t analog_pin, float (*adc_to_watts)(uint16_t adc_va
this->adc_to_watts = adc_to_watts; this->adc_to_watts = adc_to_watts;
} }
/**
* @brief Initializes the ESPMega_CT object.
*
* Reads the energy data from FRAM, sets the last conversion timestamp to current time, and calculates the current power.
*/
void ESPMega_CT::begin() void ESPMega_CT::begin()
{ {
this->last_conversion_timestamp = millis(); this->last_conversion_timestamp = millis();
@ -28,11 +14,6 @@ void ESPMega_CT::begin()
this->power = adc_to_watts(ESPMega_analogRead(this->analog_pin)); this->power = adc_to_watts(ESPMega_analogRead(this->analog_pin));
} }
/**
* @brief The main loop function of the ESPMega_CT object.
*
* Calculates the energy consumed since the last loop iteration, updates the current power, and writes the energy data to FRAM.
*/
void ESPMega_CT::loop() void ESPMega_CT::loop()
{ {
this->energy += (millis() - this->last_conversion_timestamp) / 3600000 * this->power; this->energy += (millis() - this->last_conversion_timestamp) / 3600000 * this->power;
@ -41,41 +22,22 @@ void ESPMega_CT::loop()
ESPMega_FRAM.write(fram_address, (uint8_t *)&this->energy, 16); ESPMega_FRAM.write(fram_address, (uint8_t *)&this->energy, 16);
} }
/**
* @brief Resets the energy data stored in FRAM and the energy variable.
*/
void ESPMega_CT::reset_energy() void ESPMega_CT::reset_energy()
{ {
this->energy = 0; this->energy = 0;
ESPMega_FRAM.write16(fram_address, 0); ESPMega_FRAM.write16(fram_address, 0);
} }
/**
* @brief Returns the energy consumed since the object was initialized.
*
* @return The energy consumed since the object was initialized.
*/
long double ESPMega_CT::get_energy() long double ESPMega_CT::get_energy()
{ {
return this->energy; return this->energy;
} }
/**
* @brief Returns the current power consumption.
*
* @return The current power consumption.
*/
float ESPMega_CT::get_power() float ESPMega_CT::get_power()
{ {
return this->power; return this->power;
} }
/**
* @brief A built-in function to convert ADC value to watts.
*
* @param adc_value The ADC value to convert to watts.
* @return The power in watts.
*/
float ESPMega_CT::adc_to_watts_builtin(uint16_t adc_value) float ESPMega_CT::adc_to_watts_builtin(uint16_t adc_value)
{ {
const float RATIO = 0.1; const float RATIO = 0.1;

View File

@ -1,54 +1,13 @@
/**
* @brief Class for measuring current and power consumption using a current transformer and an ADC.
*
*/
#pragma once #pragma once
#include <ESPMegaPRO.h> #include <ESPMegaPRO.h>
class ESPMega_CT { class ESPMega_CT {
public: public:
/**
* @brief Construct a new ESPMega_CT object
*
* @param analog_pin The analog pin to which the current transformer is connected.
* @param adc_to_watts A function pointer to a function that converts ADC values to watts.
* @param fram_address The address in FRAM where the energy consumption data is stored.
*/
ESPMega_CT(uint8_t analog_pin,float(*adc_to_watts)(uint16_t adc_value), uint32_t fram_address); ESPMega_CT(uint8_t analog_pin,float(*adc_to_watts)(uint16_t adc_value), uint32_t fram_address);
/**
* @brief Initializes the object.
*
*/
void begin(); void begin();
/**
* @brief Updates the power and energy consumption values.
*
*/
void loop(); void loop();
/**
* @brief Returns the current power consumption in watts.
*
* @return float The current power consumption in watts.
*/
float get_power(); float get_power();
/**
* @brief Returns the total energy consumption in watt-hours.
*
* @return long double The total energy consumption in watt-hours.
*/
long double get_energy(); long double get_energy();
/**
* @brief Resets the energy consumption value to zero.
*
*/
void reset_energy(); void reset_energy();
private: private:
uint8_t analog_pin; uint8_t analog_pin;
uint32_t fram_address; uint32_t fram_address;

View File

@ -1,28 +0,0 @@
#include "espmega_iot_homeassistant.hpp"
void publishDiscoveryPayload(const char* component, const char* config) {
String topic = "homeassistant/" + String(component) + "/config";
mqttClient.publish(topic.c_str(), config);
}
void publishDiscoveryPayload(const char* component, const char* name, const char* deviceClass, const char* unitOfMeasurement, const char* stateTopic, const char* commandTopic, const char* availabilityTopic, const char* payloadAvailable, const char* payloadNotAvailable, const char* uniqueId) {
String config = "{";
config += "\"name\":\"" + String(name) + "\",";
config += "\"device_class\":\"" + String(deviceClass) + "\",";
config += "\"unit_of_measurement\":\"" + String(unitOfMeasurement) + "\",";
config += "\"state_topic\":\"" + String(stateTopic) + "\",";
config += "\"command_topic\":\"" + String(commandTopic) + "\",";
config += "\"availability_topic\":\"" + String(availabilityTopic) + "\",";
config += "\"payload_available\":\"" + String(payloadAvailable) + "\",";
config += "\"payload_not_available\":\"" + String(payloadNotAvailable) + "\",";
config += "\"unique_id\":\"" + String(uniqueId) + "\"";
config += "}";
String topic = "homeassistant/" + String(component) + "/config";
mqttClient.publish(topic.c_str(), config.c_str());
}
// Example usage:
publishDiscoveryPayload("sensor", "temperature", "temperature", "°C", "home/temperature", "home/temperature/set", "home/availability", "online", "offline", "temperature_sensor");
publishDiscoveryPayload("binary_sensor", "motion", "motion", "", "home/motion", "home/motion/set", "home/availability", "online", "offline", "motion_sensor");
publishDiscoveryPayload("climate", "thermostat", "temperature", "°C", "home/thermostat", "home/thermostat/set", "home/availability", "online", "offline", "thermostat");
publishDiscoveryPayload("switch", "light", "switch", "", "home/light", "home/light/set", "home/availability", "online", "offline", "light_switch");

View File

@ -1,2 +0,0 @@
#pragma once
#include <ESPMegaPRO.h>

View File

@ -1,110 +0,0 @@
#include <user_code.hpp>
#include <espmega_iot_lcd.hpp>
/**
* @brief Sends stop bit to LCD.
*
* This function sends a stop bit to the LCD. It is only enabled if the ENABLE_INTERNAL_LCD macro is defined.
*/
void lcd_send_stop_bit()
{
#ifdef ENABLE_INTERNAL_LCD
Serial.write(0xFF);
Serial.write(0xFF);
Serial.write(0xFF);
#endif
}
/**
* Sends a command to the LCD display.
*
* @param command The command to send to the LCD display.
*/
void lcd_send_command(String command)
{
#ifdef ENABLE_INTERNAL_LCD
lcd_send_stop_bit();
Serial.print(command);
lcd_send_stop_bit();
#endif
}
/**
* @brief Resets the LCD display.
*
* If ENABLE_INTERNAL_LCD is defined, sends a reset command to the LCD display.
*
*/
void lcd_reset()
{
#ifdef ENABLE_INTERNAL_LCD
lcd_send_stop_bit();
lcd_send_command("rest");
lcd_send_stop_bit();
#endif
}
/**
* Initializes the LCD display.
*/
void lcd_init()
{
#ifdef ENABLE_INTERNAL_LCD
lcd_reset();
delay(750);
#endif
}
/**
* @brief Starts the upload process to the LCD.
*
* @param size The size of the data to be uploaded.
* @return true if the upload process started successfully, false otherwise.
*/
bool lcd_upload_start(size_t size)
{
Serial.begin(115200);
lcd_send_stop_bit();
Serial.print("rest");
lcd_send_stop_bit();
Serial.print("connect");
lcd_send_stop_bit();
delay(1000);
Serial.print("whmi-wri 1024,115200,res0");
lcd_send_stop_bit();
lcd_wait_ack();
}
/**
* Writes data to the LCD upload buffer.
*
* @param data Pointer to the data to be written.
* @param size Size of the data to be written.
* @return True if the write was successful, false otherwise.
*/
bool lcd_upload_write(uint8_t *data, size_t size)
{
for (int i = 0; i < size; i++)
{
Serial.write(data[i]);
}
}
/**
* Waits for an acknowledgement signal from the LCD.
* @return true if acknowledgement signal is received, false otherwise.
*/
bool lcd_wait_ack()
{
bool data_ok = false;
for (int i; i < 50; i++)
{
if (Serial.read() == 0x05)
{
data_ok = true;
break;
}
delay(100);
}
return data_ok;
}

View File

@ -1,14 +0,0 @@
#pragma once
#include <ESPMegaPRO.h>
void lcd_send_stop_bit();
void lcd_send_command(String command);
String lcd_wait_response();
void lcd_reset();
void lcd_init();
bool lcd_upload_start(size_t size);
bool lcd_upload_write(uint8_t* data, size_t size);
bool lcd_wait_ack();

View File

@ -1,9 +1,5 @@
#include "espmega_iot_timer.hpp" #include "espmega_iot_timer.hpp"
/**
* @brief Loop function that checks if the timer should run and calls the timer callback function.
*
*/
void ESPMega_Timer::loop() { void ESPMega_Timer::loop() {
rtctime_t curtime = ESPMega_getTime(); rtctime_t curtime = ESPMega_getTime();
if(today!=curtime.day) { if(today!=curtime.day) {
@ -18,14 +14,6 @@ void ESPMega_Timer::loop() {
} }
} }
/**
* @brief Constructor for ESPMega_Timer class.
*
* @param hour The hour at which the timer should run.
* @param minute The minute at which the timer should run.
* @param timer_callback The function to be called when the timer runs.
* @param fram_address The address in FRAM where the timer state is stored.
*/
ESPMega_Timer::ESPMega_Timer(uint8_t hour,uint8_t minute,void(*timer_callback)(), uint32_t fram_address) { ESPMega_Timer::ESPMega_Timer(uint8_t hour,uint8_t minute,void(*timer_callback)(), uint32_t fram_address) {
this->hr = hour; this->hr = hour;
this->min = minute; this->min = minute;
@ -33,10 +21,6 @@ ESPMega_Timer::ESPMega_Timer(uint8_t hour,uint8_t minute,void(*timer_callback)()
this->fram_address = fram_address; this->fram_address = fram_address;
} }
/**
* @brief Begins the timer and sets the initial timer state.
*
*/
void ESPMega_Timer::begin() { void ESPMega_Timer::begin() {
rtctime_t curtime = ESPMega_getTime(); rtctime_t curtime = ESPMega_getTime();
this-> today = curtime.day; this-> today = curtime.day;
@ -44,12 +28,6 @@ void ESPMega_Timer::begin() {
loop(); loop();
} }
/**
* @brief Sets the hour and minute at which the timer should run.
*
* @param hour The hour at which the timer should run.
* @param minute The minute at which the timer should run.
*/
void ESPMega_Timer::set(uint8_t hour,uint8_t minute) { void ESPMega_Timer::set(uint8_t hour,uint8_t minute) {
rtctime_t curtime = ESPMega_getTime(); rtctime_t curtime = ESPMega_getTime();
if ((hr < curtime.hours || (hr == curtime.hours && min <= curtime.minutes))) { if ((hr < curtime.hours || (hr == curtime.hours && min <= curtime.minutes))) {

View File

@ -1,43 +1,12 @@
#pragma once #pragma once
#include <ESPMegaPRO.h> #include <ESPMegaPRO.h>
/**
* @brief Class representing a timer for ESPMega board.
*
*/
class ESPMega_Timer { class ESPMega_Timer {
public: public:
/**
* @brief Loop function to be called in the main loop.
*
*/
void loop(); void loop();
ESPMega_Timer(uint8_t hour,uint8_t minute,void(*timer_callback)(), uint32_t fram_address);
/** void set(uint8_t hour,uint8_t minute);
* @brief Constructor for ESPMega_Timer class.
*
* @param hour The hour at which the timer should trigger.
* @param minute The minute at which the timer should trigger.
* @param timer_callback The function to be called when the timer triggers.
* @param fram_address The address of the FRAM memory to store the timer state.
*/
ESPMega_Timer(uint8_t hour, uint8_t minute, void(*timer_callback)(), uint32_t fram_address);
/**
* @brief Set the hour and minute at which the timer should trigger.
*
* @param hour The hour at which the timer should trigger.
* @param minute The minute at which the timer should trigger.
*/
void set(uint8_t hour, uint8_t minute);
/**
* @brief Begin the timer.
*
*/
void begin(); void begin();
private: private:
uint8_t today; uint8_t today;
uint8_t timer_ran_today; uint8_t timer_ran_today;

37
src/lcd.cpp Normal file
View File

@ -0,0 +1,37 @@
#include <user_code.hpp>
#include <lcd.hpp>
void lcd_send_stop_bit()
{
#ifdef ENABLE_INTERNAL_LCD
Serial.write(0xFF);
Serial.write(0xFF);
Serial.write(0xFF);
#endif
}
void lcd_send_command(String command)
{
#ifdef ENABLE_INTERNAL_LCD
lcd_send_stop_bit();
Serial.print(command);
lcd_send_stop_bit();
#endif
}
void lcd_reset()
{
#ifdef ENABLE_INTERNAL_LCD
lcd_send_stop_bit();
lcd_send_command("rest");
lcd_send_stop_bit();
#endif
}
void lcd_init()
{
#ifdef ENABLE_INTERNAL_LCD
lcd_reset();
delay(750);
#endif
}

11
src/lcd.hpp Normal file
View File

@ -0,0 +1,11 @@
#ifndef EMG_LCD_ENABLED
#include <Arduino.h>
#define EMG_LCD_ENABLED
void lcd_send_stop_bit();
void lcd_send_command(String command);
String lcd_wait_response();
void lcd_reset();
void lcd_init();
#endif

View File

@ -1,20 +1,85 @@
#include <user_code.hpp> #include <user_code.hpp>
//Timer Components char MEETING_STATE_REPORT_TOPIC[75];
ESPMega_Timer timer1(0, 50, timer1_callback, 15001); char MEETING_STATE_REQUEST_TOPIC[75];
char MEETING_ROOM_NAME[50] = "Meeting Room 04";
StaticJsonDocument<2048> meeting_info;
#define TOTAL_SLOT 22 // max init cycle 17
uint8_t selected_slot = 1;
uint8_t cycle_slot_start = 1;
uint8_t slot_hours[TOTAL_SLOT + 1] = {8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15, 16, 16, 17, 17, 18, 18, 19};
uint8_t slot_minutes[TOTAL_SLOT + 1] = {0, 30, 0, 30, 0, 30, 0, 30, 0, 30, 0, 30, 0, 30, 0, 30, 0, 30, 0, 30, 0, 30, 0};
// Display Componets // Display Componets
#define elcd ESPMega_EXTLCD
// Link with Dual state button object with id 2 on page 1 named bt0 // Link with Dual state button object with id 2 on page 1 named bt0
NexDSButton bt0 = NexDSButton(1, 2, "bt0"); NexPicture lt_bt = NexPicture(1, 1, "lt_bt");
NexPicture av_bt = NexPicture(1, 3, "av_bt");
NexButton left_bt = NexButton(1, 5, "left_bt");
NexButton right_bt = NexButton(1, 6, "right_bt");
NexPicture slot1 = NexPicture(1, 7, "slot1");
NexPicture slot2 = NexPicture(1, 8, "slot2");
NexPicture slot3 = NexPicture(1, 9, "slot3");
NexPicture slot4 = NexPicture(1, 10, "slot4");
NexPicture slot5 = NexPicture(1, 11, "slot5");
// Lights on 0,1,2,3,4,5
// A/V on 6
// List of Component ID Message to listen to // List of Component ID Message to listen to
NexTouch *nex_listen_list[] = NexTouch *nex_listen_list[] =
{ {
&bt0, &lt_bt,
&av_bt,
&slot1,
&slot2,
&slot3,
&slot4,
&slot5,
&left_bt,
&right_bt,
NULL}; NULL};
void bt0PopCallback(void *ptr) bool light_group_state()
{ {
pwm_toggle(2); for (int i = 0; i <= 5; i++)
{
if (pwm_get_state(i))
return true;
}
return false;
}
void lt_bt_cb(void *ptr)
{
Serial.println("ltcb");
bool state = !light_group_state();
for (int i = 0; i++; i <= 5)
pwm_set_state(i, state);
}
void av_bt_cb(void *ptr)
{
Serial.println("avcb");
pwm_toggle(3);
}
void left_bt_cb(void *ptr)
{
Serial.println("leftcb");
if(cycle_slot_start>0){
cycle_slot_start--;
write_time_slot();
}
}
void right_bt_cb(void *ptr)
{
Serial.println("rightcb");
if(cycle_slot_start<TOTAL_SLOT-5){
cycle_slot_start++;
write_time_slot();
}
} }
/* /*
@ -24,6 +89,10 @@ Peripheral Initialization Routine
void user_pre_init() void user_pre_init()
{ {
nexInit(); nexInit();
memcpy(MEETING_STATE_REPORT_TOPIC, MQTT_BASE_TOPIC, 20);
strcat(MEETING_STATE_REPORT_TOPIC, "/meeting/report");
memcpy(MEETING_STATE_REQUEST_TOPIC, MQTT_BASE_TOPIC, 20);
strcat(MEETING_STATE_REQUEST_TOPIC, "/meeting/request");
} }
/* /*
@ -31,12 +100,13 @@ This code will run after every component is initialized
*/ */
void user_init() void user_init()
{ {
timer1.begin(); send_stop_bit();
ESPMega_EXTLCD.print("page home"); ESPMega_EXTLCD.print("page dashboard");
ESPMega_EXTLCD.write(0xFF); send_stop_bit();
ESPMega_EXTLCD.write(0xFF); left_bt.attachPop(left_bt_cb, &left_bt);
ESPMega_EXTLCD.write(0xFF); right_bt.attachPop(right_bt_cb, &right_bt);
bt0.attachPop(bt0PopCallback, &bt0); lt_bt.attachPop(lt_bt_cb, &lt_bt);
av_bt.attachPop(av_bt_cb, &av_bt);
} }
/* /*
@ -56,10 +126,31 @@ void virtual_interrupt_user_callback(int pin, int state)
void pwm_changed_user_callback(int pin) void pwm_changed_user_callback(int pin)
{ {
if (pin == 2) if (pin >= 0 && pin <= 5)
{ {
// inform the lcd when pwm 2 changed if (light_group_state())
bt0.setValue(pwm_get_state(2)); {
elcd.write("lt_bt.pic=6");
send_stop_bit();
}
else
{
elcd.write("lt_bt.pic=5");
send_stop_bit();
}
}
else if (pin == 6)
{
if (pwm_get_state(6))
{
elcd.write("av_bt.pic=8");
send_stop_bit();
}
else
{
elcd.write("av_bt.pic=7");
send_stop_bit();
}
} }
} }
@ -68,32 +159,51 @@ This code will run every 15 seconds
*/ */
void timer_tick_callback() void timer_tick_callback()
{ {
if (standalone)
{
timer1.loop();
}
} }
void timer1_callback() void ac_changed_user_callback(int mode, int temperature, int fan_speed)
{ {
for (int i = 0; i < 16; i++) }
void meeting_state_callback(String topic, String payload)
{
DeserializationError error = deserializeJson(meeting_info, payload);
}
void mqtt_connected_user_callback()
{
mqtt.subscribe(MEETING_STATE_REPORT_TOPIC, meeting_state_callback);
mqtt.publish(MEETING_STATE_REQUEST_TOPIC, "request");
}
void user_state_request_callback()
{
}
void write_time_slot()
{
for (int i = 1; i <= 5; i++)
{ {
pwm_set_state(i, 1); elcd.printf("slot%d_time.txt=%02d:%02d\n%02d:%02d", i, slot_hours[cycle_slot_start + i - 1],
slot_minutes[cycle_slot_start + i - 1], slot_hours[cycle_slot_start + i],
slot_minutes[cycle_slot_start + i]);
} }
} }
void ac_changed_user_callback(int mode, int temperature, int fan_speed) { void send_stop_bit()
{
ESPMega_EXTLCD.write(0xFF);
ESPMega_EXTLCD.write(0xFF);
ESPMega_EXTLCD.write(0xFF);
} }
void mqtt_connected_user_callback() { uint8_t get_current_time_slot()
{
} rtctime_t curtime = ESPMega_getTime();
for(uint8_t i=0;i<=TOTAL_SLOT;i++) {
void user_state_request_callback() { if(slot_hours[i]>curtime.hours || (slot_hours[i]==curtime.hours && slot_minutes[i]>curtime.hours)) {
return i;
} }
}
void user_mqtt_callback(char* topic, uint8_t topic_length, char* payload, unsigned int payload_length) { return 255;
} }

View File

@ -3,34 +3,23 @@
#include <Nextion.h> #include <Nextion.h>
#include <PubSubClient.h> #include <PubSubClient.h>
#include <PubSubClientTools.h> #include <PubSubClientTools.h>
#include <ArduinoJson.h>
#include "espmega_iot_timer.hpp" #include "espmega_iot_timer.hpp"
#include "espmega_iot_external_lcd.hpp" #include "espmega_iot_external_lcd.hpp"
// Bus Overclocking Configuration
// Do not enable if you are using external I/O cards as it will cause signal integrity issues.
// Choose only one mode
//#define OVERCLOCK_FM
//#define OVERCLOCK_FM2
// I/O Configuration
#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_WEBUI
// #define ENABLE_ANALOG_MODULE
// #define ENABLE_WEBUI
// IR Kit Configuration // Infrared Transciever
#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 RAW_BUFFER_LENGTH 750
#define AC_MAX_TEMPERATURE 30 #define AC_MAX_TEMPERATURE 30
#define AC_MIN_TEMPERATURE 15 #define AC_MIN_TEMPERATURE 15
#define DHT22_PIN 32
// External LCD Configuration // External LCD Configuration
#define ENABLE_EXTERNAL_LCD #define ENABLE_EXTERNAL_LCD
@ -41,24 +30,27 @@
#define ESPMega_EXTLCD Serial2 #define ESPMega_EXTLCD Serial2
#endif #endif
// Analog Module Configuration
#define ANALOG_REPORTING_INTERVAL 500
// User Defined Functions // User Defined Functions
void timer1_callback();
void bt0PopCallback(void *ptr);
// User Defined IoT Core Callback Functions (Required)
void user_mqtt_callback(char* topic, uint8_t topic_length, char* payload, unsigned int payload_length);
void user_state_request_callback();
void mqtt_connected_user_callback();
void user_pre_init(); void user_pre_init();
void user_init(); void user_init();
void user_loop(); void user_loop();
void virtual_interrupt_user_callback(int pin, int state);
void pwm_changed_user_callback(int pin); void pwm_changed_user_callback(int pin);
void ac_changed_user_callback(int mode, int temperature, int fan_speed); void ac_changed_user_callback(int mode, int temperature, int fan_speed);
void timer_tick_callback(); void timer_tick_callback();
void virtual_interrupt_user_callback(int pin, int state); void timer1_callback();
void mqtt_connected_user_callback();
void bt0PopCallback(void *ptr);
void user_state_request_callback();
void meeting_state_callback(String topic, String payload);
void send_stop_bit();
void write_time_slot();
void av_bt_cb(void *ptr);
void lt_bt_cb(void *ptr);
void left_bt_cb(void *ptr);
void right_bt_cb(void *ptr);
extern char MQTT_BASE_TOPIC[];
// ESPMega IoT Core Build-in Functions // ESPMega IoT Core Build-in Functions
extern void pwm_set_state(int id, int state); extern void pwm_set_state(int id, int state);
@ -70,26 +62,10 @@ extern bool pwm_get_state(int id);
extern uint16_t pwm_get_value(int id); extern uint16_t pwm_get_value(int id);
extern boolean pwm_group_state(int id1, int id2); extern boolean pwm_group_state(int id1, int id2);
extern bool input_get_state(int id); extern bool input_get_state(int id);
extern bool standalone;
extern PubSubClient mqtt;
// IR Kit Build-in Functions
#ifdef ENABLE_IR_MODULE
extern void ac_set_state(int mode, int temperature, int fan_speed); extern void ac_set_state(int mode, int temperature, int fan_speed);
extern uint8_t ac_get_temperature(); extern uint8_t ac_get_temperature();
extern uint8_t ac_get_mode(); extern uint8_t ac_get_mode();
extern uint8_t ac_get_fan_speed(); extern uint8_t ac_get_fan_speed();
#endif extern bool standalone;
extern PubSubClient mqtt_client;
//Analog Expansion Card Build-in Functions extern PubSubClientTools mqtt;
#ifdef ENABLE_ANALOG_MODULE
extern void dac_set_value(int id, int value);
extern void dac_set_state(int id, bool state);
extern void enable_adc(int id);
extern void disable_adc(int id);
extern void enable_dac(int id);
extern uint16_t adc_get_value(int id);
extern bool adc_get_state(int id);
extern uint16_t dac_get_value(int id);
extern bool dac_get_state(int id);
#endif