def process_goal(self, goal_handle):

        flag_success = False
        result = msgRosIotResult()

        goal_id = goal_handle.get_goal_id()
        rospy.loginfo("Processing goal : " + str(goal_id.id))

        goal = goal_handle.get_goal()

        
        # Goal Processing
        if(goal.protocol == "mqtt"):
            rospy.logwarn("MQTT")

            if(goal.mode == "pub"):
                rospy.logwarn("MQTT PUB Goal ID: " + str(goal_id.id))

                rospy.logwarn(goal.topic + " > " + goal.message)

                ret = iot.mqtt_publish( self._config_mqtt_server_url, 
                                        self._config_mqtt_server_port,
                                        goal.topic, 
                                        goal.message, 
                                        self._config_mqtt_qos   )

                if(ret == 0):
                    rospy.loginfo("MQTT Publish Successful.")
                    result.flag_success = True
                else:
                    rospy.logerr("MQTT Failed to Publish")
                    result.flag_success = False

            elif(goal.mode == "sub"):
                rospy.logwarn("MQTT SUB Goal ID: " + str(goal_id.id))
                rospy.logwarn(goal.topic)

                ret = iot.mqtt_subscribe_thread_start(  self.mqtt_sub_callback, 
                                                        self._config_mqtt_server_url, 
                                                        self._config_mqtt_server_port, 
                                                        goal.topic, 
                                                        self._config_mqtt_qos   )
                if(ret == 0):
                    rospy.loginfo("MQTT Subscribe Thread Started")
                    result.flag_success = True
                else:
                    rospy.logerr("Failed to start MQTT Subscribe Thread")
                    result.flag_success = False

        rospy.loginfo("Send goal result to client")
        if (result.flag_success == True):
            rospy.loginfo("Succeeded")
            goal_handle.set_succeeded(result)
        else:
            rospy.loginfo("Goal Failed. Aborting.")
            goal_handle.set_aborted(result)

        rospy.loginfo("Goal ID: " + str(goal_id.id) + " Goal Processing Done.")
Esempio n. 2
0
    def process_goal(self, goal_handle):
        """
        This function is called is a separate thread to process Goal
        """

        flag_success = False
        result = msgRosIotResult()

        goal_id = goal_handle.get_goal_id()
        rospy.loginfo("Processing goal : " + str(goal_id.id))

        goal = goal_handle.get_goal()

        # Goal Processing
        if goal.protocol == "mqtt":
            rospy.logwarn("MQTT")

            if goal.mode == "pub":
                rospy.logwarn("MQTT PUB Goal ID: " + str(goal_id.id))

                rospy.logwarn(goal.topic + " > " + goal.message)

                ret = iot.mqtt_publish(self._config_mqtt_server_url,
                                       self._config_mqtt_server_port,
                                       goal.topic, goal.message,
                                       self._config_mqtt_qos)

                if ret == 0:
                    rospy.loginfo("MQTT Publish Successful.")
                    result.flag_success = True
                    msg_split = goal.message.split(",")
                    result_x = msg_split[0].split("(")[1]
                    result_y = msg_split[1]
                    result_theta = msg_split[2].split(")")[0]
                    rospy.logwarn('MESSAGE IMP: ' + result_x + result_y +
                                  result_theta)
                    iot.publish_message_to_spreadsheet(
                        turtle_x=result_x,
                        turtle_y=result_y,
                        turtle_theta=result_theta)
                else:
                    rospy.logerr("MQTT Failed to Publish")
                    result.flag_success = False

            elif goal.mode == "sub":
                rospy.logwarn("MQTT SUB Goal ID: " + str(goal_id.id))
                rospy.logwarn(goal.topic)

                ret = iot.mqtt_subscribe_thread_start(
                    self.mqtt_sub_callback, self._config_mqtt_server_url,
                    self._config_mqtt_server_port, goal.topic,
                    self._config_mqtt_qos)
                if ret == 0:
                    rospy.loginfo("MQTT Subscribe Thread Started")
                    result.flag_success = True
                else:
                    rospy.logerr("Failed to start MQTT Subscribe Thread")
                    result.flag_success = False

        rospy.loginfo("Send goal result to client")
        if result.flag_success:
            rospy.loginfo("Succeeded")
            goal_handle.set_succeeded(result)
        else:
            rospy.loginfo("Goal Failed. Aborting.")
            goal_handle.set_aborted(result)

        rospy.loginfo("Goal ID: " + str(goal_id.id) + " Goal Processing Done.")
    def process_goal(self, goal_handle):
        """
        This function process the goal from incoming from the Action client and then
        sends appropriate results to the action client based on whether the goal has been
        completed or failed.

        Parameters:
            goal_handle (object): This is the goal handle of the goal incoming from the
                Acion client
        """
        result = msgRosIotResult()

        goal_id = goal_handle.get_goal_id()
        rospy.loginfo("Processing goal : " + str(goal_id.id))

        goal = goal_handle.get_goal()

        # Goal Processing
        if goal.protocol == "mqtt":
            rospy.logwarn("MQTT")

            if goal.mode == "pub":
                rospy.logwarn("MQTT PUB Goal ID: " + str(goal_id.id))

                rospy.logwarn(goal.topic + " > " + goal.message)

                ret = iot.mqtt_publish(self._config_mqtt_server_url,
                                       self._config_mqtt_server_port,
                                       goal.topic, goal.message,
                                       self._config_mqtt_qos)

                if ret == 0:
                    rospy.loginfo("MQTT Publish Successful.")
                    result.flag_success = True
                else:
                    rospy.logerr("MQTT Failed to Publish")
                    result.flag_success = False

            elif goal.mode == "sub":
                rospy.logwarn("MQTT SUB Goal ID: " + str(goal_id.id))
                rospy.logwarn(goal.topic)

                ret = iot.mqtt_subscribe_thread_start(
                    self.mqtt_sub_callback, self._config_mqtt_server_url,
                    self._config_mqtt_server_port, goal.topic,
                    self._config_mqtt_qos)
                if ret == 0:
                    rospy.loginfo("MQTT Subscribe Thread Started")
                    result.flag_success = True
                else:
                    rospy.logerr("Failed to start MQTT Subscribe Thread")
                    result.flag_success = False

        rospy.loginfo("Send goal result to client")
        if result.flag_success is True:
            rospy.loginfo("Succeeded")
            goal_handle.set_succeeded(result)
        else:
            rospy.loginfo("Goal Failed. Aborting.")
            goal_handle.set_aborted(result)

        rospy.loginfo("Goal ID: " + str(goal_id.id) + " Goal Processing Done.")
Esempio n. 4
0
	def process_goal(self, goal_handle):
		"""
			This function is called is a separate thread to process Goal.
		"""
		flag_success = False
		result = msgRosIotResult()

		goal_id = goal_handle.get_goal_id()
		rospy.loginfo("Processing goal : " + str(goal_id.id))

		goal = goal_handle.get_goal()

		# Goal Processing
		if goal.protocol == "mqtt":
			rospy.logwarn("MQTT")

			if goal.mode == "pub":
				rospy.logwarn("MQTT PUB Goal ID: " + str(goal_id.id))

				rospy.logwarn(goal.topic + " > " + goal.message)

				ret = iot.mqtt_publish(self._config_mqtt_server_url,
									   self._config_mqtt_server_port,
									   goal.topic,
									   goal.message,
									   self._config_mqtt_qos)

				if ret == 0:
					rospy.loginfo("MQTT Publish Successful.")
					result.flag_success = True
				else:
					rospy.logerr("MQTT Failed to Publish")
					result.flag_success = False

			elif goal.mode == "sub":
				rospy.logwarn("MQTT SUB Goal ID: " + str(goal_id.id))
				rospy.logwarn(goal.topic)

				ret = iot.mqtt_subscribe_thread_start(self.mqtt_sub_callback,
													  self._config_mqtt_server_url,
													  self._config_mqtt_server_port,
													  goal.topic,
													  self._config_mqtt_qos)
				if ret == 0:
					rospy.loginfo("MQTT Subscribe Thread Started")
					result.flag_success = True
				else:
					rospy.logerr("Failed to start MQTT Subscribe Thread")
					result.flag_success = False

		elif goal.protocol == "http":
			rospy.logwarn("HTTP")
			
			rospy.logwarn("HTTP GET Goal ID: " + str(goal_id.id))

			rospy.logwarn(goal.topic + " > " + goal.message)

			# update_spreadsheet(spreadsheet_id, id, 'team_id', 'unique_id', '{'turtle_x': x, 'turtle_y': y, 'turtle_theta': theta,...,..}')
			ret = iot.update_spreadsheet(goal.topic, # using topic to send spreadsheet_id 
										goal.mode,
										literal_eval(goal.message) # data points with column names in dict format str
										)

			if ret == 0:
				rospy.loginfo("Updating Spreadsheet Successful.")
				result.flag_success = True
			else:
				rospy.logerr("Updating Spreadsheet Failed")
				result.flag_success = False

		rospy.loginfo("Send goal result to client")
		if result.flag_success == True:
			rospy.loginfo("Succeeded")
			goal_handle.set_succeeded(result)
		else:
			rospy.loginfo("Goal Failed. Aborting.")
			goal_handle.set_aborted(result)

		rospy.loginfo("Goal ID: " + str(goal_id.id) + " Goal Processing Done.")
Esempio n. 5
0
    def process_goal(self, goal_handle):
        '''***********************************************
        Name: process_goal

        Objective: This function is called is a separate thread to process Goal.

        Arguments: goal object for the goal

        Returns: None
        **************************************************'''
        flag_success = False
        result = msgRosIotResult()

        goal_id = goal_handle.get_goal_id()
        rospy.loginfo("Processing goal : " + str(goal_id.id))

        goal = goal_handle.get_goal()

        # Goal Processing
        if goal.protocol == "mqtt":
            rospy.logwarn("MQTT")

            if goal.mode == "pub":
                rospy.logwarn("MQTT PUB Goal ID: " + str(goal_id.id))

                rospy.logwarn(goal.topic + " > " + goal.message)

                ret = iot.mqtt_publish(self._config_mqtt_server_url,
                                       self._config_mqtt_server_port,
                                       goal.topic,
                                       goal.message,
                                       self._config_mqtt_qos)

                if ret == 0:
                    rospy.loginfo("MQTT Publish Successful.")
                    result.flag_success = True
                    ss_msg = re.sub('[()]', '', goal.message)
                    ss_msg_arr = ss_msg.split(',')
                    self.ss_publish(ss_msg_arr)
                    self.ss_publish(ss_msg_arr,'eyrc')
                else:
                    rospy.logerr("MQTT Failed to Publish")
                    result.flag_success = False

            elif goal.mode == "sub":
                rospy.logwarn("MQTT SUB Goal ID: " + str(goal_id.id))
                rospy.logwarn(goal.topic)

                ret = iot.mqtt_subscribe_thread_start(self.mqtt_sub_callback,
                                                      self._config_mqtt_server_url,
                                                      self._config_mqtt_server_port,
                                                      goal.topic,
                                                      self._config_mqtt_qos)
                if ret == 0:
                    rospy.loginfo("MQTT Subscribe Thread Started")
                    result.flag_success = True
                else:
                    rospy.logerr("Failed to start MQTT Subscribe Thread")
                    result.flag_success = False

        rospy.loginfo("Send goal result to client")
        if result.flag_success is True:
            rospy.loginfo("Succeeded")
            goal_handle.set_succeeded(result)
        else:
            rospy.loginfo("Goal Failed. Aborting.")
            goal_handle.set_aborted(result)

        rospy.loginfo("Goal ID: " + str(goal_id.id) + " Goal Processing Done.")
    def process_goal(self, goal_handle):

        flag_success = False
        result = msgRosIotResult()

        goal_id = goal_handle.get_goal_id()
        rospy.loginfo("Processing goal : " + str(goal_id.id))

        goal = goal_handle.get_goal()

        # Goal Processing
        if (goal.protocol == "mqtt"):
            rospy.logwarn("MQTT")

            if (goal.mode == "pub"):
                rospy.logwarn("MQTT PUB Goal ID: " + str(goal_id.id))

                rospy.logwarn(goal.topic + " > " + str(goal.message))

                ret = iot.mqtt_publish(self._config_mqtt_server_url,
                                       self._config_mqtt_server_port,
                                       self._config_mqtt_pub_topic,
                                       goal.message, self._config_mqtt_qos)

                if (ret == 0):
                    rospy.loginfo("MQTT Publish Successful.")
                    result.flag_success = True
                else:
                    rospy.logerr("MQTT Failed to Publish")
                    result.flag_success = False

                send_x = goal.message[1]
                send_y = goal.message[4]
                send_theta = goal.message[7]

                if goal.message[1] == '-':
                    send_x = -1 * int(goal.message[2])
                if goal.message[4] == '-':
                    send_y = -1 * int(goal.message[5])
                if goal.message[7] == '-':
                    send_theta = -1 * int(goal.message[8])

                send_sheet = {
                    "id": "Sheet1",
                    "turtle_x": send_x,
                    "turtle_y": send_y,
                    "turtle_theta": send_theta
                }
                response = requests.get(self._sheet_url, params=send_sheet)
                URL1 = "https://script.google.com/macros/s/AKfycbw850dk4moVgebU2GGe0PUQUvvg8jTpSjBQCawJt3_13vgujLk/exec"
                parameters = {
                    "id": "task1",
                    "team_id": "VB_1266",
                    "unique_id": "EyrcSaka",
                    "turtle_x": send_x,
                    "turtle_y": send_y,
                    "turtle_theta": send_theta
                }
                response1 = requests.get(URL1, params=parameters)
                rospy.loginfo(response1.content)

            elif (goal.mode == "sub"):
                rospy.logwarn("MQTT SUB Goal ID: " + str(goal_id.id))
                rospy.logwarn(goal.topic)

                ret = iot.mqtt_subscribe_thread_start(
                    self.mqtt_sub_callback, self._config_mqtt_server_url,
                    self._config_mqtt_server_port, self._config_mqtt_sub_topic,
                    self._config_mqtt_qos)
                if (ret == 0):
                    rospy.loginfo("MQTT Subscribe Thread Started")
                    result.flag_success = True
                else:
                    rospy.logerr("Failed to start MQTT Subscribe Thread")
                    result.flag_success = False

        rospy.loginfo("Send goal result to client")
        if (result.flag_success == True):
            rospy.loginfo("Succeeded")
            goal_handle.set_succeeded(result)
        else:
            rospy.loginfo("Goal Failed. Aborting.")
            goal_handle.set_aborted(result)

        rospy.loginfo("Goal ID: " + str(goal_id.id) + " Goal Processing Done.")
Esempio n. 7
0
    def process_goal(self, goal_handle):

        flag_success = False
        result = msgRosIotResult()

        goal_id = goal_handle.get_goal_id()
        rospy.loginfo("Processing goal : " + str(goal_id.id))

        goal = goal_handle.get_goal()

        # Goal Processing
        if (goal.protocol == "mqtt"):
            rospy.logwarn("MQTT")

            if (goal.mode == "pub"):
                rospy.logwarn("MQTT PUB Goal ID: " + str(goal_id.id))

                rospy.logwarn(goal.topic + " > " + str(goal.final_x))

                ret = iot.mqtt_publish(
                    self._config_mqtt_server_url,
                    self._config_mqtt_server_port, goal.topic, "final_x:" +
                    str(goal.final_x) + "\n" + "final_y:" + str(goal.final_y) +
                    "\n" + "final_theta" + str(goal.final_theta) + "\n",
                    self._config_mqtt_qos)
                parameters = {
                    "id": "Sheet1",
                    "turtle_x": goal.final_x,
                    "turtle_y": goal.final_y,
                    "turtle_theta": goal.final_theta
                }
                response = requests.get(self.URL, params=parameters)
                rospy.logwarn("mqqt pub requested")
                if (ret == 0):

                    rospy.loginfo("MQTT Publish Successful.")
                    result.flag_success = True
                else:
                    rospy.logerr("MQTT Failed to Publish")
                    result.flag_success = False

            elif (goal.mode == "sub"):
                rospy.logwarn("MQTT SUB Goal ID: " + str(goal_id.id))
                rospy.logwarn(goal.topic)

                ret = iot.mqtt_subscribe_thread_start(
                    self.mqtt_sub_callback, self._config_mqtt_server_url,
                    self._config_mqtt_server_port, goal.topic,
                    self._config_mqtt_qos)
                if (ret == 0):
                    rospy.loginfo("MQTT Subscribe Thread Started")
                    result.flag_success = True
                else:
                    rospy.logerr("Failed to start MQTT Subscribe Thread")
                    result.flag_success = False

        rospy.loginfo("Send goal result to client")
        if (result.flag_success == True):
            rospy.loginfo("Succeeded")
            goal_handle.set_succeeded(result)
        else:
            rospy.loginfo("Goal Failed. Aborting.")
            goal_handle.set_aborted(result)

        rospy.loginfo("Goal ID: " + str(goal_id.id) + " Goal Processing Done.")