Пример #1
0
def text():
	if request.method == 'POST':
		if request.form['text']:
			#for mac: airport -s
			pattern1 = r"\s*(.*)\s+(([0-9a-f]{2}:){5}[0-9a-f]{2})"
			#for windows: powershell or cmd -- netsh wlan show network mode=bssid
			pattern2 = r"SSID \d{1,2} : (.*)\n.*\n.*\n.*\n.*(([0-9a-f]{2}:){5}[0-9a-f]{2})"
			#order is very important!
			if  re.compile(pattern2, re.M).findall(request.form['text']):
				pattern = pattern2
			else:
				pattern = pattern1

			ssid = []
			bssid = []
			for ss, bss, dummy in re.compile(pattern, re.M).findall(request.form['text']):
				ssid.append(ss)
				bssid.append(bss)
			if len(ssid) == 0 or len(bssid) == 0:
				return redirect(url_for('index'))
			w = wifilib.wifi()
			wifi = w.query(ssid, bssid)
			if wifi['err']:
				return jsonify({'total':0, 'err':wifi['err'], 'msg':wifi['msg']})
			total = len(wifi['ssid'])
			if total == 0:
				return jsonify({'total':0, 'err':0, 'msg':'not found!'})
			task = query_task.apply_async((wifi['ssid'], wifi['bssid']))
			return jsonify({'total':total, 'err':0, 'msg':'waiting...'}), 202, {'Location': url_for('taskstatus',
												  task_id=task.id)}
	return redirect(url_for('index'))
Пример #2
0
def text():
	if request.method == 'POST':
		res=''
		if request.form['text']:
			res=request.form['text']
		else:
			p = subprocess.Popen('netsh wlan show network mode=bssid', shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
			for line in p.stdout.readlines():
				res+=line
        #for windows: powershell or cmd -- netsh wlan show network mode=bssid
        pattern2 = r"SSID \d{1,2} : (.*)\n.*\n.*\n.*\n.*(([0-9a-f]{2}:){5}[0-9a-f]{2})"
        #order is very important!
        if  re.compile(pattern2, re.M).findall(res):
            pattern = pattern2
            
        ssid = []
        bssid = []
        for ss, bss, dummy in re.compile(pattern, re.M).findall(res):
            ssid.append(ss.strip('\r'))
            bssid.append(bss)
        if len(ssid) == 0 or len(bssid) == 0:
            return redirect(url_for('index'))
        w = wifilib.wifi()
        wifi = w.query(ssid, bssid)
        if wifi['err']:
            return jsonify({'total':0, 'err':wifi['err'], 'msg':wifi['msg']})
        total = len(wifi['ssid'])
        if total == 0:
            return jsonify({'total':0, 'err':0, 'msg':'not found!'})
        task = query_task.apply_async((wifi['ssid'], wifi['bssid']))
        return jsonify({'total':total, 'err':0, 'msg':'waiting...'}), 202, {'Location': url_for('taskstatus',
                                                task_id=task.id)}
	return redirect(url_for('index'))
Пример #3
0
def request_task(self, ssid, bssid):
	w = wifilib.wifi()
	self.update_state(state='REQUEST',
						  meta={'ssid':ssid, 'bssid':bssid})
	rsp = w.request(ssid, bssid)
	if rsp['flag']:
		del rsp['flag']
		del rsp['msg']
		return rsp
	else:
		return rsp
Пример #4
0
 def runtest(self):
     c = contact.contact()
     c.checkForContacts()
     w = wifi.wifi()
     w.wifiTest()
     n = note.Note()
     n.testNotes()
     a = app.app()
     a.apptest()
     p = photo.photo()
     p.phototest()
     v = video.video()
     v.videotest()
     m = media.Media()
     m.MediaCheck()
Пример #5
0
def query_task(self, ssid, bssid):
	'''
	err:0, data:[{'ssid':xx, 'bssid':xx}, ...]
	'''
	w = wifilib.wifi()
	data = []

	total = len(ssid)
	for i in xrange(total):
		self.update_state(state='REQUEST',
						  meta={'ssid':ssid[i], 'bssid':bssid[i], 'index':i, 'total':total})
		rsp = w.request(ssid[i], bssid[i])
		if rsp['flag']:
			del rsp['flag']
			del rsp['msg']
			data.append(rsp)
	return {'err':0,'total':len(data),'data':data, 'index':len(data)}
Пример #6
0
def text():
    if request.method == 'POST':
        if request.form['text']:
            #for mac: airport -s
            pattern1 = r"\s*(.*)\s+(([0-9a-f]{2}:){5}[0-9a-f]{2})"
            #for windows: powershell or cmd -- netsh wlan show network mode=bssid
            pattern2 = r"SSID \d{1,2} : (.*)\n.*\n.*\n.*\n.*(([0-9a-f]{2}:){5}[0-9a-f]{2})"
            #order is very important!
            if re.compile(pattern2, re.M).findall(request.form['text']):
                pattern = pattern2
            else:
                pattern = pattern1

            ssid = []
            bssid = []
            for ss, bss, dummy in re.compile(pattern, re.M).findall(
                    request.form['text']):
                ssid.append(ss)
                bssid.append(bss)
            if len(ssid) == 0 or len(bssid) == 0:
                return redirect(url_for('index'))
            w = wifilib.wifi()
            wifi = w.query(ssid, bssid)
            if wifi['err']:
                return jsonify({
                    'total': 0,
                    'err': wifi['err'],
                    'msg': wifi['msg']
                })
            total = len(wifi['ssid'])
            if total == 0:
                return jsonify({'total': 0, 'err': 0, 'msg': 'not found!'})
            task = query_task.apply_async((wifi['ssid'], wifi['bssid']))
            return jsonify({
                'total': total,
                'err': 0,
                'msg': 'waiting...'
            }), 202, {
                'Location': url_for('taskstatus', task_id=task.id)
            }
    return redirect(url_for('index'))
Пример #7
0
 def wifi(self):
     w = wifi.wifi()
     w.wifiTest()
Пример #8
0
import asyncio
import statusled
import logger
from time import sleep
import wifi
import sensor

log = logger.logger()
led = statusled.led()
wifi = wifi.wifi()


#log.action("work")
led.checkLed()
#import setup
#wifi.isInternetOn()

#wifi.setWifi('<ssid>','<passphrase>')

#wifi.isInternetOn()






Пример #9
0
from qrReader import qrReader
from wifi import wifi
from statusled import led
from time import sleep

led = led()
qr = qrReader()
wifi = wifi()

led.red()
if(wifi.isInternetOn()):
	led.green()
ssid, password = qr.read()
led.yellow()
wifi.setWifi(ssid,password)

while(not wifi.isInternetOn()):
	sleep(1)
led.green()


"""
ssid=<SSID>
psk=<passphrase>
"""
Пример #10
0
import ds3231
i2c = I2C(0, scl=22, sda=21)
ds = ds3231.DS3231(i2c)
rtc = RTC()
ds.alarm1_tm
ds.rtc_tm

import settings
import wifi
wifi_settings = settings.load_settings("wifi.json")
ip_addr       = wifi.connect_sta(wifi_settings['SSID'], wifi_settings['Password'], wifi_settings['Hostname'])

import ntptime
ntp_settings = settings.load_settings("ntp.json")
ntptime.ntp_query("192.168.16.10")
ds.rtc

import settings
import wifi
wifi_settings = settings.load_settings("wifi.json")
ip_addr       = wifi.connect_sta(wifi_settings['SSID'], wifi_settings['Password'], wifi_settings['Hostname'])

print(''.join('{:02x} '.format(x) for x in ds.read_ds3231_rtc()))

import settings
import wifi
ws = settings.load_settings("wifi.json")
w  = wifi.wifi(ws)
w.connect()

Пример #11
0
def main():
    # LED output - turn it on whilst we're booting...
    led = Pin(2, Pin.OUT)
    led.value(1)

    # Initialise the DS3231 battery-backed RTC
    i2c = I2C(0, scl=22, sda=21)
    ds  = ds3231.DS3231(i2c)
    print("DS3231 time   : {}".format(ds.rtc_tm))
    print("Hands position: {}".format(ds.alarm1_tm))

    # Initialise the mechanical clock
    clock = dgclock.DGClock("clock.json", ds.alarm1) # Read the config file, and initialise hands at last known position

    # Intialise the display
    ui = dgui.DGUI(clock.hands_tm)

    # Read the WiFi settings
    wifi_settings = settings.load_settings("wifi.json")
    network       = wifi.wifi(wifi_settings)

    # Read the NTP server to use
    ntp_settings  = settings.load_settings("ntp.json")
    next_ntp_sync = ds.rtc + 30 # First sync attempt after 30 seconds
    set_time      = 0           # Resetting the DS RTC not needed

    try:
        while True:
            # Tell the UI what the time is
            ui.now_tm = ds.rtc_tod_tm
            now       = ds.rtc_tod

            # Move the clock to show current TOD unless stopped
            if ui.mode == 'Normal' or ui.mode == 'Set':
                clock.move(now)

            # Update the non-volatile copy of the hand position
            ds.alarm1_tm  = clock.hands_tm
            sleep_ms(10) # Allow time for this to complete - DS3231 write can fail otherwise

            # LED states
            if clock.mode == "Run" and ui.now_tm[3] == 22 and ui.now_tm[4] == 0:
                # Run mode  - on at 22:00:00 until 22:01:00
                led.value(1)
            elif clock.mode == "Wait":
                # Wait mode - on
                led.value(1)
            elif clock.mode == "Fast" and clock.hands_tm[5] % 2 == 0:
                # Fast mode - on for even seconds
                led.value(1)
            else:
                # Otherwise off
                led.value(0)

            # Tell the UI where the clock thinks the hands are
            ui.hands_tm   = clock.hands_tm
            ui.clock_mode = clock.mode

            # Check that we have a WiFi connection, and attempt to reconnect if it's dropped
            network.connect()

            # Handle any button presses
            if ui.handle_buttons():  # Adjust hands was selected, so copy from UI to the clock
                clock.hands_tm = ui.time_to_set

            # Update the screen
            ui.update_screen()

            # Periodically re-sync the clocks
            if ds.rtc > next_ntp_sync:
                print("Querying {}".format(ntp_settings['NTP']))
                (ntp_time, millis, ticks) = ntptime.ntp_query(ntp_settings['NTP'])
                old_time                = ds.rtc
                if ntp_time is not None:
                    #ds.rtc        = ntp_time        # Copy the received time into the RTC as quickly as possible to minimise error

                    error_ms = 1000 - millis # Convert fractional part to error in milliseconds

                    set_at_ticks = ticks_add(ticks, error_ms)
                    set_time     = ntp_time + 1

                    print("Got {}.{:03d} @ {} - error in milliseconds {} - setting {} @ {}".format(ntp_time, millis, ticks, error_ms, set_time, set_at_ticks))

                    next_ntp_sync = ntp_time + 3654 # Just a bit less than once an hour
                    #print("Sync (disabled) RTC to NTP - {} (delta {})".format(ds.rtc_tod_tm, old_time - ntp_time))
                else:
                    ui.ntp_sync   = False
                    next_ntp_sync = ds.rtc + 321 # Just a bit more than five minutes
                    print("NTP sync failed at  {}".format(ui.now_tm))
            else:
                gc.collect() # Don't waste time garbage collecting if we're also setting the clock

            if set_time > 0:
                tick_err = ticks_diff(ticks_ms(), set_at_ticks)
                if -100 < tick_err and tick_err < 100: # Allow a 100ms "buffer"
                    ds.rtc = set_time
                    ui.ntp_sync   = True
                    print("Set DS RTC {} ({}) @ {}".format(set_time, ds.rtc_tm, ticks_ms()))
                    set_time = 0
                elif tick_err > 100: # Missed - try again on the next second
                    set_time += 1
                    set_at_ticks = ticks_add(set_at_ticks, 1000)
                    print("Missed the ticks - trying again @ {}".format(set_at_ticks))
                else:
                    print("Tick error {}".format(tick_err))

    except KeyboardInterrupt:
        # Try to relinquish the I2C bus
        print("Hands left at : {}".format(ds.alarm1_tm))
        i2c.deinit()
        ui.tft.deinit()