Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot install wiring-pi because of libwiringpi cloning failed #31

Closed
hyourinseta opened this issue Oct 13, 2015 · 11 comments
Closed

Cannot install wiring-pi because of libwiringpi cloning failed #31

hyourinseta opened this issue Oct 13, 2015 · 11 comments
Labels

Comments

@hyourinseta
Copy link

When i tried to install wiring pi using npm, it failed and shown below error

# npm install wiring-pi

\
> wiring-pi@2.1.0 install /root/.node-red/node_modules/wiring-pi
> /bin/bash ./install.sh

Cloning libWiringPi ... failed.

================================================================================
FATAL: Cloning libWiringPi failed.
Please check install.log and fix any problems. If you're still stuck,
then please open a new issue then post all the output and as many details as you can to
  https://github.com/eugeneware/wiring-pi/issues
================================================================================

npm WARN This failure might be due to the use of legacy binary "node"
npm WARN For further explanations, please read
/usr/share/doc/nodejs/README.Debian

npm ERR! wiring-pi@2.1.0 install: `/bin/bash ./install.sh`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the wiring-pi@2.1.0 install script.
npm ERR! This is most likely a problem with the wiring-pi package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     /bin/bash ./install.sh
npm ERR! You can get their info via:
npm ERR!     npm owner ls wiring-pi
npm ERR! There is likely additional logging output above.

npm ERR! System Linux 4.1.7+
npm ERR! command "/usr/bin/nodejs" "/usr/bin/npm" "install" "wiring-pi"
npm ERR! cwd /root/.node-red
npm ERR! node -v v0.10.29
npm ERR! npm -v 1.4.21
npm ERR! code ELIFECYCLE
npm ERR! 
npm ERR! Additional logging details can be found in:
npm ERR!     /root/.node-red/npm-debug.log
npm ERR! not ok code 0

The error tells me that I have to tell the wiring-pi author. Can you help me?

@nekuz0r
Copy link
Collaborator

nekuz0r commented Oct 19, 2015

Can you post the content of the file install.log in node_modules/wiring-pi ?

@nekuz0r
Copy link
Collaborator

nekuz0r commented Oct 23, 2015

Cannot reproduce, maybe you had issue with your internet connection

@erikkallen
Copy link

had the same thing turned out git was not installed
sudo apt-get install git-core fixed it

@dtrouillet
Copy link

I had the same problem and now it is solved thanks to you @erikkallen 👍

@IgorGanapolsky
Copy link

@erikkallen Is there a solution for this on a Mac?

@erikkallen
Copy link

I think git should be on your system, you can check this by typing git in your terminal, if it is not available you could try installing the xcode-commandline tools as described here http://railsapps.github.io/xcode-command-line-tools.html if that does not work I wouldn't know

@caiusCitiriga
Copy link

any news for mac?

@tillepille
Copy link

@IgorGanapolsky and @caiusCitiriga , this is not supposed to work on a Mac since the required hardware isn't there.. Or did i miss anything?

@caiusCitiriga
Copy link

@tillepille ouch, it's how I was supposing.... So, here's what I'm trying to get. I'm developing my core scripts for the raspi on a Mac, using typescript. So, the @types gets successfully installed, the package though is not. Is there a workaround where I can "mock this whole thing?" I wouldn't like to switch lib, or machine. In fact, the same code ported on the raspi, and ran npm i works like a charm (of course)

@tillepille
Copy link

Unfortunately I don't have a good solution for you...
The only thing that comes to my mind is writing your own dummy lib, to use on the mac, but this seems really needlessly complicated.

My workflow was developing on Mac with Atom and then pushing to a git, from wich i pull on the raspi to run and test the code.

@caiusCitiriga
Copy link

@tillepille Well, I appreciate your support anyways :)

Workaround

If it can be useful to someone, I've found a workaround. It's ugly, not very practical without setting some scripts in the package, but for me, after some configuration, it turned out to be very useful.

So here's the stuff that you need:

  • Virtualbox (i know, it sounds crazy)
  • A Ubuntu server distro (server because it comes without the GUI by default)
  • A Raspberry Pi
  • A local network
  • A folder where you store all of your code on your mac. Eg: ~/Code

Now, the main problem for us mac folks, is that we cannot build wiringPi, but a ubuntu machine can. So the solution:

  • Link togheter the Mac Code folder with the Ubuntu VM, using the VirtualBox shared folder
  • The ubuntu VM starts a watcher for file changes (I use Typescript to build the dist)
  • On the VM you will only install through npm the wiringpi-node package.
  • The next npm install will be performed from mac
  • With a SSH connection through the machines, and a bit of npm scripts, you can automate the whole build and deploy process

The setup step by step

[1] Get the VM ready and set

Install your Ubuntu distro on Virtualbox creating a new VM.
For the configuration I've chosen:

  • 2 cores
  • 2048 MB of RAM
  • 16 MB of VRAM
  • Bridged connection
  • 10GB of virtual hard drive

Note: the bridged connection is the most important part.
This one allows your VM to be seen on your local network as a physical machine, and shares the same network with your host.

Create your VM, attach to the virtual CDRom unit the ISO of your distro and boot it up.
Follow the step to install the distro as normal.

Note: during the install, when the packages selection comes up, remember to check the SSH. Otherwise you'll have to apt-get install it.

Once the installation is done, log into the machine and assign a static IP.
Mine was:

  • 192.168.1.12 for the VM
  • 192.168.1.2 for the Mac
  • 192.168.1.10 for the Pi

In the VM terminal type:

sudo nano /etc/network/interfaces

This will open up the interfaces configuration file. Here, add your network configuration.
Mine looks like this:

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

source /etc/network/interfaces.d/*

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto enp0s3
iface enp0s3 inet static
    address 192.168.1.12
    netmask 255.255.255.0
    network 192.168.1.1
    broadcast 192.168.1.255
    gateway 192.168.1.1
    dns-nameservers 8.8.8.8 8.8.4.4

Press Ctrl + X and save your changes.
Reboot the system with:

sudo reboot

You should reboot your network interfaces with the ifup and ifdown commands, but this is a bullet proof method, and as long as we are on a VM, the boot time should be quite faster.

Be aware that I'm using ubuntu 16.04 LTS. In which the network names were slightly changed. In this case, the previously called eth0 which was the primary network adapter (AKA Ethernet), now it's called enp0s3. In my opinion? eth0 was so damn intuitive!

Now on your host machine (Mac), you have to get an SSH connection to the VM, you don't want to use the Virtual Box's window every time.

So, in order to do that, open your terminal and type:

ssh <your-username>@<host-ip>

where your username will be the username you use to log in the VM and the host-ip is the static ip we've set earlier.

You should be prompted for the password.
At this point the connection is successfully set up. Now we need one more thing, the ssh shared passphare. In order to automatically login without typing the password every time.

To do so, close the ssh session, and on your mac terminal type the following commands:

ssh-keygen

This will prompt you with a series of questions, just press ENTER to each one, till you reach something like this:

Generating public/private rsa key pair.
Enter file in which to save the key (/home/demo/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/demo/.ssh/id_rsa.
Your public key has been saved in /home/demo/.ssh/id_rsa.pub.
The key fingerprint is:
4a:dd:0a:c6:35:4e:3f:ed:27:38:8c:74:44:4d:93:67 demo@a
The key's randomart image is:
+--[ RSA 2048]----+
|          .oo.   |
|         .  o.E  |
|        + .  o   |
|     . = = .     |
|      = S = .    |
|     o + = +     |
|      . o + o .  |
|           . o   |
|                 |
+-----------------+

Now we'll use ssh-copy-id to copy the generated key to the VM.
Note: Most likely you won't have ssh-copy-id on your mac. That's an easy fix, just type:

brew install ssh-copy-id

Once installed, run:

ssh-copy-id <your-username>@<vm-ip-address>

Once again, the useranme you use to login and the VM address.
You should see something like this:

The authenticity of host '198.51.100.0 (198.51.100.0)' can't be established.
RSA key fingerprint is b1:2d:33:67:ce:35:4d:5f:f3:a8:cd:c0:c4:48:86:12.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '198.51.100.0' (RSA) to the list of known hosts.

Type your password and that's all!
Now try to login into your VM with this command:

ssh <your-username>@<vm-ip-address>

If everything went well, you should be able to login without the password.

[2] Configure the VM for node develpment

Same old routine:

  • add PPAs
  • install node 9.x
  • install build essentials
  • install git-core (this will be needed for wiringPi)
$ sudo apt-get update
$ cd ~
$ curl -sL https://deb.nodesource.com/setup_9.x -o nodesource_setup.sh
$ sudo bash nodesource_setup.sh
$ sudo apt-get install nodejs
$ sudo apt-get install build-essential
$ sudo apt-get install git-core

You should have now all the needed packages installed. Give it a check firing:

$ node -v
$ npm --version
$ git -v

[3] Link the two machines workspaces

You will find this feature under the machine settings in VirtualBox. Pick a folder that you will use on your mac to develop your project, and share it with the VM.

Login into the VM, you will find the folder at this location, assuming that is called Code

cd /media/sf_Code

Once you've cd into it, init your npm project in a new folder. (from mac, or VM, it doesn't matter)

$ npm i typescript
$ npm i wiringpi-node

The structure that is use is to separate the src folder and the dist folder. And put all my core code inside the src

Init your tsconfig.json file:

node_modules/.bin/tsc --init

Tweak your tsconfig file as you like.

[4] Start the watcher

The watcher can be started with this command:

node_modules/.bin/tsc --watch

Note: the watcher must be launched from the VM, in the same folder shared with the mac. Because you'll code on Mac. So in our case will be: /media/sf_Code/main

[4] The deploy

Now suppose that we have a index.ts file in the src folder, this would be enough to have something to deploy.

So here's what we will be doing:

  • Remove the dist folder (to be sure that we have the last build)
  • Build again
  • Copy the content of the dist folder to the raspberry with scp
  • Run the code on the raspberry
$ rm -rf dist
$ node_modules/.bin/tsc
$ scp -r dist/ <your-raspi-username>@<your-raspi-ip>:<the-deploy-directory>
$ ssh <your-raspi-username>@<your-raspi-ip>
$ cd <the-deploy-directory>
$ sudo node index.js

The in my case was: /home/maxine/core
You should be all ready and set at this point.

Pro tip: scripts and @types

To make all this process less painful and more automated I've created some scripts that will handle all this for me. The only thing I need to trigger in order to deploy, is a npm script.

Here's the npm package scripts:

"scripts": {
        "build": "tsc",
        "build-dev": "tsc --watch",
        "transfer-nobuild": "sh ./scripts/trans-no-build.sh"
    },

Here's the content of the transfer-nobuild.sh:

This is a version of the script that uses the last builded dist from the tsc compiler. In my case the out-tsc folder. This allows me to keep the watcher running while I develop

# prepare a dist folder, remove it if its exists first
rm -rf dist;
mkdir dist;

# copy all the contents from the out-tsc to the dist
cp -r ./out-tsc dist;

# and copy the configs too
cp -r ./src/configs dist;

# Remove the previous zip if any
rm -rf core.zip;

# Create a fresh zip, skipping node_modules folder and .git folder
zip -r core.zip . -x ./node_modules/**\* ./.git/**\*;

# Copy the zip via SSH to the raspi
scp core.zip maxine@192.168.1.10:/home/maxine;

# Login via SSH on the raspi and launch the following commands:
# - Go to the home folder
# - Unzip the previously received zip file into a folder called core
# - Cd into core
# - NPM I
# - When all done, echo a message and close connection
ssh maxine@192.168.1.10 'cd /home/maxine/; unzip -o core.zip -d core; cd core; npm i; echo; echo ========== TRANSFER COMPLETED ==========; exit;';

wiringpi-node @types

Unfortunately I've found only the @types/wiring-pi. But for what I've learned from the documentation of the library, the methods are the same.
So what I've did, was install the @types for wiring-pi (the old lib), inspect the declaration file, copy the content and transform it into a interface. I'll use that interface whenever I have to referr to wiringpi-node. If you want more infos about this, feel free to ask :)

That's all!

Hope it helps someone, and I apoligise for the lenght. If there's something not clear, please ask. If you can improve this somehow, feel free to do it.

Here's a working repository of a robot that I've built using this solution:
https://github.com/hugo-bot-org/core

Go further with the scripts usage

If you're a cool guy, you do most of your work from the terminal.
And if you use custom aliases and functions, you should seriously take a look at this:
https://www.npmjs.com/package/shell-profiler

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants