/* * Esp32SerialMonitor - read a Selectronic SP PRO from an ESP32 and print a * dashboard to the USB serial monitor, using the thin Sppro C++ wrapper. * * The SP PRO serial port is RS-232 (+/-12V) - you MUST use a level shifter * (MAX3232); do not wire it straight to a GPIO. See docs/HARDWARE.md: * * SP PRO RJ45 pin 3 (TXD) --> MAX3232 R1IN ; R1OUT --> ESP32 GPIO16 (RX2) * ESP32 GPIO17 (TX2) --> MAX3232 T1IN ; T1OUT --> SP PRO RJ45 pin 6 (RXD) * SP PRO RJ45 pin 4/5 (GND)--> MAX3232 GND --> ESP32 GND (common ground!) * ESP32 3V3 --> MAX3232 VCC (+ four 0.1uF charge-pump caps) * * Build with PlatformIO (this folder has its own platformio.ini): * cd examples/Esp32SerialMonitor && pio run * or open the .ino in the Arduino IDE after installing this library. */ #include static const int PIN_RX = 16; /* ESP32 RX2 <- MAX3232 R1OUT */ static const int PIN_TX = 17; /* ESP32 TX2 -> MAX3232 T1IN */ static const char *PASSWORD = ""; /* inverter serial-port password ("" if none) */ /* Sppro wraps any Arduino Stream; here it is UART2. */ Sppro sp(Serial2); bool ready = false; static bool connectSppro() { if (sp.login(PASSWORD) != SPPRO_OK) { Serial.println("login failed - check wiring/password"); return false; } if (sp.readScales() != SPPRO_OK) { Serial.println("could not read scale factors"); return false; } Serial.println("connected to SP PRO"); return true; } static void show(const char *name) { const sppro_reg_t *reg = sppro_reg_by_name(name); if (!reg) return; if (reg->conv == SPPRO_C_SHUNT_NAME) { Serial.printf("%-26s %12s\n", reg->description, sp.name(name)); } else { double v; if (sp.read(name, v) != SPPRO_OK) Serial.printf("%-26s (read error)\n", reg->description); else Serial.printf("%-26s %12.2f %s\n", reg->description, v, reg->units); } } void setup() { Serial.begin(115200); Serial2.begin(SPPRO_BAUD, SERIAL_8N1, PIN_RX, PIN_TX); delay(200); ready = connectSppro(); } void loop() { if (!ready) { delay(2000); ready = connectSppro(); return; } Serial.println("\n== Selectronic SP PRO =="); show("BatteryVolts"); show("BattSocPercent"); show("BatteryTemperature"); show("DCBatteryPower"); show("LoadAcPower"); show("CombinedKacoAcPowerHiRes"); show("ACGeneratorPower"); delay(5000); }