Example #1
0
class DAMRWEB:
    def __init__(self, namespace, SAS_name, SAS_value):

        self.topic_vel = 'cmd_vel'
        self.topic_stop = 'motor_stop'

        self.namespace = namespace
        self.SAS_name = SAS_name
        self.SAS_value = SAS_value

        self.topic_options = Topic()
        self.topic_options.max_size_in_megabytes = '10'  #### Try : '1024'
        self.topic_options.default_message_time_to_live = 'PT5S'

        self.bus_service = ServiceBusService(
            service_namespace=self.namespace,
            shared_access_key_name=self.SAS_name,
            shared_access_key_value=self.SAS_value)

        self.cmd_values = {
            'N': "100 100",
            'S': '-100 -100',
            'W': '-50 50',
            'E': '50 -50'
        }
        self.bot_list = []

    #create topics of cmd_vel and motor stop
    def createLocalbot(self, bot_id):

        self.bus_service.create_topic((self.topic_vel + bot_id),
                                      self.topic_options)
        self.bus_service.create_topic((self.topic_stop + bot_id),
                                      self.topic_options)
        # self.bus_service.create_subscription((self.topic_vel+bot_id), bot_id)
        # self.bus_service.create_subscription((self.topic_stop+bot_id), bot_id)
        self.bot_list.append(bot_id)

        pass

    def remoteControl(self, bot_id, cmd_dirn):

        msg = Message(self.cmd_values[cmd_dirn].encode('utf-8'))
        self.bus_service.send_topic_message((self.topic_vel + bot_id), msg)

    def remoteControlStop(self, bot_id):

        msg = Message('0 0'.encode('utf-8'))
        self.bus_service.send_topic_message((self.topic_vel + bot_id), msg)

    def deleteTopic(self, bot_id):
        self.bus_service.delete_topic((self.topic_vel + bot_id))
        self.bus_service.delete_topic((self.topic_stop + bot_id))

    def cleanup(self):

        for bot in self.bot_list:
            self.deleteTopic(bot)
Example #2
0
class AbcServiceBus:

    def __init__(self):
        self._namespace = '_namespace'
        self._topic_name = '_topic_name'
        self._service_bus = AzureServiceBus()

    def send_insert_notification(self, record_id):
        message_json = {'ids': [record_id]}
        self._service_bus.send_topic_message(
            namespace_name=self._namespace,
            topic_name=self._topic_name,
            message_json=message_json
        )
        return True
Example #3
0
def sendWindBeringData(msg):
    try:
        bus_service = ServiceBusService(
        service_namespace='kanmessagebus',
        shared_access_key_name='client',
        shared_access_key_value='dNj7Z+fOvV49WNETUL0Guj3KVVdZude/fqzmj95GHKo=')

        mesage = Message(msg)
        bus_service.send_topic_message("wind_bearing", mesage)

    except Exception as e:
        if hasattr(e, 'message'):
            print(e.message)
        else:
            print(e)
Example #4
0
def sendWeatherData(msg):
    try:
        bus_service = ServiceBusService(
        service_namespace='kanmessagebus',
        shared_access_key_name='weather',
        shared_access_key_value='tweaVJ8+++wUl3f568/E9vgAH21FK2SpcPBXn5F8Kts=')

        mesage = Message(msg)
        bus_service.send_topic_message("weather_station", mesage)

    except Exception as e:
        if hasattr(e, 'message'):
            print(e.message)
        else:
            print(e)