测试成功读取存储GPS数据到数据库应用
来源:互联网 发布:自拍比镜子丑 知乎 编辑:程序博客网 时间:2024/04/29 07:55
测试成功读取存储GPS数据到数据库应用
Rc.local 自动启动:
Su –ubuntu–c “/usr/bin/getGps.sh” &
/usr/bin/getGps.sh:
#!/bin/bash
python getGps.py &
sleep 2
getGps.py 代码:
#!/usr/bin/envpython
importserial
importrospy
fromstd_msgs.msg import String
importtime
import os
#logf =open('your_log_file.txt', 'a')
ser =serial.Serial('/dev/ttyACM0',baudrate=9600)
#ser = serial.Serial('/dev/ttyACM1', baudrate=9600)
defget_gps():
#init publisher
pub = rospy.Publisher('gpsStr', String,queue_size=10)
rospy.init_node('gps_node', anonymous=True)
rate = rospy.Rate(1) #10Hz = one second togo 10 time
while not rospy.is_shutdown():
#line = ser.readline()
#line = ser.read(ser.inWaiting())
allLine = ser.read(ser.inWaiting())
strline = allLine.split('\r\n')
#print strline
for line in strline:
print line
if line.find("GPGLL") ==1:
#if line.find("GPRMC") ==1:
print line
strlist = line.split(',')
print len(strlist)
arrLen = len(strlist)
if (arrLen >=5 andstrlist[1]!="" and strlist[2]!="" and strlist[3]!="" andstrlist[4]!=""):
print strlist[1]
print strlist[2]
print strlist[3]
print strlist[4]
pubStr =strlist[1]+'|'+strlist[2]+'|'+strlist[3]+'|'+strlist[4]
print pubStr
pub.publish(pubStr)
os.system("php/usr/bin/get_gps.php "+strlist[1]+""+strlist[3]+" ")
time.sleep(2)
rate.sleep()
if__name__ == "__main__":
try:
get_gps()
except rospy.ROSInterruptException:
pass
get_gps.php 代码:
<?php
//initRecordNum : For upload data to Server , every time to sendlimit records
//initRecordNum();
echo"\n";
@$gpsA = $argv[1];
@$gpsB = $argv[2];
//echo "key: $key \n";
if(($gpsA == "") || ($gpsB =="")){
echo "\n";
echo "Must to add argumentsafter Command! Excample: php/PATH/file.php [gpsA gpsB] \n";
echo "\n";
}else{
//get runing phpprocess PID of this time.
$species="S";
$sn="raspi"; //This must be theRobot Serial
//do {
unset ($_POST_data);
//get processPID in lock file.
//$ip_address= system("curlmembers.3322.org/dyndns/getip");
date_default_timezone_set('Asia/Singapore');
$datetime = date('Y-m-dH:i:s');
$update_time = $datetime;
$_POST_data["species"] =$species;
$_POST_data["sn"] = $sn;
$_POST_data["gpsA"] =$gpsA;
$_POST_data["gpsB"] =$gpsB;
$_POST_data["update_time"]= $update_time;
//write Serviceprocess PID into meter_connect.lock
echo "Getting gps successed! | gpsA is $gpsA | gpsB is $gpsB | updateTime is $update_time \n";
//*-- send data toelectrom server= **---------------------------------------------------*//
$url = "http://192.168.0.250/huge/index.php/robot-curl-receive-gps";
$fields_string = '';
$fields_string =http_build_query($_POST_data); // $_POST_data isarray of key value pairs
$ch = curl_init(); //open connection
// set the url,number of POS vars, POST data
curl_setopt($ch, CURLOPT_URL, $url);//用PHP取回的URL地址。你也可以在用curl_init()函数初始化时设置这个选项
curl_setopt($ch, CURLOPT_POST,count($_POST_data));//做一个正规的HTTP POST,设置这个选项为一个非零值
curl_setopt($ch, CURLOPT_POSTFIELDS,$fields_string); //post 参数数据
curl_setopt($ch, CURLOPT_FORBID_REUSE,1); //当进程处理完毕后强制关闭会话,不再缓存供重用
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);//设定是否显示头信息,返回字符串,而不是调用curl_exec()后直接输出
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT,10); // time to connect
curl_setopt($ch, CURLOPT_TIMEOUT,30); // time for reply
//$result =curl_exec($ch); // execture post
$run_curl = curl_exec($ch); // execture post
$res = curl_getinfo($ch);
$statusCode = curl_getinfo($ch,CURLINFO_HTTP_CODE);
echo "<br>statusCode :$statusCode";
$CURLINFO_EFFECTIVE_URL = curl_getinfo($ch,CURLINFO_EFFECTIVE_URL);
$connect_time = curl_getinfo($ch,CURLINFO_CONNECT_TIME );
$CURLINFO_CONTENT_LENGTH_UPLOAD=curl_getinfo($ch,CURLINFO_CONTENT_LENGTH_UPLOAD);
$CURLINFO_SIZE_UPLOAD = curl_getinfo($ch,CURLINFO_SIZE_UPLOAD);
$CURLINFO_CONTENT_TYPE = curl_getinfo($ch, CURLINFO_CONTENT_TYPE);
echo "<br>CURLINFO_CONTENT_LENGTH_UPLOAD : $CURLINFO_CONTENT_LENGTH_UPLOAD ";
echo "<br>connect_time :$connect_time";
echo "<br>CURLINFO_EFFECTIVE_URL :$CURLINFO_EFFECTIVE_URL";
echo "<br>CURLINFO_SIZE_UPLOAD :$CURLINFO_SIZE_UPLOAD";
echo "<br>CURLINFO_CONTENT_TYPE :$CURLINFO_CONTENT_TYPE";
curl_close($ch); //close connection
//sleep(3);
//}while(true); //do while to getip
}//else
?>
- 测试成功读取存储GPS数据到数据库应用
- 从文本文件读取数据存储到数据库
- Revit明细表读取、将明细表数据存储到sql server数据库、python读取数据库
- android GPS数据读取
- 读取数据库数据到记事本
- C#读取txt数据存储到数组
- 将数据存储到文件中和读取
- 数据库 SQLite3存储和读取数据
- 已解决问题:从Excel中读数据到数据库,本地VS运行都成功,网站发布后不能读取数据
- 【Android架构GPS篇】之定位数据如何从GPS芯片到应用层
- 【Android架构GPS篇】之定位数据如何从GPS芯片到应用层
- GPS数据读取与处理
- 读取Android GPS NMEA数据
- GPS数据读取与处理
- 读取Excel数据到SQL数据库
- 读取数据库数据到html table中
- .Net读取Excle数据写入到数据库
- 从数据库中读取数据到Excel
- [Python]项目打包:5步将py文件打包成exe文件
- leetcode(56).219. Contains Duplicate II
- 微服务的反模式和陷阱
- unity 使用Occlusion降低Batches
- 有return的情况下try catch finally的执行顺序(最有说服力的总结) 后面的神评论
- 测试成功读取存储GPS数据到数据库应用
- 设计模式-观察者模式(Java)
- hdu1085(母函数/完全背包)
- pencil
- API 25 (Android 7.1.1 API) widget.Space
- android 未来的学习方向
- 解决ADB端口占用问题
- linux下性能分析nmon安装配置
- 位运算