Toggle Navigation
Hatchery
Eggs
Volume Controll
__init__.py
Users
Badges
Login
Register
MCH2022 badge?
go to mch2022.badge.team
__init__.py
raw
Content
import rgb import uinterface import urequests import buttons, defines import virtualtimers import machine hostname = machine.nvs_getstr("vol_cntr","hostname") monitor_url = 'http://'+hostname+'.at.event.campzone.nl:8000/volume' def vol_down(button_is_down): if button_is_down: change_vol('down') def vol_up(button_is_down): if button_is_down: change_vol('up') def reset_host(button_is_down): if button_is_down: rgb.clear() rgb.scrolltext('Enter Hostname') buttons.register(defines.BTN_A, enter_host) def enter_host(button_is_down): name = machine.nvs_getstr("vol_cntr","hostname") rgb.clear() rgb.scrolltext('Host:' + name) if not name: rgb.clear() rgb.scrolltext('Host not setup') #new_name = uinterface.text_input() #rgb.clear() #rgb.scrolltext('Set hostname:') #new_name = uinterface.text_input() #print(new_name) buttons.register(defines.BTN_DOWN, vol_down) buttons.register(defines.BTN_UP, vol_up) buttons.register(defines.BTN_A, enter_host) def change_vol(direction): data = {'vol_cmd': direction} result = urequests.post(monitor_url, json=data) show(result.json()['volume']) def refresh(): result = urequests.get(monitor_url) show(result.json()['volume']) return 5000 def show(vol): rgb.clear() rgb.text(vol) uinterface.connect_wifi() virtualtimers.new(0,refresh)