python script for receive GPS data
I receive the information sent from the GPS device to the Python script, but the information I receive is not understandable to me. Help me understand this information through Python and I can display it on Google Maps.
import socket sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock_ip = '192.168.150.2' sock_port = 5000 sock.bind((sock_ip, sock_port)) sock.listen(1) while True: c, addr = sock.accept() print('one client connect !!') data = c.recv(2048) print(data) c.close()
The output of this script is as follows: https://i.stack.imgur.com/gZy8h.png
See also questions close to this topic
Python: response to the browser then continue to delete files
I have one web based python tool, which is used for building the softwares using SVN checkout.
I have delete the record once the checkout and testing done. While deleting the record it has to delete all the checkout files along with DB rows. But those checkouts are very big (in GBs) So when I click on delete in browser it first deletes the rows in DB tables, but for file delete takes more time almost 1 to 2 mins. I have tried
threadingcall after delete the database return to browser and proceed for deleting the files. But it doesn't help.
I tried the below code:
import threading def data_delete(inputs): # call function to take delete the database rows deleteDataBaseRows_function(inputs) id1 = 1 id2 = 2 # call the maintainence_function here t = threading.Thread(target=deletefiles_function, args=[id1, id2]) # setDaemon=False to stop the thread after complete t.setDaemon(False) # starting the thread t.start() # return response/anything-else you want to return return "it worked" def deleteDataBaseRows_function(inputs): # deleting the database process here print "table rows deleted" def deletefiles_function(id1, id2): print "Files are deleted" res = profile_update("inputs") print res
I got the below output:
table rows deleted Files are deleted response to the browser
But My expected behavior is after delete the database rows, the User should proceed with other work on the browser tool (otherwise he has wait until he completes the entire file deletion), in backend the files start deleting it.
table rows deleted response to the browser Files are deleted
Make distutils place compiled extensions in the right folder
I wrote a Python C extension that I'm building with distutils. This is
from distutils.core import setup, Extension utilsmodule = Extension('utils', sources = ['utilsmodule.c']) setup (name = 'myPackage', version = '1.0', description = 'My package', ext_modules = [utilsmodule])
When I run
python setup.y build, the extension is built correctly but the
.pydfile goes into the folder
build/lib.win-amd64-3.7, and not into the module's root where Python looks for modules to import. I need to move that file out of
buildafter building to be able to import it.
I thought about adding a line after
setup()that moves the file, but that seems a bit dirty, I'm guessing that distutils should do that work.
What is the right way to compile an extension in a way that it can be imported by other Python files immediately after build?
Plotting ode solution in phase plane
I am trying to plot the solution to my ode using solver integrate.odeint however I am not obtaining a solution when I attempt to plot it. I can't see where the formulation of my code is wrong.
Please find below: import numpy as np import matplotlib.pyplot as pl from numpy import sin, cos import numpy as np import matplotlib.pyplot as plt import scipy.integrate as integrate import matplotlib.animation as animation from math import*
g = 9.81 l = 1.6 l_big = 2.0 l_small = 1.6 m = 0.01 alpha = 0.4 k = 100 def sh2(r1,t): theta1,omega1 = r1 sh2_theta1 = omega1/(l + ((1/2)*alpha*(1+np.tanh(theta1*omega1*k))))**2 sh2_omega1 = -g*(l + ((1/2)*alpha*(1+np.tanh(theta1*omega1*k))))*sin(theta1) #return sh2_theta1, sh2_omega1 return np.array([sh2_theta1, sh2_omega1],float) init_state = np.radians([69.0,0]) dt = 1/40 time = np.arange(0,10.0,dt) timexo = np.arange(0,10.0,dt) state2 = integrate.odeint(sh2,init_state,time) #print(state2) print(len(state2),len(timexo)) plt.plot(timexo[0:2500],state2[0:2500]) plt.show() #phase plot attempt # initial values x_0 = 0 # intial angular position v_0 = 1.0 # initial angular momentum t_0 = 0 # initial time # initial y-vector from initial position and momentum y0 = np.array([x_0,v_0]) # max value of time and points in time to integrate to t_max = 10 N_spacing_in_t = 1000 # create vector of time points you want to evaluate t = np.linspace(t_0,t_max,N_spacing_in_t) # create vector of positions for those times y_result = np.zeros((len(t), 2)) # loop through all demanded time points for it, t_ in enumerate(t): # get result of ODE integration up to the demanded time y = integrate.odeint(sh2,init_state,t_) # write result to result vector y_result[it,:] = y # get angle and angular momentum angle = y_result[:,0] angular_momentum = y_result[:,1] # plot result pl.plot(angle, angular_momentum,'-',lw=1) pl.xlabel('angle $x$') pl.ylabel('angular momentum $v$') pl.gcf().savefig('pendulum_single_run.png',dpi=300) pl.show()
The output of this code :
Plot 1 : correct plot for the ode solution over time
Plot 2 : empty plot for the phase plane which is whaat is causing problems.
Any hints are welcomed. On a less important note my first plot gives two lines I was only expecting the blue line though.