Ejemplo n.º 1
0
def app_start():
    connectWifi()
    oled.fill(0)
    oled.fill_rect(0, 0, 128, 10, 1)
    oled.hctext('App Store', 1, 0)

    if not wlan.isconnected():
        oled.hctext('No WiFi :(', 24, 1)
        oled.hctext('Connection', 32, 1)
        oled.hctext('[B] to Quit', 56, 1)
        oled.show()
        while (btn.B.value()):
            sleep_ms(100)
        return 1

    REPO_URL = readConfig()['apprepourl']

    oled.hctext('Connecting to', 24, 1)
    oled.hctext('Repository', 34, 1)
    oled.show()

    listing = (urequests.get("%slisting.json" % REPO_URL)).json()

    s0id = 0
    while True:
        s0id = selectVList('Apps Available',
                           list(map(lambda a: a['name'], listing['apps'])),
                           s0id, 1)
        if s0id == -1: return 0
        if viewAppDetail(listing['apps'][s0id]):
            installApp(REPO_URL, listing['apps'][s0id])

    return 0
Ejemplo n.º 2
0
def app_start():
    connectWifi()
    oled.fill(0)
    oled.fill_rect(0, 0, 128, 10, 1)
    oled.hctext('SGP Weather', 1, 0)

    if not wlan.isconnected():
        oled.hctext('No WiFi :(', 24, 1)
        oled.hctext('Connection', 32, 1)
        oled.hctext('[B] to Quit', 56, 1)
        oled.show()
        while (btn.B.value()):
            sleep_ms(100)
        return 1

    oled.hctext('Connecting to', 24, 1)
    oled.hctext('data.gov.sg', 32, 1)
    oled.show()
    r1 = urequests.get(
        'https://api.data.gov.sg/v1/environment/24-hour-weather-forecast')
    r2 = urequests.get(
        'https://api.data.gov.sg/v1/environment/2-hour-weather-forecast')
    d1 = r1.json()
    d2 = r2.json()

    forecast = d1['items'][0]['general']['forecast']
    rhumid = d1['items'][0]['general']['relative_humidity']
    temp = d1['items'][0]['general']['temperature']
    wind = d1['items'][0]['general']['wind']
    oled.fill(0)
    oled.fill_rect(0, 0, 128, 10, 1)
    oled.hctext('24 Hour Forecast', 1, 0)
    oled.text(forecast, 0, 17, 1)
    oled.text('RH ' + str(rhumid['low']) + '-' + str(rhumid['high']) + ' %', 0,
              32, 1)
    oled.text('Temp ' + str(temp['low']) + '-' + str(temp['high']) + ' C', 0,
              40, 1)
    oled.text('Wind Dir ' + str(wind['direction']), 0, 48, 1)
    oled.text(
        ' @ ' + str(wind['speed']['low']) + '-' + str(wind['speed']['high']) +
        ' km/h', 0, 56, 1)
    oled.show()

    while btn.A.value() and btn.B.value():
        sleep_ms(100)
    sleep_ms(200)

    forecasts = []
    for area in d2['items'][0]['forecasts']:
        forecasts.extend([area['area'][:16], area['forecast'][:16], ''])
    sid = 0
    while True:
        sid = selectVList('2 Hour Nowcast', forecasts, sid, 1)
        if sid == -1: return 0
Ejemplo n.º 3
0
def app_start():
    connectWifi()
    oled.fill(0)
    oled.fill_rect(0, 0, 128, 10, 1)
    oled.hctext('SGP Environment', 1, 0)

    if not wlan.isconnected():
        oled.hctext('No WiFi :(', 24, 1)
        oled.hctext('Connection', 32, 1)
        oled.hctext('[B] to Quit', 56, 1)
        oled.show()
        while (btn.B.value()):
            sleep_ms(100)
        return 1

    oled.hctext('Connecting to', 24, 1)
    oled.hctext('data.gov.sg', 32, 1)
    oled.show()
    psi = urequests.get('https://api.data.gov.sg/v1/environment/psi')
    psi = psi.json()

    psi_24 = psi['items'][0]['readings']['psi_twenty_four_hourly']
    pm10_24 = psi['items'][0]['readings']['pm10_twenty_four_hourly']
    pm25_24 = psi['items'][0]['readings']['pm25_twenty_four_hourly']
    #psi3 = psi['items'][0]['readings']['psi_three_hourly']

    oled.fill(0)
    oled.fill_rect(0, 0, 128, 10, 1)
    oled.hctext('SGP Environment', 1, 0)
    oled.hctext('24 hour values:', 17, 1)
    oled.text('PSI   ' + str(psi_24['national']), 0, 32, 1)
    oled.hctext('(%s)' % psidescriptor(psi_24['national']), 40, 1)
    oled.text('PM10  %d ug/m^3' % pm10_24['national'], 0, 48, 1)
    oled.text('PM2.5 %d ug/m^3' % pm25_24['national'], 0, 56, 1)
    #oled.text(' @ '+str(wind['speed']['low'])+'-'+str(wind['speed']['high'])+' km/h',0,56,1)
    oled.show()

    while btn.A.value() and btn.B.value():
        sleep_ms(100)
    sleep_ms(200)
    return
Ejemplo n.º 4
0
def app_start():
	BAT = battery()
	config = readConfig()
	vfs = os.statvfs('/')
	timenow = str(localtime()).replace(' ','')

	items = [
	'Name:%s'%config['name'],
	'Machine Unique:',
	hexlify(machine.unique_id()).decode('utf-8').upper(),
	'',
	'C01N_OS %s'%config['version'],
	'uPy %s'%os.uname().release,
	'',
	'Localtime:',
	timenow[:12],
	timenow[12:],
	'',
	'VBAT: %.2fV'%BAT.voltage(),
	'Battery: %d%%'%(100*BAT.percentage()),
	'',
	'RAM Heap Free:',
	'%d B'%gc.mem_free(),
	'',
	'Flash VFS Size:',
	'%d B'%(vfs[0]*vfs[2]),
	'Flash VFS Free:',
	'%d B'%(vfs[0]*vfs[3]),
	'',
	'WiFi %s'%('Connected!' if wlan.isconnected() else 'Unavaliable'),
	wlan.config('essid'),
	'WiFi MAC:',
	hexlify(wlan.config('mac')).decode('utf-8').upper(),
	]

	selected = 0
	while selected != -1:
		selected = selectVList('Sys Info', items, selected, 1)
		sleep_ms(300)
Ejemplo n.º 5
0
def startMultiPlayer(isClient):
	import network
	import usocket as socket
	global gameSocket, gameSocket, clientAddr
	import uos
	prefixlen = len("CoinGame-Checkers")
	if not isClient:
		gameName = ubinascii.hexlify(uos.urandom(4)).upper().decode()
		wlanAP.active(True)         # activate the interface
		wlanAP.config(essid='CoinGame-Checkers-' + gameName) # set the ESSID of the access point
		#ap.setNoDelay(1);

		sleep_ms(1000)
		gameSocket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
		gameSocket.bind(('', 52354))


		oled.fill(0)
		oled.hctext("Waiting", 32-12, 1)
		oled.hctext("Checkers", 32-4, 1)
		oled.hctext("Game: " + gameName, 32+4, 1)
		oled.show()
		data, clientAddr = gameSocket.recvfrom(1)

	else:
		#wlan = network.WLAN(network.STA_IF) # create station interface
		wlan.active(True)
		dotcnt = 0
		validGames = []
		while len(validGames) == 0:
			oled.fill(0)
			oled.hctext("Scanning" + "."*(dotcnt+1), 32-4, 1)
			oled.show()
			dotcnt = (dotcnt+1)%3
			wlan.active(True)
			scanResults = wlan.scan()
			for ap in scanResults:
				ssid, bssid, channel, RSSI, authmode, hidden = ap
				if ssid.startswith("CoinGame-Checkers-"):
					validGames.append(ssid[18:])

		ap_name = validGames[selectVList("Select Game", validGames, 0)].decode()
		wlan.active(True)
		wlan.connect('CoinGame-Checkers-' + ap_name, '') # connect to an AP
		#wlan.setNoDelay(1);
		dotcnt = 0
		while not wlan.isconnected():
			oled.fill(0)
			oled.hctext("Connecting" + "."*(dotcnt+1), 22, 1)
			#oled.hctext("Channel: " + str(wlan.config("channel")), 32, 1)
			oled.hctext("Game: " + ap_name, 42, 1)
			oled.show()
			sleep_ms(500)
			dotcnt = (dotcnt+1)%3

		oled.fill(0)
		oled.hctext("WIFI: OK", 32, 1)
		oled.hctext("Game: ...", 42, 1)
		oled.show()

		gameSocket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
		sockaddr = socket.getaddrinfo('192.168.4.1', 52354)[0][-1]
		gameSocket.connect(sockaddr)
		gameSocket.send(numToBin(0))
		#TODO: exchange names between devices

		oled.fill(0)
		oled.hctext("CONNECTED", 32, 1)
		oled.show()

	startSession(isClient)