Is there a way to track jetson nano board using gps? - python

I am doing a project where I have to install the jetson nano board to a train and detect the gps location of it. But I cannot find a proper solution to include gps module to the jetson board. Please it would be great if there is anyone who can help me with it.
Thanks in advance!

So from what I know exactly the best way to do so would be to get an actual gps module for the jetson nano (do not know which exact model but I think we can go with the popular 4g model) and an example of one is https://www.waveshare.com/sim7600g-h-4g-for-jetson-nano.htm but you can also do something that isn't so accurate. Little bash script, hope it helps.
So first I would ssh into your device, you can run ifconfig to get a little bit of an idea. It by default would be wlan0 for the wirless module and eth0 for the wired connection.
Let's make the file
touch nanoloc.sh && sudo chmod +x nanoloc.sh
Then just run this little script here:
#!/bin/bash
#define what shell we want to use above
format="json" #xml or json
user="" #add your current user
nano_ip="$(curl ifconfig.co)"
ip_locaddr=https://freegeoip.app/$format/$nano_ip
data_file=/mnt/c/Users/$user/output.$format #change this to your expected path
touch data_file #make the file
echo data_file #make sure we have the right one
curl "$ip_locaddr" > data_file #write it out
cat data_file #let's see what it says
Now you should be able to see what it outputs when you run ./nanoloc.sh
Hope this helps, also am running this from WSL (you can see from the path where it's mounted) and tested on Linux.

Related

how to run chmod in python?

I was working with a sensor called Rplidar. To connect the Rplidar with my operating system(Ubuntu) sometimes i have to use this command in the terminal:
sudo chmod 666 /dev/ttyUSB0
After running this instruction, ubuntu can detect the Rplidar. Later on, i will run a python script to work with the Rplidar. Now I want to include this command inside my python script so that i do not need to run it in the terminal before working with the Rplidar. Is there any way that i could do it in python script?
The simple answer is that chmod is provided in the os module in Python:
https://docs.python.org/3/library/os.html#os.chmod
so all you need to do is run:
import os
filename = 'example.dat'
os.chmod(filename,
stat.S_IRUSR |
stat.S_IWUSR |
stat.S_IRGRP |
stat.S_IWGRP |
stat.S_IROTH)
so there's no need to shell out to perform this operation normally. Also have a look at the os.path and shutil modules for much more support in this area.
Things get a little complicated if you need to perform this operation with elevated privileges, but that's actually not the solution here.
Also, it is not a good idea to give 666 permissions to system devices. This can open up security problems when any user on the system has read/write access to system devices. As a matter of principle, use the least permissions required for correct operation.
As #KlausD. comments, you shouldn't be forcing permission changes on these device nodes anyway. The correct approach is to perform a one-time operation of adding the relevant user to the dialout group on your system. Then by being in the correct group, the user running your application will have access to the device. This is already answered here:
https://askubuntu.com/questions/112568/how-do-i-allow-a-non-default-user-to-use-serial-device-ttyusb0
Just run this once:
sudo adduser kazi dialout
then log out and back in for it to take effect. Your Rplidar app will run fine.
You can use the subprocess library to run shell command in Python
import subprocess
subprocess.Popen(["sudo", "chmod", "666", "/dev/ttyUSB0"], stdout=subprocess.PIPE, shell=True)

How to remove Profiling *.gcda:Cannot open errors with python virtualenv builder?

In jenkins output I am getting the following errors. Is this a problem or can it be silenced?
profiling:/opt/Python-3.6.1/Python/structmember.gcda:Cannot open
profiling:/opt/Python-3.6.1/Python/getcompiler.gcda:Cannot open
profiling:/opt/Python-3.6.1/Objects/odictobject.gcda:Cannot open
profiling:/opt/Python-3.6.1/Objects/enumobject.gcda:Cannot open
profiling:/opt/Python-3.6.1/Objects/descrobject.gcda:Cannot open
profiling:/opt/Python-3.6.1/Objects/cellobject.gcda:Cannot open
profiling:/opt/Python-3.6.1/Objects/bytes_methods.gcda:Cannot open
profiling:/opt/Python-3.6.1/Objects/accu.gcda:Cannot open
profiling:/opt/Python-3.6.1/Parser/myreadline.gcda:Cannot open
profiling:/opt/Python-3.6.1/Parser/parser.gcda:Cannot open
profiling:/opt/Python-3.6.1/Modules/xxsubtype.gcda:Cannot open
profiling:/opt/Python-3.6.1/Modules/symtablemodule.gcda:Cannot open
profiling:/opt/Python-3.6.1/Modules/zipimport.gcda:Cannot open
profiling:/opt/Python-3.6.1/Modules/stringio.gcda:Cannot open
profiling:/opt/Python-3.6.1/Modules/textio.gcda:Cannot open
profiling:/opt/Python-3.6.1/Modules/bufferedio.gcda:Cannot open
profiling:/opt/Python-3.6.1/Modules/bytesio.gcda:Cannot open
profiling:/opt/Python-3.6.1/Modules/fileio.gcda:Cannot open
profiling:/opt/Python-3.6.1/Modules/iobase.gcda:Cannot open
profiling:/opt/Python-3.6.1/Modules/_iomodule.gcda:Cannot open
profiling:/opt/Python-3.6.1/Modules/_localemodule.gcda:Cannot open
I built python from source on the debian 8 server.
I fixed this issue by doing change owner. I was setting up homeassistant using Python 3.6.3 build using ./configure --enable-optimizations.
From my virtual env i got these errors but fixed them doing: from su / root account
sudo chown -R homeassistant:homeassistant /home/pi/Python-3.6.3
I thought maybe it could help other people ;)
Have a nice day! Ciao!
This happened to me when I did ./configure --enable-optimizations. If you remove --enable-optimizations, compile and install it again - these messages are not shown anymore.
To sum things up, here's an example with a fresh version of Python:
wget https://www.python.org/ftp/python/3.6.3/Python-3.6.3.tgz
tar xvf Python-3.6.3.tgz
cd Python-3.6.3
./configure
make
sudo make altinstall
python3.6
The gcda files are gcc profiling records, which are used for seeing which functions the CPU spent most of its time in. This tells you where you can get the most bang for your buck, when optimising the code.
You can retain the Python code opinisations, but not have the profiling, by using the configuration options --enable-optimizations --disable-profiling. Well, worked for me.
As the configure script will tell you, if you do not have the --enable-optimizations you will lose out on the best performance.
You are probably getting gcda files because you interrupted the Python build part-way through. When you run with --enable-optimizations the Python build run in three phases
Builds the code
Runs all the test modules to profile the code
Re-compiles the code to optimise it based on the profiling
It pretty common to think the test phase is just to check the code is working correctly, as this is what it looks like it is doing, but be patient and leave it and it will compile again, the second time omitting the profiling.
So, its better to compile with --enable-optimizations and without --disable-profiling and just wait, as you should get better code that way.

Cannot allocate memory with tshark in Python

So, I have been playing around with my Raspberry Pi Zero and tshark in SSH when I thought, why not make a script that did all the work for me? So I used nano and created a python file called script.py and inside I wrote:
import os
os.system('sudo tshark -i eth0 -w capture-output.pcap')
I then did /python script.py which started off well but when it got to capturing on eth0 it stopped and said:
tshark: Couldn't create child process: cannot allocate memory.
Sorry about my python newbieness but please help because I am designing a Hak5 Packet squrriel clone. Thank you anyway and I look forward to hearing from you soon, Thomas
EDIT
So, I have kind of resolved this issue by doing sudo -i then creating a sh file instead of a python one but I prefer the python language so would really like to know what was happening. Thank you very much, Thomas

running as sudo from python for pyshark / tshark

I'm trying to do a live capture with pyshark, but it wants to run tshark using sudo. I'm not sure how to run sudo out of python. The github thread states: "you can create a 'script' that just runs "sudo tshark" and tell pyshark to run that instead of tshark."
Buuuuut I'm not too sure how to do that. I was looking at Using sudo with Python script
but again not sure how to "run that instead of tshark"
Has anyone done this? Can anyone advise?
Bit more info here: If you're an admin user, you don' t need sudo to run "tshark -c 100 -i en0". If you "sudo chmod 777 /dev/bpf*" that works for things like Carnivore in Processing, but does zip all for Pyshark. Trying to edit Startup items to give you read access is moot on OSX because Yosemite tossed it.
Other info: https://apple.stackexchange.com/questions/138694/what-is-access-bpf-group
I'm really starting to think something is just up w/ PyShark itself.
Thanks
Don't use sudo to run Wireshark. Instead, configure your user account to be able to use Wireshark without root access. Detailed instructions are here: https://ask.wireshark.org/questions/7976/wireshark-setup-linux-for-nonroot-user
WELP. turns out it was just because I hadn't used 'en0' Marking this as solved. HA.

How to copy files in python?

Basically, what I want to do is this (in a psuedo bash-ish code)
#create ramdisk raid
diskutil erasevolume HFS+ "r1" `hdiutil attach -nomount ram://4661720`;
diskutil erasevolume HFS+ "r2" `hdiutil attach -nomount ram://4661720`;
diskutil createRAID stripe SpeedDisk HFS+ /Volumes/r1 /Volumes/r2;
#copy minecraft server files to ramdisk
cp minecraft_Server /Volumes/SpeedDisk
#start minecraft_server
cd /Volumes/SpeedDisk/minecraft_server
java -Xms2G -Xmx2G -jar minecraft_server.jar nogui
#once I stop the server, copy the files to my harddrive
cd ~
cp /Volumes/SpeedDisk/minecraft_server minecraft_server/
I'm not sure about how to do this ^ in real life :p I was considering using python but it seems like there are problems with os.system for copying files.
Also, I would like to know if there is a way for me to eject the ramdisks when I am done. This is all going to be done in Mac OS X Leopard. The reason I'm doing all of this is to speed up my minecraft server a bit without buying an SSD.
I was considering using python but it seems like there are problems with os.system for copying files.
...then use the right tool for the job:
shutil.copytree()
Shell scripting seems to be the best solution for this kind of problem ( assuming that you want this to work on a single platform mac osx ). Write a shell script with these commands and use that script everytime you want to execute these commands.

Categories