Closed hyourinseta closed 8 years ago
Can you post the content of the file install.log
in node_modules/wiring-pi
?
Cannot reproduce, maybe you had issue with your internet connection
had the same thing turned out git was not installed
sudo apt-get install git-core
fixed it
I had the same problem and now it is solved thanks to you @erikkallen 👍
@erikkallen Is there a solution for this on a Mac?
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
any news for mac?
@IgorGanapolsky and @caiusCitiriga , this is not supposed to work on a Mac since the required hardware isn't there.. Or did i miss anything?
@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)
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.
@tillepille Well, I appreciate your support anyways :)
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:
Now, the main problem for us mac folks, is that we cannot build wiringPi, but a ubuntu machine can. So the solution:
Install your Ubuntu distro on Virtualbox creating a new VM. For the configuration I've chosen:
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:
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.
Same old routine:
$ 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
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.
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
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:
$ 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
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.
"scripts": {
"build": "tsc",
"build-dev": "tsc --watch",
"transfer-nobuild": "sh ./scripts/trans-no-build.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;';
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
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
When i tried to install wiring pi using npm, it failed and shown below error
The error tells me that I have to tell the wiring-pi author. Can you help me?