mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-07 00:09:51 +03:00
Add support for wemos c3 mini
This commit is contained in:
@@ -238,7 +238,8 @@ export const BOARD_PROFILES: BoardProfiles = {
|
|||||||
'MH-ET': 'MH-ET Live D1 Mini',
|
'MH-ET': 'MH-ET Live D1 Mini',
|
||||||
LOLIN: 'Lolin D32',
|
LOLIN: 'Lolin D32',
|
||||||
OLIMEX: 'Olimex ESP32-EVB',
|
OLIMEX: 'Olimex ESP32-EVB',
|
||||||
OLIMEXPOE: 'Olimex ESP32-POE'
|
OLIMEXPOE: 'Olimex ESP32-POE',
|
||||||
|
C3MINI: 'Lolin C3 mini'
|
||||||
};
|
};
|
||||||
|
|
||||||
export interface BoardProfileName {
|
export interface BoardProfileName {
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ export const GPIO_VALIDATOR = {
|
|||||||
if (
|
if (
|
||||||
value &&
|
value &&
|
||||||
(value === 1 ||
|
(value === 1 ||
|
||||||
(value >= 6 && value <= 12) ||
|
(value >= 10 && value <= 12) ||
|
||||||
(value >= 14 && value <= 15) ||
|
(value >= 14 && value <= 15) ||
|
||||||
value === 20 ||
|
value === 20 ||
|
||||||
value === 24 ||
|
value === 24 ||
|
||||||
|
|||||||
@@ -846,7 +846,7 @@ void AsyncWebSocketClient::binary(AsyncWebSocketMessageBuffer * buffer)
|
|||||||
|
|
||||||
IPAddress AsyncWebSocketClient::remoteIP() {
|
IPAddress AsyncWebSocketClient::remoteIP() {
|
||||||
if(!_client) {
|
if(!_client) {
|
||||||
return IPAddress(0U);
|
return IPAddress((uint32_t)0);
|
||||||
}
|
}
|
||||||
return _client->remoteIP();
|
return _client->remoteIP();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,6 +49,9 @@ void APSettingsService::startAP() {
|
|||||||
WiFi.softAPConfig(_state.localIP, _state.gatewayIP, _state.subnetMask);
|
WiFi.softAPConfig(_state.localIP, _state.gatewayIP, _state.subnetMask);
|
||||||
esp_wifi_set_bandwidth((wifi_interface_t)ESP_IF_WIFI_AP, WIFI_BW_HT20);
|
esp_wifi_set_bandwidth((wifi_interface_t)ESP_IF_WIFI_AP, WIFI_BW_HT20);
|
||||||
WiFi.softAP(_state.ssid.c_str(), _state.password.c_str(), _state.channel, _state.ssidHidden, _state.maxClients);
|
WiFi.softAP(_state.ssid.c_str(), _state.password.c_str(), _state.channel, _state.ssidHidden, _state.maxClients);
|
||||||
|
#ifdef ARDUINO_LOLIN_C3_MINI
|
||||||
|
WiFi.setTxPower(WIFI_POWER_8_5dBm); //https://www.wemos.cc/en/latest/c3/c3_mini.html#about-wifi
|
||||||
|
#endif
|
||||||
if (!_dnsServer) {
|
if (!_dnsServer) {
|
||||||
IPAddress apIp = WiFi.softAPIP();
|
IPAddress apIp = WiFi.softAPIP();
|
||||||
emsesp::EMSESP::logger().info(F("Starting Access Point with captive portal on %s"), apIp.toString().c_str());
|
emsesp::EMSESP::logger().info(F("Starting Access Point with captive portal on %s"), apIp.toString().c_str());
|
||||||
|
|||||||
@@ -75,6 +75,9 @@ void NetworkSettingsService::manageSTA() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
WiFi.begin(_state.ssid.c_str(), _state.password.c_str()); // attempt to connect to the network
|
WiFi.begin(_state.ssid.c_str(), _state.password.c_str()); // attempt to connect to the network
|
||||||
|
#ifdef ARDUINO_LOLIN_C3_MINI
|
||||||
|
WiFi.setTxPower(WIFI_POWER_8_5dBm); //https://www.wemos.cc/en/latest/c3/c3_mini.html#about-wifi
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1152,6 +1152,17 @@ rest_server.post(EMSESP_BOARDPROFILE_ENDPOINT, (req, res) => {
|
|||||||
data.eth_power = 12
|
data.eth_power = 12
|
||||||
data.eth_phy_addr = 0
|
data.eth_phy_addr = 0
|
||||||
data.eth_clock_mode = 3
|
data.eth_clock_mode = 3
|
||||||
|
} else if (board_profile == 'C3MINI') {
|
||||||
|
// Lolin C3 mini
|
||||||
|
data.led_gpio = 7
|
||||||
|
data.dallas_gpio = 2
|
||||||
|
data.rx_gpio = 4
|
||||||
|
data.tx_gpio = 5
|
||||||
|
data.pbutton_gpio = 9
|
||||||
|
data.phy_type = 0
|
||||||
|
data.eth_power = 0
|
||||||
|
data.eth_phy_addr = 0
|
||||||
|
data.eth_clock_mode = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('boardProfile POST. Sending back, profile: ' + board_profile + ', ' + 'data: ' + JSON.stringify(data))
|
console.log('boardProfile POST. Sending back, profile: ' + board_profile + ', ' + 'data: ' + JSON.stringify(data))
|
||||||
|
|||||||
@@ -81,3 +81,14 @@ board_upload.flash_size = 16MB
|
|||||||
board_build.partitions = esp32_partition_16M.csv
|
board_build.partitions = esp32_partition_16M.csv
|
||||||
build_flags = ${common.build_flags}
|
build_flags = ${common.build_flags}
|
||||||
build_unflags = ${common.unbuild_flags}
|
build_unflags = ${common.unbuild_flags}
|
||||||
|
|
||||||
|
[env:lolin_c3_mini]
|
||||||
|
extra_scripts =
|
||||||
|
pre:scripts/build_interface.py
|
||||||
|
scripts/rename_fw.py
|
||||||
|
board = lolin_c3_mini
|
||||||
|
platform = espressif32
|
||||||
|
board_upload.flash_size = 4MB
|
||||||
|
board_build.partitions = esp32_partition_4M.csv
|
||||||
|
build_flags = ${common.build_flags}
|
||||||
|
build_unflags = ${common.unbuild_flags}
|
||||||
|
|||||||
@@ -128,9 +128,11 @@ void AnalogSensor::reload() {
|
|||||||
} else if (sensor.type() == AnalogType::COUNTER) {
|
} else if (sensor.type() == AnalogType::COUNTER) {
|
||||||
LOG_DEBUG(F("Adding analog I/O Counter sensor on GPIO%d"), sensor.gpio());
|
LOG_DEBUG(F("Adding analog I/O Counter sensor on GPIO%d"), sensor.gpio());
|
||||||
pinMode(sensor.gpio(), INPUT_PULLUP);
|
pinMode(sensor.gpio(), INPUT_PULLUP);
|
||||||
|
#ifndef ARDUINO_LOLIN_C3_MINI
|
||||||
if (sensor.gpio() == 25 || sensor.gpio() == 26) {
|
if (sensor.gpio() == 25 || sensor.gpio() == 26) {
|
||||||
dacWrite(sensor.gpio(), 255);
|
dacWrite(sensor.gpio(), 255);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
sensor.polltime_ = 0;
|
sensor.polltime_ = 0;
|
||||||
sensor.poll_ = digitalRead(sensor.gpio());
|
sensor.poll_ = digitalRead(sensor.gpio());
|
||||||
publish_sensor(sensor);
|
publish_sensor(sensor);
|
||||||
@@ -160,7 +162,9 @@ void AnalogSensor::reload() {
|
|||||||
} else if (sensor.offset() < 0) {
|
} else if (sensor.offset() < 0) {
|
||||||
sensor.set_offset(0);
|
sensor.set_offset(0);
|
||||||
}
|
}
|
||||||
dacWrite(sensor.gpio(), sensor.offset());
|
#ifndef ARDUINO_LOLIN_C3_MINI
|
||||||
|
dacWrite(sensor.gpio(), sensor.offset());
|
||||||
|
#endif
|
||||||
sensor.set_value(sensor.offset());
|
sensor.set_value(sensor.offset());
|
||||||
} else {
|
} else {
|
||||||
digitalWrite(sensor.gpio(), sensor.offset() > 0 ? 1 : 0);
|
digitalWrite(sensor.gpio(), sensor.offset() > 0 ? 1 : 0);
|
||||||
@@ -572,7 +576,9 @@ bool AnalogSensor::command_setvalue(const char * value, const int8_t gpio) {
|
|||||||
sensor.set_offset(v);
|
sensor.set_offset(v);
|
||||||
sensor.set_value(v);
|
sensor.set_value(v);
|
||||||
pinMode(sensor.gpio(), OUTPUT);
|
pinMode(sensor.gpio(), OUTPUT);
|
||||||
dacWrite(sensor.gpio(), sensor.offset());
|
#ifndef ARDUINO_LOLIN_C3_MINI
|
||||||
|
dacWrite(sensor.gpio(), sensor.offset());
|
||||||
|
#endif
|
||||||
publish_sensor(sensor);
|
publish_sensor(sensor);
|
||||||
return true;
|
return true;
|
||||||
} else if (v == 0 || v == 1) {
|
} else if (v == 0 || v == 1) {
|
||||||
|
|||||||
@@ -691,7 +691,7 @@ void Console::load_system_commands(unsigned int context) {
|
|||||||
std::vector<int8_t> data; // led, dallas, rx, tx, button, phy_type, eth_power, eth_phy_addr, eth_clock_mode
|
std::vector<int8_t> data; // led, dallas, rx, tx, button, phy_type, eth_power, eth_phy_addr, eth_clock_mode
|
||||||
std::string board_profile = Helpers::toUpper(arguments.front());
|
std::string board_profile = Helpers::toUpper(arguments.front());
|
||||||
if (!EMSESP::system_.load_board_profile(data, board_profile)) {
|
if (!EMSESP::system_.load_board_profile(data, board_profile)) {
|
||||||
shell.println(F("Invalid board profile (S32, E32, MH-ET, NODEMCU, OLIMEX, OLIMEXPOE, CUSTOM)"));
|
shell.println(F("Invalid board profile (S32, E32, MH-ET, NODEMCU, OLIMEX, OLIMEXPOE, C3MINI, CUSTOM)"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
EMSESP::webSettingsService.update(
|
EMSESP::webSettingsService.update(
|
||||||
|
|||||||
@@ -856,7 +856,7 @@ void EMSdevice::generate_values_web(JsonObject & output) {
|
|||||||
if (dv.numeric_operator > 0) {
|
if (dv.numeric_operator > 0) {
|
||||||
obj["s"] = Helpers::render_value(s, (float)1 / dv.numeric_operator, 1);
|
obj["s"] = Helpers::render_value(s, (float)1 / dv.numeric_operator, 1);
|
||||||
} else if (dv.numeric_operator < 0) {
|
} else if (dv.numeric_operator < 0) {
|
||||||
obj["s"] = Helpers::render_value(s, (-1) * dv.numeric_operator, 0);
|
obj["s"] = Helpers::render_value(s, (float)(-1) * dv.numeric_operator, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int16_t dv_set_min, dv_set_max;
|
int16_t dv_set_min, dv_set_max;
|
||||||
|
|||||||
@@ -1321,8 +1321,8 @@ void Mqtt::publish_ha_climate_config(uint8_t tag, bool has_roomtemp, bool remove
|
|||||||
doc["curr_temp_tpl"] = currtemp_s;
|
doc["curr_temp_tpl"] = currtemp_s;
|
||||||
}
|
}
|
||||||
|
|
||||||
doc["min_temp"] = Helpers::render_value(min_s, 5, 0, EMSESP::system_.fahrenheit() ? 2 : 0);
|
doc["min_temp"] = Helpers::render_value(min_s, (uint32_t)5, 0, EMSESP::system_.fahrenheit() ? 2 : 0);
|
||||||
doc["max_temp"] = Helpers::render_value(max_s, 30, 0, EMSESP::system_.fahrenheit() ? 2 : 0);
|
doc["max_temp"] = Helpers::render_value(max_s, (uint32_t)30, 0, EMSESP::system_.fahrenheit() ? 2 : 0);
|
||||||
doc["temp_step"] = "0.5";
|
doc["temp_step"] = "0.5";
|
||||||
|
|
||||||
// the HA climate component only responds to auto, heat and off
|
// the HA climate component only responds to auto, heat and off
|
||||||
|
|||||||
@@ -353,6 +353,15 @@ void System::wifi_tweak() {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef ARDUINO_LOLIN_C3_MINI
|
||||||
|
// https://www.wemos.cc/en/latest/c3/c3_mini.html
|
||||||
|
bool System::is_valid_gpio(uint8_t pin) {
|
||||||
|
if ((pin >= 11 && pin <= 19) || (pin > 21)) {
|
||||||
|
return false; // bad pin
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
#else
|
||||||
// check for valid ESP32 pins. This is very dependent on which ESP32 board is being used.
|
// check for valid ESP32 pins. This is very dependent on which ESP32 board is being used.
|
||||||
// Typically you can't use 1, 6-11, 12, 14, 15, 20, 24, 28-31 and 40+
|
// Typically you can't use 1, 6-11, 12, 14, 15, 20, 24, 28-31 and 40+
|
||||||
// we allow 0 as it has a special function on the NodeMCU apparently
|
// we allow 0 as it has a special function on the NodeMCU apparently
|
||||||
@@ -364,6 +373,7 @@ bool System::is_valid_gpio(uint8_t pin) {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// Starts up the UART Serial bridge
|
// Starts up the UART Serial bridge
|
||||||
void System::start() {
|
void System::start() {
|
||||||
@@ -1224,6 +1234,8 @@ bool System::load_board_profile(std::vector<int8_t> & data, const std::string &
|
|||||||
data = {0, 0, 36, 4, 34, PHY_type::PHY_TYPE_LAN8720, -1, 0, 0}; // Olimex ESP32-EVB (uses U1TXD/U1RXD/BUTTON, no LED or Dallas)
|
data = {0, 0, 36, 4, 34, PHY_type::PHY_TYPE_LAN8720, -1, 0, 0}; // Olimex ESP32-EVB (uses U1TXD/U1RXD/BUTTON, no LED or Dallas)
|
||||||
} else if (board_profile == "OLIMEXPOE") {
|
} else if (board_profile == "OLIMEXPOE") {
|
||||||
data = {0, 0, 36, 4, 34, PHY_type::PHY_TYPE_LAN8720, 12, 0, 3}; // Olimex ESP32-POE
|
data = {0, 0, 36, 4, 34, PHY_type::PHY_TYPE_LAN8720, 12, 0, 3}; // Olimex ESP32-POE
|
||||||
|
} else if (board_profile == "C3MINI") {
|
||||||
|
data = {7, 2, 4, 5, 9, PHY_type::PHY_TYPE_NONE, 0, 0, 0}; // Lolin C3 Mini
|
||||||
} else if (board_profile == "CUSTOM") {
|
} else if (board_profile == "CUSTOM") {
|
||||||
// send back current values
|
// send back current values
|
||||||
data = {(int8_t)EMSESP::system_.led_gpio_,
|
data = {(int8_t)EMSESP::system_.led_gpio_,
|
||||||
|
|||||||
@@ -26,7 +26,11 @@
|
|||||||
|
|
||||||
#define EMS_MAXBUFFERSIZE 33 // max size of the buffer. EMS packets are max 32 bytes, plus extra for BRK
|
#define EMS_MAXBUFFERSIZE 33 // max size of the buffer. EMS packets are max 32 bytes, plus extra for BRK
|
||||||
|
|
||||||
#define EMSUART_NUM UART_NUM_2 // on the ESP32 we're using UART2
|
#ifdef ARDUINO_LOLIN_C3_MINI
|
||||||
|
#define EMSUART_NUM UART_NUM_1 // on C3 mini we're using UART1
|
||||||
|
#else
|
||||||
|
#define EMSUART_NUM UART_NUM_2 // on the ESP32 we're using UART2
|
||||||
|
#endif
|
||||||
#define EMSUART_BAUD 9600 // uart baud rate for the EMS circuit
|
#define EMSUART_BAUD 9600 // uart baud rate for the EMS circuit
|
||||||
|
|
||||||
#define EMS_TXMODE_DEFAULT 1
|
#define EMS_TXMODE_DEFAULT 1
|
||||||
|
|||||||
Reference in New Issue
Block a user