Tiny Core Linux

Tiny Core Extensions => TCE Q&A Forum => Topic started by: kagouraki on March 31, 2023, 09:54:47 AM

Title: SignalK on picore 13,1
Post by: kagouraki on March 31, 2023, 09:54:47 AM
Hello guys ! you have made an awesome OS here !

I want to install signalK(https://signalk.org/) in piCore 13.1 on a raspberry pi zero 2 W to build a NMEA183/2000 gateway and multiplexer.

i have setup my zero2 with networkmanager for wifi, TC(gui) and node.js.tcz installed and all works perfect.
Now the problem starts when i follow these instructions to install the signalK in this site https://www.npmjs.com/package/signalk-server
When i execute through ssh the

Code: [Select]
sudo npm install -g signalk-server
i get this error and i cant compile it.

Code: [Select]
tc@box:~$ sudo npm install -g signalk-server
npm WARN deprecated json-schema-ref-parser@9.0.9: Please switch to @apidevtools/json-schema-ref-parser
npm WARN deprecated json-schema-ref-parser@3.3.1: Please switch to @apidevtools/json-schema-ref-parser
npm WARN deprecated core-js@2.6.12: core-js@<3.23.3 is no longer maintained and not recommended for usage due to the number of issues. Because of the V8 engine whims, feature detection in old core-js versions could cause a slowdown up to 100x even if nothing is polyfilled. Some versions have web compatibility issues. Please, upgrade your dependencies to the actual version of core-js.
npm WARN checkPermissions Missing write access to /tmp/tcloop/node.js/usr/local/lib/node_modules
npm ERR! code EROFS
npm ERR! syscall access
npm ERR! path /tmp/tcloop/node.js/usr/local/lib/node_modules
npm ERR! errno -30
npm ERR! rofs EROFS: read-only file system, access '/tmp/tcloop/node.js/usr/local/lib/node_modules'
npm ERR! rofs Often virtualized file systems, or other file systems
npm ERR! rofs that don't support symlinks, give this error.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/tc/.npm/_logs/2023-03-31T13_42_58_630Z-debug.log
tc@box:~$

I uploaded the log file in pastebin    https://pastebin.com/uHkTt8pW

What am i doing wrong ? is it even possible to run signalK-server in picore ?
It would be great if someone could just make a .tcz file so we could just install it !

Thank you in advance for your support !

Giorgos from Greece
Title: Re: SignalK on picore 13,1
Post by: Juanito on March 31, 2023, 10:46:13 AM
You could try setting the copy2fs flag for node.js - this will require a reboot.
Title: Re: SignalK on picore 13,1
Post by: kagouraki on March 31, 2023, 12:18:42 PM
I have seen a thread in the forums that was mentioning this solution after i made this post and i have tried it. It seems to installing and i was watching htop and while it was installing first the ram filled to full and then the 5gb swap partition i have in the sd card filled with 300mb.
Then i had an error in the terminal that there is not enough space. How can i solve this problem ? Is there a solution in which i can compile signalk elsewhere and create a tcz and install it this way?
Title: Re: SignalK on picore 13,1
Post by: Juanito on March 31, 2023, 12:45:19 PM
If signalk is open source it is probably possible to compile it and make an extension out of it.
Title: Re: SignalK on picore 13,1
Post by: kagouraki on April 01, 2023, 06:17:09 AM
Yes it is. Can you please point me in the right direction ? I am  a hobby programmer so not much knowledge here :(
Title: Re: SignalK on picore 13,1
Post by: Juanito on April 01, 2023, 08:15:02 AM
The first step would be to download the source and untar it.

Check for files named Makefile, cmake or meson to know which build system to use.
Title: Re: SignalK on picore 13,1
Post by: kagouraki on April 01, 2023, 08:39:04 AM
ok. This is beyond my knowledge. Perhaps someone can do this. Is there a place where i can add a feature request ?
Title: Re: SignalK on picore 13,1
Post by: stelian on April 04, 2023, 02:35:16 AM
I did give it a try to package each individual npm module into a different tcz, but it looks like node.js doesn't like symlinks:

Code: [Select]
$ /usr/local/lib/node_modules/npm/node_modules/signalk-server/bin/signalk-server
internal/modules/cjs/loader.js:969
  throw err;
  ^

Error: Cannot find module '@signalk/server-api'
Require stack:
- /tmp/tcloop/signalk-server/usr/local/lib/node_modules/npm/node_modules/signalk-server/lib/index.js
- /tmp/tcloop/signalk-server/usr/local/lib/node_modules/npm/node_modules/signalk-server/bin/signalk-server
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:966:15)
    at Function.Module._load (internal/modules/cjs/loader.js:842:27)
    at Module.require (internal/modules/cjs/loader.js:1026:19)
    at require (internal/modules/cjs/helpers.js:72:18)
    at Object.<anonymous> (/tmp/tcloop/signalk-server/usr/local/lib/node_modules/npm/node_modules/signalk-server/lib/index.js:28:22)
    at Module._compile (internal/modules/cjs/loader.js:1138:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)
    at Module.load (internal/modules/cjs/loader.js:986:32)
    at Function.Module._load (internal/modules/cjs/loader.js:879:14)
    at Module.require (internal/modules/cjs/loader.js:1026:19) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/tmp/tcloop/signalk-server/usr/local/lib/node_modules/npm/node_modules/signalk-server/lib/index.js',
    '/tmp/tcloop/signalk-server/usr/local/lib/node_modules/npm/node_modules/signalk-server/bin/signalk-server'
  ]
}

@signalk/server-api is installed into /usr/local/lib/node_modules/npm/node_modules/@signalk/server-api, but it is searched in /tmp/tcloop...

Any idea on how to get past this ? (except by building a monolithic node.js + signalk-server ?)

Title: Re: SignalK on picore 13,1
Post by: kagouraki on April 04, 2023, 03:10:28 AM
I made some progress yesterday. I downloaded the LTS armv7l binaries for nodejs. I extracted them and made a tcz and installed it so everything is in place and latest version odlf nodejs. So i was in the stage you are now where it could write to the read only partition. I read an old post here which was sugesting the copy2fs.flg option but that leaves no ram in the pizero2. So i though why use the -g option in the npm install ? So i omited it and it installed signalK fine. So now i need to figure out what is static and what not and copy them to the nodejs binaries before i compile the tcz. Today i will have more progress. The tinycorebook is AWESOME by the way. Very good and clear writing!
Title: Re: SignalK on picore 13,1
Post by: stelian on April 04, 2023, 08:00:54 AM
-g stands for global, with this modules will be installed into /usr/local/..., without it the modules are installed into $HOME/node_modules/

You succeeded installing into $HOME, great, but everything will be lost on reboot.

What you can do is move your $HOME/node_modules to /mnt/mmcblk0p2/node_modules, and make a symlink from your home directory to that. It should work I guess...

But this is not the proper way to package things for tinycorelinux into tcz files...
Title: Re: SignalK on picore 13,1
Post by: kagouraki on April 04, 2023, 10:57:35 AM
Actually the home directory is backed up by filetool.sh so nothing is erased after a reboot.
But this is not ideal because you have all the node_modules in ram when you boot and pizero2 has only 512mb.
I will make a tcz with node.js AND the all the modules required for signalk. These files dont change unless you want to upgrade to newer version.
All the signalk configuration and webapps etc are stored in ~\.signalk folder so these will be persistent(if you choose to backup with filetool.sh) and changable when you are booted. I think this is the perfect method.
I will post my progress here in someone wants signalk on piCore 13.1
Title: Re: SignalK on picore 13,1
Post by: Rich on April 04, 2023, 11:47:29 AM
Hi kagouraki
What stelian says make sense:
Code: [Select]
mv ~/.signalk /mnt/mmcblk0p2/
ln -s /mnt/mmcblk0p2/ ~/.signalk
Your  .signalk  directory will now be persistent because it resides on your sdcard.
Your backup will save the  ~/.signalk  link instead of the contents it points to.
If the  .signalk  directory is large, your backup/restore should be noticeably faster.
Title: Re: SignalK on picore 13,1
Post by: kagouraki on April 04, 2023, 12:04:28 PM
Yes, what you suggest is smarter but what is going on with data corruption if something is written when you unplug the pizero2?

Stelian actually suggested to copy all the modules to the mmcblk0p2 not only the config files.

I like your option but i need to know the risk of having data corruption
Title: Re: SignalK on picore 13,1
Post by: Rich on April 04, 2023, 12:43:30 PM
Hi kagouraki
These are some posts by Greg Erskine on his experiences with RaspberyPi:
https://forum.tinycorelinux.net/index.php/topic,22997.msg144014.html#msg144014
https://forum.tinycorelinux.net/index.php/topic,23810.msg150038.html#msg150038
https://forum.tinycorelinux.net/index.php/topic,25565.msg163908.html#msg163908

Corruption is always a possibility if power loss occurs while a write is in progress. This
also holds true if it happens while a backup is being run.

A power loss is a random event with respect to when a write is occurring.
If you are worried about it:

If the config files are rarely written to, make an occasional copy of them to another device.

If they are often written to, consider a small UPS to prevent unintended power loss.
Title: Re: SignalK on picore 13,1
Post by: Paul_123 on April 04, 2023, 12:51:27 PM
If an application requires persistent storage, then I typically like to put that data on a third partition....that way if something does cause file system corruption it doesn't' prevent the system from booting.
Title: Re: SignalK on picore 13,1
Post by: stelian on April 04, 2023, 01:58:22 PM
Putting the .signalk (configuration files) on the persistent partition makes sense. Putting all the modules does not. Neither loading all into RAM.

What needs to be done is package individual signalk modules into individual .tcz files, each of them putting its files into /usr/local/lib/node_modules... something. Same as it is done with python site-packages modules for example.

But, as I said, dependency search is node.js is broken by the usage of symbolic links. This is the thing that needs to be addressed, by modifying node.js code. As I never touched node.js I don't know if this is obvious, or hard.

As a quick solution, I would have gone the same path as kagouraki: "I will make a tcz with node.js AND the all the modules required for signalk."
Title: Re: SignalK on picore 13,1
Post by: kagouraki on April 04, 2023, 04:21:04 PM
Progress made ! I have the node.js and signalK up and running as a single tcz. I dont have GUI right now because i dont need it. I have barebones piCore 13.1 plus wifi firmware, network manager, nano, htop, openssh and 88mb of ram usage on boot. When i

tce-load -i NodePlusSignalK.tcz

I get 200 mb ram usage and 230 mb free. Total ram on pizero2 is 430 mb.
Here is to be noted that signalK is on defaults. Nothing further installed.

Why is my tcz taking 120 mb of ram ?

As i have understand from the tinycorebook the tcz procedure is like mounting an .iso with daemon tools.
You see the files but you wont "load" then until sou execute them. Am i wrong ?

I am trying to have as small footprint as i can get...
Title: Re: SignalK on picore 13,1
Post by: Rich on April 04, 2023, 04:55:53 PM
Hi kagouraki
Do you have any  copy2fs  files in your  tce  directory?
Title: Re: SignalK on picore 13,1
Post by: kagouraki on April 04, 2023, 05:05:29 PM
No, i am not.
Title: Re: SignalK on picore 13,1
Post by: curaga on April 05, 2023, 02:19:16 AM
It may be just cache. For accurate measurements do "sudo cache-clear; free -m". (the +-cache column counts both droppable caches and tmpfs files, so it's not the same).

That said, running huge & bloated stuff like node.js on limited hardware is not ideal.
Title: Re: SignalK on picore 13,1
Post by: kagouraki on April 05, 2023, 02:56:06 AM
I will test and report back in the afternoon. I am at work now. Goodmornig to everyone !
Title: Re: SignalK on picore 13,1
Post by: Juanito on April 05, 2023, 03:16:11 AM
You could also use wpa_supplicant rather than networkmanager for wifi.
Title: Re: SignalK on picore 13,1
Post by: kagouraki on April 05, 2023, 03:40:14 AM
In my next project which is the continue of this one i want to build an MFD like the raymarine i70 or garmin gmi20. I want to use kip from signalk but i want from kip to manage the wifi through a custom settings page. Nmcli is very straight forword and i have already made the scripts for wifi requesting, managing etc. Is wpa_suplicant also doable and straightforward as nmcli ? I want static and dhcp configurations
Title: Re: SignalK on picore 13,1
Post by: Juanito on April 05, 2023, 03:56:42 AM
I suggested wpa_supplicant because it has fewer dependencies than networkmanager.
Title: Re: SignalK on picore 13,1
Post by: kagouraki on April 05, 2023, 04:05:32 AM
Yes, i understand why are you sugesting this and this is what i tried at first but then i could figure out how to setup everything(station or hotspot, dhcp or static etc) so i gave up and used networkmanager which is WAY more userfriendly
Title: Re: SignalK on picore 13,1
Post by: Paul_123 on April 05, 2023, 10:29:38 AM
zram is enabled by default, which turns some memory into a compressed swap space.   A standard swap partition is not enabled by default, but can help if you are pushing the memory limits.

which is WAY more userfriendly

This normally means resource heavy bloated software.
Title: Re: SignalK on picore 13,1
Post by: patrikg on April 06, 2023, 08:10:20 AM
The tinycorebook is AWESOME by the way. Very good and clear writing!

Yes you are correct, and you may also go to the great wiki for more great stuff to read, as a newbie or nerd.
Here the link:
https://wiki.tinycorelinux.net/doku.php?id=welcome

Happy Hacking
Title: Re: SignalK on picore 13,1
Post by: kagouraki on April 07, 2023, 10:22:19 AM
Hello i am back !

1)
So i sorted the thing with the RAM. I have in my sdCard a 2GB linux swap partition and i will use this partition as swap. So i used the bootcode nozswap.
The pizero 2 is advertised to have 512mb ram but in htop only 428mb are available when i boot piCore. Is there a way to use the full 512mb ?

2)
Here you can find the tcz i made with node.js and signalK https://drive.google.com/file/d/1Y6fTLX_1fDAXSk1UBbeAzUPf2-zhNzzV/view?usp=sharing
If i boot without loading my tcz, i have a 60mb Ram usage (all my required tcz for wifi, networkmanager, nano, openssh, htop are loaded on boot)
Now if i tce-load -i NodePlusSignalK.tcz after everything loads i have 183mb or RAM usage.
Is this normal ? The loop mounted tcz takes actually space in my system? Aren't tcz's the way to go if you dont want the size intensive stuff on your RAM?

Title: Re: SignalK on picore 13,1
Post by: Paul_123 on April 07, 2023, 10:40:43 AM
The kernel, rpi firmware, and the system ram disk (initrd) take space.  loop mounted tcz do use some space for symlinks from the ram disk to the loop mounted extension and the mount itself uses memory, even though the contents of the mount are sill in the tcz.

You are loading extremely bloated packages with extra dependencies.   type mount at the command prompt, and look at all of the extensions that are loop mounted.

Why do you need htop.  busybox provides top.   Why do you need nano, busybox provides "vi".   I assume you are doing that because it is "easy" for you, but that comes with a sacrifice of memory usage.