Go to advanced search

by NPDedyukhin
Mon Apr 20, 2020 4:24 pm
Forum: Beginners
Topic: Connect to Yandex disk
Replies: 7
Views: 1128

Re: Connect to Yandex disk

Hello! Found a solution? I have the same problem: In my opinion, everything is in: !!!!! sudo nano / etc / fstab: I just did this: sudo apt-get install davfs2 sudo mkdir /mnt/ya.disk sudo chmod -R 777 /mnt/ya.disk sudo mount -t davfs https://webdav.yandex.ru /mnt/ya.disk -o uid = pi, gid = pi, rw, ...
by NPDedyukhin
Tue Jan 07, 2020 6:38 am
Forum: Python
Topic: The script that edits the file "wpa_supplicant.conf"
Replies: 5
Views: 526

The script that edits the file "wpa_supplicant.conf"

Good afternoon! :) I have a text file on my device that contains a list. (lines). lines[0] is the name of the WiFi network that the user entered earlier. lines[1] - this is the password from the WiFi network that the user entered earlier. Now my task is to edit the file “wpa_supplicant.conf” with th...
by NPDedyukhin
Fri Dec 13, 2019 4:53 am
Forum: Python
Topic: Program code protection.
Replies: 3
Views: 347

Re: Program code protection.

The closest you get to that on a Pi is the serial number, but they are not completely unique (for Pi Zero to 3, at least). Also, depending on the method used to read the serial number, it isn't hard to fake it. In addition, as long as someone has physical access to the Pi and SD card, they could pr...
by NPDedyukhin
Thu Dec 12, 2019 8:40 am
Forum: Python
Topic: Program code protection.
Replies: 3
Views: 347

Program code protection.

Good day! :) In order to protect the source code for the future device, I was interested in this question: What parameter can be used that is unique for a particular raspberry pi device to bind the program code to this parameter? For example, a cell phone has an IMEI code. I want to check before run...
by NPDedyukhin
Tue Dec 10, 2019 6:57 pm
Forum: Python
Topic: Parent script termination
Replies: 17
Views: 1058

Re: Parent script termination

To be fair, in your first reply you were pretty explicit about the OP needing to put the functionality in the imported file into functions, then importing the file only once and calling the functions in the parent program (at the point where the OP was trying to do repeated imports). Ah yes, the su...
by NPDedyukhin
Sat Dec 07, 2019 8:00 pm
Forum: Python
Topic: Parent script termination
Replies: 17
Views: 1058

Re: Parent script termination

Does this work? I changed a few things. lines = ["A","B","C","D","E","F"] import pygame pygame.quit() pygame.init() screen = pygame.display.set_mode((400,400)) a = 0 # Starts the new program. def start(): subprocess.run('child_script.py', shell=True) done = False while not done: for event in pygame...
by NPDedyukhin
Tue Dec 03, 2019 3:58 am
Forum: Python
Topic: Parent script termination
Replies: 17
Views: 1058

Re: Parent script termination

To Paeryn, that is also how I start a new python program running, do you have any other ideas on how to start a new program besides "import"? Python's import module_name does not, has never and never will "start a new program module_name running". If you want your Python program to start another pr...
by NPDedyukhin
Sun Dec 01, 2019 2:19 pm
Forum: Python
Topic: Parent script termination
Replies: 17
Views: 1058

Parent script termination

Good day! I have a parent script (it iterates over the list items when I press the arrows on the keyboard, and if it reaches the last item, it starts over, and when you press Enter, the following script is launched.): lines = ["A","B","C","D","E","F"] import pygame pygame.quit() pygame.init() screen...
by NPDedyukhin
Fri Nov 29, 2019 8:23 am
Forum: Camera board
Topic: Pi Camera Cable Length
Replies: 5
Views: 395

Pi Camera Cable Length

Good day to all! :)

Why does the Pi Camera have such a short cable?

If I want to place the camera on the street, then it turns out the device itself will also have to be placed on the street?

Or are there other ways? :geek:
by NPDedyukhin
Fri Oct 11, 2019 4:58 am
Forum: Python
Topic: Writing the result to the list and to a text file.
Replies: 5
Views: 836

Re: Writing the result to the list and to a text file.

A more Pythonic way to do it which allows processing of the lines as they are output - import os lines = os.popen('sudo iwlist wlan0 scan | grep "ESSID"').read().strip().split("\n") with open("/home/pi/Desktop/pi_cam/networks.txt", "w") as f: for line in lines: f.write(line.strip()+"\n") Thank you ...
by NPDedyukhin
Thu Oct 10, 2019 4:37 pm
Forum: Python
Topic: Writing the result to the list and to a text file.
Replies: 5
Views: 836

Re: Writing the result to the list and to a text file.

myCmd = 'sudo iwlist wlan0 scan | grep "ESSID"' Change that line to myCmd = 'sudo iwlist wlan0 scan | grep "ESSID" > /home/pi/Desktop/pi_cam/networks.txt' then delete the rest of the program after the call to os.system(). The whole python piece becomes redundant. You may as well run sudo iwlist wla...
by NPDedyukhin
Thu Oct 10, 2019 3:59 pm
Forum: Python
Topic: Writing the result to the list and to a text file.
Replies: 5
Views: 836

Writing the result to the list and to a text file.

Good afternoon! There is such a script: #!/usr/bin/env python # -*- coding: utf-8 -*- import os myCmd = 'sudo iwlist wlan0 scan | grep "ESSID"' os.system (myCmd) After executing it, I see the result in the console: ESSID:"Dedyu" ESSID:"ROSTELECOM_7F98C" ESSID:"TP-LINK_9_19" ESSID:"ROSTELECOM_A0439" ...
by NPDedyukhin
Thu Oct 10, 2019 2:36 pm
Forum: Beginners
Topic: Setting privileges for the script
Replies: 12
Views: 586

Re: Setting privileges for the script

Your Python program worked for me on a pi 3B using buster without a 'sudo'. But, if you do need to execute something which needs to be 'sudo' you can do that by adding the 'sudo' within the Python code - import os myCmd = 'mkdir /magic' os.system(myCmd) [email protected]:~/tmp $ python2 mk.py mkdir: cannot c...
by NPDedyukhin
Thu Oct 10, 2019 6:49 am
Forum: Beginners
Topic: Setting privileges for the script
Replies: 12
Views: 586

Setting privileges for the script

Good afternoon! :) Faced such a problem: I execute a command from the shell in a python script. The command is executed successfully only when I launch it manually through the console using "sudo". The command is: sudo python wifi_scan_01.py The script itself is as follows: import os #обращаемся к о...
by NPDedyukhin
Wed Oct 09, 2019 7:48 pm
Forum: Python
Topic: WiFi Scanner
Replies: 6
Views: 866

Re: WiFi Scanner

See Executing Shell Commands with Python Not found, error 404 Simple error extra character added to end of address Try : https://linuxhandbook.com/execute-shell-command-python Thanks for the tip. I figured out how to do it. The code is as follows: import os myCmd = 'iwlist wlan0 scan | grep "ESSID"...
by NPDedyukhin
Wed Oct 09, 2019 7:36 pm
Forum: Python
Topic: WiFi Scanner
Replies: 6
Views: 866

Re: WiFi Scanner

gkaiseril wrote:
Wed Oct 09, 2019 7:31 pm
See Executing Shell Commands with Python
Not found, error 404
by NPDedyukhin
Wed Oct 09, 2019 7:20 pm
Forum: Python
Topic: WiFi Scanner
Replies: 6
Views: 866

WiFi Scanner

Good afternoon! :P

When we connect the Raspberry Pi to a WiFi network, we can enter a command in the console to see a list of available networks:

iwlist wlan0 scan

What should a python script look like that will do the same? :roll:
by NPDedyukhin
Wed Oct 09, 2019 7:16 pm
Forum: Python
Topic: Writing to a text file in a specific line.
Replies: 10
Views: 1112

Re: Writing to a text file in a specific line.

Good afternoon! ;) I have a variable, it takes a certain value. I know that the value of this variable should always be on the third line in my text file. Always the third line. It doesn’t matter what is now contained in the third line. When a variable changes its value, you just need to open the f...
by NPDedyukhin
Wed Oct 09, 2019 7:13 pm
Forum: Python
Topic: Writing to a text file in a specific line.
Replies: 10
Views: 1112

Re: Writing to a text file in a specific line.

try this... #!/usr/bin/env python3 # open existing file Lines = [] with open("test.txt","r") as f: line = f.readline() while line: Lines.append(line.strip()) line = f.readline() # change the 3rd line var = 1.234 Lines[2] = str(var) # write the file again with open('test.txt', 'w') as f: for item in...
by NPDedyukhin
Wed Oct 09, 2019 4:37 pm
Forum: Python
Topic: Writing to a text file in a specific line.
Replies: 10
Views: 1112

Writing to a text file in a specific line.

Good afternoon! ;) I have a variable, it takes a certain value. I know that the value of this variable should always be on the third line in my text file. Always the third line. It doesn’t matter what is now contained in the third line. When a variable changes its value, you just need to open the fi...
by NPDedyukhin
Wed Oct 09, 2019 2:17 pm
Forum: Python
Topic: Round trip cycle
Replies: 2
Views: 460

Re: Round trip cycle

Good afternoon! :) I have a variable: "a" It can take two values: 1 or 2. By default, the variable must be of type: 1 Further, using "pygame", we analyze events on the keyboard - if one of the arrows is pressed (left or right), the variable value changes from 1 to 2, and vice versa - each time you ...
by NPDedyukhin
Wed Oct 09, 2019 1:59 pm
Forum: Python
Topic: i2c_lcd and python. Display of variable value.
Replies: 3
Views: 411

Re: i2c_lcd and python. Display of variable value.

Good afternoon! There is a module "i2c_lcd" and python. At the beginning of the script, I assign the variable "a" to 1 (am I doing the assignment correctly?) Next, I try to display the value of the variable on the display. I wrote a script like this: #!/usr/bin/env python # -*- coding: utf-8 -*- a ...
by NPDedyukhin
Wed Oct 09, 2019 1:49 pm
Forum: Python
Topic: i2c_lcd and python. Display of variable value.
Replies: 3
Views: 411

i2c_lcd and python. Display of variable value.

Good afternoon! There is a module "i2c_lcd" and python. At the beginning of the script, I assign the variable "a" to 1 (am I doing the assignment correctly?) Next, I try to display the value of the variable on the display. I wrote a script like this: #!/usr/bin/env python # -*- coding: utf-8 -*- a =...
by NPDedyukhin
Wed Oct 09, 2019 12:39 pm
Forum: Python
Topic: A script that reads the Enter key, and runs the following script
Replies: 7
Views: 682

Re: A script that reads the Enter key, and runs the following script

Problem is that the python script running in the background won't have keyboard focus so pressing the enter key won't do anything. Would you be open to using a physical button connected to the GPIO pins? That would be much easier. Alternatively, have a look at this stack overflow question/answers w...
by NPDedyukhin
Wed Oct 09, 2019 7:20 am
Forum: Python
Topic: A script that reads the Enter key, and runs the following script
Replies: 7
Views: 682

Re: A script that reads the Enter key, and runs the following script

Problem is that the python script running in the background won't have keyboard focus so pressing the enter key won't do anything. Would you be open to using a physical button connected to the GPIO pins? That would be much easier. Alternatively, have a look at this stack overflow question/answers w...

Go to advanced search