• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Can't read JSON file from network

 
Ranch Hand
Posts: 35
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:
 
Rancher
Posts: 517
15
Notepad Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Marshal
Posts: 4501
572
VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 4501
572
VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 4501
572
VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 4501
572
VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 4501
572
VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Great - have a cow for figuring it out and for reporting back with your solution  

 
Don't play dumb with me! But you can try this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic