In my application I want to turn on certain GPIO pins that are on the Raspberry Pi from my PC's C++ script. My PC is currently running on Windows 10 and my Raspberry Pi on Raspbian.
The general idea I had was to write python scripts on the Raspberry Pi itself and run them somehow from my PC when needed. Although, I am not sure how to do this or if it's possible in C++. I know I can ssh into my Raspberry Pi and run scripts manually but the idea of this application is automation. I am able to connect my PC to the Raspberry Pi either by Ethernet or USB cables.
I have seen USB to GPIO modules that would probably work better although for now I am stuck with my Raspberry Pi.
Any knowledge or resources on how to do this is greatly appreciated.
Maybe be what you need is a client and server program to control your GPIO pins. Check out my client and server programs and dont forget to read the answer and its comments and make the change accordingly for the program to work.(My progams motives is to control an LED through the client and server programs , similar to controlling the GPIO pins )
Program getting stuck at accept statement
PS: I hope you are having some knowledge about Threading and sockets.
This answer will be pretty broad so feel free to leave a comment with questions.
The first things that are needed, are the python scripts on the Pi which control the GPIOs in however fashion we like. From then on we are able to execute these commands via ssh from almost any device. Although, we want this process to be automated. In other words, the user doesn't have to enter credentials to ssh into the Pi but rather have the program automatically do so.
Luckily, this library allows us to do so. -> https://www.libssh.org/
There is nice documentation as to how to create ssh sessions and executing the commands that we want. So I won't go into much detail. Although I will comment on one procedure that the documentation recommends but gave me a problem.
When authenticating the user via password we use method ssh_userauth_password(ssh_session session, const char* username, const char* password). The documentation suggests setting the second parameter to NULL. Which was what was giving me the problem.
Simply change this to the login name you use when you normally ssh into the Raspberry Pi. For most the default name is "pi".
ssh_userauth_password(my_ssh_session, "pi", password);
Related
How could I launch code.py that only exists on a raspberry, from a python command line on a computer connected by an Ethernet cable. Machine A and the raspberry are connected to each other by a simple ethernet cable, and none of those two endpoints are connected to the internet. They only have the latest version of python installed and can't have anything more installed on them.
It looks like subprocess.Popen() could be a way to tackle it. But with the little knowledge I have I can't understand and know for sure if using this method is suitable !
Thank you for your time :)
I would like to build a camera trigger for my phone by simulating a BLE keyboard that sends the Volume Up key to the phone connected by Bluetooth. I want this because I want to trigger the native Camera app, and not an embedded camera view.
I'm agnostic about technology used but ideally for simplicity I'd like it to be a command line utility in my Macbook, with something like Go or Node.js.
I've looked into Noble for Node.js, which doesn't seem to be oriented at emitting, and found projects for arduino, and found a couple of StackOverflow questions asking the same, but nothing definitive yet.
Apparently the Bleno project for Node.js could be better suited, but apparently it's very outdated.
Would someone please point me in the right direction?
Thank you
Edit
I was able to use Bleno to emit 0xEA and 0xE9 (Volume Up and Volume Down apparently), and using the LightBlue app I'm able to inspect that receive those messages, however, connecting to the MacBook through the phone's bluetooth does not increase/decrease volume.
Edit
Found this outdated project written in Swift 3 for reference
Edit Apparently the pybluez project looks like it could be a good option
You should be able to use the terminal for that. Eg. in Windows, you can start the camera app using start microsoft.windows:camera
Something similar should be available even in Mac. Try that out. Otherwise, go to the root directory where the camera app is stored. And then trigger that from code.
You need to create a Bluetooth HID (or HID over GATT) peripheral that your phone can connect to and will receive the key commands from.
There is a project here that did it with a Raspberry Pi:
https://gist.github.com/ukBaz/a47e71e7b87fbc851b27cde7d1c0fcf0#gistcomment-2997623
Unfornately the underlaying Bluetooth library will not move across to your Mac Book.
The HID protocol is documented here: https://github.com/jpbrucker/BLE_HID/blob/master/doc/HID.md
In summary, I think what your saying is that you want to make an cli application which is on your laptop/desktop connect to your phone via Bluetooth and simulate a volume key from your laptop/desktop keyboard.
Android:
To do this you will need:
Python 3.5 or above
PyBluez
Keyboard(Python module/API)
Android Studio
Java Development Kit 8 (preferably 11 or 14)
Android BLE
So in order to do this I would create a cli application with python3 and I would record the key presses on the laptop/desktop machine by using the keyboard module this then gets transmitted(bluetooth) via the PyBluez module to your phone. Your phone then accepts the bluetooth data via Android BLE and then simulates the volume button press.
DISCLAIMER:
This only works when the phone is already paired to your pc and only work on android phones 4.4.4 and above.
Some Links That Could Help You:
Bluetooth lib for python 3 ,
detect key press in python? ,
Create a socket for 4.0 bluetooth transmission
IOS:
To do this you will need:
Python 3.5 or above
PyBluez
Keyboard(Python module/API)
XCode
Swift
Core Bluetooth Module
So in order to do this I would create a cli application with python3 and I would record the key presses on the laptop/desktop machine by using the keyboard module this then gets transmitted(bluetooth) via the PyBluez module to your phone. Your phone then accepts the bluetooth data via Core Blutooth Module in swift and then simulates the volume button press.
DISCLAIMER:
The phone and laptop/desktop must be paired before it runs this might sound obvious but some people might ignore this.
Some Links That Could Help You:
iOS use the volume buttons as input ,
https://developer.apple.com/documentation/corebluetooth/transferring_data_between_bluetooth_low_energy_devices
I'm using PyZMQ for IPC (over TCP) on Windows 10, as part of an automated updater. I have noticed that on some computers, a firewall prompt appears to select if it can use public or private internet, despite the fact that it makes no connections to the internet - only to localhost.
This PyInstaller-packaged script is launched by a user-land script.
So:
Script launches my PyInstaller-packaged script->
Script uses pyzmq strictly to connect to localhost->
Windows prompts how it should be allowed through firewall
This prompt doesn't stop the program, but I don't want users to see that and wonder what virus they might have.
This is the code that supposedly triggers it:
sckt = self.zmq_context.socket(zmq.REQ)
sckt.connect('tcp://localhost:%s' % updater_shared_port)
Is there anything I can do to stop that pop-up from Windows Firewall?
Thanks!
Yes, there is something:
may implement the connection by some other than tcp:// transport class.
ZeroMQ can help you build your ideas via smart transports{ ipc:// | inproc:// | vmci:// } given you need not assemble/disassemble the full-height-L3-ISO-OSI stack to reach a counterparty, hosted on the same localhost.
The firewall could be configured to allow your programmes to run unhindered. That might be a nuissance to do by hand. There's probably a way to have an installer configure the firewall appropriately, but that'll be a ton of work to set up.
On the off-chance that it's the binding end that's the causing the pop up (not the connecting end as you suggest), apparently one can bind a zmq socket to a particular interface. This is done with a connection string such as zmq_bind(socket, "tcp://127.0.0.1:5555"); This will clamp the socket to the loopback, which may well not trouble the firewall at all. zmq_bind(socket, "tcp://*:5555) will open a socket on all interfaces, including any Internet facing interfaces, which should certainly grab the attention of the firewall. If you've not already tried that, might be worth a quick go.
I have for the first time installed the OpenCV module for python3, and i am trying to find the best way to use OpenCV with a connected MCU (Microcontroller Unit) such as Arduino, or to control I/O of a Raspberry Pi 3..
In the past:
I have written a python GUI with tkinter and programmed the MCU to be controlled via serial communication. The MCU receives a string of data that is being written to the port. When I click a button in my python GUI, it then executes the programmed functions.
I have then also turned the host computer into a web server, and have written a front end using HTML/CSS/JavaScript, more specifically using AJAX, which then makes a call to a PHP back end script that in turn executes a python script(could use bash script), which is sending commands to a MCU.
(Yes it's secure. And mildly confusing to most people.)
In saying that, I have had some time to have a play around with some examples of OpenCV, but it has been quite difficult finding documentation that is clear and gives me an idea of how to use the module within robotics/mechatronics and industrial automation projects. All the uses I have seen have been mentioned using Arduino and processing.
So my question after explaining this is, how do I start using OpenCV object/face recognition and have it send commands serially?
Is Arduino processing the only option or can this be achieved with just the python modules and the code embedded on the MCU?
Thank you in advance to anyone who may be able to give me some guidance.
I am using Python 2.7 and wifi library (https://wifi.readthedocs.org/en/latest/) on a Raspberry Pi. I have managed to install wifi library using:
sudo pip install wifi
on the terminal. The library seems to work but I can't figure out the way to connect to a wifi using a password. The documentation on the website is a bit difficult to understand, especially if you are a Python noob like me. I used this:
>>> from wifi import Cell, Scheme
>>> Cell.all('wlan0')
and I got all the wifi networks available and also the one I want to connect to called test1. So I am sure that the library works. I followed the steps on the website but got a permission denied error at:
>>> scheme.save()
Also, before that there was this command:
>>> scheme = Scheme.for_cell('wlan0', 'home', cell)
Does anyone know what that 'home' refer to? Is it the SSID name? Can anyone help me connect to a wifi called test1 whose password is passwordtest1? Is there any easier way to connect to wifi through terminal so as not to use Python?. Thanks in advance.
After some research, I didn't find a way to connect easily to a wifi using Python on a Raspberry Pi. So I solved my problem by using the wifi command on the Terminal:
sudo wifi connect --ad-hoc SSID_Name
Which automatically asks me for an input: passkey> .Where you can actually type the password, press enter and after that it automatically connects to the wifi. After that I can run my Python script which needs a connection to the internet in order to run. The wifi command is preferable to other terminal commands when it comes to my problem cause it needs less time to connect to a wifi manually. For example it is preferable to the process which uses this terminal command:
sudo nano /etc/network/interfaces
I hope this helps everyone who has the same problem.