jfjlaros / simpleRPC

Simple RPC implementation for Arduino.
MIT License
50 stars 17 forks source link

Crash after processing any command on ESP32 #31

Closed prutschman-iv closed 9 months ago

prutschman-iv commented 9 months ago

I've used simpleRPC successfully on an Arduino and a Teensy 4. I'm now trying it on an ESP32 (Adafruit Huzzah32 feather) and running into a crash. Specifically, the board resets after completing any RPC call, including requesting a command list.

Here's a minimal reproduction:

#include <simpleRPC.h>

void setup() {
  Serial.begin(115200);
}

void loop() {
  interface(Serial, millis, "uptime: returns uptime in milliseconds");
}

If I reset the board, wait 5 seconds, and then call simple_rpc call -b 115200 COM6 I get a response like 7427. If I issue the command back-to-back, I get responses like 2450, 2427, 2475 indicating a reset has taken place. (Probably flashing an LED on reset would be a more obvious way of indicating the reset, now that I think about it.)

Software Versions: simpleRPC 3.2.0 Arduino IDE 2.2.1 esp32 BSP (Espressif's) 2.0.11

jfjlaros commented 9 months ago

Connecting to the serial port usually resets the device, so the board is reset before the RPC call takes place.

You could test this by leaving the serial connection open between calls, e.g.,

>>> from simple_rpc import Interface
>>> interface = Interface('COM6')
>>> interface.uptime()
1234
>>> interface.uptime()
2345
prutschman-iv commented 9 months ago

It was indeed related to the serial connection, thank you! Persisting the connection, as you suggested, prevents the reboots, so I'm good to go. (Although weirdly, it was definitely closing the serial connection that caused the reboot, rather than connecting the serial. I can get the first call to uptime to return an arbitrarily high value by waiting a long time after a reboot before I open the connection, then issuing the first call.)

jfjlaros commented 9 months ago

Hmm, maybe that is an ESP specific thing then.