I have a python script which uses pygsm as the library for sending and receiving sms. However, I wish to put this script on auto-run upon booting up the raspberry pi. But the connecting time of the huawei modem usually takes a while, hence causing the shell script to skip the step. How do I make it so that it would confirm that it is connected to perform the python script?
This is not a python-related question, try a linux forum on boot sequence timeout
Related
I’m trying to connect mavproxy, mission planner and dronekit to my hexa.
i am not using a companion computer my setup is as follows:
i have a pc running windows for mission planner and on that same pc im running a virtual machine with ubuntu 16.04 running dronekit and mavproxy.
first I'm running mavproxy and forking out 2 connections, 1 for mission planner and one for dronekit with the following code:
mavproxy.py --master=/dev/ttyUSB0(I'm telling mavproxy to use the serial which the telemetry dongle is connected to) --baudrate=57600 --out=127.0.0.1:14551(ip address on my virtual ubuntu) --out=10.0.0.7:14550 (IP for my windows machine)
I am able to connect to the drone in mission planner via the UDP at port 14550. and I am able to send commands via mavproxy console such as change modes/arm etc.
my problem is when I execute my connect script from dronekit to connect to the drone I'm getting a timeout error.
the code
from dronekit import connect, VehicleMode, LocationGlobalRelative
import time
import argparse
parser = argparse.ArgumentParser(description = ‘commands’)
parser.add_argument(’–connect’)
args =parser.parse_args()
connection_string = args.connect
vehicle = connect(connection_string ,wait_ready=True)
when I open a new terminal I run the command to launch and connect drone kit
python connect.py --connect 127.0.0.1:14551
once I run this it gets stuck and after 30 seconds I get the following output:
dronekit.TimeoutError: wait_ready experienced a timeout after 30 seconds.
sometimes I get the following output:
gcs failsafe cleared
and then it gets stuck and after 30 seconds:
dronekit.APIException: Timeout in initializing connection.
I searched for about 3 days for solutions and tried everything that is out there pretty much, such as telling dronekit to wait longer than 30 seconds, but still, I get the same error.
I updated dronekit to the latest version, updated pymavlink and pyserial. also downgraded them to check if it will solve this but nothing works.
my main question is: is this error happening because dronekit can only run on a companion computer? and is not built for connecting threw telemetry radio?
if not, what am I doing wrong?
I sincerely am lost and praying that someone can help me.
thanks in advance. I would literally pay someone for a solution.
and again, sorry for the double post.
I am fairly new to sockets in python and I want to know how i can remotely run commands to another computer. At the moment, I've looked a bit into sockets and I know how to send text messages across networks. And yes, I've port-forwarded my PC.
If this explanation is confusing, let me give examples:
When you
import os
in the python shell and use
os.system(<command>)
, it will run the specified command in your shell. I want to achieve that, but on a remote computer. I am able to establish a connection and I'm successfully able to transfer bytes over a WLAN.
Issue: I don't know how to send python commands via. sockets and I would like to learn how to do it. I know I could implement the code onto the client's connection side of things, but I don't want it hardcoded. I want something like a 'live terminal' of the client's computer allowing me to type commands in and watch them being performed remotely on the client's computer. I'd appreciate some help!
P.S. I'm using Python 3.7.4
You have to do roughly the same thing you were doing with sending text messages. You must have had a client running your python script and your own computer(the server) running a script as well. The only difference between you sending a text message to the client and you sending a command would be in the python script the client is running.
In that python script, instead of printing the command to the console, you can just execute that command using os.system()
I have a python script that checks the temperature every 24 hours, is there a way to leave it running if I shut the computer down/log off.
Shutdown - no.
Logoff - potentially, yes.
If you want to the script to automatically start when you turn the computer back on, then you can add the script to your startup folder (Windows) or schedule the script (Windows tasks, cron job, systemd timer).
If you really want a temperature tracker that is permanently available, you can use a low-power solution like the Raspberry Pi rather than leaving your pc on.
The best way to accomplish this is to have your program run on some type of server that your computer can connect to. A server could be anything from a raspberry pi to an old disused computer or a web server or cloud server. You would have to build a program that can be accessed from your computer, and depending on the server and you would access it in a lot of different ways depending the way you build your program and your server.
Doing things this way means your script will always be able to check the temperature because it will be running on a system that stays on.
Scripts are unable to run while your computer is powered off. What operating system are you running? How are you collecting the temperature? It is hard to give much more help without this information.
One thing I might suggest is powering on the system remotely at a scheduled time, using another networked machine.
You can take a look at the following pages
http://www.wikihow.com/Automatically-Turn-on-a-Computer-at-a-Specified-Time
http://lifehacker.com/5831504/how-can-i-start-and-shut-down-my-computer-automatically-every-morning
Additionally once it turn on, you can perform a cronjob, for execute your python code by a console command >> python yourfile.py . What is the Windows version of cron?
I have a simple python script to send data from a Windows 7 box to a remote computer via SFTP. The script is set to continuously send a single file every 5 minutes. This all works fine but I'm worried about the off chance that the process stops or fails and the customer doesn't notice the data files have stopped coming in. I've found several ways to monitor python processes in a ubuntu/unix environment but nothing for Windows.
If there are no other mitigating factors in your design or requirements, my suggestion would be to simplify the script so that it doesn't do the polling; it simply sends the file when invoked, and use Windows Scheduler to invoke the script on whatever schedule you need. By relying on a core Windows service, you can factor that complexity out of your script.
You can check out restartme the following link shows how you can use it
http://www.howtogeek.com/130665/quickly-and-automatically-restart-a-windows-program-when-it-crashes/
I have been interested in finding an alternative to the UI in SAS for quite some time now. We license SAS on our server instead of our desktops, so furthermore we have to launch a remote desktop application to execute code.
I was able to use a Telnet connection instead to remotely connect to the server, and batch execute SAS programs. Then I was interested in whether a python script could be made to connect remotely, and batch execute code, and this script could be executed in jEdit as a BeanShell script.
So far, I have Python code which successfully opens and closes the Telnet connection. It can do basic shell functions like call "dir". However, when I pass the exact same line that I use to execute SAS from command prompt on the remote server with a telnet connection in Python, nothing happens.
Is it possible the server is preventing me from executing code from a script? I use a "read_until" statement for the prompt before running any code.
Here's a few ideas...
The issue you are having above may be related to Local Security Policy settings in Windows (if it is running on a windows server). I'm far from an expert on that stuff but I remember older SAS/Intranet installations required some rumaging around in there to get them working.
As an alternative to the approach you are trying above you could also setup a SAS session on the server that listens for incoming socket requests as per this article:
http://analytics.ncsu.edu/sesug/2000/p-1003.pdf
And finally... Not sure if this helps or not by I remotely execute SAS jobs using PSEXEC. A description of how I set it all up can be found here:
http://www.runsubmit.com/questions/260/hide-sas-batch-jobs-winxp
Good luck
This paper outlines how you can use a Python script to connect to a Unix server using SSH, copy the SAS program written locally onto the server, batch submit it, and download the results back to your local machine, all using a BeanShell macro script for jEdit.