Remote Debugging of OpenEMS

Hello All,

Has anyone here debugged the OpenEMS code remotely with Eclipse? I would like to have the OpenEMS instance running on a server without a GUI and still be able to debug and work with the code there.

Eg, VS Code has plugins to allow for remote debugging in such situations. Does Eclipse have a similar plugin? Eclipse has a debug setting for Remote Java Application but it is not available in the BndTools perspective. Should I be using that?

Thank you! :slight_smile:

Hi @dsen,

I have never tried it myself, but using bndtools it should be possible:

19.5 Remote Launching
The purpose of the aQute Remote project is to provide remote debugging support for bnd projects. It can be used to debug bundles and bndrun files in a remote machine running an OSGi framework with an agent installed on it; it can also install a framework on a remote machine before it uses the agent. The architecture is heavily optimized to run on small remote machines.

Regards,
Stefan

JAVA_TOOL_OPTIONS='-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5005' java -jar ./openems-edge.jar

If you change to suspend=n, then process will not wait for debugger to attach. It will work just like within Eclipse/IDE launch.

The bnd launcher does not fork/launch new process, so all options which you specify for first Java process apply directly to openEMS. The JAVA_TOOL_OPTIONS is not well documented, but works across multiple places.

Cheers,
Łukasz

1 Like

Hi @all,

For those who are having trouble with remote debugging:

Here’s my current method for remote debugging OpenEMS in Docker:

  1. File: root\openems\tools\docker\edge\root\etc\s6-overlay\s6-rc.d\svc-openems-edge\run.sh

Modification:

#!/usr/bin/with-contenv bash 
# shellcheck shell=bash 

exec s6-notifyoncheck -d -n 300 -w 1000 -c "nc -z 127.0.0.1 8080" s6-setuidgid abc /usr/bin/java -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5005 -Dfelix.cm.dir=/var/opt/openems/config -Dopenems.data.dir=/var/opt/openems/data -jar /opt/openems/openems-edge.jar
  1. File: root\.vscode\launch.json

Modification:

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "java",
            "name": "Debug (Attach) - Remote",
            "request": "attach",
            "hostName": "localhost",
            "port": 5005
        }
    ]
}
  1. File: root\openems\tools\docker\edge\docker-compose.yml

Modification:

version: "3"

services:
  openems-edge:
    image: openems/edge:latest
    container_name: openems_edge
    hostname: openems_edge
    restart: unless-stopped
    volumes:
      - openems-edge-conf:/var/opt/openems/config:rw
      - openems-edge-data:/var/opt/openems/data:rw
    ports:
      - 8080:8080 # Apache-Felix
      - 8085:8085 # UI-Websocket
      - 5005:5005 # RemoteDebug

  openems-ui:
    image: openems/ui-edge:latest
    container_name: openems_ui
    hostname: openems_ui
    restart: unless-stopped
    volumes:
      - openems-ui-conf:/etc/nginx:rw
      - openems-ui-log:/var/log/nginx:rw
    environment:
      - UI_WEBSOCKET=ws://localhost:8085
    ports:
      - 80:80
      - 443:443

volumes:
  openems-edge-conf:
  openems-edge-data:
  openems-ui-conf:
  openems-ui-log:

This setup works for me.

My Question:
Is there a way to hot code replace the Java code in the Dockerized EdgeApp? I don’t understand what this remote launcher from Bnd does and how to configure the EdgeApp.bndrun file.

Hardware:
Raspberry Pi 4 running OpenEMS Edge and UI with Docker Compose headless. I want to remote debug and develop on another machine in the same LAN.

Does anyone have experience or additional information or solutions?