Using python to copy files from/to raspberri pi - python

I'm writing a python script running on a NAS and picking up files from inside of a raspberry pi.
Didn't find any examples how to access raspberry pi.
Can somebody give advice?
Thank you

Please do more research.
The easiest way is probably to run Secure Copy (SCP) over SSH from python on NAS. See this thread
If you want to serve files to other clients (e.g. your laptop), consider running file server on RPI. Perhaps FTP: FTP on RPI tutorial
Otherwise you can implement HTTP like interface (REST API for example) and "get" files via HTTP. Don't skim on the security and access rights to your API.

Related

How to send data from Android/iOS app to a python script running on a raspberry pi using Bluetooth?

So me and my friend are working on this project where a raspberry pi with certain sensors collects some data and outputs it.
Now, we want certain parameters to be passed on runtime. So we were thinking of creating a react-native app which could connect with the Pi using Bluetooth. Once connected, it could then send the arguments over Bluetooth.
The python script would then intercept these arguments and then run its program and then send its output back to the app.
While searching for libraries to help me with this, I came across this library: https://github.com/Polidea/react-native-ble-plx
While going through the documentation, I came across https://github.com/Polidea/react-native-ble-plx/wiki/Characteristic-Writing, which seems to be the method used for writing some data and sending it.
In Bluetooth terms, what exactly are these services and characteristics and do I have to create my own service and characteristic while working on my project? Or can I write to any existing characteristic so that the python script can read that?
If I have wrongly understood certain concepts, please correct me. Also if there are any better ways to architect this approach please let me know
Currently, there is no official Expo Bluetooth API. I looked up the same library you are looking at and I find it a little complicated.
I found this link https://askubuntu.com/questions/838697/share-files-between-2-computers-via-bluetooth-from-terminal, where you could open up one terminal and use Bluetoothctl to connect to a specific device. Now, open up another terminal and use the bluetooth-sendto --device= MAC:ADDRESS (read that link) to send the file from Raspberry Pi to a phone (I tested on Android and it worked).
You could also send data from the phone to Raspberry Pi. Again, check out that link.

Script that can automatically download new data from the server to my local backup

I have an application running on linux server and I need to create a local backup of it's data.
However, new data is being added to the application after every hour and I want to sync my local backup data with server's data.
I want to write a script (shell or python) that can automatically download new added data from the linux server to my local machine backup. But I am newbie to the linux envoirnment and don't know how to write shell script to achieve this.
What is the better way of achieving this ? And what would be the script to do so ?
rsync -r fits in your use case and it's a single line command.
rsync -r source destination
or the options you need according to your specific case.
So, you don't need a python script for that, but you can still write it and let it use the command above.
Moreover, if you want the Python script to do it in an automatic way, you may check the event scheduler module.
This depends on where and how your data is stored on the Linux server, but you could write a network application which pushes the data to a client and the client saves the data on the local machine. You can use sockets for that.
If the data is available via aan http server and you know how to write RESTful APIs, you could use that as well and make a task run on your local machine every hour which calls the REST API and handles its (JSON) data. Keep in mind that you need to secure the API if the server is running online and not in the same LAN.
You could also write a small application which downloads the files every hour from the server over FTP (if you want to backup files stored on the system). You will need to know the exact path of the file(s) to do this though.
All solutions above are meant for Python programming. Using a shell script is possible, but a little more complicated. I would use Python for this kind of tasks, as you have a lot of network related libraries available (ftp, socket, http clients, simple http servers, WSGI libraries, etc.)

Synchronize python files between my development computer and my raspberry

I am writing a web python application with tornado framework on a raspberry pi.
What i actually do is to connect to my raspberry with ssh. I am writing my source code with vi, on the raspberry.
What i want to do is to write source code on my development computer but i do not know how to synchronize (transfer) this source code to raspberry.
It is possible to do that with ftp for example but i will have to do something manual.
I am looking for a system where i can press F5 on my IDE and this IDE will transfer modified source files. Do you know how can i do that ?
Thanks
Some IDEs like JetBrains PyCharm are supporting automatically file upload via ssh/scp/ftp.
Following a couple of bad experiences where I lost code which was only on my Pi's SD card, I now run WinSCP on my laptop, and edit files from Pi on my laptop, they open in Notepad++ and WinSCP automatically saves edits to Pi. And also I can use WinSCP folder sync feature to copy contents of SD card folder to my latop. Not perfect, but better what I was doing before
I have done this before using bitbucket as a standard repository and it is not too bad. If you set up cron scripts to git pull it's almost like continuous integration.

Run an OpenCV code on cloud machine [Azure]

I'm new to Azure but already have an 8-core machine running there with Ubuntu 12.04 and OpenCV properly installed. Also, i have an executable (C++) that receives an image as argument and prints the result on terminal (in case, if the object was found or not in the image).
So, what i need is to call this executable from my notebook to another C++ code. Basically speaking, I need to run a program on my notebook that call another one on Azure, passing an image as argument. I do not have much experience on this area, so all help is welcome. I heard i need to do this using Python, so how would it be ? And why ?
Thanks!!
You can do it in whatever language you want. The answer to make 2 machines "talk" via Internet is always sockets, can't be done other way.
If I were you I'll do it this way:
A program in Azure listens to a port (server) and when you want your notebook software to process an image, that software will connect to that port and send the image, then the server will process it using OpenCV and return the results to the client if needed so.
Other way can be that the server software queries a database or looks for a directory if there are new images each X seconds, and your client software will upload to that directory the image vía ftp or scp (more secure) or whatever. This way will be more difficult to retrieve the results.
Now, you need to know about language programming to develop this.

Python access webcam and audio input

Can a python script on my server access the webcam and audio input of a user as easily and as well as a Flash plugin can?
No: the "plugin" you mention runs in the user's browser, your server-side script (Python or otherwise) runs on the server, a completely different proposition. This relates to your other recent question about a server-side script accessing information on your desktop: your client machine tends to be very protected against possibly malicious server-side apps (never enough, but everybody keeps trying to make it more and more protected these days).
Server-side web scripts have no access to the client other than through requests. You need to use JavaScript, Java, or Flash to access devices that the browser (and consequently user) allows them to.
Not as easy, no. But there are extensions you can use. E.g.
A Win32 Python Extension for Accessing Video Devices (e.g. a USB WebCam, a TV-Card, ...)
http://videocapture.sourceforge.net/
Tutorial:
http://technobabbler.com/?p=22

Categories