def start(self, group): if not self.is_on: raise RuntimeError('Start Wifi before this method') try: # Intialize ESP-NOW and resiger coallback function. espnow.init() espnow.add_peer(StuduinoBitRadio.BROADCAST_MAC_ADDRESS) espnow.on_recv(self.__recv_cb) except OSError as e: print(e) self.__group = group
Chefs[chef_num]['queue'].append(table_num) # เพ่ิ่มเข้า queue # refill food if (Chefs[chef_num]['food_remain'] == 0): if (chef_num == 1): tim = Timer(3) tim.init(period=TIME_REFILL, mode=Timer.ONE_SHOT, callback=refill_food_chef1) else: tim = Timer(3) tim.init(period=TIME_REFILL, mode=Timer.ONE_SHOT, callback=refill_food_chef2) if (Chefs[chef_num]['current_queue'] == 0): # ถ้าเชฟว่างก็ให้ทำอาหาร handleQueue(chef_num) else: Chefs[chef_num]['out_order_queue'].append(table_num) print('out of order') # pass update_oled(chef_num) if (__name__ == "__main__"): update_oled(1) update_oled(2) init_wifi() espnow.on_recv(onOrder) while (1): pass
parse for tuple<string> ''' print('old:', msg) msg = msg.replace("\"", "$") msg = msg.replace("'", "\"") msg = msg.replace("$", "'") print('new:', msg) msg = json.loads(msg) msgs = eval(msg['msg']) setterOLED(*msgs) connect = False start = False espnow.on_recv(recieveFromController) setterOLED('connecting...') while (not connect): print('wait for connection...') time.sleep(1) lb.on() time.sleep(1) lb.off() setterOLED('connected') print('connected') espnow.send(UNICAST_CONTROLLER, 'connected') connect = True setLed() lb.on() # connect
receive_sensor_callback(data) def set_all_wheels(left_control_pin, right_control_pin): global forward_direction global curve_direction left_pin = forward_direction right_pin = forward_direction if curve_direction == 1: right_pin = 0 elif curve_direction == -1: left_pin = 0 set_wheel(left_pin, left_control_pin) set_wheel(right_pin, right_control_pin) ## initializing network## w = network.WLAN() w.active(True) espnow.init() espnow.on_recv(receive_callback) ################## while True: set_all_wheels(left_control_pin, right_control_pin)
def getFromPlayer(): # config espnow # espnow.init() espnow.on_recv(receive_callback)
amount_state = 10 # state of game2 problem_game = [] selected_game = 1 # selected, 1, 2 select = False # state for select or not select game _start = False # state for start and end game # time.sleep(3) # wating for display show problem selected_game = 1 # storage for save ans from player storage = { '1': [], # player1 '2': [] # player2 } print('wait for connection') espnow.on_recv(callBackConnect) connectMain() while (signal['p1'] != True or signal['p2'] != True or signal['display'] != True): ledBuildIn.on() time.sleep(0.5) ledBuildIn.off() time.sleep(0.5) for device, ready in signal.items(): if (not ready): print('wait', device) time.sleep(1)
def recieveFromController(*dobj): global connect msg = dobj[0][1].decode("utf-8") mac = ''.join(["{:02X}".format(x) for x in dobj[0][0]]) controller_mac = ''.join(["{:02X}".format(x) for x in UNICAST_CONTROLLER]) print(mac, msg) time.sleep(0.2) if (mac == controller_mac and msg == 'connecting'): connect = True connect = False start = False espnow.on_recv(recieveFromController) while (not connect): print('wait for connection') time.sleep(1) lb.on() time.sleep(1) lb.off() print('connected') espnow.send(UNICAST_CONTROLLER, 'connected') connect = True lb.on() # connect # print(leds, leds['1'], type(leds['1'])) #config espnow espnow.on_recv(receive_callback)