web_test.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 import time
00003 import json
00004 import rospy
00005 import rospkg
00006 import datetime
00007 import requests
00008 
00009 
00010 # {
00011 #   "modelId": "LA140",
00012 #   "batteryLevel": 100,
00013 #   "machineStatus": {
00014 #     "systemStatus": "OK",
00015 #     "subsystemsStatuses": [
00016 #       {
00017 #         "componentId": "string",
00018 #         "componentStatus": "OK",
00019 #         "componentDetailedStatus": "OK"
00020 #       }
00021 #     ]
00022 #   },
00023 #   "mapVersion": 1,
00024 #   "isMaintenance": true,
00025 #   "isVirtual": true
00026 # }
00027 
00028 # {
00029 #   "batteryLevel": 100,
00030 #   "floorSticker": "1001",
00031 #   "orientation": "90",
00032 #   "currentX": "2400",
00033 #   "currentY": "1200",
00034 #   "mapVersion": 1,
00035 #   "machineStatus": "READY"
00036 # }
00037 
00038 def main():
00039     rospy.init_node("web_test", anonymous=True)
00040     # path_to_file = rospkg.RosPack().get_path("caja_web") + '/logs'
00041     # log_time = datetime.datetime.fromtimestamp(time.time()).strftime('%d-%m-%y:%H:%M:%S.%f')
00042     # log_file = open(path_to_file + '/' + log_time + '-log_web.txt', 'w')
00043     url_prefix = 'http://52.38.170.95:8080'
00044     loop_rate = rospy.Rate(10)
00045 
00046     login_request = json.dumps({
00047         "modelId": "LA120",
00048         "batteryLevel": 100,
00049         "machineStatus": {
00050             "systemStatus": "OK",
00051             "subsystemsStatuses": [
00052                 {
00053                     "componentId": "string",
00054                     "componentStatus": "OK",
00055                     "componentDetailedStatus": "OK"
00056                 }
00057             ]
00058         },
00059         "mapVersion": 1,
00060         "isMaintenance": True,
00061         "isVirtual": True
00062     })
00063 
00064     keep_alive_request = json.dumps({
00065         "batteryLevel": 100,
00066         "floorSticker": "1001",
00067         "missionInfo": {},
00068         "orientation": "90",
00069         "currentX": "2400",
00070         "currentY": "1200",
00071         "mapVersion": 1,
00072         "machineStatus": "READY"
00073     })
00074 
00075     requests.post(url_prefix + '/machines/999/login', data=login_request, headers={'Content-type': 'application/json'})
00076 
00077     while not rospy.is_shutdown():
00078         request_time  = rospy.get_rostime()
00079         requests.post(url_prefix + '/machines/999/keepAlive', data=keep_alive_request, headers={'Content-type': 'application/json'}).json()
00080         #response_time = rospy.get_rostime().to_nsec()
00081 
00082         dt = (rospy.get_rostime()-request_time).to_sec()
00083 
00084         print "delta: " + str(dt)
00085 
00086 
00087 
00088         loop_rate.sleep()
00089 
00090 
00091     log_file.close()
00092 
00093 if __name__ == '__main__':
00094     main()


ric_board
Author(s): RoboTiCan
autogenerated on Fri Oct 27 2017 03:02:31