I have a project in my job.
The target is to prepare 14 SD cards for provisioning any Raspberry Pi 3.
So I have to found a solution to do it automatically and follow which SD card is ready to start and which one is complete.
I have the idea to build with a Python3 program and a tkinter interface because I know a little bit Python and not others languages...
The program should work like this :
List every Windows drives where SD card is mounted
Push a button in front of the letter of the SD card drive to start the provisioning.
The provisioning is all steps to make the SD cards bootable with an OS. So I have to pass some DISKPART commands or equivalent in Python I think, if you have any suggestions ?
Show a statut in front of each drive to follow if the drive is pending, working, complete, etc.
I have a huge interogation about this. My program has to refresh every informations. I mean the program should work in real time or not ? What is the best way to proceed ?
To be clear, I don't want someone building to me this program, I just want to have some good idea to implement.
Thank you
You can use this module to execute commands. For example:
import subprocess
completed = subprocess.run(['ls', '-1'])
print('returncode:', completed.returncode)
I can't help with the Python part, but if you have a WinAPI window with message handling (so the WindowProc thing), WM_DEVICECHANGE is the message, here are the actual event categories and RegisterDeviceNotification is how you subscribe to it. Complete (but C) MSDN example is here
While implementing it may require some work, viability itself depends on getting access/not getting access to the message queue (from Python). Based on this and this it seems to be possible, but I have no experience with it.
Related
Ive been looking the net dry to find a solution to this and i hope you can help me.
The main goal is that i have my client which interacts with Bybit API servers, their servers has a strict time window offset that i need to be in the bounds of and to do it so, i choose the method of resyncing my time since that worked, but more options might be available for this so feel free to let me know if you got other suggestions.
What i am looking for, is a way for me to tell the python script to resync my time.
It Could be something like w32tm /resync, however all that ive found out after alot of testing is that any deployed script even adminstrator shell commands can not execute w32tm commands unless a typed password is used, and even trying with a typing emulator to automaticly fake the typing, that didnt work.
So is there another way for me to force a /resync of time?
Im looking forward to hearing your answers and hopefully you can stear me in the right direction.
Best regards.
Mathias.
Easier install NPT software o the machines and it runs a service.
These are accurate.
As suggested you let one machine in the network sync time from Meinberg and the rest of the network gets their time form the NTP Server.
https://www.meinbergglobal.com/english/sw/ntp.htm
How can I send keystrokes and mouse movements to a specific running program through its PID. I've used both pywinauto and pynput, and they work great, but I want to send keys to a program that is not in focus. I found this question: How to I send keystroke to Linux process in Python by PID? but it never explains what filePath is a path to.
If you could help solve for this example, that would be great! I want to send the "d" key to an open Minecraft tab for 10 seconds, and then send the "a" key for the next 10 seconds and stop. I would need this to be able to run in the background, so it could not send the keys to the computer as a whole, but only to the Minecraft tab. I am on Windows 10 by the way.
Any help would be appreciated!
Pretty sure you won't be able to, at least not easily let me explain a little bit how all of this works.
Lets start with the hardware and os, the OS has certain functions to read the input you give the computer. This input goes into a "pipe", the OS is reading input, and putting into the pipe, on the other side of the pipe there may be an application running, or it may not. The OS typically manages this (which app to put on the pipe listening) by defining which app/window is active. Apps access this pipe with the API given by the OS, they read the input and decide on it.
The libraries you cited above, change the values of the keyboard and mouse, in other words, they make the OS read other values, not the real ones, then the OS puts them in the "pipe", and are read by the app that is listening on the pipe (the one active). Some apps have their own API's for this, but I would guess Minecraft doesn't. If they don't have an API, what can you do? well, as I said, nothing easy, first of all "hacking" the app, in other words change it to listen to some other input/output rather than the one given by the OS, (this would be you making your own API). The other one would be you changing the OS, which would also be extremely hard, but maybe a tiny bitty easier. It also depends on your OS, I think Microsoft does offer input injection api's
So, simple options, first, run a VM with a GUI and use pywinauto, pyautogui, etc. The other option would be if you can run it in the browser, do so, and use something like Selenium to automate the input.
Quick note, why does selenium works and the browser can read input in the background? Easy, it's not, it just executes the code it would execute if it would have read the input! javascript, cool isn't
With ahk you can do this with Python+AutoHotkey
pip install ahk
pip install "ahk[binary]"
from ahk import AHK
from ahk.window import Window
ahk = AHK()
win = Window.from_pid(ahk, pid='20366')
win.send('abc') # send keys directly to the window
Note that some programs may simply ignore inputs when they are not in focus. However, you can test this works in general even when not in focus by testing with a program like notepad
Full disclosure: I author the ahk library.
Problem
I want to secure my Raspberry pi in a special way.
I would like to start up raspberry pi without entering a password as pi user.
However, I want pi user to have zero privilege. Cant read a file, cant copy a file, simply nothing. And without access to root->'sudo su'. On the other hand when raspberry pi starts itself with pi user, I want backend process to be running as root. So to put it simply, I want it like in a zoo - two worlds but neither of them can enter the other. Clients can be present, see what process are running, see files in directories, but cant read it, copy, remove and etc. In the same time I want the backend to be untouched and running and writing files.
Reason:
I have raspberri pi product - customer get it home, when plug in power supply,RPi starts up and runs backend programs with root privilege and communicates with my desktop software.
But I dont want curious customer that plugs in HDMI and see my code. I also dont want him to take the SD card and extract the code.
I heard its possible to reverse engineer the code even if compiled. So I simply want the programs(python script) to be there but cannot be accessed in any way.
Is it possible to make such protection?
Thanks in advance
You may consider to use the following approach
Use at least two levels of hashing with MAC address and ARM chip serial number (via cat /proc/cpuinfo) with additional secret keys. Run your program only if the stored license key is the same as the result of doubly-hashed functions.
Optionally, you could rewrite critical part of your code in C, compile it statically, and remove all debug symbols. Call it using Python.
Quick optimization of your code using cython. Call its generated shared objects with a python caller script. Distribute only the shared objects and the python caller script.
This will prevent most people from reverse engineering your codes.
Just to be clear, "cant read a file" means "can't run a program", which means "can't see what process are running, see files in directories".
From your question, I don't understand why you'd even leave the pi user in place...
... runs backend programs with root privilege
Never a good idea - use service accounts instead.
But I dont want curious customer that plugs in HDMI and see my code.
Then don't enable the HDMI output, don't have a graphical desktop installed and disable the login prompt. You might want to look at a "minimal" / "lite" image.
Remember that the UART can present a login prompt, so make sure that's disabled too.
And as the config.txt and kernel need to be in cleartext in the boot partition they can be easily swapped... thus these steps are not going to be terribly effective.
I also dont want him to take the SD card and extract the code.
You could look at encrypting the filesystems (e.g: LUKS), but the Raspberry Pi has no native ability to store data and identify itself... so your encryption key can only be something like the MAC address, or stored in cleartext on the SD card...
Fundamentally this is just going to be a deterrent from casual "oh what's this" investigations.
"Physical access is total access"... once you put it in the customer's hands, you're looking at deterrents more than absolutes.
I heard its possible to reverse engineer the code even if compiled. So I simply want the programs (python script) to be there but cannot be accessed in any way.
Python doesn't get compiled until runtime, so you'll need to ship the device with your source code on it...
If you really want to secure your Intellectual Property, then perhaps the Raspberry Pi isn't the best option? It's up to you to balance cost vs security.
I'm currently working on a project where I need to create some functionality where the user can talk to the product (Raspberry Pi 3). And with talking I mean that the user should be able to say one or two words something like "product start" to the Pi and then it would get activated and do it's thing.
Now because of this, the Pi would need to be able to continuously listen and get activated when a certain combination of words is said by the user.
I've implemented the SpeechRecognition library, this sort of works but sadly there is a maximum of ~10 seconds where the Pi would listen.
I'm wondering if there are any library's which would help me with my use case, any help is welcome.
Can you explain better what do you mean by
sadly there is a maximum of ~10 seconds where the Pi would listen.
From my experience using CMUSphinx (Let me recomend the pocketsphinx version for your use-case), works continuously without problem.
Did you manage to know if the problem is on the Pi side, or the SpeechRecognition side?
What engine are you using behind SpeehRecognition. CMUSphinx, Google, Microsoft? With Google and Microsoft, it iis normal that they have a 10 seconds limitation. However, using CMUSphinx this should not happen. But, you might need to learn a bit how to set up an ASR system.
I have searched far and wide and tried a million different methods, but nothing works.
This is the scenario.
I have an RPi A+, it is connected to a sound sensor via GPIO.
I need this script to start when the Pi starts up. The Pi won't be near me or connected to a screen, so if the power fails and the Pi reboots, the script must start running again.
What I have now is a working script in a .py file.
The basic function = Detect sounds > log entry into database > send me an email.
I have nothing else, the .py file is just on my desktop.
Please help in plain English. My coding is not very good, and I had many people helping me make this happen, so I am not competent enough to create a script like this by myself - just for context on my skill level.
So basically, all I need is: Pi = on > Script = running.
If the Pi goes off and back on again, the script must fire again without ay intervention and start detecting sound.
Thanks so much!
First of all make your python script as a standalone, it should start with something like
#!/usr/bin/python and could be executed only by typing the script name in shell.
Then take a look at several topics such as "starting a python program at boot". You will find several methods :
put in rc.local (with &) => not good for a service
put in crontab #reboot directive (with &) => may not be implemented in all Linux distros
put in init.d : https://raspberrypi.stackexchange.com/questions/13415/using-init-d-script-to-start-my-python-program-on-startup => the best solution but may be difficult to apprehend