0
\$\begingroup\$

we are working on a project where an ESP32 communicates with a solar inverter (Axpert KS/MKS/V) over RS232 to fetch status data (e.g., PV power, battery voltage) via the QPIGS<cr> command. The ESP32 then sends this data to an MQTT broker.

To protect the inverter from unauthorized commands (in case the ESP32 is compromised via OTA or network access), I plan to use an ATtiny as a middle layer between the ESP32 and the inverter. The ATtiny would act as a command filter, allowing only QPIGS<cr> to pass through to the inverter and blocking any other commands (e.g., those that could change charging parameters).

Problem:

Despite setting the same baud rate and RS232 communication parameters, the ATtiny is having trouble communicating with the inverter (e.g., incomplete or failed data transmissions). The ESP32 can communicate directly with the inverter without issues.

Questions:

  1. Is using an ATtiny a reliable way to filter RS232 commands for this application, or could it be causing the communication issues?
  2. Could the limited processing power or serial handling of the ATtiny be the problem? Should I consider a different MCU or hardware filter approach?
  3. What are the best practices to ensure robust RS232 communication between an MCU and an inverter while maintaining security?

System Details:

  • Inverter: Axpert KS/MKS/V
  • ESP32: Communicating over RS232
  • ATtiny: Acting as a command filter, forwarding only QPIGS<cr>.
  • Baud rate: 2400
  • Protocol: RS232

Any advice on resolving these issues or suggestions for alternative solutions would be appreciated!

\$\endgroup\$
7
  • 2
    \$\begingroup\$ I'd start by checking the Baud rate the attiny is transmitting at. Given it's using an internal oscillator, it could be as much as 10% out without calibration. \$\endgroup\$ Commented Oct 9 at 20:19
  • 3
    \$\begingroup\$ Your text says that your inverter communicates over RS485, but your schematic has a MAX232. A MAX232 doesn't do RS485 comms, it does RS232 comms (as implied by the part name). For RS485 you'll need to use a MAX485 (or similar) part. \$\endgroup\$
    – brhans
    Commented Oct 9 at 20:35
  • 2
    \$\begingroup\$ And a couple of frame-challenges to your system layout: 1 - there's no need for the ATtiny to filter responses from the inverter back to your ESP32 - just wire it straight through. 2 - don't even bother having the Attiny check to see what your ESP32 sends. If there's any activity coming from the ESP32, then ignore the content and just fire off a QPIGS to the inverter. \$\endgroup\$
    – brhans
    Commented Oct 9 at 21:17
  • \$\begingroup\$ Thanks @brhans for this suggestion, we wanted a hardware filter because esp can be hacked even after locking OTA, so if we don't have a hardware filtration for commands to protect the inverter what's the alternative solution? \$\endgroup\$ Commented Oct 10 at 6:44
  • \$\begingroup\$ You've missed my point. I'm not suggesting that you not use the ATtiny - I'm suggesting that you simplify your system using the ATtiny. The responses form the inverter going back to the ESP do not need to pass through the ATtiny since you're not filtering those, and if the only command you want to go to the inverter is QPIGS, then just have the ATTing generate that command itself, triggered by the ESP. \$\endgroup\$
    – brhans
    Commented Oct 10 at 11:04

1 Answer 1

2
\$\begingroup\$
  1. The ATTiny itself may not be unrealiable. The reliability issues may come from the code that runs on it or from the hardware you built around it. It's unlikely it's the ATTiny that causes communication issues.

For example, you have no stable clock source so you must be running on the internal RC oscillator - you need to check if it is accurate enough for UART communications.

Also you are using a MAX232 which is a 5V chip at 3.3V, so it does not have to work at all.

  1. Wthout seeing your code, hard to tell. But why not change approach that the ATTiny is the one that sends request to solar charger as the only command, and let ESP receive the response. That way nothing can be sent from ESP. So unlikely the limited processing power is the issue, based on all the other issues already mentioned.

  2. Your design has no RS485 in it at all. RS485 is a bus where anyone can send anything they like and someone responds. Anyway, the separate small micro that is unprogrammable and can only send safe commands on request sounds neat but excessive solution.

So just to be clear, the ESP32 is not communicating with RS-485, and there is no protocol called RS-485, it's an electrical interface where e.g. ModBus protocol can be used. There is nothing related to RS-485 in your design. If the module communicates over RS-485, your design is incompatible with RS-485.

\$\endgroup\$
3
  • \$\begingroup\$ I appreciate your answer @Justme, I'm sorry to mention RS485, we are using RS232, and the question is updated. \$\endgroup\$ Commented Oct 10 at 6:47
  • \$\begingroup\$ @AbdulkaderKhateeb your question title still reads "RS485". \$\endgroup\$
    – brhans
    Commented Oct 10 at 11:05
  • \$\begingroup\$ Thans @brhans, it's just updated to RS232 \$\endgroup\$ Commented Oct 10 at 19:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.