traccar各设备通讯协议分析(坐标转换、逆地址解析)

OSM协议字符串:

  1. 2024-06-16 21:23:13 192.168.3.158   POST /?id=349574&timestamp=1714318553&lat=30.552737&lon=114.204453&speed=0.0&bearing=0.0&altitude=0.0&accuracy=0.0&batt=48.0 HTTP/1.1
  2. Content-Type: application/x-www-form-urlencoded
  3. User-Agent: Dalvik/2.1.0 (Linux; U; Android 10; HRY-AL00a Build/HONORHRY-AL00a)
  4. Host: 192.168.3.103:8082
  5. Connection: Keep-Alive
  6. Accept-Encoding: gzip
  7. Content-Length: 0
  8.  
  9.  
  10. 2024-06-16 21:23:43 192.168.3.158   POST /?id=349574&timestamp=1714318553&lat=30.552737&lon=114.204453&speed=0.0&bearing=0.0&altitude=0.0&accuracy=0.0&batt=48.0 HTTP/1.1
  11. Content-Type: application/x-www-form-urlencoded
  12. User-Agent: Dalvik/2.1.0 (Linux; U; Android 10; HRY-AL00a Build/HONORHRY-AL00a)
  13. Host: 192.168.3.103:8082
  14. Connection: Keep-Alive
  15. Accept-Encoding: gzip
  16. Content-Length: 0
  17.  
  18.  
  19. 2024-06-16 21:24:13 POST /?id=349574&timestamp=1714318553&lat=30.552737&lon=114.204453&speed=0.0&bearing=0.0&altitude=0.0&accuracy=0.0&batt=48.0 HTTP/1.1
  20. Content-Type: application/x-www-form-urlencoded
  21. User-Agent: Dalvik/2.1.0 (Linux; U; Android 10; HRY-AL00a Build/HONORHRY-AL00a)
  22. Host: 192.168.3.103:8082
  23. Connection: Keep-Alive
  24. Accept-Encoding: gzip
  25. Content-Length: 0
  26.  
  27.  
  28. 2024-06-16 21:24:43 POST /?id=349574&timestamp=1714318553&lat=30.552737&lon=114.204453&speed=0.0&bearing=0.0&altitude=0.0&accuracy=0.0&batt=48.0 HTTP/1.1
  29. Content-Type: application/x-www-form-urlencoded
  30. User-Agent: Dalvik/2.1.0 (Linux; U; Android 10; HRY-AL00a Build/HONORHRY-AL00a)
  31. Host: 192.168.3.103:8082
  32. Connection: Keep-Alive
  33. Accept-Encoding: gzip
  34. Content-Length: 0
  35.  
  36.  
  37. 2024-06-16 21:25:13 POST /?id=349574&timestamp=1714318553&lat=30.552737&lon=114.204453&speed=0.0&bearing=0.0&altitude=0.0&accuracy=0.0&batt=48.0 HTTP/1.1
  38. Content-Type: application/x-www-form-urlencoded
  39. User-Agent: Dalvik/2.1.0 (Linux; U; Android 10; HRY-AL00a Build/HONORHRY-AL00a)
  40. Host: 192.168.3.103:8082
  41. Connection: Keep-Alive
  42. Accept-Encoding: gzip
  43. Content-Length: 0
  44.  
  45.  
  46. 2024-06-16 21:25:43 POST /?id=349574&timestamp=1714318553&lat=30.552737&lon=114.204453&speed=0.0&bearing=0.0&altitude=0.0&accuracy=0.0&batt=48.0 HTTP/1.1
  47. Content-Type: application/x-www-form-urlencoded
  48. User-Agent: Dalvik/2.1.0 (Linux; U; Android 10; HRY-AL00a Build/HONORHRY-AL00a)
  49. Host: 192.168.3.103:8082
  50. Connection: Keep-Alive
  51. Accept-Encoding: gzip
  52. Content-Length: 0
  53.  
  54.  

原文作者: BG6RSH | 查看原帖

此条目发表在技术交流分类目录。将固定链接加入收藏夹。

《traccar各设备通讯协议分析(坐标转换、逆地址解析)》有一条回应

  1. BG6RSH说:

    # 高德地图逆地址解析函数# 逆地址解析功能监听处理函数,PYTHON代码。

    1. from http.server import BaseHTTPRequestHandler, HTTPServer
    2. import requests
    3. import json
    4. import urllib.parse
    5.  
    6. mapquest_addr = ”’
    7. "results": [
    8.    {{
    9.      "providedLocation": {{ }},
    10.      "locations": [
    11.        {{
    12.          "street": "{0}",
    13.          "adminArea5": "{1}",
    14.          "adminArea5Type": "City",
    15.          "adminArea4": "{2}",
    16.          "adminArea4Type": "County",
    17.          "adminArea3": "{3}",
    18.          "adminArea3Type": "State",
    19.          "adminArea1": "{4}",
    20.          "adminArea1Type": "Country",
    21.          "postalCode": "{5}",    
    22.        }}
    23.      ]
    24.    }}
    25.  ]
    26. ”’
    27.  
    28. proxies = {
    29. }
    30. traccar_url = ‘http://nas.atoo.top:8082’
    31.  
    32.  
    33. # 高德地图逆地址解析函数
    34. def amap_geocode(lat, lng):
    35.     amap_url = ‘https://restapi.amap.com/v3/geocode/regeo?’
    36.     parameters = {
    37.         ‘output’: ‘json’,
    38.         ‘key’: ‘de6cf58608a044b643da48377c6bdbfb’,
    39.         ‘radius’: ‘1000’,
    40.         ‘xtensions’: ‘base’,
    41.         ‘location’: ‘{0},{1}’.format(lat, lng)
    42.     }
    43.  
    44.     response = requests.get(amap_url, parameters, proxies=proxies)
    45.     if response.status_code == 200:
    46.         print(response.text)
    47.         return response.text
    48.     else:
    49.         return ”
    50.  
    51.  
    52. # 高德地图坐标转换
    53. def amap_coordinate_convert(lat, lon):
    54.     amap_url = ‘https://restapi.amap.com/v3/assistant/coordinate/convert?’
    55.     parameters = {
    56.         ‘output’: ‘json’,
    57.         ‘key’: ‘de6cf58608a044b643da48377c6bdbfb’,
    58.         ‘coordsys’: ‘gps’,
    59.         ‘locations’: ‘{0},{1}’.format(lon, lat)
    60.     }
    61.     response = requests.get(amap_url, parameters, proxies=proxies)
    62.     # print(lat, lon, requests)
    63.     if response.status_code == 200:
    64.         # print(response.text)
    65.         coordinate_json = json.loads(response.text)
    66.         if coordinate_json[‘status’] == ‘1’:
    67.             coordinate = coordinate_json[‘locations’].split(‘,’)
    68.             return coordinate[0], coordinate[1]
    69.         return –1, –1
    70.  
    71.  
    72. # 逆地址解析功能监听处理函数
    73. class GeocodeHandler(BaseHTTPRequestHandler):
    74.     def do_GET(self) –> None:
    75.         request_str = self.requestline
    76.         # print(request_str)
    77.         l = request_str.find(‘location=’)
    78.         r = request_str.rfind(‘ HTTP’)
    79.         if l != –1 and r != –1:
    80.             request_str = request_str[l + 9:r]
    81.             point = request_str.split(‘,’)
    82.             # print(point[1],point[0])
    83.             address_json = json.loads(amap_geocode(point[1], point[0]))
    84.             address = mapquest_addr.format(address_json[‘regeocode’][‘formatted_address’],
    85.                                            address_json[‘regeocode’][‘addressComponent’][‘city’],
    86.                                            address_json[‘regeocode’][‘addressComponent’][‘district’],
    87.                                            address_json[‘regeocode’][‘addressComponent’][‘province’],
    88.                                            address_json[‘regeocode’][‘addressComponent’][‘country’],
    89.                                            address_json[‘regeocode’][‘addressComponent’][‘adcode’]
    90.                                            )
    91.             print(address)
    92.         else:
    93.             address = ”
    94.         self.send_response(200)
    95.         self.send_header(‘Content-type’, ‘text/html;charset=utf-8’)
    96.         self.end_headers()
    97.         self.wfile.write(bytes(address, ‘utf-8’))
    98.  
    99.  
    100. class OsmAndProtocolHandler(BaseHTTPRequestHandler):
    101.     def do_GET(self):
    102.         # content_length = int(self.headers[‘Content-Length’])
    103.         # body = self.rfile.read(content_length)
    104.         # data = json.loads(body.decode(‘utf-8’))
    105.         request_str = self.requestline
    106.         l = request_str.find(‘GET /?’)
    107.         r = request_str.rfind(‘ HTTP’)
    108.         if l != –1 and r != –1:
    109.             data = urllib.parse.parse_qs(self.requestline[l + 6:r])
    110.             print(‘Data’, data)
    111.             # data = json.loads(self.requestline)
    112.             lat, lon = amap_coordinate_convert(data[‘lat’][0], data[‘lon’][0])
    113.             parameters = {
    114.                 ‘id’: data[‘id’][0],
    115.                 ‘timestamp’: data[‘timestamp’][0],
    116.                 ‘lat’: lat,
    117.                 ‘lon’: lon,
    118.                 ‘speed’: data[‘speed’][0],
    119.                 ‘bearing’: data[‘bearing’][0],
    120.                 ‘altitude’: data[‘altitude’][0],
    121.                 ‘accuracy’: data[‘accuracy’][0],
    122.                 ‘batt’: data[‘batt’][0]
    123.             }
    124.             response = requests.post(traccar_url, parameters, proxies=proxies)
    125.             print(‘parameters’, parameters)
    126.             self.send_response(200)
    127.             self.send_header(‘Content-type’, ‘text/html;charset=utf-8’)
    128.             self.end_headers()
    129.             self.wfile.write(bytes(json.dumps(parameters), ‘utf-8’))
    130.  
    131.  
    132. def run(server_address, handler_class=BaseHTTPRequestHandler):
    133.     # server_address = (”, 8000)
    134.     httpd = HTTPServer(server_address, handler_class)
    135.     httpd.serve_forever()
    136.  
    137.  
    138. if __name__ == ‘__main__’:
    139.     print(‘traccar坐标转换代理服务器’)
    140.     # run((”, 80), GeocodeHandler)
    141.     run((”, 8082), OsmAndProtocolHandler)

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理。