def enable(showStatus=True): global failed, state, nw if not state: if not nw.isconnected(): nw.active(True) ssid = badge.nvs_get_str('system', 'wifi.ssid', 'hackerhotel-insecure') password = badge.nvs_get_str('system', 'wifi.password') if showStatus: easydraw.msg("Connecting to '"+ssid+"'...") nw.connect(ssid, password) if password else nw.connect(ssid) timeout = badge.nvs_get_u8('system', 'wifi.timeout', 5) while not nw.isconnected(): time.sleep(1) timeout = timeout - 1 if (timeout<1): if showStatus: easydraw.msg("Error: could not connect!") disable() failed = True return False state = True failed = False if showStatus: easydraw.msg("Connected!") return True
def init(): global sta_if sta_if = network.WLAN(network.STA_IF) sta_if.active(True) ssid = badge.nvs_get_str('badge', 'wifi.ssid', '') password = badge.nvs_get_str('badge', 'wifi.password', '') if password: sta_if.connect(ssid, password) else: sta_if.connect(ssid)
def draw(y, sleep=False): print("> angelshifts draw") name = badge.nvs_get_str("engel", "shift_name", "") loc = badge.nvs_get_str("engel", "shift_loc", "") start = int(badge.nvs_get_str("engel", "shift_start", 0)) end = int(badge.nvs_get_str("engel", "shift_end", 0)) if name: time_text = generate_timedelta_text(start, end) ugfx.string(0, y - 14, "{}: {} @ {}".format(time_text, name, loc), "Roboto_Regular12", ugfx.BLACK) # ugfx.flush() return 60000, 14 else: return 120000, 0
def loop(): print("> angelshifts loop") last_update = int(badge.nvs_get_str("engel", "update", "0")) print("last update: ", last_update) if api_key: # Perform update if update_interval has passed if last_update + update_interval < easyrtc.time.time(): print("angelshifts: updating...") wifi.init() tries = 0 while not wifi.sta_if.isconnected(): time.sleep(0.1) tries += 1 if tries >= wifi_tries: return wakeup_interval next_shift = get_next_shift(api_key) if next_shift: badge.nvs_set_str("engel", "shift_name", next_shift["name"]) badge.nvs_set_str("engel", "shift_loc", next_shift["Name"]) badge.nvs_set_str("engel", "shift_start", next_shift["start"]) badge.nvs_set_str("engel", "shift_end", next_shift["end"]) badge.nvs_set_u8("engel", "notified", 0) else: badge.nvs_set_str("engel", "shift_name", "") badge.nvs_set_str("engel", "update", str(easyrtc.time.time())) else: print("angelshifts: no update needed") # Notify about upcoming shift if it starts in less than notify_time if badge.nvs_get_str("engel", "shift_name", "") and not bool( badge.nvs_get_u8("engel", "notified")): start = int(badge.nvs_get_str("engel", "shift_start", "")) now = easyrtc.time.time() if start > now and start < now + notify_time: global notified badge.vibrator_init() badge.vibrator_activate(200) ugfx.string( 0, 0, "NEXT SHIFT IN {} MINUTES!".format(notify_time // 60), "PermanentMarker22", ugfx.BLACK) ugfx.flush() return wakeup_interval else: print("no api key set up") return 0
def connectWiFi(): nw = network.WLAN(network.STA_IF) if not nw.isconnected(): nw.active(True) ssid = badge.nvs_get_str('system', 'wifi.ssid', '') password = badge.nvs_get_str('system', 'wifi.password', '') nw.connect(ssid, password) if password else nw.connect(ssid) print("Connecting to '" + ssid + "'...") timeout = 150 while not nw.isconnected(): time.sleep(0.1) timeout = timeout - 1 if (timeout < 1): print("Timeout while connecting!") nw.active(True) return False return True
def connectWiFi(): nw = network.WLAN(network.STA_IF) if not nw.isconnected(): nw.active(True) ssid = badge.nvs_get_str('badge', 'wifi.ssid', '') password = badge.nvs_get_str('badge', 'wifi.password', '') nw.connect(ssid, password) if password else nw.connect(ssid) easydraw.msg("Connecting to wifi...", "Loading...", True) timeout = 150 while not nw.isconnected(): time.sleep(0.1) timeout = timeout - 1 if (timeout < 1): easydraw.msg("Timeout :(") nw.active(True) return False return True
def draw_batterylow(percent): ugfx.clear(ugfx.WHITE) ugfx.string(0, 0, str(percent) + "% - BATTERY LOW, PLEASE CHARGE!", "Roboto_Regular12", ugfx.BLACK) #ugfx.string(0, 15, "BATTERY LOW! PLEASE CHARGE THE BATTERY!","Roboto_Regular12",ugfx.BLACK) nick = badge.nvs_get_str("owner", "name", "Hacker1337") ugfx.string(0, 40, nick, "PermanentMarker36", ugfx.BLACK) ugfx.set_lut(ugfx.LUT_FASTER) ugfx.flush()
def nickname(y=0, font=version.font_nickname_large, color=ugfx.BLACK, lineHeight=15): nick = badge.nvs_get_str("owner", "name", 'WELCOME TO HACKERHOTEL') lines = lineSplit(nick, ugfx.width(), font) for i in range(len(lines)): line = lines[len(lines) - i - 1] pos_x = int((ugfx.width() - ugfx.get_string_width(line, font)) / 2) ugfx.string(pos_x, y + lineHeight * (len(lines) - i - 1), line, font, color) return len(lines) * lineHeight
def draw_home(percent, cstate, status): ugfx.clear(ugfx.WHITE) if (cstate): ugfx.string(0, 0, str(percent) + "% & Charging... | " + status, "Roboto_Regular12", ugfx.BLACK) else: ugfx.string(0, 0, str(percent) + "% | " + status, "Roboto_Regular12", ugfx.BLACK) htext = badge.nvs_get_str("owner", "htext", "") if (htext != ""): draw_logo(160, 25, htext) nick = badge.nvs_get_str("owner", "name", "Anonymous") ugfx.string(0, 40, nick, "PermanentMarker36", ugfx.BLACK) ugfx.set_lut(ugfx.LUT_FULL) ugfx.flush() ugfx.set_lut(ugfx.LUT_FASTER)
def start(): if badge.safe_mode(): splash = 'splash' else: splash = badge.nvs_get_str('boot', 'splash', 'splash') if splash.startswith('bpp '): splash = splash[4:len(splash)] badge.mount_bpp() elif splash.startswith('sdcard '): splash = splash[7:len(splash)] badge.mount_sdcard() __import__(splash)
def populate_apps(): global apps apps = [] try: userApps = os.listdir('lib') except OSError: userApps = [] for app in userApps: add_app(app,read_metadata(app)) add_app("installer",{"name":"Installer", "category":"system"}) add_app("update",{"name":"Update apps", "category":"system"}) add_app("checkforupdates",{"name":"Update firmware", "category":"system"}) add_app(badge.nvs_get_str('boot','splash','splash'),{"name":"Home", "category":"system"})
def enable(showStatus=True): global failed global state if not state: nw = network.WLAN(network.STA_IF) if not nw.isconnected(): nw.active(True) ssid = badge.nvs_get_str('badge', 'wifi.ssid', '') password = badge.nvs_get_str('badge', 'wifi.password', '') if showStatus: easydraw.msg("Connecting to '" + ssid + "'...") result = "?" if password: nw.connect(ssid, password) else: nw.connect(ssid) timeout = badge.nvs_get_u8('badge', 'wifi.timeout', 30) show = round(timeout / 5) while not nw.isconnected(): newShow = round(timeout / 5) if show != newShow: easydraw.msg("(" + str(round(timeout / 2)) + " seconds)") show = newShow time.sleep(0.5) timeout = timeout - 1 if (timeout < 1): if showStatus: easydraw.msg("Error: could not connect!") disable() failed = True return False state = True failed = False if showStatus: easydraw.msg("Connected!") return True
def draw(y, sleep=2): global message enabled = badge.nvs_get_u8("sweary","enable", 0) if enabled and seeded and sleep: nick = badge.nvs_get_str("owner", "name", 'Offensive Owner') ugfx.clear(ugfx.BLACK) ugfx.flush() ugfx.clear(ugfx.WHITE) ugfx.flush() ugfx.string_box(0,10,296,26, nick + " says:", "Roboto_BlackItalic24", ugfx.BLACK, ugfx.justifyLeft) ugfx.string_box(0,45,296,38, message, "PermanentMarker36", ugfx.BLACK, ugfx.justifyCenter) return [interval, 0] return [9999999999, 0]
def main(): print("> Main") global api_key ugfx.init() ugfx.input_init() ugfx.clear(ugfx.BLACK) ugfx.flush() ugfx.clear(ugfx.WHITE) ugfx.flush() ugfx.input_attach(ugfx.BTN_B, appglue.home) ugfx.input_attach(ugfx.BTN_SELECT, prompt_api_key) wifi.init() while not wifi.sta_if.isconnected(): time.sleep(0.1) pass api_key = badge.nvs_get_str("engel", "key", "") if not api_key: prompt_api_key() show_shift_list()
# This file is executed on every boot (including wake-boot from deepsleep) import badge, machine, esp, ugfx, sys, time badge.init() ugfx.init() esp.rtcmem_write(0, 0) esp.rtcmem_write(1, 0) # setup timezone #timezone = badge.nvs_get_str('system', 'timezone', 'CET-1CEST-2,M3.5.0/02:00:00,M10.5.0/03:00:00') #time.settimezone(timezone) if badge.safe_mode(): splash = 'splash' else: splash = badge.nvs_get_str('boot', 'splash', 'splash') if machine.wake_reason() == (7, 0): print('[BOOT] Cold boot') import post_ota else: if machine.wake_reason() == (3, 4): print("[BOOT] Wake from sleep (timer)") elif machine.wake_reason() == (3, 1): print("[BOOT] Wake from sleep (button)") else: (reset_cause, wake_reason) = machine.wake_reason() (reset_cause_desc, wake_reason_desc) = machine.wake_description() print("[BOOT] " + str(reset_cause) + ": " + reset_cause_desc + ", " + str(wake_reason) + ": " + wake_reason_desc) load_me = esp.rtcmem_read_string()
# This file is executed on every boot (including wake-boot from deepsleep) import badge, machine, esp, ugfx, sys, time badge.init() ugfx.init() ugfx.input_init() esp.rtcmem_write(0, 0) esp.rtcmem_write(1, 0) # setup timezone timezone = badge.nvs_get_str('system', 'timezone', 'CET-1CEST-2,M3.5.0/02:00:00,M10.5.0/03:00:00') time.settimezone(timezone) if badge.safe_mode(): splash = 'splash' else: splash = badge.nvs_get_str('boot', 'splash', 'splash') if machine.reset_cause() != machine.DEEPSLEEP_RESET: print('[BOOT] Cold boot') else: print("[BOOT] Wake from sleep") load_me = esp.rtcmem_read_string() if load_me: splash = load_me print("starting %s" % load_me) esp.rtcmem_write_string("") try: if not splash == "shell":
import system, badge, dialogs def callback(value): if value: badge.nvs_set_str("owner", "name", value) system.home() nickname = badge.nvs_get_str("owner", "name", "") dialogs.prompt_text("Nickname", nickname, cb=callback)
files = uos.listdir('/media') for f in files: if f.endswith('.png'): pictures.append("/media/"+f) try: apps = uos.listdir('/lib') for app in apps: files = uos.listdir('/lib/'+app) for f in files: if f.endswith('.png'): pictures.append("/lib/"+app+"/"+f) except: pass current = badge.nvs_get_str('splash', 'logo', None) while True: options = [] for f in pictures: title = f if f == current: title += " [Enabled]" options.append(title) options.append("Default logo") options.append("< Exit") selected = term.menu("Picture", options, 0, "") if selected > len(pictures): system.home(True) if selected == len(pictures):
import network, badge, time sta_if = None defaultSsid = badge.nvs_get_str('badge', 'wifi.ssid', 'hackerhotel-insecure') defaultPassword = badge.nvs_get_str('badge', 'wifi.password') timeout = badge.nvs_get_str('badge', 'wifi.timeout', 5) def status(): global sta_if if sta_if == None: return False return sta_if.isconnected() def connect(ssid=defaultSsid, password=defaultPassword): init() sta_if.active(True) if password: sta_if.connect(ssid, password) else: sta_if.connect(ssid) def disconnect(): sta_if.disconnect() def init(): global sta_if if sta_if == None: sta_if = network.WLAN(network.STA_IF) def wait(duration=timeout, showStatus=False): if showStatus:
def setup(): global api_key print("setup") api_key = badge.nvs_get_str("engel", "key", "")
import ugfx import badge import network strength = 0 if(ntwork_if = network.WLAN(network.STA_IF); sta_if.active(True)): for network in ntwork_if.scan(): if(network[0].decode("ascii")==badge.nvs_get_str("badge","wifi.ssid",""): strength = network[3] else: pass #do error handling here
ugfx.init() ugfx.input_init() # Make sure WiFi is connected wifi.init() def set_message(text): ugfx.clear(ugfx.WHITE) ugfx.string(10, 10, text, "Roboto_Regular12", 0) ugfx.flush() badge.eink_busy_wait() set_message("Phonebook is loading. Please be patient") debug_enabled = badge.nvs_get_str("oneliner", "debug") == "True" def debug(message): if debug_enabled: set_message(message) limit = 5 offset = 1 def load_entries(limit, offset): debug("Waiting for wifi...") # Wait for WiFi connection
def nickname(y=25, font="PermanentMarker36", color=ugfx.BLACK): nick = badge.nvs_get_str("owner", "name", 'Henk de Vries') ugfx.string_box(0, y, 296, 38, nick, font, color, ugfx.justifyCenter)
ugfx.clear(ugfx.WHITE); ugfx.string(10,10,"Waiting for wifi...","Roboto_Regular12", 0) ugfx.flush() # Wait for WiFi connection while not wifi.sta_if.isconnected(): time.sleep(0.1) pass ugfx.clear(ugfx.BLACK) ugfx.flush() ugfx.clear(ugfx.WHITE) ugfx.flush() input_string = badge.nvs_get_str("Hashtag", "hashtag", "") hashtag = dialogs.prompt_text("What hashtag should we display?", input_string) if hashtag: badge.nvs_set_str("Hashtag", "hashtag", hashtag) tweets = [] def get_tweets(hashtag): gc.collect() try: data = requests.get("http://server/html/twitter/get.php?hashtag="+hashtag) except: print("Could not download JSON!") time.sleep(1) return try: global tweets
def nickname(y=0, font=version.font_nickname_large, color=ugfx.BLACK): nick = badge.nvs_get_str("owner", "name", 'WELCOME TO DISOBEY') lines = lineSplit(nick, ugfx.width(), font) for i in range(len(lines)): ugfx.string_box(0, y + 15 * i, ugfx.width(), 15, lines[i], font, color, ugfx.justifyCenter)
import ugfx, time, badge, machine, deepsleep, gc, appglue, virtualtimers, easydraw, wifi, rtc, term, term_menu, orientation, tasks.powermanagement as pm, uos, json, sys, tasks.otacheck as otacheck # Default values default_logo = '/media/hackerhotel.png' # Read splashscreen configuration from NVS cfg_disabled = badge.nvs_get_u8('splash', 'disabled', False) cfg_term_menu = badge.nvs_get_u8('splash', 'term_menu', True) cfg_wifi = badge.nvs_get_u8('splash', 'wifi', True) cfg_shell = badge.nvs_get_u8('splash', 'shell', False) cfg_services = badge.nvs_get_u8('splash', 'services', True) cfg_logo = badge.nvs_get_str('splash', 'logo', default_logo) cfg_nickname = badge.nvs_get_u8('splash', 'nickname', True) cfg_led_animation = badge.nvs_get_str('splash', 'ledApp', None) # Small hack to install logo if needed try: media = uos.listdir("/media") if not "hackerhotel.png" in media: raise (BaseException("Logo not available")) except: import install_hh_logo # If the user holds down the START button during boot we skip this app and go straight into the launcher if badge.safe_mode() or cfg_disabled: appglue.start_app("launcher", False) # Drop directly into uPython shell if requested if cfg_shell: appglue.start_app("shell", False)
# This file is executed on every boot (including wake-boot from deepsleep) import badge, machine, esp, ugfx, sys badge.init() ugfx.init() esp.rtcmem_write(0, 0) esp.rtcmem_write(1, 0) if badge.safe_mode(): splash = 'splash' else: splash = badge.nvs_get_str('boot', 'splash', 'splash') if machine.reset_cause() != machine.DEEPSLEEP_RESET: print('[BOOT] Cold boot') else: print("[BOOT] Wake from sleep") load_me = esp.rtcmem_read_string() if load_me: splash = load_me print("starting %s" % load_me) esp.rtcmem_write_string("") try: if not splash == "shell": __import__(splash) else: ugfx.clear(ugfx.WHITE) ugfx.flush(ugfx.LUT_FULL) except BaseException as e: sys.print_exception(e) import easydraw easydraw.msg("A fatal error occured!", "Still Crashing Anyway", True) easydraw.msg("") easydraw.msg("Guru meditation:")
import term, orientation, system, time, uos, json, badge system.serialWarning() term.header(True, "Services") print("Loading...") apps = uos.listdir('/lib') services = [] for app in apps: if "ledsrv.py" in uos.listdir('/lib/'+app): services.append(app) current = badge.nvs_get_str('splash', 'ledApp', None) while True: options = [] for service in services: title = service if service == current: title += " [Enabled]" options.append(title) options.append(" None (disable LED services)") options.append("< Exit") selected = term.menu("Services", options, 0, "") if selected > len(services): system.home(True) if selected == len(services): current = None try: badge.nvs_erase_key('splash', 'ledApp') except:
import ugfx, badge, deepsleep nick = badge.nvs_get_str("owner", "name", "Hacker1337") #Nice clean screen ugfx.clear(ugfx.BLACK) ugfx.flush() ugfx.clear(ugfx.WHITE) ugfx.flush() ugfx.string_box(0, 10, 296, 26, "STILL", "Roboto_BlackItalic24", ugfx.BLACK, ugfx.justifyCenter) ugfx.string_box(0, 45, 296, 38, nick, "PermanentMarker36", ugfx.BLACK, ugfx.justifyCenter) ugfx.string_box(0, 94, 296, 26, "Anyway", "Roboto_BlackItalic24", ugfx.BLACK, ugfx.justifyCenter) #the line under the text str_len = ugfx.get_string_width(nick, "PermanentMarker36") line_begin = int((296 - str_len) / 2) line_end = str_len + line_begin ugfx.line(line_begin, 83, line_end, 83, ugfx.BLACK) #the cursor past the text cursor_pos = line_end + 5 ugfx.line(cursor_pos, 46, cursor_pos, 81, ugfx.BLACK) ugfx.flush(ugfx.LUT_FULL) ugfx.flush(ugfx.LUT_FULL) badge.eink_busy_wait()
# THANKYOU # author of the original irc_pager. beautifully simple IRC solution! # - Pepijn de Vos (https://badge.sha2017.org/projects/irc_pager) import badge, ugfx, appglue, wifi, time, woezel import usocket as socket name = badge.nvs_get_str('owner', 'name', 'n00b') log_messages = [] fonts = ['Roboto_Regular18', 'PermanentMarker36', 'pixelade13'] logo_width = 77 logo_path = '/lib/hackeriet/hackeriet-77.png' is_updating = False # Add 20 width to hide list scrollbars log_ui_list = ugfx.List(logo_width, 0, ugfx.width() - logo_width + 30, ugfx.height() - 13) log_ui_list.enabled(False) def log(text): global log_messages log_messages.insert(0, text) # Keep log short if len(log_messages) > 10: log_messages.pop() # Write all log lines, then flush buffer while (log_ui_list.count() > 0): log_ui_list.remove_item(0)