def loop(): sta_if = network.WLAN(network.STA_IF) sta_if.active(True) # Activate standalone interface sta_if.scan() # Scan for available access points sta_if.connect("SHA2017-insecure" ) # Connect to the public SHA2017 AP without a password sta_if.isconnected() # Check for successful connection sta_if.ifconfig() # Print connection information r = urequests.get( 'https://br-gpsgadget-new.azurewebsites.net/data/raintext/?lat=52.28&lon=5.52' ) lines = r.text.splitlines() raindata = [int(lines[i].split('|')[0]) for i in range(len(lines))] if sum(raindata) > 0: # Plot graph ugfx.clear(ugfx.WHITE) for i in range(len(raindata)): ugfx.area(12 * i, 127 - (raindata[i] // 2), 11, 127, ugfx.BLACK) ugfx.flush() badge.leds_init() badge.leds_send_data(bytes([0, 0, raindata[0] // 2, 0] * 6), 24) # all blue with intensity of current rain badge.vibrator_init() badge.vibrator_activate(9) time.sleep(2) badge.leds_disable() return 15 * 60 * 1000
def program_main(): ugfx.init() ugfx.clear(ugfx.WHITE) badge.leds_init() try: badge.eink_png(0, 0, logo_path) except: log('+ Failed to load graphics') # Name tag ugfx.string(ugfx.width() - ugfx.get_string_width(name, fonts[1]), ugfx.height() - 36, name, fonts[1], ugfx.BLACK) # Button info ugfx.string(0, ugfx.height() - 13, '[FLASH to update] [B to exit]', fonts[2], ugfx.BLACK) ugfx.flush() ugfx.input_init() ugfx.input_attach(ugfx.BTN_B, lambda pressed: exit_app()) ugfx.input_attach(ugfx.BTN_FLASH, lambda pressed: start_self_update()) HOST = "chat.freenode.net" PORT = 6667 NICK = name + "[luv]" REALNAME = name + ' @ SHA2017' log('+ waiting for network...') wifi.init() while not wifi.sta_if.isconnected(): time.sleep(0.1) s = socket.socket() s.connect((HOST, PORT)) s.send(bytes("NICK %s\r\n" % NICK, "UTF-8")) s.send(bytes("USER %s 0 * :%s\r\n" % (NICK, REALNAME), "UTF-8")) s.send(bytes("JOIN #sha2017\r\n", "UTF-8")) # IRC Client while True: line = s.readline().rstrip() parts = line.split() if parts: if (parts[0] == b"PING"): s.send(bytes("PONG %s\r\n" % line[1], "UTF-8")) blink_led(green) if (parts[1] == b"PRIVMSG"): blink_led(red) msg = b' '.join(parts[3:]) rnick = line.split(b'!')[0] log(b'%s: %s' % (rnick, msg))
import time sta_if = network.WLAN(network.STA_IF) sta_if.active(True) # Activate standalone interface sta_if.scan() # Scan for available access points sta_if.connect( "SHA2017-insecure") # Connect to the public SHA2017 AP without a password sta_if.isconnected() # Check for successful connection sta_if.ifconfig() # Print connection information r = urequests.get( 'https://br-gpsgadget-new.azurewebsites.net/data/raintext/?lat=52.28&lon=5.52' ) lines = r.text.splitlines() raindata = [int(lines[i].split('|')[0]) for i in range(len(lines))] if sum(raindata) > 0: # Plot graph ugfx.clear(ugfx.WHITE) for i in range(len(raindata)): ugfx.area(12 * i, 127 - (raindata[i] // 2), 11, 127, ugfx.BLACK) ugfx.flush() badge.leds_init() badge.leds_send_data(bytes([0, 0, raindata[0] // 2, 0] * 6), 24) # all blue with intensity of current rain badge.vibrator_init() badge.vibrator_activate(9) time.sleep(2) badge.leds_disable()