def __init__(self): self.app = gui() self.channel_number = open("audio_files/channel.txt", "r").readline() self.channelEdit = False self.isRecording = False self.emgMode = False self.app.setBg("mediumslateblue") self.app.setFg("pink") self.app.setExpand("NONE") self.coords = { "Record": [76, 404, 188, 483], "SOS": [79, 496, 178, 533], "1": [83, 565, 138, 594], "2": [158, 565, 224, 594], "3": [241, 565, 301, 594], "4": [83, 609, 138, 637], "5": [158, 609, 224, 637], "6": [241, 609, 301, 637], "7": [83, 652, 138, 684], "8": [158, 652, 224, 684], "9": [241, 652, 301, 684], "0": [158, 702, 224, 726], "change channel": [83, 702, 138, 726], "done": [241, 702, 301, 726] } self.app.addImage("show", "img/idle.png", 0, 0) self.app.setImageMap("show", self.click, self.coords) self.app.addLabel("l1", "<click on the device>") self.driver = stmpy.Driver() self.driver.start(keep_active=True) self.create_driver()
def __init__(self, db, host, port, id, rootTopic, tpm): self._db = db self._authenticated = False #Not yet authenticated with authentication server. self._mqtt = mqtt.Client() self._mqtt.on_connect = self.onConnect self._mqtt.on_message = self.onMessage self._host = host self._id = id self._port = port self._rootTopic = rootTopic self._sessions = [] self._tpm = tpm self._driver = stmpy.Driver() self._walkieHandlers = { WALKIE_MESSAGE.JOIN_CHANNEL.value: self.handleJoinChannel, WALKIE_MESSAGE.LOGIN.value: self.handleLoginRequest, WALKIE_MESSAGE.REGISTER.value: self.handleRegisterRequest, WALKIE_MESSAGE.LEAVE_CHANNEL.value: self.handleLeaveChannel, WALKIE_MESSAGE.LIST_MESSAGES.value: self.handleListMessages, WALKIE_MESSAGE.GET_MESSAGE.value: self.handleGetMessage, WALKIE_MESSAGE.SEND_MESSAGE.value: self.handleSendMessage, WALKIE_MESSAGE.SIGN_OUT.value: self.handleLogoutRequest, WALKIE_MESSAGE.LIST_CHANNELS.value: self.handleListChannels } self._authHandlers = { AUTH_SERVER_MESSAGE.REGISTER.value: self.handleRegisterResponse, AUTH_SERVER_MESSAGE.LOGIN.value: self.handleLoginResponse, }
def __init__(self, broker_ip, broker_port): self.broker_ip = broker_ip self.broker_port = broker_port self.mqtt_client = mqtt.Client() self.mqtt_client.on_connect = self.on_connect self.mqtt_client.on_message = self.on_message self.driver = stmpy.Driver()
def create_driver(self): self.id = socket.gethostname() + str(randint(0, 100)) self.recorder = Recorder(self.id) self.playback = Player(self.id) self.recorder_emg = RecorderEmergency(self.id) self.driver = stmpy.Driver() self.driver.add_machine(self.recorder.create_machine('recorder_stm')) self.driver.add_machine(self.playback.create_machine('playback_stm')) self.driver.add_machine( self.recorder_emg.create_machine('recorder_emg_stm')) self.driver.start()
def main(): walkieNumber = input('What is your worker number? ') # we start the stmpy driver and add 2 walkies stm_driver = stmpy.Driver() stm_driver.add_machine(WalkieLogic.create_machine(name=walkieNumber)) #add the line below to create another walkie on one computer #stm_driver.add_machine(WalkieLogic.create_machine(name = "2")) stm_driver.start(keep_active=True) command = CommandSender.CommandSenderComponent(walkieNumber)
def __init__(self): self.timer_ids = list() # create a new MQTT client self.mqtt_client = mqtt.Client() #decomment # callback methods self.mqtt_client.on_connect = self.on_connect #decomment self.mqtt_client.on_message = self.on_message #decomment # Connect to the broker self.mqtt_client.connect(MQTT_BROKER, MQTT_PORT) #decomment # subscribe to proper topic(s) of your choice self.mqtt_client.subscribe(MQTT_TOPIC_INPUT) #decomment # start the internal loop to process MQTT messages self.mqtt_client.loop_start() #decomment self.stm_driver = stmpy.Driver() self.stm_driver.start(keep_active=True)
def __init__(self): """ Start the component. ## Start of MQTT We subscribe to the topic(s) the component listens to. The client is available as variable `self.client` so that subscriptions may also be changed over time if necessary. The MQTT client reconnects in case of failures. ## State Machine driver We create a single state machine driver for STMPY. This should fit for most components. The driver is available from the variable `self.driver`. You can use it to send signals into specific state machines, for instance. """ # get the logger object for the component self._logger = logging.getLogger(__name__) print('logging under name {}.'.format(__name__)) self._logger.info('Starting Component') # create a new MQTT client self._logger.debug('Connecting to MQTT broker {} at port {}'.format( MQTT_BROKER, MQTT_PORT)) self.mqtt_client = mqtt.Client() # callback methods self.mqtt_client.on_connect = self.on_connect self.mqtt_client.on_message = self.on_message # Connect to the broker self.mqtt_client.connect(MQTT_BROKER, MQTT_PORT) # subscribe to proper topic(s) of your choice self.mqtt_client.subscribe(MQTT_TOPIC_INPUT) # start the internal loop to process MQTT messages self.mqtt_client.loop_start() # we start the stmpy driver, without any state machines for now self.stm_driver = stmpy.Driver() self.stm_driver.start(keep_active=True) self._logger.debug('Component initialization finished') self.machines = []
def __init__(self): # Starter systemet ved å legge til oppforsel og sensorobjektene # create a new MQTT client self.mqtt_client = mqtt.Client() # callback methods self.mqtt_client.on_connect = self.on_connect self.mqtt_client.on_message = self.on_message # Connect to the broker self.mqtt_client.connect(MQTT_BROKER, MQTT_PORT) # subscribe to proper topic(s) of your choice self.mqtt_client.subscribe(MQTT_TOPIC_INPUT) # start the internal loop to process MQTT messages self.mqtt_client.loop_start() self.stm_driver = stmpy.Driver() self.stm_driver.start(keep_active=True) pi_FSM = pi_fsm("the_STM",self) self.pi_stm = pi_FSM self.MQTT_TOPIC_INPUT = MQTT_TOPIC_INPUT self.MQTT_TOPIC_OUTPUT = MQTT_TOPIC_OUTPUT self.userID = "" self.stm_driver.add_machine(self.pi_stm.stm) self.Scanner = scanner() self.SoundScanner = Sound() self.soundValue = 0
def __init__(self): # get the logger object for the component self._logger = logging.getLogger(__name__) print('logging under name {}.'.format(__name__)) self._logger.info('Starting Component') # create a new MQTT client self._logger.debug('Connecting to MQTT broker {} at port {}'.format(MQTT_BROKER, MQTT_PORT)) self.mqtt_client = mqtt.Client() # callback methods self.mqtt_client.on_connect = self.on_connect self.mqtt_client.on_message = self.on_message # Connect to the broker self.mqtt_client.connect(MQTT_BROKER, MQTT_PORT) # subscribe to proper topic(s) of your choice self.mqtt_client.subscribe(MQTT_TOPIC_INPUT) # start the internal loop to process MQTT messages self.mqtt_client.loop_start() # we start the stmpy driver, without any state machines for now self.stm_driver = stmpy.Driver() self.stm_driver.start(keep_active=True) self._logger.debug('Component initialization finished')
size=(600, 25), orientation='horizontal', font=('Helvetica', 20), enable_events=True, key='slider') ], [button_subscribe, button_unsubscribe], [button_in, button_out], [sg.Button('Power off', font=('Helvetica', 20))], [sg.Button('Message', font=('Helvetica', 20))]] window = sg.Window('Braze device', layout, size=(1000, 500)) device_id = 0 if len(sys.argv) > 1: device_id = sys.argv[1] """ Setup """ mqtt_client = mqtt.Client() main_driver = stmpy.Driver() second_driver = stmpy.Driver() device = Device(main_driver, second_driver, device_id) voicerecognizer = VoiceRecognizer(main_driver) main_driver.add_machine(device.stm) # commend out the line under to disable voice recognizion second_driver.add_machine(voicerecognizer.stm) def application(main_driver, second_driver): # logging.DEBUG: Most fine-grained logging, printing everything # logging.INFO: Only the most important informational log items # logging.WARN: Show only warnings and errors. # logging.ERROR: Show only error messages.
import stmpy from appJar import gui stm_driver = stmpy.Driver() stm_driver.start(keep_active=True) class GUI: def send_signal(self, new_stm_id): # self.stm.send('msg_received') self.stm.send('msg_received') #print(new_stm) def print_to_receiving(self): print("transition: idle to receiving, trigger: msg_received") def print_to_sending(self): print("transition: idle to sending, trigger: record_button") def print_back_to_idle(self): print("back to idle state") def print_to_receiving_emg_msg(self): print("going to receiving_emg_msg state") def print_to_sending_emg_msg(self): print("going to sending_emg_msg state") def print_do(self): print("do function")
'effect': 'registration(*); sendMessageReg(*)' } idle = {'name': 'idle'} validating_login = { 'name': 'validating_login', 'defer': 'registationRequest; loginRequest; delete_user; log_out' } validating_registration = { 'name': 'validation_registration', 'defer': 'registationRequest; loginRequest; delete_user; log_out' } driver = stmpy.Driver() server = AuthenticationServer_MQTT(MQTT_BROKER, MQTT_PORT, driver, MQTT_TOPIC_INPUT, MQTT_TOPIC_OUTPUT) authenticationSender = AuthenticationServer_Sender(server) machine = stmpy.Machine( name='Authentication_server', transitions=[t0, t1, t2, t3, t4, t5, t6], obj=authenticationSender, states=[idle, validating_login, validating_registration]) authenticationSender.stm = machine driver.add_machine(machine) server.start() driver.start()