diff --git a/interface/src/project/SettingsApplication.tsx b/interface/src/project/SettingsApplication.tsx index c4df56b45..334607a6d 100644 --- a/interface/src/project/SettingsApplication.tsx +++ b/interface/src/project/SettingsApplication.tsx @@ -124,13 +124,18 @@ const SettingsApplication: FC = () => { name="board_profile" label={LL.BOARD_PROFILE()} value={data.board_profile} - disabled={processingBoard} + disabled={processingBoard || data.board_profile === 'C3MINI'} variant="outlined" onChange={changeBoardProfile} margin="normal" select > {boardProfileSelectItems()} + {data.board_profile === 'C3MINI' && ( + + C3 Mini + + )} Custom… diff --git a/interface/src/project/validators.ts b/interface/src/project/validators.ts index a626489d2..bc33ceff6 100644 --- a/interface/src/project/validators.ts +++ b/interface/src/project/validators.ts @@ -7,7 +7,7 @@ export const GPIO_VALIDATOR = { if ( value && (value === 1 || - (value >= 6 && value <= 12) || + (value >= 10 && value <= 12) || (value >= 14 && value <= 15) || value === 20 || value === 24 || diff --git a/lib/ESPAsyncWebServer/AsyncWebSocket.cpp b/lib/ESPAsyncWebServer/AsyncWebSocket.cpp index b4425000b..3b810ac60 100644 --- a/lib/ESPAsyncWebServer/AsyncWebSocket.cpp +++ b/lib/ESPAsyncWebServer/AsyncWebSocket.cpp @@ -846,7 +846,7 @@ void AsyncWebSocketClient::binary(AsyncWebSocketMessageBuffer * buffer) IPAddress AsyncWebSocketClient::remoteIP() { if(!_client) { - return IPAddress(0U); + return IPAddress((uint32_t)0); } return _client->remoteIP(); } diff --git a/lib/framework/APSettingsService.cpp b/lib/framework/APSettingsService.cpp index bdc02958c..0f9967aff 100644 --- a/lib/framework/APSettingsService.cpp +++ b/lib/framework/APSettingsService.cpp @@ -49,6 +49,9 @@ void APSettingsService::startAP() { WiFi.softAPConfig(_state.localIP, _state.gatewayIP, _state.subnetMask); 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); + #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) { IPAddress apIp = WiFi.softAPIP(); emsesp::EMSESP::logger().info(F("Starting Access Point with captive portal on %s"), apIp.toString().c_str()); diff --git a/lib/framework/NetworkSettingsService.cpp b/lib/framework/NetworkSettingsService.cpp index 58739d47a..814bd5dde 100644 --- a/lib/framework/NetworkSettingsService.cpp +++ b/lib/framework/NetworkSettingsService.cpp @@ -75,6 +75,9 @@ void NetworkSettingsService::manageSTA() { }); 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 } } diff --git a/mock-api/server.js b/mock-api/server.js index 942b14b20..7fed12ded 100644 --- a/mock-api/server.js +++ b/mock-api/server.js @@ -1152,6 +1152,17 @@ rest_server.post(EMSESP_BOARDPROFILE_ENDPOINT, (req, res) => { data.eth_power = 12 data.eth_phy_addr = 0 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)) diff --git a/platformio.ini b/platformio.ini index 444bf4039..b1293acdd 100644 --- a/platformio.ini +++ b/platformio.ini @@ -81,3 +81,14 @@ board_upload.flash_size = 16MB board_build.partitions = esp32_partition_16M.csv build_flags = ${common.build_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} diff --git a/src/analogsensor.cpp b/src/analogsensor.cpp index 826f370f6..413db6513 100644 --- a/src/analogsensor.cpp +++ b/src/analogsensor.cpp @@ -128,9 +128,11 @@ void AnalogSensor::reload() { } else if (sensor.type() == AnalogType::COUNTER) { LOG_DEBUG(F("Adding analog I/O Counter sensor on GPIO%d"), sensor.gpio()); pinMode(sensor.gpio(), INPUT_PULLUP); + #ifndef ARDUINO_LOLIN_C3_MINI if (sensor.gpio() == 25 || sensor.gpio() == 26) { dacWrite(sensor.gpio(), 255); } + #endif sensor.polltime_ = 0; sensor.poll_ = digitalRead(sensor.gpio()); publish_sensor(sensor); @@ -160,7 +162,9 @@ void AnalogSensor::reload() { } else if (sensor.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()); } else { 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_value(v); pinMode(sensor.gpio(), OUTPUT); - dacWrite(sensor.gpio(), sensor.offset()); + #ifndef ARDUINO_LOLIN_C3_MINI + dacWrite(sensor.gpio(), sensor.offset()); + #endif publish_sensor(sensor); return true; } else if (v == 0 || v == 1) { diff --git a/src/console.cpp b/src/console.cpp index 80c06df14..afce647ab 100644 --- a/src/console.cpp +++ b/src/console.cpp @@ -691,7 +691,7 @@ void Console::load_system_commands(unsigned int context) { std::vector data; // led, dallas, rx, tx, button, phy_type, eth_power, eth_phy_addr, eth_clock_mode std::string board_profile = Helpers::toUpper(arguments.front()); 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; } EMSESP::webSettingsService.update( diff --git a/src/emsdevice.cpp b/src/emsdevice.cpp index b8ce08716..51667ddb1 100644 --- a/src/emsdevice.cpp +++ b/src/emsdevice.cpp @@ -856,7 +856,7 @@ void EMSdevice::generate_values_web(JsonObject & output) { if (dv.numeric_operator > 0) { obj["s"] = Helpers::render_value(s, (float)1 / dv.numeric_operator, 1); } 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; diff --git a/src/mqtt.cpp b/src/mqtt.cpp index 1198ca6ec..898fd1cce 100644 --- a/src/mqtt.cpp +++ b/src/mqtt.cpp @@ -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["min_temp"] = Helpers::render_value(min_s, 5, 0, EMSESP::system_.fahrenheit() ? 2 : 0); - doc["max_temp"] = Helpers::render_value(max_s, 30, 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, (uint32_t)30, 0, EMSESP::system_.fahrenheit() ? 2 : 0); doc["temp_step"] = "0.5"; // the HA climate component only responds to auto, heat and off diff --git a/src/system.cpp b/src/system.cpp index 4a3d0217a..ec91d3672 100644 --- a/src/system.cpp +++ b/src/system.cpp @@ -353,6 +353,15 @@ void System::wifi_tweak() { #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. // 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 @@ -364,6 +373,7 @@ bool System::is_valid_gpio(uint8_t pin) { } return true; } +#endif // Starts up the UART Serial bridge void System::start() { @@ -1224,6 +1234,8 @@ bool System::load_board_profile(std::vector & 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) } else if (board_profile == "OLIMEXPOE") { 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") { // send back current values data = {(int8_t)EMSESP::system_.led_gpio_, diff --git a/src/uart/emsuart_esp32.h b/src/uart/emsuart_esp32.h index ba3863925..9dcea414d 100644 --- a/src/uart/emsuart_esp32.h +++ b/src/uart/emsuart_esp32.h @@ -26,7 +26,11 @@ #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 EMS_TXMODE_DEFAULT 1 diff --git a/src/web/WebSettingsService.cpp b/src/web/WebSettingsService.cpp index 878f6472c..cb97f36d6 100644 --- a/src/web/WebSettingsService.cpp +++ b/src/web/WebSettingsService.cpp @@ -81,7 +81,11 @@ void WebSettings::read(WebSettings & settings, JsonObject & root) { StateUpdateResult WebSettings::update(JsonObject & root, WebSettings & settings) { // load default GPIO configuration based on board profile std::vector data; // // led, dallas, rx, tx, button, phy_type, eth_power, eth_phy_addr, eth_clock_mode - settings.board_profile = root["board_profile"] | EMSESP_DEFAULT_BOARD_PROFILE; + #ifdef ARDUINO_LOLIN_C3_MINI + settings.board_profile = "C3MINI"; + #else + settings.board_profile = root["board_profile"] | EMSESP_DEFAULT_BOARD_PROFILE; + #endif if (!System::load_board_profile(data, settings.board_profile.c_str())) { settings.board_profile = "CUSTOM"; EMSESP::logger().info("No board profile found. Re-setting to %s", settings.board_profile.c_str());