Win a copy of Machine Learning Systems: Designs that scale this week in the Scala forum
or Xamarin in Action: Creating native cross-platform mobile apps in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Can't read JSON file from network  RSS feed

 
Ranch Hand
Posts: 35
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am on a mac and trying to read a json file located on a network connected raspberry pi. The pi and the file are visible in Finder and can also be reached via ssh. But when I try to read the file from Java the error message is /nsp/pi/sprinkler/schedule.json (No such file or directory)"

Here is the Code:
 
Ranch Hand
Posts: 506
12
Java Notepad
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know pi programming. But, try creating a java.net.URL with the file path and then use URL's openStream() method to get an InputStream and read the file.
 
Mike Gauthier
Ranch Hand
Posts: 35
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We had visitors for a few days so now I am back to this problem.

I tried to change to a url type read but couldn't get that to work either. I tried prepending:
http:
file:
ftp:
and even //nsp.local/pi/sprinkler/schedule.json

but all these resulted in timeout or no protocol errors.

The has to be some way of reading the pi file over the network, but I have not found it.

 
Saloon Keeper
Posts: 1929
239
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What protocol is the PI using to share the files/file-system: SAMBA/SMB/CIFS, NFS, HTTP/WebDAV, FTP, etc?
 
Ron McLeod
Saloon Keeper
Posts: 1929
239
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the operating system running on the PI device?
 
Mike Gauthier
Ranch Hand
Posts: 35
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The pi is running samba under the latest stretch (debian) operating system.
The Mac Finder can see the pi, drill down, and open the schedule.json file so there must be a way to do this. I just haven't found it yet.
I'll be happy to supply any other information that might help.
 
Mike Gauthier
Ranch Hand
Posts: 35
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In case it helps, this is the samba configuration file

[global]
workgroup = WORKGROUP
netbios name = NSP
realm = NSP
oplocks = no
kernel oplocks = no
max protocol = NT1
dns proxy = no
log file = /var/log/samba/log.%m
max log size = 1000
syslog = 0

panic action = /usr/share/samba/panic-action %d
server role = standalone server
passdb backend = tdbsam
obey pam restrictions = yes
unix password sync = yes
passwd program = /usr/bin/passwd %u
passwd chat = *Enter\snew\s*\spassword:* %n\n *Retype\snew\s*\spassword:* %n\n *password\supdated\ssuccessfully* .
pam password change = yes
map to guest = bad user
usershare allow guests = yes

[homes]
comment = Home Directories
browseable = no
read only = yes
create mask = 0700
directory mask = 0700
valid users = %S

[printers]
comment = All Printers
browseable = no
path = /var/spool/samba
printable = yes
guest ok = no
read only = yes
create mask = 0700

[print$]
comment = Printer Drivers
path = /var/lib/samba/printers
browseable = yes
read only = yes
guest ok = no

[pi]
path = /home/pi
valid users = pi
read only = no

[Raspi]
path = /
valid users = pi
read only = no

 
Ron McLeod
Saloon Keeper
Posts: 1929
239
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to specify a UNC path in the form \\computer\folders\file

Either of these should work:
    "\\\\nsp\\pi\\sprinkler\\schedule.json"
    "\\\\nsp/pi/sprinkler/schedule.json"
 
Mike Gauthier
Ranch Hand
Posts: 35
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i went back to the original code but changed the file name to
"\\\\nsp\\pi\\sprinkler\\schedule.json" and then I tried "\\\\nsp/pi/sprinkler/schedule.json"
I also tried both of the above with nsp.local instead of just nsp.

All cases result in file not found error.

run:
\\nsp\pi\sprinkler\schedule.json (No such file or directory)
BUILD SUCCESSFUL (total time: 8 seconds)

 
Ron McLeod
Saloon Keeper
Posts: 1929
239
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Mike Gauthier wrote:run:
\\nsp\pi\sprinkler\schedule.json (No such file or directory)
BUILD SUCCESSFUL (total time: 8 seconds)


Hmm ... I would have expected that to work - must be a MAC thing.

One last suggestion is to try: "file:///nsp/pi/sprinkler/schedule.json"

If that doesn't work, you could looking at the JCIFS library.
 
Mike Gauthier
Ranch Hand
Posts: 35
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, already tried that.

On the jcifs subject, I stumbled upon that and at first blush it looks to me that Mac must mount the shared resource first and then read it maybe with smb.

Definitely looks like a Mac thing here so I am headed over to that forum.

Thanks for assisting here.
 
Mike Gauthier
Ranch Hand
Posts: 35
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
After a good deal of research and experimenting, I was able to read the shared file using jcifs and SmbFileInputStream.

Here is the code I ended up with:
 
Ron McLeod
Saloon Keeper
Posts: 1929
239
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Great - have a cow for figuring it out and for reporting back with your solution 

 
Die Fledermaus does not fear such a tiny ad:
Rocket Oven Kickstarter - from the trailboss
https://coderanch.com/t/695773/Rocket-Oven-Kickstarter-trailboss
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!