diff --git a/include/mqtt.h b/include/mqtt.h index 0c8f7033..736b38c2 100644 --- a/include/mqtt.h +++ b/include/mqtt.h @@ -23,7 +23,12 @@ PubSubClient client(espClient); void sendValues() { Serial.printf("Sending values in MQTT.\n"); -#ifdef ARDUINO_M5Stick_C +#ifdef ARDUINO_M5Stick_C_Plus2 + //Add Power values + // getBatteryVoltage returns battery voltage [mV] as an int16_t + float batteryVoltage = (float) M5.Power.getBatteryVoltage() / 1000; // convert to V as a float + snprintf(jsonbuff + strlen(jsonbuff),MAX_MSG_SIZE - strlen(jsonbuff) , "\"%s\":\"%.3gV\",", "M5BatV", batteryVoltage); +#elif ARDUINO_M5Stick_C //Add M5 APX values snprintf(jsonbuff + strlen(jsonbuff),MAX_MSG_SIZE - strlen(jsonbuff) , "\"%s\":\"%.3gV\",\"%s\":\"%gmA\",", "M5VIN", M5.Axp.GetVinVoltage(),"M5AmpIn", M5.Axp.GetVinCurrent()); snprintf(jsonbuff + strlen(jsonbuff),MAX_MSG_SIZE - strlen(jsonbuff) , "\"%s\":\"%.3gV\",\"%s\":\"%gmA\",", "M5BatV", M5.Axp.GetBatVoltage(),"M5BatCur", M5.Axp.GetBatCurrent()); diff --git a/include/mqttserial.h b/include/mqttserial.h index 589d2357..d413c743 100644 --- a/include/mqttserial.h +++ b/include/mqttserial.h @@ -2,7 +2,9 @@ #define mqttSerial_h #include "Stream.h" #include -#ifdef ARDUINO_M5Stick_C_Plus +#ifdef ARDUINO_M5Stick_C_Plus2 +#include +#elif ARDUINO_M5Stick_C_Plus #include #elif ARDUINO_M5Stick_C #include diff --git a/platformio.ini b/platformio.ini index a16631f9..379b26ac 100644 --- a/platformio.ini +++ b/platformio.ini @@ -68,6 +68,23 @@ lib_deps = build_flags = "-D ARDUINO_M5Stick_C_Plus" +[env:m5stickcplus2] +platform = espressif32 +board = m5stick-c +framework = arduino +monitor_speed = 115200 +upload_speed = 115200 +; Uncomment this line to allow for remote upgrade. If name resolution does not work for you, replace with the IP of ESPAltherma +; upload_port = ESPAltherma.local +; Uncomment this line if you want to define the protocol. Autodetected otherwise. +; upload_protocol = espota + +lib_deps = + M5StickCPlus2 + PubSubClient + +build_flags = "-D ARDUINO_M5Stick_C_Plus2" + [env:native] # Used to run unit test; g++ must be in PATH. platform = native diff --git a/src/main.cpp b/src/main.cpp index 31603c27..a1633610 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,4 +1,6 @@ -#ifdef ARDUINO_M5Stick_C_Plus +#ifdef ARDUINO_M5Stick_C_Plus2 +#include +#elif ARDUINO_M5Stick_C_Plus #include #elif ARDUINO_M5Stick_C #include @@ -93,12 +95,12 @@ void extraLoop() ArduinoOTA.handle(); } -#if defined(ARDUINO_M5Stick_C) || defined(ARDUINO_M5Stick_C_Plus) +#if defined(ARDUINO_M5Stick_C) || defined(ARDUINO_M5Stick_C_Plus) || defined(ARDUINO_M5Stick_C_Plus2) if (M5.BtnA.wasPressed()){//Turn back ON screen - M5.Axp.ScreenBreath(12); + M5.Display.wakeup(); LCDTimeout = millis() + 30000; - }else if (LCDTimeout < millis()){//Turn screen off. - M5.Axp.ScreenBreath(0); + } else if (LCDTimeout < millis()) { //Turn screen off. + M5.Display.sleep(); } M5.update(); #endif @@ -245,21 +247,23 @@ void initRegistries(){ } void setupScreen(){ -#if defined(ARDUINO_M5Stick_C) || defined(ARDUINO_M5Stick_C_Plus) +#if defined(ARDUINO_M5Stick_C) || defined(ARDUINO_M5Stick_C_Plus) || defined(ARDUINO_M5Stick_C_Plus2) M5.begin(); +#if !defined(ARDUINO_M5Stick_C_Plus2) M5.Axp.EnableCoulombcounter(); +#endif M5.Lcd.setRotation(1); - M5.Axp.ScreenBreath(12); + M5.Lcd.setBrightness(127); M5.Lcd.fillScreen(TFT_WHITE); - M5.Lcd.setFreeFont(&FreeSansBold12pt7b); - m5.Lcd.setTextDatum(MC_DATUM); + M5.Lcd.setFont(&FreeSansBold12pt7b); + M5.Lcd.setTextDatum(MC_DATUM); int xpos = M5.Lcd.width() / 2; // Half the screen width int ypos = M5.Lcd.height() / 2; // Half the screen width M5.Lcd.setTextColor(TFT_DARKGREY); - M5.Lcd.drawString("ESPAltherma", xpos,ypos,1); + M5.Lcd.drawString("ESPAltherma", xpos,ypos); delay(2000); M5.Lcd.fillScreen(TFT_BLACK); - M5.Lcd.setTextFont(1); + M5.Lcd.setFont(&Font0); M5.Lcd.setTextColor(TFT_GREEN); #endif } @@ -269,7 +273,7 @@ void setup() Serial.begin(115200); setupScreen(); MySerial.begin(9600, SERIAL_CONFIG, RX_PIN, TX_PIN); - pinMode(PIN_THERM, OUTPUT); + pinMode(PIN_THERM, OUTPUT); digitalWrite(PIN_THERM, HIGH); #ifdef PIN_SG1 diff --git a/src/setup.h b/src/setup.h index 227ad81b..894e71bf 100644 --- a/src/setup.h +++ b/src/setup.h @@ -17,8 +17,8 @@ #define FREQUENCY 30000 //query values every 30 sec -#if defined(ARDUINO_M5Stick_C) || defined(ARDUINO_M5Stick_C_Plus) -//Values used when **M5StickC** or **M5STickCPlus** environment is selected: +#if defined(ARDUINO_M5Stick_C) || defined(ARDUINO_M5Stick_C_Plus) || defined(ARDUINO_M5Stick_C_Plus2) +// Values used when M5StickC, M5STickCPlus or M5Stick_C_Plus2 environment is selected: #define RX_PIN 36// Pin connected to the TX pin of X10A #define TX_PIN 26// Pin connected to the RX pin of X10A #else