Raspberrypi gpio pin 13 change back to default after setup with RPi.GPIO - gpio

I use gpio with RPi.GPIO library.I want to change pin 13 (GPIO.23) to OUTPUT mode.
Here is my code:
#gpio-test.py
import RPi.GPIO as io
io.setmode(io.BCM)
io.setup(13, io.OUT)
Before running this script, I use "gpio readall" to check the gpio,it show like this befor run script
after run this script shows like :
after run script
But after few secondes, the pin 13 change back to INPUT mode automatic.Change other pins is ok,only this pin 13 cannot.Does anybody know why?

my workmate changed the config.txt for the temperature sensor.He added this code:dtoverlay=w1-gpio-pullup,gpiopin=13

Related

How to disable QuickEdit Mode with Python

I am trying to make a function that simply disables QuickEdit Mode in the python console. Here is what I have:
import ctypes
from ctypes import wintypes
def disable_quick_edit_mode():
kernel32 = ctypes.WinDLL('kernel32')
dword_for_std_input_handle = ctypes.wintypes.DWORD(-10)
dword_for_enable_extended_flags = ctypes.wintypes.DWORD(0x0080)
std_input_handle = kernel32.GetStdHandle(dword_for_std_input_handle)
kernel32.SetConsoleMode(std_input_handle, dword_for_enable_extended_flags)
last_error = kernel32.GetLastError()
return last_error
This returns error code 6 (ERROR_INVALID_HANDLE)
Any suggestions?
I just realized that this code works fine as long as stdin is not being redirected, as is probably the case when running from an IDE. I tried running the .py from Windows Explorer with a 10 second sleep and everything appears operational.

how to run the admin command prompt using python?

I want to run a script on the admin cmd prompt using python os.system
import os
import sys
import keyboard
import time
os.system('cls')
print('+'* 60)
os.system('netsh wlan set hostednetwork mode=allow ssid=test3 key=987654321')
time.sleep(2)
p = input('')
keyboard.press_and_release('enter')
print('#' * 60)
os.system('netsh wlan start hostednetwork')
time.sleep(2)
keyboard.press_and_release('enter')
v = input('')
How can I call the admin cmd prompt ?
Thank you in advance
I found a way to make this happen
so my idea is to to create script to share wifi using python, and the problem is you have to execute the script using admin command prompt. and to solve that, follow my steps:
1 - create the python script for the commands(copy mine in the original question)
2 - create a simple text file like this one
pause
python name.py
pause
3 - save it under the extension of " .bat " (example.bat)
4 - go to your system directory (mine is "C:\Windows\System32")
5 - copy the the batch file there
6 - create a shortcut for this batch file (it will ask to be in your desktop, click OK)
7 - go to the properties of this shortcuted file click on advanced and give it the admin
access - click OK
8- copy or cut your script.py file to the same directory (mine is "C:\Windows\System32")
and that's it, just launch your batch file in the desktop and here you go everything works fine.

Controlling a minecraft server with python

I've searched a lot for this and have not yet found a definitive solution. The closest thing I've found is this:
import shutil
from os.path import join
import os
import time
import sys
minecraft_dir = ('server diectory')
world_dir = ('server world driectory')
def server_command(cmd):
os.system('screen -S -X stuff "{}\015"'.format(cmd))
on = "1"
while True:
command=input()
command=command.lower()
if on == "1":
if command==("start"):
os.chdir(minecraft_dir)
os.system('"C:\Program Files\Java\jre1.8.0_111\bin\java.exe" -Xms4G -Xmx4G -jar craftbukkit-1.10.2.jar nogui java')
print("Server started.")
on = "0"
else:
server_command(command)
When I launch this program and type 'start' the CMD flashes up and closes instantly. Instead I want the CMD to stay open with the minecraft sever running from it. I'm not sure why this happens or what the problem is, any help would be greatly appreciated.
p.s. I have edited this to my needs (such as removing a backup script that was unnecessary) but it didn't work before. The original link is: https://github.com/tschuy/minecraft-server-control
os.system will simply run the command then return to your python script with no way to further communicate with it.
On the other hand using subprocess.Popen gives you access to the process while it runs, including writing to it's .stdin which is how you send data to the server:
def server_command(cmd):
process.stdin.write(cmd+"\n") #just write the command to the input stream
process = None
executable = '"C:\Program Files\Java\jre1.8.0_111\bin\java.exe" -Xms4G -Xmx4G -jar craftbukkit-1.10.2.jar nogui java'
while True:
command=input()
command=command.lower()
if process is not None:
if command==("start"):
os.chdir(minecraft_dir)
process = subprocess.Popen(executable, stdin=subprocess.PIPE)
print("Server started.")
else:
server_command(command)
you can also pass stdout=subprocess.PIPE so you can also read it's output and stderr=subprocess.PIPE to read from it's error stream (if any)
As well instead of process.stdin.write(cmd+"\n") you could also use the file optional parameter of the print function, so this:
print(cmd, file=process.stdin)
Will write the data to process.stdin formatted in the same way that print normally does, like ending with newline for you unless passing end= to override it etc.
Both of the above answers do not work in the environment I tried them in.
I think the best way is to use RCON, not sending keys to a window.
RCON is the protocol used by games to run commands.
Many python libraries support Minecraft RCON, and the default server.properties file has an option for RCON.
We will use the python module: MCRON.
Install it. It works for windows, mac, linux.
Type:
pip install mcrcon
Lets configure your server to allow RCON.
In server.properties, find the line 'enable-rcon' and make it look like this:
enable-rcon=true
Restart and stop your server.
Find the line 'rcon.password' and set it to any password you will remember.
You can leave the port default at 25575.
Now, open your terminal and type:
mcron localhost
Or your server ip.
You will be prompted to enter the password you set.
Then you can run commands and will get the result.
But we are doing this with python, not the PYPI MCRON scripts - so do this.
from mcrcon import MCRcon as r
with r('localhost', 'insertyourpasswordhere') as mcr:
resp = mcr.command('/list')
print(resp) #there are 0/20 players online: - This will be different for you.

How to change boot partition for Beaglebone Black after flashing Debian 8.4 to eMMC?

I'm trying to get the current Debian 8.4 SD card image onto my Beaglebone Black's eMMC. The flashing itself worked flawlessly by enabling (uncommenting) this line in the /boot/uEnv.txt file:
cmdline=init=/opt/scripts/tools/eMMC/init-eMMC-flasher-v3.sh
Flashing completed successfully with blinking LED's as described in the HowTo. Next, I connected a serial-USB cable to the J1 connector in order to see the boot process in Putty's serial console. The system starts to boot but then stops with an error message:
Begin: Waiting for root file system ... Begin: Running /scripts/local-block ... done.
Begin: Running /scripts/local-block ... done.
[line above repeats multiple times]
Begin: Running /scripts/local-block ... done.
done.
Gave up waiting for root device. Common problems:
- Boot args (cat /proc/cmdline)
- Check rootdelay= (did the system wait long enough?)
- Check root= (did the system wait for the right device?)
- Missing modules (cat /proc/modules; ls /dev)
ALERT! /dev/mmcblk1p1 does not exist. Dropping to a shell!
I then get an (initramfs) prompt. From there, I figured out that mmcblk1p1 is not the right partition, it should be mmcblk0p1 instead. I think this is because of a different enumeration when the SD card is removed.
Now the big question: How and where can I set the partition the system starts from? It must be defined somewhere. I can mount the root partition mmcblk0p1 and edit files from the prompt, so I hope that there's just a small config file I need to tweak. Do I need to add something to the /boot/uEnv.txt file? (I already commented out the flasher script after flashing, of course).
Thanks for your help!
It should be as easy as editing uEnv.txt.
There should be a line containing: root=/dev/mmcblk1p1 - just edit that to say /dev/mmcblk0p1.
The current version of the flasher script (Dec 2019) changes the boot designation to eMMC automagically upon successful completion of the flash.

Wine error: Application tried to create a window, but no driver could be loaded

I made a fcgi-isapi bridge, which I compile with wineg++ (keyword winelib). It is running a pure Win32 isapi extension using LoadLibrary/GetProcAddress. This works fine for a simple demo isapi dll, but not for a more complex one, where wine crashes somewhere inside the dll. WINEDEBUG=+olerelay,+storage,+relay gives me the following output:
0009:Call KERNEL32.InterlockedIncrement(00000150) ret=1001eebe
0009:Call KERNEL32.UnhandledExceptionFilter(0033f428) ret=7bc8e2f5
wine: Unhandled page fault on write access to 0x00000150 at address 0x7b8716bd (thread 0009), starting debugger...
Application tried to create a window, but no driver could be loaded.
Make sure that your X server is running and that $DISPLAY is set correctly.
couldn't load main module (0)
0009:Ret KERNEL32.UnhandledExceptionFilter() retval=00000000 ret=7bc8e2f5
Unhandled exception: page fault on write access to 0x00000150 in 32-bit code (0x7b8716bd).
Register dump:
CS:0023 SS:002b DS:002b ES:002b FS:0063 GS:006b
EIP:7b8716bd ESP:0033f8cc EBP:0033f8e0 EFLAGS:00010246( R- -- I Z- -P- )
EAX:00000001 EBX:00000000 ECX:00000000 EDX:00000150
ESI:0033f8fc EDI:0033f8d4
Stack dump:
0x0033f8cc: 7bc6592e 00000150 00000000 7ca3c7d4
0x0033f8dc: 00000000 0033fdc8 7b823b61 7b8be9d4
0x0033f8ec: 000102d1 0033f8f4 1001eebe 00000150
0x0033f8fc: 7ef82158 7ca3c7d0 f775d2c8 0033faac
0x0033f90c: 7bcd7208 00000000 f775c2b1 0000000f
0x0033f91c: 7bcbbed8 1004e06c 00000002 00115760
Backtrace:
=>0 0x7b8716bd in kernel32 (+0x616bd) (0x0033f8e0)
1 0x7b823b61 in kernel32 (+0x13b60) (0x0033fdc8)
2 0x7ef813d0 (0x0033fe18)
3 0x7ef815f5 (0x0033fe60)
4 0x7b85e84c in kernel32 (+0x4e84b) (0x0033fe78)
5 0x7b85f903 in kernel32 (+0x4f902) (0x0033feb8)
6 0x7bc77600 (0x0033fed8)
7 0x7bc7a59d (0x0033ffa8)
8 0x7bc775de (0x0033ffc8)
9 0x7bc4c65e (0x0033ffe8)
(tested with Wine 1.4.1 and 1.6.2, both give exactly the same output (only some different numbers)
My questions:
What happens really and how can I figure out the reason for the page fault error?
Does wine try to run a graphical debugger or is the dll itself trying to create a X11 object? And why does it fail? This installation is running in a 32bit chroot environment on a 64bit host, but I called xhost + and tested X11 using xlogo, gedit and even with a Win32 GUI application using Wine. There doesn't seem to be any X11 problem.
Update: here is the link to the source: http://gist.github.com/daald/5f37de8352e1c8ca62db
Try
wineconsole --backend=curses fastcgi-to-isapi.exe
As this post describes:
Wine has three options to run apps in command line mode:
On the bare linux console (wine)
On the linux console with curses (wine wineconsole --backend=curses)
In a win32 window (wine wineconsole --backend=user)
For wineconsole, the user backend is the default, that's why your
command line tried to open a window.
It does however not print the output of the program. If you need the output, you can first start wineconsole in interactive mode, then run the exe from there:
me#mycomputer:~$ wineconsole
Microsoft Windows 6.1.7601 (3.0)
Z:\home\me> HelloWorld.exe
Hello World!
Obviously not a good solution if you want to do it programmatically though.
As per this post, wine is meant for graphical programs. To run your program without a graphical interface, use wineconsole instead, e.g.
wineconsole fastcgi-to-isapi.exe
See: Text mode programs (CUI: Console User Interface).
Alternatively use a X virtual framebuffer, see: Run wine totally headless.

Resources