Start Edit
I'm connecting the Pi directly to my PC with an ethernet cable.
End Edit
I'm trying to share a folder that's on a Raspberry Pi (running Jessie Lite) with my laptop (running Windows 7) so I can use Node.js to write a simple text file to it.
I set up samba on the Pi in the following way:
$ sudo apt-get install samba samba-common-bin
$ sudo vi /etc/samba/smb.conf
and in smb.conf
made sure the following lines were like so:
workgroup = WORKGROUP
wins support = yes
and added the directory I want to share:
[pihome]
comment= LED SW UI Home
path=/home/ledswui
browseable=yes
writeable=yes
only guest=yes
create mask=0777
directory mask=0777
public=yes
Then I did:
$ sudo smbpasswd -a pi
and typed in a password (although I'm setting public = yes
, so that's probably redundant, but why not?).
Then I made the directory I want to share:
$ cd /home
$ sudo mkdir ledswui/
$ sudo chmod 777 ledswui/
I'm just using this individually for a fun project so I don't really mind setting permissions to 777.
With my eth0
settings like so in /etc/network/interfaces
:
auto eth0
iface eth0 inet dhcp
I reboot the Pi, login, then connect with an ethernet cord to my Windows 7 machine. I can see the Pi (\\RASPBERRYPI
) under Networks > Computers. I also see it pop up when I type net view
into command prompt. However, after a few seconds I notice that, in the "Network and Connections" dialog, the "Local Area Connection" adapter drops the connection. I have to disable and re-enable "Local Area Connection" again. After being re-enabled, it says "Identifying..." and I again see the Pi on the "Networks" tab under "Computers", next to my PC. But then "Local Area Connection" switches to "Unidentified network" and the Pi disappears. Process repeats. Because of all this I can't access the Pi to write files to it.
For example, in Node.js, I try:
const exec = require('child_process').exec;
exec('net view', function(error, stdout, stderr) {
if (stdout.indexOf('RASPBERRYPI') > -1) {
saveFile("//RASPBERRYPI/test.txt", "hi");
}
if (error !== null) {
console.log(error);
}
});
and get:
Uncaught Error: UNKNOWN: unknown error, open '\\RASPBERRYPI\test.txt\'
Even though the Pi's shared folder shows up for a few seconds (during which I call the above Node.js script), I still get that error.
Anyone know why Windows 7 is dropping the Pi's shared folder? Is that what's causing Node.js to have issues writing files to the Pi, even though the Pi appears to connect for a brief moment?