[Tutorial] Accessing VS Code through a browser

2GB is not sufficient?

That might be sufficient but I’ve noticed running Code Server myself on a VM that I had to bump the RAM up to 4 GB to get decent performance. I bet 2.5 or 3 GB might be sufficient. And as always YMMV and it depends on what else you have running. But I find that an RPi 3 with 1 GB RAM is pretty much fully loaded with an openHABian install already. Adding another service that requires 1 GB all by itself is going to cause problems.

3 Likes

hmm, My VS-Server is running on a ubuntu LX-container with 512MB ram and I don’t feel any lag/delay, even though my openhab config is at least medium in size.

I would think adding VS Server as an option would be good, in addition to all the other optional features openhabian is offering, like grafana, influxdb, FIND, etc…

Installing “all” of them might bring your device to a limit, but then again, openhabian as the central tool, good “warn” the user.

does a PR has to be a working prototype or can it be as simple as an idea?

For an idea you can file an issue. A PR is working cure ready to be merged.

If you really want this to happen, you should submit a PR which needs to be a working prototype. You can submit the idea but there is no guarantee that anyone will do anything about just an idea.

1 Like

Thanks for the effort. I tried to do the steps but some things are not clear. Can you please clarify:

  1. Create file code-server.service for autostart → this should go into /usr/lib/systemd/system ?
  2. I could copy the vscode extension (find tthe tiny downloads button in the middle of the screen) and copy it to op/coder ? I did not have a folder /opt/code-server/
  3. How do I actually access it , i.e. what is the browser url ? 192.168.1.30:8080…
  4. It does not show up in the dashboard. There are two dashboard.cfg enties in this tutorial, yours with coder.link… and the one from papaPhil who adds codeserver.link…

Depends on your operating system, so cannot answer.

If installed within VS-Code, you should not need to take care about copying.

Guess what this means:

192.168.1.30:9090

Depends, my tutorial was for openHAB 2.x. This config has changed a bit in openHAB 3.x but the community search will surely lead you to a working solution.

Thank you. I tried 9090, of course, but is not working. The service seems to be running though.

[09:03:03] root@RPi4:~# sudo systemctl status code-server
● code-server.service - Code Server IDE
   Loaded: loaded (/lib/systemd/system/code-server.service; enabled; vendor preset: enabled)
   Active: activating (auto-restart) (Result: exit-code) since Thu 2023-01-12 09:03:04 CET; 1s ago
  Process: 9363 ExecStart=/opt/coder/code-server --port 9090 --auth none --disable-telemetry (code=exited, status=203/EXEC)
 Main PID: 9363 (code=exited, status=203/EXEC)

You could check which port the service is bound to, just can’t remember the correct command…

Update for OpenHabian 3.4.1 (non-docker)

TLDR;
save yourself the trouble. Its not mature. It can get it to partially work until you restart your system.

You still want to try it?
These were the steps that I did, on a plain (non docker) OpenHabian 3.4.0 RPI4 (buster) system:

Install the code server

open a root shell on your openhabian system, then
curl -fsSL https://code-server.dev/install.sh | sh
It issues with multiple errors, you may have to force an update nodejs and the package manager npm. Not sure if the npm update is really mandatory. Anyway, it will give you a hint on the console how to upgrade it.

Edit the configuration (optional)

The configuration is used when you start the code-server manually on the command line. If you start it as a service, you can pass parameters direcly. See below.

nano ~/.config/code-server/config.yaml
change auth to “none” and address to 0.0.0.0:9090
If you leave the configuration at 127.0.0.1, you can only access code server on the machine that it is running on. Mind the port 9090 because 8080 is taken by OpenHab already.

Add autostart

First create the service file
nano /usr/lib/systemd/system/code-server.service

and put the following code there:

[Unit]
Description=Code Server IDE
After=network.target

[Service]
Type=simple
User=openhab
Group=openhab
WorkingDirectory=/opt/coder
Restart=on-failure
RestartSec=10
ExecStart=/usr/bin/code-server --bind-addr 0.0.0.0  --port 9090 --auth none --disable-telemetry
StandardOutput=file:/var/log/code-server-output.log
StandardError=file:/var/log/code-server-error.log

[Install]

WantedBy=multi-user.target

then activate it:
systemctl daemon-reload && systemctl enable code-server.service && systemctl start code-server.service

Check if that was successful with
systemctl status code-server

If the output reads at some point code=exited, status=203/EXEC please check the path of the execStart parameter. First post from @hmerk points to the executable in opt/coder/code-server which did not work for me.
However, you may still be able to start the code server manually by typing code-server in your terminal window.

Now wait a little. When You open the browser at (e.g.) 192.168.1.30:9090 it may show “500” and Cannot find module ‘minimist’. Shell says the same, eventually. There is an issue about this, but no solution. You have to fix this manually:

Optional: install missing files

when starting code-server, you will find some modules are missing. It starts with “minimist” and goes on and on. Long story short, you have to issue these commands.

npm install -g minimist yazl yauzl @microsoft/1ds-core-js spdlog  vscode-regexpp vscode-proxy-agent @vscode/ripgrep xterm-headless  @parcel/watcher
sudo apt-get install libsecret-1-dev
npm install keytar

The VScode files belong to root now. In order to be able to modify settings within the browser editor, we need to change ownership. Most files, also settings.json are in /lib/node_modules.
chown -R openhab:openhab /lib/node_modules

Check port binding

netstat -lnp
it should read port 9090 somewhere.

Install openhab add on

according to this, it should be as simple as calling
code-server --install-extension openhab.openhab
If you installed the missing packages above, this command should complete successfully.

Set up openhab extension

create token (main UI, bottom left click, scroll down, click create token)
In your browser, go to 192.168.1.xx:9090 It should start the Visual Studio Code window. Go to File → preferences → Extensions-> OpenHab → settings.json and enter
{
“workbench.colorTheme”: “Visual Studio Dark”,
“security.workspace.trust.untrustedFiles”: “open”,
“openhab.connection.authToken”: “oh.codeserver.*******”,
“openhab.connection.host”: “192.168.1.30”,
“openhab.connection.port”: 8080,
“openhab.host”: “192.168.1.30”,
“openhab.port”: 8080,
“openhab.password”: “habopen”,
“openhab.username”: “openhab”,
“workbench.startupEditor”: “none”,
“openhab.karafCommand”: “ssh openhab@192.168.1.30 -p 8101 -t ‘log:tail’”
}

Beware ! When you copy this, often the quotes " will be swapped for similar /italic versions ! Make sure you have proper quotes in the config file.

Insecure context !?

VSCode will complain that you are accessing it in an insecure context. This is due to the fact that so far you use http. While I have not encountered any limitations, here is how to fix. (find

What else ?

keep in mind that if you created folders as root, they may not be accessible by the openhabian user which normally runs the system.
To change ownership, do e.g.
sudo chown -R openhab:openhab /opt/coder

On my system everything works as expected, except for the syntax highlighting. It does some highlighting of brackets but nothing else. Mouse - over for items shows their state, code checking is fine.

A word of warning. All this above does not use any password or other security measures. Never expose to the internet. For local use or via VPN is probably ok.

Update / persisting issues

  • syntax highlighting does not work, except for brackets.
  • language setting is not persisted

Overall rating: probably not worth the installation effort. Took me more than a day of work and left me with a unreliable solution.

Thanks for summarizing the new process.
As I am using openHAB 3.4 purely with GUI config, I did not and cannot follow up changes anymore.

If that’s an issue, why not simply create it ???